Skip to content

HTTP Basic auth encoding (again) #112

@mkofahl

Description

@mkofahl

This issue is based on #19, which targets the character encoding used during http authentication.

I expect the following change to be useless, because enc is the codepage independent base64 string. No need to require any special character set.

byte[] bytes = Base64.decodeBase64(enc.getBytes(basicParserCharset));

The actual question is the character encoding of the base64 decoded byte sequence stored in bytes. When storing this byte sequence as String (UTF-16), the platform's default charset matters:

String s = new String(bytes);

I suggest implementing some simple encoding detection at this point and constructing the string platform independent similar to:

if(isUTF8(bytes)) {
    s = new String(bytes, Charset.forName("UTF-8"));
}
else {
    final String latin = new String(bytes, Charset.forName("ISO-8859-1"));
    final byte[] lbytes = latin.getBytes(Charset.forName("UTF-8"));
    s = new String(lbytes);
}

Actually, the list of expected charsets should be configurable.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions