Skip to content

Commit b359c3f

Browse files
committed
[refactor] re-org SSL engine init (so that BC engine boots as well)
1 parent b15706e commit b359c3f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/main/java/org/jruby/ext/openssl/SSLContext.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ private class InternalContext {
867867
final List<X509AuxCertificate> clientCert,
868868
final List<X509AuxCertificate> extraChainCert,
869869
final int verifyMode,
870-
final int timeout) throws NoSuchAlgorithmException, KeyManagementException {
870+
final int timeout) throws NoSuchAlgorithmException {
871871

872872
if ( pKey != null && xCert != null ) {
873873
this.privateKey = pKey.getPrivateKey();
@@ -884,12 +884,26 @@ private class InternalContext {
884884
this.clientCert = clientCert;
885885
this.extraChainCert = extraChainCert;
886886
this.verifyMode = verifyMode;
887-
//this.timeout = timeout;
887+
this.timeout = timeout;
888888

889889
// initialize SSL context :
890890

891891
final javax.net.ssl.SSLContext sslContext = SecurityHelper.getSSLContext(protocol);
892892

893+
this.sslContext = sslContext;
894+
}
895+
896+
void initSSLContext(final ThreadContext context) throws KeyManagementException {
897+
final KeyManager[] keyManager = new KeyManager[] { new KeyManagerImpl(this) };
898+
final TrustManager[] trustManager = new TrustManager[] { new TrustManagerImpl(this) };
899+
// SSLContext (internals) on Sun JDK :
900+
// private final java.security.Provider provider; "SunJSSE"
901+
// private final javax.net.ssl.SSLContextSpi; sun.security.ssl.SSLContextImpl
902+
sslContext.init(keyManager, trustManager, OpenSSL.getSecureRandomFrom(context));
903+
// if secureRandom == null JSSE will try :
904+
// - new SecureRandom();
905+
// - SecureRandom.getInstance("PKCS11", cryptoProvider);
906+
893907
if ( protocolForClient ) {
894908
final SSLSessionContext clientContext = sslContext.getClientSessionContext();
895909
clientContext.setSessionTimeout(timeout);
@@ -898,25 +912,12 @@ private class InternalContext {
898912
}
899913
}
900914
if ( protocolForServer ) {
901-
final SSLSessionContext serverContext = sslContext.getClientSessionContext();
915+
final SSLSessionContext serverContext = sslContext.getServerSessionContext();
902916
serverContext.setSessionTimeout(timeout);
903917
if ( sessionCacheSize >= 0 ) {
904918
serverContext.setSessionCacheSize(sessionCacheSize);
905919
}
906920
}
907-
this.sslContext = sslContext;
908-
}
909-
910-
protected void initSSLContext(final ThreadContext context) throws KeyManagementException {
911-
final KeyManager[] keyManager = new KeyManager[] { new KeyManagerImpl(this) };
912-
final TrustManager[] trustManager = new TrustManager[] { new TrustManagerImpl(this) };
913-
// SSLContext (internals) on Sun JDK :
914-
// private final java.security.Provider provider; "SunJSSE"
915-
// private final javax.net.ssl.SSLContextSpi; sun.security.ssl.SSLContextImpl
916-
sslContext.init(keyManager, trustManager, OpenSSL.getSecureRandomFrom(context));
917-
// if secureRandom == null JSSE will try :
918-
// - new SecureRandom();
919-
// - SecureRandom.getInstance("PKCS11", cryptoProvider);
920921
}
921922

922923
final Store store;
@@ -929,7 +930,7 @@ protected void initSSLContext(final ThreadContext context) throws KeyManagementE
929930
final List<X509AuxCertificate> clientCert; // assumed always != null
930931
final List<X509AuxCertificate> extraChainCert; // empty assumed == null
931932

932-
//final int timeout;
933+
private final int timeout;
933934

934935
private final javax.net.ssl.SSLContext sslContext;
935936

0 commit comments

Comments
 (0)