Search in sources :

Example 66 with Provider

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

the class SecurityTest method test_getProviderLjava_lang_String.

/**
     * java.security.Security#getProvider(String)
     */
public final void test_getProviderLjava_lang_String() {
    // Returns null if no provider with the specified name is installed
    assertNull(Security.getProvider("SOMEINCORRECTPROVIDERNAME"));
    // Returns null if name is null
    assertNull(Security.getProvider(null));
    // test for existing providers
    Provider[] providers = Security.getProviders();
    assertTrue("getProviders returned zero length array", providers.length > 0);
    for (Provider p : providers) {
        String providerName = p.getName();
        assertSame(p, Security.getProvider(providerName));
    }
    // test for newly installed provider
    Provider p = new MyProvider();
    try {
        Security.addProvider(p);
        assertSame(p, Security.getProvider(p.getName()));
    } finally {
        // clean up
        Security.removeProvider(p.getName());
    }
}
Also used : Provider(java.security.Provider)

Example 67 with Provider

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

the class Signature2Test method test_initVerifyLjava_security_Certificate.

/**
     * java.security.Signature#initVerify(java.security.cert.Certificate)
     */
public void test_initVerifyLjava_security_Certificate() throws Exception {
    Provider p = new MyProvider();
    p.put("DSA", "tests.java.security.support.cert.MyCertificate$1");
    Provider myProvider = new MyProvider();
    Security.addProvider(myProvider);
    try {
        Provider[] pp = Security.getProviders();
        if (pp == null) {
            return;
        }
        try {
            Signature.getInstance("DSA").initVerify((Certificate) null);
            fail();
        } catch (NullPointerException expected) {
        }
    } finally {
        Security.removeProvider(myProvider.getName());
    }
}
Also used : Provider(java.security.Provider)

Example 68 with Provider

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

the class Signature2Test method test_getInstanceLjava_lang_StringLjava_lang_String_java_security_Provider.

/**
     * java.security.Signature#getInstance(java.lang.String,
     *        java.security.Provider)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String_java_security_Provider() throws Exception {
    Provider[] providers = Security.getProviders("Signature.DSA");
    for (int i = 0; i < providers.length; i++) {
        Signature signature = Signature.getInstance("DSA", providers[i]);
        assertEquals("DSA", signature.getAlgorithm());
        assertEquals(providers[i], signature.getProvider());
    }
    try {
        Signature.getInstance((String) null, (Provider) null);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        Signature.getInstance("DSA", (Provider) null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        Signature.getInstance((String) null, providers[0]);
        fail();
    } catch (NullPointerException expected) {
    }
    try {
        Signature.getInstance("bogus", providers[0]);
        fail();
    } catch (NoSuchAlgorithmException expected) {
    }
}
Also used : Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Provider(java.security.Provider)

Example 69 with Provider

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

the class MessageDigest2Test method test_getInstanceLjava_lang_StringLjava_lang_String.

/**
     * java.security.MessageDigest#getInstance(java.lang.String,
     *        java.lang.String)
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
    for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
        for (String algorithm : e.getValue()) {
            MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
            assertNotNull(md);
        }
    }
    for (List<String> algorithms : digestAlgs.values()) {
        for (String algorithm : algorithms) {
            try {
                MessageDigest.getInstance(algorithm, "UnknownProvider");
                fail("expected NoSuchProviderException");
            } catch (NoSuchProviderException expected) {
            }
        }
    }
    for (Provider provider : digestAlgs.keySet()) {
        try {
            MessageDigest.getInstance("UnknownDigest", provider.getName());
            fail("expected NoSuchAlgorithmException");
        } catch (NoSuchAlgorithmException expected) {
        }
    }
    for (Provider provider : digestAlgs.keySet()) {
        try {
            MessageDigest.getInstance(null, provider.getName());
            fail("expected NullPointerException");
        } catch (NullPointerException expected) {
        }
    }
    try {
        MessageDigest.getInstance("AnyDigest", (String) null);
        fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) NoSuchProviderException(java.security.NoSuchProviderException) Provider(java.security.Provider)

Example 70 with Provider

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

the class MessageDigest2Test method test_getAlgorithm.

/**
     * java.security.MessageDigest#getAlgorithm()
     */
public void test_getAlgorithm() throws Exception {
    for (Entry<Provider, List<String>> e : digestAlgs.entrySet()) {
        for (String algorithm : e.getValue()) {
            MessageDigest md = MessageDigest.getInstance(algorithm, e.getKey().getName());
            assertEquals(algorithm, md.getAlgorithm());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MessageDigest(java.security.MessageDigest) Provider(java.security.Provider)

Aggregations

Provider (java.security.Provider)243 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)49 ArrayList (java.util.ArrayList)26 MessageDigest (java.security.MessageDigest)21 List (java.util.List)20 Key (java.security.Key)19 KeyStore (java.security.KeyStore)19 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 SecureRandom (java.security.SecureRandom)13 IOException (java.io.IOException)12 NoSuchProviderException (java.security.NoSuchProviderException)12 SecretKey (javax.crypto.SecretKey)12 KeyStoreException (java.security.KeyStoreException)11 CertificateException (java.security.cert.CertificateException)11 Cipher (javax.crypto.Cipher)11 KeyGenerator (javax.crypto.KeyGenerator)11 MyExemptionMechanismSpi.tmpKey (org.apache.harmony.crypto.tests.support.MyExemptionMechanismSpi.tmpKey)11