Search in sources :

Example 1 with KeyStoreSpi

use of java.security.KeyStoreSpi in project robovm by robovm.

the class MyCertificate method test_KeyStoreSpi.

@SuppressWarnings("cast")
public void test_KeyStoreSpi() {
    try {
        MyKeyStoreSpi ksSpi = new MyKeyStoreSpi();
        assertNotNull(ksSpi);
        assertTrue(ksSpi instanceof KeyStoreSpi);
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
}
Also used : MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) KeyStoreSpi(java.security.KeyStoreSpi) MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) SignatureException(java.security.SignatureException) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 2 with KeyStoreSpi

use of java.security.KeyStoreSpi in project robovm by robovm.

the class MyCertificate method testKeyStoreSpi02.

/**
     * Test for <code>KeyStoreSpi()</code> constructor and abstract engine
     * methods. Assertion: creates new KeyStoreSpi object.
     */
public void testKeyStoreSpi02() throws NoSuchAlgorithmException, UnrecoverableKeyException, CertificateException {
    KeyStoreSpi ksSpi = new MyKeyStoreSpi();
    assertNull("engineGetKey(..) must return null", ksSpi.engineGetKey("", new char[0]));
    assertNull("engineGetCertificateChain(..) must return null", ksSpi.engineGetCertificateChain(""));
    assertNull("engineGetCertificate(..) must return null", ksSpi.engineGetCertificate(""));
    assertEquals("engineGetCreationDate(..) must return Date(0)", new Date(0), ksSpi.engineGetCreationDate(""));
    try {
        ksSpi.engineSetKeyEntry("", null, new char[0], new Certificate[0]);
        fail("KeyStoreException must be thrown from engineSetKeyEntry(..)");
    } catch (KeyStoreException expected) {
    }
    try {
        ksSpi.engineSetKeyEntry("", new byte[0], new Certificate[0]);
        fail("KeyStoreException must be thrown from engineSetKeyEntry(..)");
    } catch (KeyStoreException expected) {
    }
    try {
        ksSpi.engineSetCertificateEntry("", null);
        fail("KeyStoreException must be thrown " + "from engineSetCertificateEntry(..)");
    } catch (KeyStoreException expected) {
    }
    try {
        ksSpi.engineDeleteEntry("");
        fail("KeyStoreException must be thrown from engineDeleteEntry(..)");
    } catch (KeyStoreException expected) {
    }
    assertNull("engineAliases() must return null", ksSpi.engineAliases());
    assertFalse("engineContainsAlias(..) must return false", ksSpi.engineContainsAlias(""));
    assertEquals("engineSize() must return 0", 0, ksSpi.engineSize());
    try {
        ksSpi.engineStore(null, null);
        fail("IOException must be thrown");
    } catch (IOException expected) {
    }
}
Also used : MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyStoreSpi(java.security.KeyStoreSpi) MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) Date(java.util.Date)

Example 3 with KeyStoreSpi

use of java.security.KeyStoreSpi in project robovm by robovm.

the class MyCertificate method testKeyStoreSpi01.

public void testKeyStoreSpi01() throws IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableEntryException, KeyStoreException {
    final boolean[] keyEntryWasSet = new boolean[1];
    KeyStoreSpi ksSpi = new MyKeyStoreSpi() {

        @Override
        public void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException {
            keyEntryWasSet[0] = true;
        }
    };
    BadKeyStoreEntry badEntry = new BadKeyStoreEntry();
    BadKeyStoreProtectionParameter badParameter = new BadKeyStoreProtectionParameter();
    KeyStore.SecretKeyEntry dummyEntry = new KeyStore.SecretKeyEntry(new SecretKey() {

        @Override
        public String getAlgorithm() {
            return null;
        }

        @Override
        public String getFormat() {
            return null;
        }

        @Override
        public byte[] getEncoded() {
            return null;
        }
    });
    try {
        ksSpi.engineStore(null);
    } catch (UnsupportedOperationException expected) {
    }
    assertNull("Not null entry", ksSpi.engineGetEntry("aaa", null));
    assertNull("Not null entry", ksSpi.engineGetEntry(null, badParameter));
    assertNull("Not null entry", ksSpi.engineGetEntry("aaa", badParameter));
    try {
        ksSpi.engineSetEntry("", null, null);
        fail("KeyStoreException or NullPointerException must be thrown");
    } catch (KeyStoreException expected) {
    } catch (NullPointerException expected) {
    }
    try {
        ksSpi.engineSetEntry("", new KeyStore.TrustedCertificateEntry(new MyCertificate("type", new byte[0])), null);
        fail("KeyStoreException must be thrown");
    } catch (KeyStoreException expected) {
    }
    try {
        ksSpi.engineSetEntry("aaa", badEntry, null);
        fail("KeyStoreException must be thrown");
    } catch (KeyStoreException expected) {
    }
    ksSpi.engineSetEntry("aaa", dummyEntry, null);
    assertTrue(keyEntryWasSet[0]);
}
Also used : KeyStoreException(java.security.KeyStoreException) KeyStoreSpi(java.security.KeyStoreSpi) MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) KeyStore(java.security.KeyStore) SecretKey(javax.crypto.SecretKey) MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) PublicKey(java.security.PublicKey) Key(java.security.Key) SecretKey(javax.crypto.SecretKey)

