pnowojski commented on a change in pull request #6355: 
[FLINK-9878][network][ssl] add more low-level ssl options
URL: https://github.com/apache/flink/pull/6355#discussion_r210523907
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/net/SSLUtils.java
 ##########
 @@ -225,38 +229,65 @@ public static SSLContext 
createSSLClientContext(Configuration sslConfig) throws
        public static SSLContext createSSLServerContext(Configuration 
sslConfig) throws Exception {
 
                Preconditions.checkNotNull(sslConfig);
-               SSLContext serverSSLContext = null;
 
-               if (getSSLEnabled(sslConfig)) {
-                       LOG.debug("Creating server SSL context from 
configuration");
+               if (!getSSLEnabled(sslConfig)) {
+                       return null;
+               }
 
-                       String keystoreFilePath = 
sslConfig.getString(SecurityOptions.SSL_KEYSTORE);
+               LOG.debug("Creating server SSL context from configuration");
 
-                       String keystorePassword = 
sslConfig.getString(SecurityOptions.SSL_KEYSTORE_PASSWORD);
+               String keystoreFilePath = 
sslConfig.getString(SecurityOptions.SSL_KEYSTORE);
+               String keystorePassword = 
sslConfig.getString(SecurityOptions.SSL_KEYSTORE_PASSWORD);
+               String certPassword = 
sslConfig.getString(SecurityOptions.SSL_KEY_PASSWORD);
+               String sslProtocolVersion = 
sslConfig.getString(SecurityOptions.SSL_PROTOCOL);
+               int sessionCacheSize = 
sslConfig.getInteger(SecurityOptions.SSL_SESSION_CACHE_SIZE);
+               int sessionTimeoutMs = 
sslConfig.getInteger(SecurityOptions.SSL_SESSION_TIMEOUT);
+               int handshakeTimeoutMs = 
sslConfig.getInteger(SecurityOptions.SSL_HANDSHAKE_TIMEOUT);
+               int closeNotifyFlushTimeoutMs = 
sslConfig.getInteger(SecurityOptions.SSL_CLOSE_NOTIFY_FLUSH_TIMEOUT);
 
-                       String certPassword = 
sslConfig.getString(SecurityOptions.SSL_KEY_PASSWORD);
+               Preconditions.checkNotNull(keystoreFilePath, 
SecurityOptions.SSL_KEYSTORE.key() + " was not configured.");
+               Preconditions.checkNotNull(keystorePassword, 
SecurityOptions.SSL_KEYSTORE_PASSWORD.key() + " was not configured.");
+               Preconditions.checkNotNull(certPassword, 
SecurityOptions.SSL_KEY_PASSWORD.key() + " was not configured.");
 
-                       String sslProtocolVersion = 
sslConfig.getString(SecurityOptions.SSL_PROTOCOL);
+               KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+               try (FileInputStream keyStoreFile = new FileInputStream(new 
File(keystoreFilePath))) {
+                       ks.load(keyStoreFile, keystorePassword.toCharArray());
+               }
 
-                       Preconditions.checkNotNull(keystoreFilePath, 
SecurityOptions.SSL_KEYSTORE.key() + " was not configured.");
-                       Preconditions.checkNotNull(keystorePassword, 
SecurityOptions.SSL_KEYSTORE_PASSWORD.key() + " was not configured.");
-                       Preconditions.checkNotNull(certPassword, 
SecurityOptions.SSL_KEY_PASSWORD.key() + " was not configured.");
+               // Set up key manager factory to use the server key store
+               KeyManagerFactory kmf = KeyManagerFactory.getInstance(
+                       KeyManagerFactory.getDefaultAlgorithm());
+               kmf.init(ks, certPassword.toCharArray());
 
-                       KeyStore ks = 
KeyStore.getInstance(KeyStore.getDefaultType());
-                       try (FileInputStream keyStoreFile = new 
FileInputStream(new File(keystoreFilePath))) {
-                               ks.load(keyStoreFile, 
keystorePassword.toCharArray());
-                       }
+               // Initialize the SSLContext
+               javax.net.ssl.SSLContext serverSSLContext = 
javax.net.ssl.SSLContext.getInstance(sslProtocolVersion);
+               serverSSLContext.init(kmf.getKeyManagers(), null, null);
+               if (sessionCacheSize >= 0) {
+                       
serverSSLContext.getServerSessionContext().setSessionCacheSize(sessionCacheSize);
+               }
+               if (sessionTimeoutMs >= 0) {
+                       
serverSSLContext.getServerSessionContext().setSessionTimeout(sessionTimeoutMs / 
1000);
+               }
 
-                       // Set up key manager factory to use the server key 
store
-                       KeyManagerFactory kmf = KeyManagerFactory.getInstance(
-                                       
KeyManagerFactory.getDefaultAlgorithm());
-                       kmf.init(ks, certPassword.toCharArray());
+               return new SSLContext(serverSSLContext, handshakeTimeoutMs, 
closeNotifyFlushTimeoutMs);
+       }
 
-                       // Initialize the SSLContext
-                       serverSSLContext = 
SSLContext.getInstance(sslProtocolVersion);
-                       serverSSLContext.init(kmf.getKeyManagers(), null, null);
+       /**
+        * Wrapper around javax.net.ssl.SSLContext, adding SSL handshake and 
close notify timeouts
+        * which cannot be set on the SSL context directly.
+        */
+       public static class SSLContext {
+               public final javax.net.ssl.SSLContext sslContext;
 
 Review comment:
   maybe make private and provide getters?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to