Search in sources :

Example 11 with AndroidOnly

use of dalvik.annotation.AndroidOnly in project robovm by robovm.

the class HandshakeCompletedEventTest method testClientAuth.

/**
     * Implements the actual test case. Launches a server and a client, requires
     * client authentication and checks the certificates afterwards (not in the
     * usual sense, we just make sure that we got the expected certificates,
     * because our self-signed test certificates are not valid.)
     */
@AndroidOnly("Uses bks key store. Change useBKS to false to run on the RI")
public void testClientAuth() throws Exception {
    boolean useBKS = true;
    listener = new MyHandshakeListener();
    String serverKeys = (useBKS ? SERVER_KEYS_BKS : SERVER_KEYS_JKS);
    String clientKeys = (useBKS ? CLIENT_KEYS_BKS : CLIENT_KEYS_JKS);
    TestServer server = new TestServer(true, TestServer.CLIENT_AUTH_WANTED, serverKeys);
    TestClient client = new TestClient(true, clientKeys);
    Thread serverThread = new Thread(server);
    Thread clientThread = new Thread(client);
    serverThread.start();
    Thread.currentThread().sleep(3000);
    clientThread.start();
    serverThread.join();
    clientThread.join();
    // The server must have completed without an exception.
    Exception e = server.getException();
    if (e != null) {
        e.printStackTrace();
    }
    // The client must have completed without an exception.
    e = client.getException();
    if (e != null) {
        e.printStackTrace();
    }
    assertNull(e);
    assertTrue(listener.completeDone);
}
Also used : IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 12 with AndroidOnly

use of dalvik.annotation.AndroidOnly in project robovm by robovm.

the class CertificateTest method testVerifyMD2.

@AndroidOnly("MD2 is not supported by Android")
public void testVerifyMD2() throws Exception {
    Provider[] providers = Security.getProviders("CertificateFactory.X509");
    for (Provider provider : providers) {
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X509", provider);
        Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(selfSignedCertMD2.getBytes()));
        try {
            certificate.verify(certificate.getPublicKey());
            fail("MD2 should not be allowed");
        } catch (NoSuchAlgorithmException e) {
        // expected
        } catch (Throwable e) {
            throw new AssertionError(provider.getName(), e);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertificateFactory(java.security.cert.CertificateFactory) Provider(java.security.Provider) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 13 with AndroidOnly

use of dalvik.annotation.AndroidOnly in project robovm by robovm.

the class MessageDigestTestMD2 method testMessageDigest2.

@AndroidOnly("Android allows usage of MD2 in third party providers")
public void testMessageDigest2() throws Exception {
    Provider provider = new MyProvider();
    Security.addProvider(provider);
    try {
        MessageDigest digest = MessageDigest.getInstance("MD2");
        digest = MessageDigest.getInstance("1.2.840.113549.2.2");
    } finally {
        Security.removeProvider(provider.getName());
    }
}
Also used : MessageDigest(java.security.MessageDigest) Provider(java.security.Provider) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 14 with AndroidOnly

use of dalvik.annotation.AndroidOnly in project robovm by robovm.

the class SignatureTestMD2withRSA method testSignature2.

@AndroidOnly("Android allows usage of MD2withRSA in third party providers")
public void testSignature2() throws Exception {
    Provider provider = new MyProvider();
    Security.addProvider(provider);
    Signature signature = Signature.getInstance("MD2withRSA");
    signature = Signature.getInstance("MD2WithRSA");
    signature = Signature.getInstance("MD2WITHRSA");
    signature = Signature.getInstance("MD2withRSAEncryption");
    signature = Signature.getInstance("MD2WithRSAEncryption");
    signature = Signature.getInstance("MD2WITHRSAENCRYPTION");
    signature = Signature.getInstance("MD2/RSA");
    signature = Signature.getInstance("1.2.840.113549.1.1.2");
    Security.removeProvider(provider.getName());
}
Also used : Signature(java.security.Signature) Provider(java.security.Provider) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 15 with AndroidOnly

use of dalvik.annotation.AndroidOnly in project robovm by robovm.

the class OldTimeZoneTest method test_getDisplayNameZILjava_util_Locale.

@AndroidOnly("fail on RI. See comment below")
public void test_getDisplayNameZILjava_util_Locale() {
    TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
    assertEquals("PST", tz.getDisplayName(false, 0, Locale.US));
    assertEquals("Pacific Daylight Time", tz.getDisplayName(true, 1, Locale.US));
    assertEquals("Pacific Standard Time", tz.getDisplayName(false, 1, Locale.UK));
    // RI always returns short time zone name as "PST"
    // ICU zone/root.txt patched to allow metazone names.
    assertEquals("PST", tz.getDisplayName(false, 0, Locale.FRANCE));
    assertEquals("heure avancée du Pacifique", tz.getDisplayName(true, 1, Locale.FRANCE));
    assertEquals("heure normale du Pacifique", tz.getDisplayName(false, 1, Locale.FRANCE));
}
Also used : TimeZone(java.util.TimeZone) AndroidOnly(dalvik.annotation.AndroidOnly)

Aggregations

AndroidOnly (dalvik.annotation.AndroidOnly)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)10 IOException (java.io.IOException)7 KeyManagementException (java.security.KeyManagementException)7 SSLEngine (javax.net.ssl.SSLEngine)7 ByteBuffer (java.nio.ByteBuffer)6 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)6 SSLException (javax.net.ssl.SSLException)6 BigInteger (java.math.BigInteger)3 Provider (java.security.Provider)3 CertificateFactory (java.security.cert.CertificateFactory)3 X509CRLSelector (java.security.cert.X509CRLSelector)3 X509Certificate (java.security.cert.X509Certificate)3 MessageDigest (java.security.MessageDigest)2 Signature (java.security.Signature)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 SignatureException (java.security.SignatureException)1 CRL (java.security.cert.CRL)1