nodece commented on a change in pull request #13740:
URL: https://github.com/apache/pulsar/pull/13740#discussion_r820469840



##########
File path: 
pulsar-common/src/main/java/org/apache/pulsar/common/util/SecurityUtility.java
##########
@@ -300,27 +310,65 @@ public static SslContext 
createNettySslContextForServer(boolean allowInsecureCon
     }
 
     public static SSLContext createSslContext(boolean allowInsecureConnection, 
Certificate[] trustCertficates,
-            Certificate[] certificates, PrivateKey privateKey) throws 
GeneralSecurityException {
+                                              Certificate[] certificates, 
PrivateKey privateKey)
+            throws GeneralSecurityException {
+        return createSslContext(allowInsecureConnection, trustCertficates, 
certificates, privateKey, null);
+    }
+
+    public static SSLContext createSslContext(boolean allowInsecureConnection, 
Certificate[] trustCertficates,
+                                              Certificate[] certificates, 
PrivateKey privateKey, String providerName)
+            throws GeneralSecurityException {
         KeyStoreHolder ksh = new KeyStoreHolder();
         TrustManager[] trustManagers = null;
         KeyManager[] keyManagers = null;
+        Provider provider = null;
+        if (providerName != null && !providerName.equals("")) {
+            if (providerName.equalsIgnoreCase(CONSCRYPT_PROVIDER_NAME)) {
+                provider = CONSCRYPT_PROVIDER;
+            } else {
+                provider = Security.getProvider(providerName);
+                if (provider == null) {
+                    log.warn("Cannot to get {} security provider, fallback to 
using JDK default security provider",
+                            providerName);
+                    provider = SSLContext.getDefault().getProvider();
+                }
+            }
+        }
 
-        trustManagers = setupTrustCerts(ksh, allowInsecureConnection, 
trustCertficates, CONSCRYPT_PROVIDER);
-        keyManagers = setupKeyManager(ksh, privateKey, certificates);
+        trustManagers = setupTrustCerts(ksh, allowInsecureConnection, 
trustCertficates, provider);
+        keyManagers = setupKeyManager(ksh, privateKey, certificates, provider);
 
-        SSLContext sslCtx = CONSCRYPT_PROVIDER != null ? 
SSLContext.getInstance("TLS", CONSCRYPT_PROVIDER)
+        SSLContext sslCtx = provider != null ? SSLContext.getInstance("TLS", 
provider)
                 : SSLContext.getInstance("TLS");
         sslCtx.init(keyManagers, trustManagers, new SecureRandom());
-        sslCtx.getDefaultSSLParameters();
         return sslCtx;
     }
 
-    private static KeyManager[] setupKeyManager(KeyStoreHolder ksh, PrivateKey 
privateKey, Certificate[] certificates)
+    private static KeyManager[] setupKeyManager(KeyStoreHolder ksh, PrivateKey 
privateKey, Certificate[] certificates,
+                                                Provider provider)
             throws KeyStoreException, NoSuchAlgorithmException, 
UnrecoverableKeyException {
         KeyManager[] keyManagers = null;
+        String algorithm = KeyManagerFactory.getDefaultAlgorithm();
+
         if (certificates != null && privateKey != null) {
             ksh.setPrivateKey("private", privateKey, certificates);
-            KeyManagerFactory kmf = 
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+            KeyManagerFactory kmf = null;
+
+            try {
+                kmf = provider != null ? 
KeyManagerFactory.getInstance(algorithm, provider) :
+                        KeyManagerFactory.getInstance(algorithm);
+            } catch (NoSuchAlgorithmException e) {
+                if (provider != null) {
+                    log.warn(
+                            "Unable to get KeyManagerFactory instance for 
algorithm [{}] on provider [{}], using JDK "
+                                    + "default",
+                            algorithm, provider.getName());
+                    kmf = KeyManagerFactory.getInstance(algorithm);
+                } else {
+                    throw e;
+                }
+            }
+

Review comment:
       Fixed.

##########
File path: 
pulsar-common/src/main/java/org/apache/pulsar/common/util/SecurityUtility.java
##########
@@ -348,9 +410,10 @@ public static SSLContext createSslContext(boolean 
allowInsecureConnection, Certi
             }
 
             trustManagers = tmf.getTrustManagers();
-
-            for (TrustManager trustManager : trustManagers) {
-                processConscryptTrustManager(trustManager);
+            if (securityProvider != null && 
securityProvider.getName().equalsIgnoreCase(CONSCRYPT_PROVIDER_NAME)) {

Review comment:
       Fixed.

##########
File path: 
pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/WebServer.java
##########
@@ -108,18 +107,24 @@ public WebServer(ProxyConfiguration config, 
AuthenticationService authentication
                             config.getTlsTrustStore(),
                             config.getTlsTrustStorePassword(),
                             config.isTlsRequireTrustedClientCertOnConnect(),
-                            config.getWebServiceTlsCiphers(),
-                            config.getWebServiceTlsProtocols(),
+                            config.getWebServiceTlsCiphers() != null ? 
config.getWebServiceTlsCiphers() :
+                                    config.getTlsCiphers(),
+                            config.getWebServiceTlsProtocols() != null ? 
config.getWebServiceTlsProtocols() :
+                                    config.getTlsCiphers(),
                             config.getTlsCertRefreshCheckDurationSec()
                     );
                 } else {
-                    sslCtxFactory = SecurityUtility.createSslContextFactory(
+                    sslCtxFactory = 
JettySslContextFactory.createServerSslContext(
+                            config.getTlsProvider(),
                             config.isTlsAllowInsecureConnection(),
                             config.getTlsTrustCertsFilePath(),
                             config.getTlsCertificateFilePath(),
                             config.getTlsKeyFilePath(),
                             config.isTlsRequireTrustedClientCertOnConnect(),
-                            true,
+                            config.getWebServiceTlsCiphers() != null ? 
config.getWebServiceTlsCiphers() :
+                                    config.getTlsCiphers(),
+                            config.getWebServiceTlsProtocols() != null ? 
config.getWebServiceTlsProtocols() :
+                                    config.getTlsCiphers(),

Review comment:
       Fixed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to