-
Notifications
You must be signed in to change notification settings - Fork 974
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
HTTPCLIENT-2353: Fix IDN hostname mismatch by normalizing host and identity with IDN #607
Conversation
4ef1ca2
to
83bdee3
Compare
@@ -228,8 +229,18 @@ private static boolean matchIdentity(final String host, final String identity, | |||
final PublicSuffixMatcher publicSuffixMatcher, | |||
final DomainType domainType, | |||
final boolean strict) { | |||
|
|||
final String punycodeHost; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Could we do it the other way around and convert identity from punycode to Unicode instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c you mean Instead of converting both strings to punycode, bring both into the same Unicode form—i.e., use IDN.toUnicode(...) rather than toASCII(...) ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c you mean Instead of converting both strings to punycode, bring both into the same Unicode form—i.e., use IDN.toUnicode(...) rather than toASCII(...) ???
@arturobernalg That is exactly what I mean. This way one would not need to normalize the hostname as it is has already been normalized to Unicode at the construction time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c changed. please take another look
078a60c
to
accc382
Compare
@@ -228,36 +229,44 @@ private static boolean matchIdentity(final String host, final String identity, | |||
final PublicSuffixMatcher publicSuffixMatcher, | |||
final DomainType domainType, | |||
final boolean strict) { | |||
|
|||
final String unicodeIdentity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unicodeIdentity
-> normalizedIdentity
would be a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@arturobernalg Please note we still have a problem with punycode encoded hostname resolution. We might address it in a separate PR though. |
2c31053
to
758ad8d
Compare
@ok2c I have fixed the test within this PR. |
final String normalizedHost; | ||
final String normalizedIdentity; | ||
try { | ||
normalizedHost = IDN.toUnicode(host); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg This is unnecessary. The hostname has already been normalized. Please see Host
and HttpHost
classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ok2c
you right. changed. Please do another pass
…th IDN.toUnicode before comparison so that Unicode and punycode forms match correctly.
6f20228
to
0f40601
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arturobernalg Looks good to me
@arturobernalg Please also cherry-pick this commit to |
@ok2c on it |
Cherry-picked to |
Normalize Unicode and punycode strings before comparing host and certificate identities. This approach ensures domains like поиск-слов.рф properly match their punycode equivalents.