use of java.security.KeyStore in project robovm by robovm.
the class TrustManagerFactory2Test method checkResult.
private void checkResult(TrustManagerFactory tmf) throws Exception {
KeyStore kStore = null;
ManagerFactoryParameters mfp = null;
try {
tmf.init(kStore);
fail("KeyStoreException must be thrown");
} catch (KeyStoreException e) {
}
try {
tmf.init(mfp);
fail("InvalidAlgorithmParameterException must be thrown");
} catch (InvalidAlgorithmParameterException e) {
}
assertNull("getTrustManagers() should return null object", tmf.getTrustManagers());
try {
kStore = KeyStore.getInstance(KeyStore.getDefaultType());
kStore.load(null, null);
} catch (KeyStoreException e) {
fail("default keystore is not supported");
return;
}
tmf.init(kStore);
mfp = (ManagerFactoryParameters) new MyTrustManagerFactorySpi.Parameters(null);
try {
tmf.init(mfp);
fail("RuntimeException must be thrown");
} catch (RuntimeException e) {
assertTrue("Incorrect exception", e.getCause() instanceof KeyStoreException);
}
mfp = (ManagerFactoryParameters) new MyTrustManagerFactorySpi.Parameters(kStore);
tmf.init(mfp);
}
use of java.security.KeyStore in project robovm by robovm.
the class SSLSessionTest method test_getPeerPrincipal.
/**
* javax.net.ssl.SSLSession#getPeerPrincipal()
*/
public void test_getPeerPrincipal() throws Exception {
Principal p1 = clientSession.getPeerPrincipal();
KeyStore store = server.getStore();
X509Certificate cert = (X509Certificate) store.getCertificate("mykey");
Principal p2 = cert.getSubjectX500Principal();
assertEquals(p1, p2);
}
use of java.security.KeyStore in project robovm by robovm.
the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector03.
/**
* Test #3 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
* constructor<br>
* Assertion: <code>InvalidAlgorithmParameterException</code> - if the
* <code>keystore</code> does not contain at least one trusted certificate
* entry
*/
public final void testPKIXBuilderParametersKeyStoreCertSelector03() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
try {
new PKIXBuilderParameters(keyTest, new X509CertSelector());
fail("InvalidAlgorithmParameterException expected");
} catch (InvalidAlgorithmParameterException e) {
// expected
}
}
use of java.security.KeyStore in project robovm by robovm.
the class PKIXBuilderParametersTest method testToString.
/**
* Test for <code>toString()</code>
*/
public final void testToString() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[2];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
keyTest.setCertificateEntry("alias1", cert[0]);
keyTest.setCertificateEntry("alias2", cert[0]);
keyTest.setCertificateEntry("alias3", cert[1]);
PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
assertNotNull(p.toString());
}
use of java.security.KeyStore in project robovm by robovm.
the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector04.
/**
* Test #4 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
* constructor<br>
* Assertion: <code>NullPointerException</code> -
* if the <code>keystore</code> is <code>null</code>
*/
public final void testPKIXBuilderParametersKeyStoreCertSelector04() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[2];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
keyTest.setCertificateEntry("alias1", cert[0]);
keyTest.setCertificateEntry("alias2", cert[0]);
keyTest.setCertificateEntry("alias3", cert[1]);
try {
PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
assertEquals(3, p.getTrustAnchors().size());
assertEquals(5, p.getMaxPathLength());
} catch (Exception e) {
fail("Unexpected exception " + e.getMessage());
}
}
Aggregations