|
68 | 68 | import javax.net.ssl.TrustManagerFactory; |
69 | 69 | import lombok.extern.slf4j.Slf4j; |
70 | 70 | import org.apache.commons.lang3.StringUtils; |
71 | | -import org.apache.pulsar.common.classification.InterfaceAudience; |
72 | 71 | import org.apache.pulsar.common.tls.TlsHostnameVerifier; |
73 | 72 |
|
74 | 73 | /** |
@@ -161,10 +160,11 @@ private static Provider loadConscryptProvider() { |
161 | 160 | // |
162 | 161 | // more details of Conscrypt's hostname verification: |
163 | 162 | // https://github.com/google/conscrypt/blob/master/IMPLEMENTATION_NOTES.md#hostname-verification |
164 | | - // there's a bug in Conscrypt while setting a custom HostnameVerifier, |
165 | | - // https://github.com/google/conscrypt/issues/1015 and therefore this solution alone |
166 | | - // isn't sufficient to configure Conscrypt's hostname verifier. The method processConscryptTrustManager |
167 | | - // contains the workaround. |
| 163 | + // |
| 164 | + // Setting the default is sufficient on its own since Conscrypt 2.6.0: TrustManagerImpl used to ignore |
| 165 | + // the default verifier (https://github.com/google/conscrypt/issues/1015), which forced Pulsar to copy it |
| 166 | + // onto every TrustManager instance, but https://github.com/google/conscrypt/pull/1060 made it fall back |
| 167 | + // to the default, so that workaround has been removed. |
168 | 168 | try { |
169 | 169 | HostnameVerifier hostnameVerifier = new TlsHostnameVerifier(); |
170 | 170 | Object wrappedHostnameVerifier = conscryptClazz |
@@ -396,54 +396,10 @@ private static TrustManager[] setupTrustCerts(KeyStoreHolder ksh, boolean allowI |
396 | 396 | } |
397 | 397 |
|
398 | 398 | trustManagers = tmf.getTrustManagers(); |
399 | | - |
400 | | - for (TrustManager trustManager : trustManagers) { |
401 | | - processConscryptTrustManager(trustManager); |
402 | | - } |
403 | 399 | } |
404 | 400 | return trustManagers; |
405 | 401 | } |
406 | 402 |
|
407 | | - /*** |
408 | | - * Conscrypt TrustManager instances will be configured to use the Pulsar {@link TlsHostnameVerifier} |
409 | | - * class. |
410 | | - * This method is used as a workaround for https://github.com/google/conscrypt/issues/1015 |
411 | | - * when Conscrypt / OpenSSL is used as the TLS security provider. |
412 | | - * |
413 | | - * @param trustManagers the array of TrustManager instances to process. |
414 | | - * @return same instance passed as parameter |
415 | | - */ |
416 | | - @InterfaceAudience.Private |
417 | | - public static TrustManager[] processConscryptTrustManagers(TrustManager[] trustManagers) { |
418 | | - for (TrustManager trustManager : trustManagers) { |
419 | | - processConscryptTrustManager(trustManager); |
420 | | - } |
421 | | - return trustManagers; |
422 | | - } |
423 | | - |
424 | | - // workaround https://github.com/google/conscrypt/issues/1015 |
425 | | - private static void processConscryptTrustManager(TrustManager trustManager) { |
426 | | - if (trustManager.getClass().getName().equals("org.conscrypt.TrustManagerImpl")) { |
427 | | - try { |
428 | | - Class<?> conscryptClazz = Class.forName("org.conscrypt.Conscrypt"); |
429 | | - Object hostnameVerifier = conscryptClazz.getMethod("getHostnameVerifier", |
430 | | - new Class[]{TrustManager.class}).invoke(null, trustManager); |
431 | | - if (hostnameVerifier == null) { |
432 | | - Object defaultHostnameVerifier = conscryptClazz.getMethod("getDefaultHostnameVerifier", |
433 | | - new Class[]{TrustManager.class}).invoke(null, trustManager); |
434 | | - if (defaultHostnameVerifier != null) { |
435 | | - conscryptClazz.getMethod("setHostnameVerifier", new Class[]{ |
436 | | - TrustManager.class, |
437 | | - Class.forName("org.conscrypt.ConscryptHostnameVerifier") |
438 | | - }).invoke(null, trustManager, defaultHostnameVerifier); |
439 | | - } |
440 | | - } |
441 | | - } catch (ReflectiveOperationException e) { |
442 | | - log.warn("Unable to set hostname verifier for Conscrypt TrustManager implementation", e); |
443 | | - } |
444 | | - } |
445 | | - } |
446 | | - |
447 | 403 | public static X509Certificate[] loadCertificatesFromPemFile(String certFilePath) throws KeyManagementException { |
448 | 404 | X509Certificate[] certificates = null; |
449 | 405 |
|
|