Search in sources :

Example 11 with Provider

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

the class KeyPairGeneratorTest method test_getInstance.

public void test_getInstance() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider provider : providers) {
        Set<Provider.Service> services = provider.getServices();
        for (Provider.Service service : services) {
            String type = service.getType();
            if (!type.equals("KeyPairGenerator")) {
                continue;
            }
            String algorithm = service.getAlgorithm();
            // AndroidKeyStore is tested in CTS.
            if ("AndroidKeyStore".equals(provider.getName())) {
                continue;
            }
            AlgorithmParameterSpec params = null;
            // TODO: detect if we're running in vogar and run the full test
            if ("DH".equals(algorithm)) {
                params = getDHParams();
            }
            try {
                // KeyPairGenerator.getInstance(String)
                KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(algorithm);
                assertEquals(algorithm, kpg1.getAlgorithm());
                if (params != null) {
                    kpg1.initialize(params);
                }
                test_KeyPairGenerator(kpg1);
                // KeyPairGenerator.getInstance(String, Provider)
                KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(algorithm, provider);
                assertEquals(algorithm, kpg2.getAlgorithm());
                assertEquals(provider, kpg2.getProvider());
                if (params != null) {
                    kpg2.initialize(params);
                }
                test_KeyPairGenerator(kpg2);
                // KeyPairGenerator.getInstance(String, String)
                KeyPairGenerator kpg3 = KeyPairGenerator.getInstance(algorithm, provider.getName());
                assertEquals(algorithm, kpg3.getAlgorithm());
                assertEquals(provider, kpg3.getProvider());
                if (params != null) {
                    kpg3.initialize(params);
                }
                test_KeyPairGenerator(kpg3);
            } catch (Exception e) {
                throw new Exception("Problem testing KeyPairGenerator." + algorithm, e);
            }
        }
    }
}
Also used : Service(java.security.Provider.Service) Service(java.security.Provider.Service) KeyPairGenerator(java.security.KeyPairGenerator) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) Provider(java.security.Provider)

Example 12 with Provider

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

the class ExemptionMechanismTest method test_genExemptionBlob.

public void test_genExemptionBlob() throws InvalidKeyException, ExemptionMechanismException {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    try {
        em.genExemptionBlob();
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
    //failed
    }
    em.init(key);
    assertNotNull(em.genExemptionBlob());
    em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    key = new Mock_ExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    em.init(key);
    try {
        em.genExemptionBlob();
        fail("ExemptionMechanismException expected");
    } catch (ExemptionMechanismException e) {
    //failed
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanismException(javax.crypto.ExemptionMechanismException) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Example 13 with Provider

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

the class ExemptionMechanismTest method testIsCryptoAllowed.

/**
     * Test for <code>isCryptoAllowed(Key key)</code> method
     */
public void testIsCryptoAllowed() throws Exception {
    //Regression for HARMONY-1029
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    assertFalse(em.isCryptoAllowed(key));
    em.init(key);
    assertFalse(em.isCryptoAllowed(key));
    em.genExemptionBlob();
    assertTrue(em.isCryptoAllowed(key));
    Key key1 = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[] { 1 });
    assertFalse(em.isCryptoAllowed(key1));
    em.init(key1);
    assertFalse(em.isCryptoAllowed(key));
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Example 14 with Provider

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

the class ExemptionMechanismTest method test_getInstanceLjava_lang_StringLjava_security_Provider.

public void test_getInstanceLjava_lang_StringLjava_security_Provider() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    try {
        ExemptionMechanism.getInstance((String) null, mProv);
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    //expected
    }
    ExemptionMechanism em = new ExemptionMechanism(new Mock_ExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    try {
        em.getInstance("WrongAlgName", mProv);
        fail("NoSuchAlgorithmException expected");
    } catch (NoSuchAlgorithmException e) {
    //expected
    }
    try {
        em.getInstance("WrongAlgName", (Provider) null);
        fail("IllegalArgumentException expected");
    } catch (IllegalArgumentException e) {
    //expected
    }
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ExemptionMechanism(javax.crypto.ExemptionMechanism) Provider(java.security.Provider)

Example 15 with Provider

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

the class ExemptionMechanismTest method test_getProvider.

public void test_getProvider() throws Exception {
    Provider mProv = (new SpiEngUtils()).new MyProvider("MyExMechProvider", "Provider for ExemptionMechanism testing", srvExemptionMechanism.concat(".").concat(defaultAlg), ExemptionMechanismProviderClass);
    ExemptionMechanism em = new ExemptionMechanism(new MyExemptionMechanismSpi(), mProv, defaultAlg) {
    };
    Key key = new MyExemptionMechanismSpi().new tmpKey("Proba", new byte[0]);
    assertEquals(mProv, em.getProvider());
}
Also used : SpiEngUtils(org.apache.harmony.security.tests.support.SpiEngUtils) MyExemptionMechanismSpi(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi) ExemptionMechanism(javax.crypto.ExemptionMechanism) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Key(java.security.Key) MyExemptionMechanismSpi.tmpKey(org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey) Provider(java.security.Provider)

Aggregations

Provider (java.security.Provider)229 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)49 ArrayList (java.util.ArrayList)25 MessageDigest (java.security.MessageDigest)21 KeyStore (java.security.KeyStore)19 List (java.util.List)18 Service (java.security.Provider.Service)15 ExemptionMechanism (javax.crypto.ExemptionMechanism)14 SpiEngUtils (org.apache.harmony.security.tests.support.SpiEngUtils)14 InvalidKeyException (java.security.InvalidKeyException)13 IOException (java.io.IOException)12 Key (java.security.Key)12 NoSuchProviderException (java.security.NoSuchProviderException)12 SecureRandom (java.security.SecureRandom)12 SecretKey (javax.crypto.SecretKey)12 KeyStoreException (java.security.KeyStoreException)11 Cipher (javax.crypto.Cipher)11 KeyGenerator (javax.crypto.KeyGenerator)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11 CertificateException (java.security.cert.CertificateException)10