use of java.security.cert.Certificate in project robovm by robovm.
the class KeyStore2Test method test_getCreationDate.
/**
* java.security.KeyStore#getCreationDate(String)
*/
public void test_getCreationDate() throws Exception {
String type = "DSA";
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
try {
keyTest.getCreationDate("anAlias");
fail();
} catch (KeyStoreException expected) {
}
keyTest.load(null, pssWord);
assertNull(keyTest.getCreationDate(""));
try {
keyTest.getCreationDate(null);
fail();
} catch (NullPointerException expected) {
}
Certificate[] chain = { new MyCertificate(type, testEncoding), new MyCertificate(type, testEncoding) };
PrivateKey privateKey1 = KeyFactory.getInstance(type).generatePrivate(new DSAPrivateKeySpec(new BigInteger("0"), new BigInteger("0"), new BigInteger("0"), new BigInteger("0")));
KeyStore.PasswordProtection pp = new KeyStore.PasswordProtection(pssWord);
KeyStore.PrivateKeyEntry pke = new KeyStore.PrivateKeyEntry(getPrivateKey(), chain);
KeyStore.PrivateKeyEntry pke1 = new KeyStore.PrivateKeyEntry(privateKey1, chain);
keyTest.setEntry("alias1", pke, pp);
keyTest.setEntry("alias2", pke1, pp);
Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
int dayExpected = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
int monthExpected = Calendar.getInstance().get(Calendar.MONTH);
int yearExpected = Calendar.getInstance().get(Calendar.YEAR);
int hourExpected = Calendar.getInstance().get(Calendar.HOUR);
int minuteExpected = Calendar.getInstance().get(Calendar.MINUTE);
Calendar.getInstance().setTimeInMillis(keyTest.getCreationDate("alias1").getTime());
int dayActual1 = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
int monthActual1 = Calendar.getInstance().get(Calendar.MONTH);
int yearActual1 = Calendar.getInstance().get(Calendar.YEAR);
int hourActual1 = Calendar.getInstance().get(Calendar.HOUR);
int minuteActual1 = Calendar.getInstance().get(Calendar.MINUTE);
assertEquals(dayExpected, dayActual1);
assertEquals(monthExpected, monthActual1);
assertEquals(yearExpected, yearActual1);
assertEquals(hourExpected, hourActual1);
assertEquals(minuteExpected, minuteActual1);
Calendar.getInstance().setTimeInMillis(keyTest.getCreationDate("alias2").getTime());
int dayActual2 = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
int monthActual2 = Calendar.getInstance().get(Calendar.MONTH);
int yearActual2 = Calendar.getInstance().get(Calendar.YEAR);
int hourActual2 = Calendar.getInstance().get(Calendar.HOUR);
int minuteActual2 = Calendar.getInstance().get(Calendar.MINUTE);
assertEquals(dayExpected, dayActual2);
assertEquals(monthExpected, monthActual2);
assertEquals(yearExpected, yearActual2);
assertEquals(hourExpected, hourActual2);
assertEquals(minuteExpected, minuteActual2);
try {
keyTest.getCreationDate(null);
fail();
} catch (NullPointerException expected) {
}
}
use of java.security.cert.Certificate in project robovm by robovm.
the class myHostnameVerifier method test_getServerCertificates.
/**
* javax.net.ssl.HttpsURLConnection#getServerCertificates()
*/
public final void test_getServerCertificates() throws Exception {
URL url = new URL("https://localhost:55555");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
try {
connection.getServerCertificates();
fail("IllegalStateException wasn't thrown");
} catch (IllegalStateException expected) {
}
HttpsURLConnection con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.508");
try {
con.getServerCertificates();
fail("SSLPeerUnverifiedException wasn't thrown");
} catch (SSLPeerUnverifiedException expected) {
}
con = new MyHttpsURLConnection(new URL("https://www.fortify.net/"), "X.509");
Certificate[] cert = con.getServerCertificates();
assertNotNull(cert);
assertEquals(1, cert.length);
}
use of java.security.cert.Certificate in project robovm by robovm.
the class myHostnameVerifier method getServerCertificates.
/*
* @see javax.net.ssl.HttpsURLConnection#getServerCertificates()
*/
public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
try {
CertificateFactory cf = CertificateFactory.getInstance(typeDone);
byte[] barr = TestUtils.getX509Certificate_v3();
ByteArrayInputStream bis = new ByteArrayInputStream(barr);
Certificate cert = cf.generateCertificate(bis);
return new Certificate[] { cert };
} catch (CertificateException se) {
throw new SSLPeerUnverifiedException("No server's end-entity certificate");
}
}
use of java.security.cert.Certificate in project robovm by robovm.
the class SSLSessionTest method test_getLocalCertificates.
/**
* javax.net.ssl.SSLSession#getLocalCertificates()
*/
public void test_getLocalCertificates() throws Exception {
KeyStore store = client.getStore();
Certificate cert = store.getCertificate("mykey");
Certificate[] certs = clientSession.getLocalCertificates();
assertEquals(cert, certs[0]);
}
use of java.security.cert.Certificate in project robovm by robovm.
the class CertificateFactory3Test method testGenerateCertPath01.
/**
* Test for <code>generateCertPath(List certificates)</code> method
* Assertion: returns CertPath with 1 Certificate
*/
public void testGenerateCertPath01() throws Exception {
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
// create list of certificates with one certificate
Certificate cert = certFs[0].generateCertificate(new ByteArrayInputStream(TestUtils.getEncodedX509Certificate()));
List<Certificate> list = new Vector<Certificate>();
list.add(cert);
for (int i = 0; i < certFs.length; i++) {
CertPath certPath = null;
certPath = certFs[i].generateCertPath(list);
assertEquals(cert.getType(), certPath.getType());
List<? extends Certificate> list1 = certPath.getCertificates();
assertFalse("Result list is empty", list1.isEmpty());
Iterator<? extends Certificate> it = list1.iterator();
assertEquals("Incorrect Certificate in CertPath", cert, it.next());
}
}
Aggregations