@@ -446,9 +446,7 @@ public IRubyObject setup(final ThreadContext context) {
446
446
*/
447
447
448
448
try {
449
- internalContext = new InternalContext (
450
- cert , key , store , clientCert , extraChainCert , verifyMode , timeout
451
- );
449
+ internalContext = createInternalContext (context , cert , key , store , clientCert , extraChainCert , verifyMode , timeout );
452
450
}
453
451
catch (GeneralSecurityException e ) {
454
452
throw newSSLError (runtime , e );
@@ -821,6 +819,15 @@ static RubyClass _SSLContext(final Ruby runtime) {
821
819
return (RubyClass ) _SSL (runtime ).getConstantAt ("SSLContext" );
822
820
}
823
821
822
+ private InternalContext createInternalContext (ThreadContext context ,
823
+ final X509Cert xCert , final PKey pKey , final Store store ,
824
+ final List <X509AuxCertificate > clientCert , final List <X509AuxCertificate > extraChainCert ,
825
+ final int verifyMode , final int timeout ) throws NoSuchAlgorithmException , KeyManagementException {
826
+ InternalContext internalContext = new InternalContext (xCert , pKey , store , clientCert , extraChainCert , verifyMode , timeout );
827
+ internalContext .initSSLContext (context );
828
+ return internalContext ;
829
+ }
830
+
824
831
/**
825
832
* c: SSL_CTX
826
833
*/
@@ -870,17 +877,19 @@ private class InternalContext {
870
877
serverContext .setSessionCacheSize (sessionCacheSize );
871
878
}
872
879
}
873
- this .sslContext = initContext ( sslContext ) ;
880
+ this .sslContext = sslContext ;
874
881
}
875
882
876
- protected javax . net . ssl . SSLContext initContext ( javax . net . ssl . SSLContext sslContext ) throws KeyManagementException {
883
+ protected void initSSLContext ( final ThreadContext context ) throws KeyManagementException {
877
884
final KeyManager [] keyManager = new KeyManager [] { new KeyManagerImpl (this ) };
878
885
final TrustManager [] trustManager = new TrustManager [] { new TrustManagerImpl (this ) };
879
- // SSLContext on Sun JDK :
886
+ // SSLContext (internals) on Sun JDK :
880
887
// private final java.security.Provider provider; "SunJSSE"
881
888
// private final javax.net.ssl.SSLContextSpi; sun.security.ssl.SSLContextImpl
882
- sslContext .init (keyManager , trustManager , null );
883
- return sslContext ;
889
+ sslContext .init (keyManager , trustManager , OpenSSL .getSecureRandomFrom (context ));
890
+ // if secureRandom == null JSSE will try :
891
+ // - new SecureRandom();
892
+ // - SecureRandom.getInstance("PKCS11", cryptoProvider);
884
893
}
885
894
886
895
final Store store ;
0 commit comments