Search in sources :

Example 1 with KeyManagerFactorySpi

use of javax.net.ssl.KeyManagerFactorySpi in project robovm by robovm.

the class KeyManagerFactorySpiTest method test_Constructor.

/**
     * javax.net.ssl.KeyManagerFactorySpi#KeyManagerFactorySpi()
     */
public void test_Constructor() {
    try {
        KeyManagerFactorySpiImpl kmf = new KeyManagerFactorySpiImpl();
        assertTrue(kmf instanceof KeyManagerFactorySpi);
    } catch (Exception e) {
        fail("Unexpected Exception " + e.toString());
    }
}
Also used : KeyManagerFactorySpiImpl(org.apache.harmony.xnet.tests.support.KeyManagerFactorySpiImpl) KeyManagerFactorySpi(javax.net.ssl.KeyManagerFactorySpi) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException)

Example 2 with KeyManagerFactorySpi

use of javax.net.ssl.KeyManagerFactorySpi in project robovm by robovm.

the class ProtectionParameterImpl method test_Constructor.

/**
     * Test for <code>KeyManagerFactory</code> constructor
     * Assertion: returns KeyManagerFactory object
     */
public void test_Constructor() throws NoSuchAlgorithmException {
    if (!DEFSupported) {
        fail(NotSupportedMsg);
        return;
    }
    KeyManagerFactorySpi spi = new MyKeyManagerFactorySpi();
    KeyManagerFactory keyMF = new myKeyManagerFactory(spi, defaultProvider, defaultAlgorithm);
    assertEquals("Incorrect algorithm", keyMF.getAlgorithm(), defaultAlgorithm);
    assertEquals("Incorrect provider", keyMF.getProvider(), defaultProvider);
    try {
        keyMF.init(null, new char[1]);
        fail("UnrecoverableKeyException must be thrown");
    } catch (UnrecoverableKeyException e) {
    } catch (Exception e) {
        fail("Unexpected: " + e.toString() + " was thrown");
    }
    keyMF = new myKeyManagerFactory(null, null, null);
    assertNull("Aalgorithm must be null", keyMF.getAlgorithm());
    assertNull("Provider must be null", keyMF.getProvider());
    try {
        keyMF.getKeyManagers();
    } catch (NullPointerException e) {
    }
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyManagerFactorySpi(javax.net.ssl.KeyManagerFactorySpi) MyKeyManagerFactorySpi(org.apache.harmony.xnet.tests.support.MyKeyManagerFactorySpi) MyKeyManagerFactorySpi(org.apache.harmony.xnet.tests.support.MyKeyManagerFactorySpi) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchProviderException(java.security.NoSuchProviderException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 3 with KeyManagerFactorySpi

use of javax.net.ssl.KeyManagerFactorySpi in project netty by netty.

the class SSLEngineTest method testSupportedSignatureAlgorithms.

@MethodSource("newTestParams")
@ParameterizedTest
public void testSupportedSignatureAlgorithms(SSLEngineTestParam param) throws Exception {
    final SelfSignedCertificate ssc = new SelfSignedCertificate();
    final class TestKeyManagerFactory extends KeyManagerFactory {

        TestKeyManagerFactory(final KeyManagerFactory factory) {
            super(new KeyManagerFactorySpi() {

                private final KeyManager[] managers = factory.getKeyManagers();

                @Override
                protected void engineInit(KeyStore keyStore, char[] chars) {
                    throw new UnsupportedOperationException();
                }

                @Override
                protected void engineInit(ManagerFactoryParameters managerFactoryParameters) {
                    throw new UnsupportedOperationException();
                }

                @Override
                protected KeyManager[] engineGetKeyManagers() {
                    KeyManager[] array = new KeyManager[managers.length];
                    for (int i = 0; i < array.length; i++) {
                        final X509ExtendedKeyManager x509ExtendedKeyManager = (X509ExtendedKeyManager) managers[i];
                        array[i] = new X509ExtendedKeyManager() {

                            @Override
                            public String[] getClientAliases(String s, Principal[] principals) {
                                fail();
                                return null;
                            }

                            @Override
                            public String chooseClientAlias(String[] strings, Principal[] principals, Socket socket) {
                                fail();
                                return null;
                            }

                            @Override
                            public String[] getServerAliases(String s, Principal[] principals) {
                                fail();
                                return null;
                            }

                            @Override
                            public String chooseServerAlias(String s, Principal[] principals, Socket socket) {
                                fail();
                                return null;
                            }

                            @Override
                            public String chooseEngineClientAlias(String[] strings, Principal[] principals, SSLEngine sslEngine) {
                                assertNotEquals(0, ((ExtendedSSLSession) sslEngine.getHandshakeSession()).getPeerSupportedSignatureAlgorithms().length);
                                assertNotEquals(0, ((ExtendedSSLSession) sslEngine.getHandshakeSession()).getLocalSupportedSignatureAlgorithms().length);
                                return x509ExtendedKeyManager.chooseEngineClientAlias(strings, principals, sslEngine);
                            }

                            @Override
                            public String chooseEngineServerAlias(String s, Principal[] principals, SSLEngine sslEngine) {
                                assertNotEquals(0, ((ExtendedSSLSession) sslEngine.getHandshakeSession()).getPeerSupportedSignatureAlgorithms().length);
                                assertNotEquals(0, ((ExtendedSSLSession) sslEngine.getHandshakeSession()).getLocalSupportedSignatureAlgorithms().length);
                                return x509ExtendedKeyManager.chooseEngineServerAlias(s, principals, sslEngine);
                            }

                            @Override
                            public java.security.cert.X509Certificate[] getCertificateChain(String s) {
                                return x509ExtendedKeyManager.getCertificateChain(s);
                            }

                            @Override
                            public PrivateKey getPrivateKey(String s) {
                                return x509ExtendedKeyManager.getPrivateKey(s);
                            }
                        };
                    }
                    return array;
                }
            }, factory.getProvider(), factory.getAlgorithm());
        }
    }
    clientSslCtx = wrapContext(param, SslContextBuilder.forClient().keyManager(new TestKeyManagerFactory(newKeyManagerFactory(ssc))).trustManager(InsecureTrustManagerFactory.INSTANCE).sslProvider(sslClientProvider()).sslContextProvider(clientSslContextProvider()).protocols(param.protocols()).ciphers(param.ciphers()).build());
    serverSslCtx = wrapContext(param, SslContextBuilder.forServer(new TestKeyManagerFactory(newKeyManagerFactory(ssc))).trustManager(InsecureTrustManagerFactory.INSTANCE).sslContextProvider(serverSslContextProvider()).sslProvider(sslServerProvider()).protocols(param.protocols()).ciphers(param.ciphers()).clientAuth(ClientAuth.REQUIRE).build());
    SSLEngine clientEngine = null;
    SSLEngine serverEngine = null;
    try {
        clientEngine = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
        serverEngine = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
        handshake(param.type(), param.delegate(), clientEngine, serverEngine);
    } finally {
        cleanupClientSslEngine(clientEngine);
        cleanupServerSslEngine(serverEngine);
        ssc.delete();
    }
}
Also used : SelfSignedCertificate(io.netty.handler.ssl.util.SelfSignedCertificate) PrivateKey(java.security.PrivateKey) SSLEngine(javax.net.ssl.SSLEngine) KeyManagerFactorySpi(javax.net.ssl.KeyManagerFactorySpi) X509ExtendedKeyManager(javax.net.ssl.X509ExtendedKeyManager) KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) KeyManager(javax.net.ssl.KeyManager) X509ExtendedKeyManager(javax.net.ssl.X509ExtendedKeyManager) ManagerFactoryParameters(javax.net.ssl.ManagerFactoryParameters) Principal(java.security.Principal) Socket(java.net.Socket) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

KeyManagerFactorySpi (javax.net.ssl.KeyManagerFactorySpi)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)2 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)1 IOException (java.io.IOException)1 Socket (java.net.Socket)1 KeyStore (java.security.KeyStore)1 NoSuchProviderException (java.security.NoSuchProviderException)1 Principal (java.security.Principal)1 PrivateKey (java.security.PrivateKey)1 CertificateException (java.security.cert.CertificateException)1 KeyManager (javax.net.ssl.KeyManager)1 ManagerFactoryParameters (javax.net.ssl.ManagerFactoryParameters)1 SSLEngine (javax.net.ssl.SSLEngine)1 X509ExtendedKeyManager (javax.net.ssl.X509ExtendedKeyManager)1 KeyManagerFactorySpiImpl (org.apache.harmony.xnet.tests.support.KeyManagerFactorySpiImpl)1 MyKeyManagerFactorySpi (org.apache.harmony.xnet.tests.support.MyKeyManagerFactorySpi)1