use of java.security.KeyManagementException in project robovm by robovm.
the class SSLParametersImpl method createDefaultKeyManager.
private static X509KeyManager createDefaultKeyManager() throws KeyManagementException {
try {
String algorithm = KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
kmf.init(null, null);
KeyManager[] kms = kmf.getKeyManagers();
return findX509KeyManager(kms);
} catch (NoSuchAlgorithmException e) {
throw new KeyManagementException(e);
} catch (KeyStoreException e) {
throw new KeyManagementException(e);
} catch (UnrecoverableKeyException e) {
throw new KeyManagementException(e);
}
}
use of java.security.KeyManagementException in project robovm by robovm.
the class SSLParametersImpl method createDefaultTrustManager.
private static X509TrustManager createDefaultTrustManager() throws KeyManagementException {
try {
String algorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
tmf.init((KeyStore) null);
TrustManager[] tms = tmf.getTrustManagers();
X509TrustManager trustManager = findX509TrustManager(tms);
return trustManager;
} catch (NoSuchAlgorithmException e) {
throw new KeyManagementException(e);
} catch (KeyStoreException e) {
throw new KeyManagementException(e);
}
}
use of java.security.KeyManagementException in project robovm by robovm.
the class IdentityTest method testAddCertificate1.
/**
* verify addCertificate(Certificate certificate) adds a certificate for this identity.
* If the identity has a public key, the public key in the certificate must be the same
*
*/
public void testAddCertificate1() throws Exception {
Identity i = new IdentityStub("iii");
PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", new byte[] { 1, 2, 3, 4, 5 });
i.setPublicKey(pk1);
// try with the same key
CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
i.addCertificate(c1);
assertSame(c1, i.certificates()[0]);
// try Certificate with different key
try {
i.addCertificate(new CertificateStub("ccc", null, null, new PublicKeyStub("k2", "fff", new byte[] { 6, 7, 8, 9, 0 })));
fail("KeyManagementException should be thrown");
} catch (KeyManagementException ok) {
}
}
use of java.security.KeyManagementException in project robovm by robovm.
the class IdentityTest method testAddCertificate4.
/**
* verify addCertificate(Certificate certificate) throws KeyManagementException if certificate is null
*/
public void testAddCertificate4() throws Exception {
try {
new IdentityStub("aaa").addCertificate(null);
fail("KeyManagementException should be thrown");
} catch (KeyManagementException ok) {
} catch (NullPointerException ok) {
}
}
use of java.security.KeyManagementException in project robovm by robovm.
the class IdentityTest method testSetPublicKey2.
/**
*
* verify Identity.setPublicKey() throws KeyManagementException if key is invalid
*
*/
public void testSetPublicKey2() throws Exception {
Identity i2 = new IdentityStub("testSetPublicKey2_2", IdentityScope.getSystemScope());
new PublicKeyStub("kkk", "testSetPublicKey2", new byte[] { 1, 2, 3, 4, 5 });
try {
i2.setPublicKey(null);
//fail("KeyManagementException should be thrown - key is null");
} catch (KeyManagementException ok) {
}
}
Aggregations