Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP Basic auth encoding (again) #112

Open
mkofahl opened this issue Aug 8, 2018 · 1 comment
Open

HTTP Basic auth encoding (again) #112

mkofahl opened this issue Aug 8, 2018 · 1 comment
Assignees

Comments

@mkofahl
Copy link

mkofahl commented Aug 8, 2018

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.

@bradmac
Copy link
Contributor

bradmac commented Aug 8, 2018

👍

@bradmac bradmac self-assigned this Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants