27
27
28
28
package org .apache .hc .client5 .http .ssl ;
29
29
30
- import java .net .IDN ;
31
30
import java .net .InetAddress ;
32
31
import java .net .UnknownHostException ;
33
32
import java .security .cert .Certificate ;
@@ -159,11 +158,11 @@ static void matchIPv6Address(final String host, final List<SubjectName> subjectA
159
158
160
159
static void matchDNSName (final String host , final List <SubjectName > subjectAlts ,
161
160
final PublicSuffixMatcher publicSuffixMatcher ) throws SSLPeerUnverifiedException {
162
- final String normalizedHost = DnsUtils .normalize (host );
161
+ final String normalizedHost = DnsUtils .normalizeUnicode (host );
163
162
for (final SubjectName subjectAlt : subjectAlts ) {
164
163
if (subjectAlt .getType () == SubjectName .DNS ) {
165
- final String normalizedSubjectAlt = DnsUtils .normalize (subjectAlt .getValue ());
166
- if (matchIdentityStrict (normalizedHost , normalizedSubjectAlt , publicSuffixMatcher )) {
164
+ final String normalizedSubjectAlt = DnsUtils .normalizeUnicode (subjectAlt .getValue ());
165
+ if (matchIdentity (normalizedHost , normalizedSubjectAlt , publicSuffixMatcher , true )) {
167
166
return ;
168
167
}
169
168
}
@@ -180,9 +179,9 @@ static void matchCN(final String host, final X509Certificate cert,
180
179
throw new SSLPeerUnverifiedException ("Certificate subject for <" + host + "> doesn't contain " +
181
180
"a common name and does not have alternative names" );
182
181
}
183
- final String normalizedHost = DnsUtils .normalize (host );
184
- final String normalizedCn = DnsUtils .normalize (cn );
185
- if (!matchIdentityStrict (normalizedHost , normalizedCn , publicSuffixMatcher )) {
182
+ final String normalizedHost = DnsUtils .normalizeUnicode (host );
183
+ final String normalizedCn = DnsUtils .normalizeUnicode (cn );
184
+ if (!matchIdentity (normalizedHost , normalizedCn , publicSuffixMatcher , true )) {
186
185
throw new SSLPeerUnverifiedException ("Certificate for <" + host + "> doesn't match " +
187
186
"common name of the certificate subject: " + cn );
188
187
}
@@ -224,21 +223,11 @@ static boolean matchDomainRoot(final String host, final String domainRoot) {
224
223
return false ;
225
224
}
226
225
227
- private static boolean matchIdentity (final String host , final String identity ,
226
+ static boolean matchIdentity (final String host , final String identity ,
228
227
final PublicSuffixMatcher publicSuffixMatcher ,
229
228
final boolean strict ) {
230
-
231
- final String normalizedIdentity ;
232
- try {
233
- // Convert only the identity to its Unicode form
234
- normalizedIdentity = IDN .toUnicode (identity );
235
- } catch (final IllegalArgumentException e ) {
236
- return false ;
237
- }
238
-
239
- // Public suffix check on the Unicode identity
240
229
if (publicSuffixMatcher != null && host .contains ("." )) {
241
- if (!publicSuffixMatcher .verifyStrict ( normalizedIdentity )) {
230
+ if (!publicSuffixMatcher .verifyInternal ( identity )) {
242
231
if (LOG .isDebugEnabled ()) {
243
232
LOG .debug ("Public Suffix List verification failed for identity '{}'" , identity );
244
233
}
@@ -251,10 +240,10 @@ private static boolean matchIdentity(final String host, final String identity,
251
240
// character * which is considered to match any single domain name
252
241
// component or component fragment..."
253
242
// Based on this statement presuming only singular wildcard is legal
254
- final int asteriskIdx = normalizedIdentity .indexOf ('*' );
243
+ final int asteriskIdx = identity .indexOf ('*' );
255
244
if (asteriskIdx != -1 ) {
256
- final String prefix = normalizedIdentity .substring (0 , asteriskIdx );
257
- final String suffix = normalizedIdentity .substring (asteriskIdx + 1 );
245
+ final String prefix = identity .substring (0 , asteriskIdx );
246
+ final String suffix = identity .substring (asteriskIdx + 1 );
258
247
259
248
if (!prefix .isEmpty () && !host .startsWith (prefix )) {
260
249
return false ;
@@ -274,25 +263,7 @@ private static boolean matchIdentity(final String host, final String identity,
274
263
}
275
264
276
265
// Direct Unicode comparison
277
- return host .equalsIgnoreCase (normalizedIdentity );
278
- }
279
-
280
- static boolean matchIdentity (final String host , final String identity ,
281
- final PublicSuffixMatcher publicSuffixMatcher ) {
282
- return matchIdentity (host , identity , publicSuffixMatcher , false );
283
- }
284
-
285
- static boolean matchIdentity (final String host , final String identity ) {
286
- return matchIdentity (host , identity , null , false );
287
- }
288
-
289
- static boolean matchIdentityStrict (final String host , final String identity ,
290
- final PublicSuffixMatcher publicSuffixMatcher ) {
291
- return matchIdentity (host , identity , publicSuffixMatcher , true );
292
- }
293
-
294
- static boolean matchIdentityStrict (final String host , final String identity ) {
295
- return matchIdentity (host , identity , null , true );
266
+ return host .equalsIgnoreCase (identity );
296
267
}
297
268
298
269
static String extractCN (final String subjectPrincipal ) throws SSLException {
0 commit comments