use of java.security.cert.CertificateFactory in project robovm by robovm.
the class X509KeyManagerTest method init.
void init(String name) {
keyType = name;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
KeyFactory kf = KeyFactory.getInstance("RSA");
keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, "1234".toCharArray());
if (keyType.equals(CLIENT)) {
keys = new PrivateKey[3];
keys[0] = kf.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
keys[1] = kf.generatePrivate(new PKCS8EncodedKeySpec(key2Bytes));
keys[2] = kf.generatePrivate(new PKCS8EncodedKeySpec(key3Bytes));
cert = new X509Certificate[3];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
cert[2] = (X509Certificate) cf.generateCertificate(certArray3);
keyTest.setKeyEntry("clientKey_01", keys[0], PASSWORD, new X509Certificate[] { cert[0] });
keyTest.setKeyEntry("clientKey_02", keys[1], PASSWORD, new X509Certificate[] { cert[0], cert[1] });
keyTest.setKeyEntry("clientKey_03", keys[2], PASSWORD, new X509Certificate[] { cert[0], cert[2] });
keyTest.setCertificateEntry("clientAlias_01", cert[0]);
keyTest.setCertificateEntry("clientAlias_02", cert[0]);
keyTest.setCertificateEntry("clientAlias_03", cert[1]);
} else if (keyType.equals(SERVER)) {
keys = new PrivateKey[1];
keys[0] = kf.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
cert = new X509Certificate[1];
cert[0] = (X509Certificate) cf.generateCertificate(certArray3);
keyTest.setKeyEntry("serverKey_00", keys[0], PASSWORD, new X509Certificate[] { cert[0] });
keyTest.setCertificateEntry("serverAlias_00", cert[0]);
}
} catch (Exception ex) {
ex.printStackTrace();
throw new IllegalArgumentException(ex.getMessage());
}
try {
factory.init(keyTest, "1234".toCharArray());
} catch (Exception e) {
fail("Could't init the KeyManagerFactory");
}
manager = (X509KeyManager) factory.getKeyManagers()[0];
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class X509Certificate2Test method test_toString.
/**
* Test for X.509 Certificate provider
*/
public void test_toString() throws Exception {
// Regression for HARMONY-3384
CertificateFactory certFact = CertificateFactory.getInstance("X509");
X509Certificate pemCert = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
// extension value is empty sequence
byte[] extnValue = pemCert.getExtensionValue("2.5.29.35");
assertEquals(Arrays.toString(new byte[] { 0x04, 0x02, 0x30, 0x00 }), Arrays.toString(extnValue));
assertNotNull(pemCert.toString());
// End regression for HARMONY-3384
}
use of java.security.cert.CertificateFactory 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.cert.CertificateFactory 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());
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class PKIXBuilderParametersTest method testGetMaxPathLength.
/**
* Test for <code>getMaxPathLength()</code>
*/
public final void testGetMaxPathLength() 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());
assertEquals(5, p.getMaxPathLength());
p.setMaxPathLength(10);
assertEquals(10, p.getMaxPathLength());
}
Aggregations