Search in sources :

Example 16 with AndroidOnly

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

the class Identity2Test method test_removeCertificateLjava_security_Certificate.

/**
     * java.security.Identity#removeCertificate(java.security.Certificate)
     */
@AndroidOnly("Spec says: Removing unknown certificates throw an exception. " + "The RI ignores unknown certificates.")
public void test_removeCertificateLjava_security_Certificate() throws Exception {
    IdentitySubclass sub = new IdentitySubclass("test", new IdentityScopeSubclass());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[1];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    sub.setPublicKey(cert[0].getPublicKey());
    CertificateImpl certImpl = new CertificateImpl(cert[0]);
    sub.addCertificate(certImpl);
    try {
        sub.removeCertificate(null);
        fail("Test 1: KeyManagementException expected.");
    } catch (KeyManagementException expected) {
    }
    assertEquals("Test 2: Certificate should not have been removed.", 1, sub.certificates().length);
    sub.removeCertificate(certImpl);
    assertEquals("Test 3: Certificate has not been removed.", 0, sub.certificates().length);
    // Removing the same certificate a second time should fail.
    try {
        sub.removeCertificate(certImpl);
        fail("Test 4: KeyManagementException expected.");
    } catch (KeyManagementException expected) {
    }
}
Also used : IdentityScopeSubclass(org.apache.harmony.security.tests.java.security.IdentityScope2Test.IdentityScopeSubclass) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) KeyManagementException(java.security.KeyManagementException) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 17 with AndroidOnly

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

the class SSLEngineTest method test_UseClientMode.

/**
     * @throws NoSuchAlgorithmException
     * javax.net.ssl.SSLEngine#setUseClientMode(boolean mode)
     * javax.net.ssl.SSLEngine#getUseClientMode()
     */
@AndroidOnly("The RI doesn't throw the expected IllegalStateException.")
public void test_UseClientMode() throws NoSuchAlgorithmException {
    SSLEngine sse = getEngine();
    try {
        sse.setUseClientMode(false);
        assertFalse(sse.getUseClientMode());
        sse.setUseClientMode(true);
        assertTrue(sse.getUseClientMode());
    } catch (Exception ex) {
        fail("Unexpected exception " + ex);
    }
    try {
        sse = getEngine(null, 1080);
        sse.setUseClientMode(true);
        sse.beginHandshake();
        try {
            sse.setUseClientMode(false);
            fail("IllegalArgumentException was not thrown");
        } catch (IllegalArgumentException iae) {
        //expected
        }
    } catch (Exception ex) {
        fail("Unexpected exception " + ex);
    }
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ReadOnlyBufferException(java.nio.ReadOnlyBufferException) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 18 with AndroidOnly

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

the class SSLEngineTest method test_wrap_ByteBuffer_ByteBuffer_04.

/**
     * javax.net.ssl.SSLEngine#wrap(ByteBuffer src, ByteBuffer dst)
     * IllegalStateException should be thrown.
     */
@AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_wrap_ByteBuffer_ByteBuffer_04() {
    String host = "new host";
    int port = 8080;
    ByteBuffer bbs = ByteBuffer.allocate(10);
    ByteBuffer bbd = ByteBuffer.allocate(10);
    SSLEngine sse = getEngine(host, port);
    try {
        sse.wrap(bbs, bbd);
        fail("IllegalStateException wasn't thrown");
    } catch (IllegalStateException iobe) {
    //expected
    } catch (Exception e) {
        fail(e + " was thrown instead of IllegalStateException");
    }
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ReadOnlyBufferException(java.nio.ReadOnlyBufferException) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 19 with AndroidOnly

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

the class SSLEngineTest method test_unwrap_ByteBuffer$ByteBuffer_04.

/**
     * javax.net.ssl.SSLEngine#unwrap(ByteBuffer src, ByteBuffer[] dsts)
     * IllegalStateException should be thrown.
     */
@AndroidOnly("The RI doesn't throw the IllegalStateException.")
public void test_unwrap_ByteBuffer$ByteBuffer_04() {
    String host = "new host";
    int port = 8080;
    ByteBuffer bbs = ByteBuffer.allocate(10);
    ByteBuffer[] bbd = { ByteBuffer.allocate(100), ByteBuffer.allocate(10), ByteBuffer.allocate(100) };
    SSLEngine sse = getEngine(host, port);
    try {
        sse.unwrap(bbs, bbd);
        fail("IllegalStateException wasn't thrown");
    } catch (IllegalStateException iobe) {
    //expected
    } catch (Exception e) {
        fail(e + " was thrown instead of IllegalStateException");
    }
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ReadOnlyBufferException(java.nio.ReadOnlyBufferException) AndroidOnly(dalvik.annotation.AndroidOnly)

Example 20 with AndroidOnly

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

the class X509CRLSelector2Test method testSetMinCRLNumberLjava_math_BigInteger.

/**
     * setMinCRLNumber(BigInteger minCRL) method testing. Tests if CRLs with any
     * crl number value match the selector in the case of null crlNumber
     * criteria, if specified minCRL value matches the selector, and if CRL with
     * inappropriate crlNumber value does not match the selector.
     */
@AndroidOnly("Uses specific class: " + "org.apache.harmony.security.asn1.ASN1OctetString.")
public void testSetMinCRLNumberLjava_math_BigInteger() {
    X509CRLSelector selector = new X509CRLSelector();
    BigInteger minCRL = new BigInteger("10000");
    CRL crl = new TestCRL(minCRL);
    selector.setMinCRLNumber(null);
    assertTrue("Any CRL should match in the case of null minCRLNumber.", selector.match(crl));
    selector.setMinCRLNumber(minCRL);
    assertTrue("The CRL should match the selection criteria.", selector.match(crl));
    selector.setMinCRLNumber(new BigInteger("10001"));
    assertFalse("The CRL should not match the selection criteria.", selector.match(crl));
}
Also used : BigInteger(java.math.BigInteger) X509CRL(java.security.cert.X509CRL) CRL(java.security.cert.CRL) X509CRLSelector(java.security.cert.X509CRLSelector) 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