Search in sources :

Example 6 with AndroidOnly

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

the class X509CRLSelector2Test method testClone.

/**
     * clone() method testing. Tests if the selector is cloned correctly: the
     * crl which matche to the initial selector should match to the clone and
     * the change of clone should not cause the change of initial selector.
     */
@AndroidOnly("Uses specific classes: " + "org.apache.harmony.security.asn1.ASN1OctetString, " + "org.apache.harmony.security.asn1.ASN1Integer.")
public void testClone() {
    X509CRLSelector selector = new X509CRLSelector();
    X500Principal iss1 = new X500Principal("O=First Org.");
    X500Principal iss2 = new X500Principal("O=Second Org.");
    X500Principal iss3 = new X500Principal("O=Third Org.");
    BigInteger minCRL = new BigInteger("10000");
    BigInteger maxCRL = new BigInteger("10000");
    Date date = new Date(200);
    selector.addIssuer(iss1);
    selector.addIssuer(iss2);
    selector.setMinCRLNumber(minCRL);
    selector.setMaxCRLNumber(maxCRL);
    selector.setDateAndTime(date);
    X509CRLSelector clone = (X509CRLSelector) selector.clone();
    TestCRL crl = new TestCRL(iss1);
    crl.setCrlNumber(minCRL);
    crl.setUpdateDates(new Date(200), new Date(200));
    assertTrue("The specified CRL should match the clone selector.", selector.match(crl));
    clone.addIssuer(iss3);
    assertFalse("The changes of the clone selector should not cause " + "the changes of initial object", selector.getIssuerNames().size() == 3);
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) BigInteger(java.math.BigInteger) X509CRLSelector(java.security.cert.X509CRLSelector) Date(java.util.Date) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 7 with AndroidOnly

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

the class X509CRLTest method testGetRevokedCertificate.

/**
     * getRevokedCertificate(X509Certificate certificate) method testing.
     * Check if the default implementation throws NullPointerException
     * on null input data.
     */
@AndroidOnly("Test filed on RI: getRevokedCertificate throws " + "RuntimeException.")
public void testGetRevokedCertificate() {
    try {
        tbt_crl.getRevokedCertificate((X509Certificate) null);
        fail("NullPointerException should be thrown " + "in the case of null input data.");
    } catch (NullPointerException e) {
    }
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) cf.generateCertificate(certArray);
        tbt_crl.getRevokedCertificate(cert);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
}
Also used : CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) SignatureException(java.security.SignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CRLException(java.security.cert.CRLException) NoSuchProviderException(java.security.NoSuchProviderException) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 8 with AndroidOnly

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

the class SSLSocketTest method test_addHandshakeCompletedListener.

/**
     * javax.net.ssl.SSLSocket#addHandshakeCompletedListener(HandshakeCompletedListener listener)
     */
@AndroidOnly("RI doesn't throw the specified IAE")
public void test_addHandshakeCompletedListener() throws IOException {
    SSLSocket ssl = getSSLSocket();
    HandshakeCompletedListener ls = new HandshakeCL();
    try {
        ssl.addHandshakeCompletedListener(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    ssl.addHandshakeCompletedListener(ls);
    ssl.close();
}
Also used : HandshakeCompletedListener(javax.net.ssl.HandshakeCompletedListener) SSLSocket(javax.net.ssl.SSLSocket) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 9 with AndroidOnly

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

the class MessageDigestTestMD2 method testMessageDigest1.

@AndroidOnly("Android doesn't include MD2 message digest algorithm")
public void testMessageDigest1() throws Exception {
    try {
        MessageDigest digest = MessageDigest.getInstance("MD2");
        fail("MD2 MessageDigest algorithm must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        MessageDigest digest = MessageDigest.getInstance("1.2.840.113549.2.2");
        fail("MD2 MessageDigest algorithm must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 10 with AndroidOnly

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

the class SignatureTestMD2withRSA method testSignature.

@AndroidOnly("Android doesn't include MD2withRSA signature algorithm")
public void testSignature() {
    try {
        Signature signature = Signature.getInstance("MD2withRSA");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        Signature signature = Signature.getInstance("MD2WithRSA");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        Signature signature = Signature.getInstance("MD2WITHRSA");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        Signature signature = Signature.getInstance("MD2withRSAEncryption");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        Signature signature = Signature.getInstance("MD2WithRSAEncryption");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        Signature signature = Signature.getInstance("MD2WITHRSAENCRYPTION");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        Signature signature = Signature.getInstance("MD2/RSA");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
    try {
        Signature signature = Signature.getInstance("1.2.840.113549.1.1.2");
        fail("MD2withRSA for signature verification must not be supported");
    } catch (NoSuchAlgorithmException e) {
    // expected
    }
}
Also used : Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) 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