Example 4 with KeyStoreSpi

use of java.security.KeyStoreSpi in project robovm by robovm.

the class MyCertificate method test_engineEntryInstanceOf.

/*
     * java.security.KeyStore.engineEntryInstanceOf(String, Class<?
     * extends Entry>)
     */
public void test_engineEntryInstanceOf() throws Exception {
    KeyStoreSpi ksSpi = new MyKeyStoreSpi();
    assertTrue(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias1", KeyStore.PrivateKeyEntry.class));
    assertFalse(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias2", KeyStore.SecretKeyEntry.class));
    assertFalse(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias3", KeyStore.TrustedCertificateEntry.class));
    try {
        assertFalse(ksSpi.engineEntryInstanceOf(null, KeyStore.TrustedCertificateEntry.class));
    } catch (NullPointerException expected) {
    }
    try {
        assertFalse(ksSpi.engineEntryInstanceOf("test_engineEntryInstanceOf_Alias1", null));
    } catch (NullPointerException expected) {
    }
}
Also used : MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) KeyStoreSpi(java.security.KeyStoreSpi) MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi)

Example 5 with KeyStoreSpi

use of java.security.KeyStoreSpi in project robovm by robovm.

the class MyCertificate method test_engineLoadLjava_security_KeyStore_LoadStoreParameter.

/**
     * java.security.KeyStoreSpi#engineLoad(KeyStore.LoadStoreParameter)
     */
public void test_engineLoadLjava_security_KeyStore_LoadStoreParameter() throws Exception {
    final String msg = "error";
    KeyStoreSpi ksSpi = new MyKeyStoreSpi() {

        public void engineLoad(InputStream stream, char[] password) {
            assertNull(stream);
            assertNull(password);
            throw new RuntimeException(msg);
        }
    };
    try {
        ksSpi.engineLoad(null);
        fail("Should throw exception");
    } catch (RuntimeException expected) {
        assertSame(msg, expected.getMessage());
    }
    // test: protection parameter is null
    try {
        ksSpi.engineLoad(new MyLoadStoreParams(null));
        fail("No expected UnsupportedOperationException");
    } catch (UnsupportedOperationException expected) {
    }
    // PasswordProtection or CallbackHandlerProtection
    try {
        ksSpi.engineLoad(new MyLoadStoreParams(new BadKeyStoreProtectionParameter()));
        fail("No expected UnsupportedOperationException");
    } catch (UnsupportedOperationException expected) {
    }
}
Also used : MyLoadStoreParams(org.apache.harmony.security.tests.support.MyLoadStoreParams) InputStream(java.io.InputStream) MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi) KeyStoreSpi(java.security.KeyStoreSpi) MyKeyStoreSpi(org.apache.harmony.security.tests.support.MyKeyStoreSpi)

Aggregations

KeyStoreSpi (java.security.KeyStoreSpi)5 MyKeyStoreSpi (org.apache.harmony.security.tests.support.MyKeyStoreSpi)5 KeyStoreException (java.security.KeyStoreException)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)1 InvalidKeyException (java.security.InvalidKeyException)1 Key (java.security.Key)1 KeyStore (java.security.KeyStore)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 PublicKey (java.security.PublicKey)1 SignatureException (java.security.SignatureException)1 UnrecoverableEntryException (java.security.UnrecoverableEntryException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 CertificateException (java.security.cert.CertificateException)1 Date (java.util.Date)1 SecretKey (javax.crypto.SecretKey)1 MyLoadStoreParams (org.apache.harmony.security.tests.support.MyLoadStoreParams)1