@@ -60,36 +60,6 @@ class ConfigSSLContextBuilderSpec extends Specification {
6060 }
6161 }
6262
63- " build a key manager" in {
64- val info = SSLConfigSettings ()
65- val keyManagerFactory = mockKeyManagerFactory
66- val trustManagerFactory = mockTrustManagerFactory
67-
68- val builder = new ConfigSSLContextBuilder (mkLogger, info, keyManagerFactory, trustManagerFactory)
69-
70- val keyStore = KeyStore .getInstance(" PKCS12" )
71- val keyPairGenerator = KeyPairGenerator .getInstance(" RSA" )
72- keyPairGenerator.initialize(2048 ) // 2048 is the NIST acceptable key length until 2030
73- val keyPair = keyPairGenerator.generateKeyPair()
74- val cert = FakeKeyStore .createSelfSignedCertificate(keyPair)
75- val password = " changeit" // cannot have a null password for PKCS12 in 1.6
76- keyStore.load(null , password.toCharArray)
77- keyStore.setKeyEntry(" playgenerated" , keyPair.getPrivate, password.toCharArray, Array (cert))
78-
79- val tempFile = java.io.File .createTempFile(" privatekeystore" , " .p12" )
80- val out = java.nio.file.Files .newOutputStream(tempFile.toPath)
81- try {
82- keyStore.store(out, password.toCharArray)
83- } finally {
84- out.close()
85- }
86- val filePath = tempFile.getAbsolutePath
87- val keyStoreConfig = KeyStoreConfig (None , Some (filePath)).withStoreType(" PKCS12" ).withPassword(Some (password))
88-
89- val actual = builder.buildKeyManager(keyStoreConfig, SSLDebugConfig ())
90- actual must beAnInstanceOf[X509KeyManager ]
91- }
92-
9363 " build a trust manager" in {
9464 val info = SSLConfigSettings ()
9565 val keyManagerFactory = mockKeyManagerFactory
@@ -132,29 +102,6 @@ class ConfigSSLContextBuilderSpec extends Specification {
132102 actual must beAnInstanceOf[CompositeX509TrustManager ]
133103 }
134104
135- " build a composite trust manager with data" in {
136- val info = SSLConfigSettings ()
137- val keyManagerFactory = new DefaultKeyManagerFactoryWrapper (KeyManagerFactory .getDefaultAlgorithm)
138- val trustManagerFactory = new DefaultTrustManagerFactoryWrapper (TrustManagerFactory .getDefaultAlgorithm)
139- val builder = new ConfigSSLContextBuilder (mkLogger, info, keyManagerFactory, trustManagerFactory)
140-
141- val certificate = CertificateGenerator .generateRSAWithSHA256()
142- val certificateData = CertificateGenerator .toPEM(certificate)
143-
144- val trustStoreConfig = TrustStoreConfig (Some (certificateData), None ).withStoreType(" PEM" )
145- val trustManagerConfig = TrustManagerConfig ().withTrustStoreConfigs(List (trustStoreConfig))
146-
147- val checkRevocation = false
148- val revocationLists = None
149-
150- val actual =
151- builder.buildCompositeTrustManager(trustManagerConfig, checkRevocation, revocationLists, SSLDebugConfig ())
152-
153- actual must beAnInstanceOf[CompositeX509TrustManager ]
154- val issuers = actual.getAcceptedIssuers
155- issuers.size must beEqualTo(1 )
156- }
157-
158105 " build a file based keystore builder" in {
159106 val info = SSLConfigSettings ()
160107 val keyManagerFactory = mock(classOf [KeyManagerFactoryWrapper ])
@@ -193,63 +140,6 @@ class ConfigSSLContextBuilderSpec extends Specification {
193140 val actual = builder.stringBuilder(data)
194141 actual must beAnInstanceOf[StringBasedKeyStoreBuilder ]
195142 }
196-
197- " validate success of the keystore with a private key" in {
198- val keyStore = KeyStore .getInstance(" PKCS12" )
199-
200- // Generate the key pair
201- val keyPairGenerator = KeyPairGenerator .getInstance(" RSA" )
202- keyPairGenerator.initialize(2048 ) // 2048 is the NIST acceptable key length until 2030
203- val keyPair = keyPairGenerator.generateKeyPair()
204-
205- // Generate a self signed certificate
206- val cert = FakeKeyStore .createSelfSignedCertificate(keyPair)
207-
208- val password = " changeit" // null passwords throw exception in 1.6
209- keyStore.load(null , password.toCharArray)
210- keyStore.setKeyEntry(" playgenerated" , keyPair.getPrivate, password.toCharArray, Array (cert))
211-
212- val keyManagerFactory = mock(classOf [KeyManagerFactoryWrapper ])
213- val trustManagerFactory = mock(classOf [TrustManagerFactoryWrapper ])
214-
215- val ksc = KeyStoreConfig (None , Some (" path" )).withPassword(Some (password))
216- val keyManagerConfig = KeyManagerConfig ().withKeyStoreConfigs(List (ksc))
217-
218- val info = SSLConfigSettings ().withKeyManagerConfig(keyManagerConfig)
219- val builder = new ConfigSSLContextBuilder (mkLogger, info, keyManagerFactory, trustManagerFactory)
220- builder.validateStoreContainsPrivateKeys(ksc, keyStore) must beTrue
221- }
222-
223- " validate a failure of the keystore without a private key" in {
224- // must be JKS, PKCS12 does not support trusted certificate entries in 1.6 at least
225- // KeyStoreException: : TrustedCertEntry not supported (PKCS12KeyStore.java:620)
226- // val keyStore = KeyStore.getInstance("PKCS12")
227- val keyStore = KeyStore .getInstance(KeyStore .getDefaultType)
228-
229- // Generate the key pair
230- val keyPairGenerator = KeyPairGenerator .getInstance(" RSA" )
231- keyPairGenerator.initialize(2048 ) // 2048 is the NIST acceptable key length until 2030
232- val keyPair = keyPairGenerator.generateKeyPair()
233-
234- // Generate a self signed certificate
235- val cert = FakeKeyStore .createSelfSignedCertificate(keyPair)
236-
237- val password = " changeit" // null passwords throw exception in 1.6 in PKCS12
238- keyStore.load(null , password.toCharArray)
239- // Don't add the private key here, instead add a public cert only.
240- keyStore.setCertificateEntry(" playgeneratedtrusted" , cert)
241-
242- val keyManagerFactory = mock(classOf [KeyManagerFactoryWrapper ])
243- val trustManagerFactory = mock(classOf [TrustManagerFactoryWrapper ])
244-
245- val ksc = KeyStoreConfig (None , Some (" path" )).withPassword(Some (password))
246- val keyManagerConfig = KeyManagerConfig ().withKeyStoreConfigs(List (ksc))
247-
248- val info = SSLConfigSettings ().withKeyManagerConfig(keyManagerConfig)
249- val builder = new ConfigSSLContextBuilder (mkLogger, info, keyManagerFactory, trustManagerFactory)
250-
251- builder.validateStoreContainsPrivateKeys(ksc, keyStore) must beFalse
252- }
253143 }
254144
255145 private def mockTrustManagerFactory = {
0 commit comments