use of java.security.cert.Certificate in project robovm by robovm.
the class CertificateFactoryTest method test_generateCertificate_InputStream_Empty.
private void test_generateCertificate_InputStream_Empty(CertificateFactory cf) throws Exception {
try {
Certificate c = cf.generateCertificate(new ByteArrayInputStream(new byte[0]));
if (!"BC".equals(cf.getProvider().getName())) {
fail("should throw CertificateException: " + cf.getProvider().getName());
}
assertNull(c);
} catch (CertificateException e) {
if ("BC".equals(cf.getProvider().getName())) {
fail("should return null: " + cf.getProvider().getName());
}
}
}
use of java.security.cert.Certificate in project robovm by robovm.
the class KeyStore2Test method test_getCertificateChainLjava_lang_String.
/**
* java.security.KeyStore#getCertificateChain(java.lang.String)
*/
public void test_getCertificateChainLjava_lang_String() throws Exception {
// Test for method java.security.cert.Certificate[]
// java.security.KeyStore.getCertificateChain(java.lang.String)
// creatCertificate();
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[2];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
try {
keyTest.getCertificateChain("anAlias");
fail();
} catch (KeyStoreException expected) {
}
keyTest.load(null, null);
// alias 1
keyTest.setCertificateEntry("alias1", cert[0]);
// alias 2
keyTest.setKeyEntry("alias2", getPrivateKey(), pssWord, cert);
Certificate[] certRes = keyTest.getCertificateChain("alias2");
assertEquals("there are more than two certificate returned from getCertificateChain", 2, certRes.length);
assertEquals("the first certificate returned from getCertificateChain is not correct", cert[0].getPublicKey(), certRes[0].getPublicKey());
assertEquals("the second certificate returned from getCertificateChain is not correct", cert[1].getPublicKey(), certRes[1].getPublicKey());
Certificate[] certResNull = keyTest.getCertificateChain("alias1");
assertNull("the certificate chain returned from getCertificateChain is NOT null", certResNull);
try {
keyTest.getCertificateChain(null);
fail();
} catch (NullPointerException expected) {
}
}
use of java.security.cert.Certificate in project robovm by robovm.
the class KSTrustedCertificateEntryTest method testToString.
/**
* Test for <codfe>toString()</code> method
* Assertion: returns non null string
*/
public void testToString() {
Certificate cert = new MyCertificate("TEST", new byte[10]);
KeyStore.TrustedCertificateEntry ksTCE = new KeyStore.TrustedCertificateEntry(cert);
assertNotNull("toString() returns null string", ksTCE.toString());
}
use of java.security.cert.Certificate in project robovm by robovm.
the class KSTrustedCertificateEntryTest method testGetTrustedCertificate.
/**
* Test for <codfe>getTrustedCertificate()</code> method
* Assertion: returns trusted Certificate from goven entry
*/
public void testGetTrustedCertificate() {
Certificate cert = new MyCertificate("TEST", new byte[10]);
KeyStore.TrustedCertificateEntry ksTCE = new KeyStore.TrustedCertificateEntry(cert);
assertEquals("Incorrect certificate", cert, ksTCE.getTrustedCertificate());
}
use of java.security.cert.Certificate in project robovm by robovm.
the class KSPrivateKeyEntryTest method testPrivateKeyEntry01.
/**
* Test for <code>PrivateKeyEntry(PrivateKey privateKey, Certificate[] chain)</code>
* constructor
* Assertion: throws NullPointerException when privateKey is null
*/
public void testPrivateKeyEntry01() {
//new Certificate[1];
Certificate[] certs = new MyCertificate[1];
PrivateKey pk = null;
try {
new KeyStore.PrivateKeyEntry(pk, certs);
fail("NullPointerException must be thrown when privateKey is null");
} catch (NullPointerException e) {
}
}
Aggregations