use of java.security.cert.Certificate in project robovm by robovm.
the class HttpsURLConnectionTest method checkConnectionStateParameters.
/**
* Checks the HttpsURLConnection getter's values and compares
* them with actual corresponding values of remote peer.
*/
public static void checkConnectionStateParameters(HttpsURLConnection clientConnection, SSLSocket serverPeer) throws Exception {
SSLSession session = serverPeer.getSession();
assertEquals(session.getCipherSuite(), clientConnection.getCipherSuite());
assertEquals(session.getLocalPrincipal(), clientConnection.getPeerPrincipal());
assertEquals(session.getPeerPrincipal(), clientConnection.getLocalPrincipal());
Certificate[] serverCertificates = clientConnection.getServerCertificates();
Certificate[] localCertificates = session.getLocalCertificates();
assertTrue("Server certificates differ from expected", Arrays.equals(serverCertificates, localCertificates));
localCertificates = clientConnection.getLocalCertificates();
serverCertificates = session.getPeerCertificates();
assertTrue("Local certificates differ from expected", Arrays.equals(serverCertificates, localCertificates));
}
use of java.security.cert.Certificate in project robovm by robovm.
the class CollectionCertStoreParametersTest method testClone01.
/**
* Test #1 for <code>clone()</code> method<br>
*/
public final void testClone01() {
Vector<Certificate> certificates = new Vector<Certificate>();
certificates.add(new MyCertificate("TEST", new byte[] { (byte) 4 }));
CollectionCertStoreParameters cp1 = new CollectionCertStoreParameters(certificates);
CollectionCertStoreParameters cp2 = (CollectionCertStoreParameters) cp1.clone();
// check that that we have new object
assertTrue(cp1 != cp2);
}
use of java.security.cert.Certificate in project robovm by robovm.
the class KeyStoreTest method test_KeyStore_cacerts.
public void test_KeyStore_cacerts() throws Exception {
if (StandardNames.IS_RI) {
return;
}
KeyStore ks = KeyStore.getInstance("AndroidCAStore");
assertEquals("AndroidCAStore", ks.getType());
assertEquals("HarmonyJSSE", ks.getProvider().getName());
ks.load(null, null);
for (String alias : Collections.list(ks.aliases())) {
Certificate c = null;
try {
c = ks.getCertificate(alias);
assertNotNull(c);
assertTrue(ks.isCertificateEntry(alias));
assertTrue(ks.entryInstanceOf(alias, TrustedCertificateEntry.class));
assertEquals(alias, ks.getCertificateAlias(c));
assertTrue(c instanceof X509Certificate);
X509Certificate cert = (X509Certificate) c;
assertEquals(cert.getSubjectUniqueID(), cert.getIssuerUniqueID());
assertNotNull(cert.getPublicKey());
assertTrue(ks.containsAlias(alias));
assertNotNull(ks.getCreationDate(alias));
assertNotNull(ks.getEntry(alias, null));
assertFalse(ks.isKeyEntry(alias));
assertNull(ks.getKey(alias, null));
assertNull(ks.getCertificateChain(alias));
} catch (Throwable t) {
throw new Exception("alias=" + alias + " cert=" + c, t);
}
}
}
use of java.security.cert.Certificate in project robovm by robovm.
the class CertificateFactoryTest method test_generateCertificate_InputStream_InvalidStart_Failure.
private void test_generateCertificate_InputStream_InvalidStart_Failure(CertificateFactory cf) throws Exception {
try {
Certificate c = cf.generateCertificate(new ByteArrayInputStream("-----BEGIN CERTIFICATE-----".getBytes()));
if (!"BC".equals(cf.getProvider().getName())) {
fail("should throw CertificateException: " + cf.getProvider().getName());
}
assertNull(c);
} catch (CertificateException expected) {
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 CertificateFactoryTest method test_generateCertificate_InputStream_Offset_Correct.
private void test_generateCertificate_InputStream_Offset_Correct(CertificateFactory cf) throws Exception {
byte[] valid = VALID_CERTIFICATE_PEM.getBytes();
byte[] doubleCertificateData = new byte[valid.length * 2];
System.arraycopy(valid, 0, doubleCertificateData, 0, valid.length);
System.arraycopy(valid, 0, doubleCertificateData, valid.length, valid.length);
MeasuredInputStream certStream = new MeasuredInputStream(new ByteArrayInputStream(doubleCertificateData));
Certificate certificate = cf.generateCertificate(certStream);
assertNotNull(certificate);
assertEquals(valid.length, certStream.getCount());
}
Aggregations