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());
}
}
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) {
}
}
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();
}
}
Aggregations