Search in sources :

Example 91 with InvalidParameterException

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

the class Security2Test method test_getProvidersLjava_lang_String.

/**
     * java.security.Security#getProviders(java.lang.String)
     */
public void test_getProvidersLjava_lang_String() {
    // Test for method void
    // java.security.Security.getProviders(java.lang.String)
    Map<String, Integer> allSupported = new HashMap<String, Integer>();
    Provider[] allProviders = Security.getProviders();
    // Add all non-alias entries to allSupported
    for (Provider provider : allProviders) {
        for (Object k : provider.keySet()) {
            String key = (String) k;
            // No aliases and no provider data
            if (!isAlias(key) && !isProviderData(key)) {
                addOrIncrementTable(allSupported, key);
            }
        }
    // end while more entries
    }
    // entry that is being aliased.
    for (Provider provider : allProviders) {
        for (Map.Entry entry : provider.entrySet()) {
            String key = (String) entry.getKey();
            if (isAlias(key)) {
                String aliasName = key.substring("ALG.ALIAS.".length()).toUpperCase();
                String realName = aliasName.substring(0, aliasName.indexOf(".") + 1) + entry.getValue();
                // aliased are identical. Such entries can occur.
                if (!aliasName.equalsIgnoreCase(realName)) {
                    // Has a real entry been added for aliasName ?
                    if (allSupported.containsKey(aliasName)) {
                        // Add 1 to the provider count of the thing being aliased
                        addOrIncrementTable(allSupported, aliasName);
                    }
                }
            }
        }
    // end while more entries
    }
    for (String filterString : allSupported.keySet()) {
        try {
            Provider[] provTest = Security.getProviders(filterString);
            int expected = allSupported.get(filterString);
            assertEquals("Unexpected number of providers returned for filter " + filterString + ":\n" + allSupported, expected, provTest.length);
        } catch (InvalidParameterException e) {
        // NO OP
        }
    }
    // exception
    try {
        Security.getProviders("Signature.SHA1withDSA :512");
        fail("InvalidParameterException should be thrown <Signature.SHA1withDSA :512>");
    } catch (InvalidParameterException e) {
    // Expected
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Support_TestProvider(tests.support.Support_TestProvider) Provider(java.security.Provider)

Example 92 with InvalidParameterException

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

the class SecurityTest method test_getProvidersLjava_util_Map.

/**
     * java.security.Security#getProviders(java.util.Map)
     */
public void test_getProvidersLjava_util_Map() {
    Map<String, String> m = new HashMap<String, String>();
    Security.getProviders(m);
    assertNull("Not null result on empty map", Security.getProviders(m));
    try {
        Security.getProviders((Map<String, String>) null);
        fail("No expected NullPointerException");
    } catch (NullPointerException e) {
    }
    // key has dot instead of space
    m.put("AAA.BBB.CCC", "aaaa");
    try {
        Security.getProviders(m);
        fail("No expected InvalidParameterException");
    } catch (InvalidParameterException e) {
    }
    Provider p = new MyProvider();
    try {
        Security.addProvider(p);
        m.clear();
        m.put("MyService.MyAlgorithm", "");
        m.put("MessageDigest.SHA-1", "");
        assertTrue("MyService.MyAlgorithm", Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
        m.clear();
        m.put("MyService.MyAlgorithm KeySize", "512");
        m.put("MessageDigest.SHA-1", "");
        assertTrue("MyService.MyAlgorithm KeySize:512", Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
        m.clear();
        m.put("MyService.MyAlgorithm KeySize", "1025");
        m.put("MessageDigest.SHA-1", "");
        assertNull("MyService.MyAlgorithm KeySize:1025", Security.getProviders(m));
        // attribute name and value are case insensitive
        m.clear();
        m.put("MyService.MyAlgorithm imPLementedIn", "softWARE");
        assertTrue(Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
        m.clear();
        m.put("MyService.MyAlgorithm ATTribute", "attributeVALUE");
        assertTrue(Arrays.equals(new Provider[] { p }, Security.getProviders(m)));
        // Regression for HARMONY-2761
        m.clear();
        m.put("MyService.NoKeySize KeySize", "512");
        assertNull("No KeySize attribute", Security.getProviders(m));
        m.clear();
        m.put("MyService.NoImplementedIn ImplementedIn", "Software");
        assertNull("No ImplementedIn attribute", Security.getProviders(m));
        m.clear();
        m.put("ABCService.NoAttribute Attribute", "ABC");
        assertNull(Security.getProviders(m));
    } finally {
        // clean up
        Security.removeProvider(p.getName());
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) HashMap(java.util.HashMap) Provider(java.security.Provider)

Example 93 with InvalidParameterException

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

the class SignatureTest method testSetParameterStringObject.

/*
     * Class under test for void setParameter(String, Object)
     */
@SuppressWarnings("deprecation")
public void testSetParameterStringObject() {
    MySignature1 s = new MySignature1("ABC");
    s.setParameter("aaa", new Object());
    try {
        Signature sig = getTestSignature();
        sig.setParameter("TestParam", new Integer(42));
        fail("expected InvalidParameterException");
    } catch (InvalidParameterException e) {
    // expected
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected: " + e);
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) Signature(java.security.Signature) MySignature1(org.apache.harmony.security.tests.support.MySignature1) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 94 with InvalidParameterException

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

the class Signature2Test method test_setParameterLjava_security_spec_AlgorithmParameterSpec.

/**
     * java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)
     */
public void test_setParameterLjava_security_spec_AlgorithmParameterSpec() throws Exception {
    Signature sig = Signature.getInstance("DSA");
    try {
        DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE, BigInteger.ONE, BigInteger.ONE);
        sig.setParameter(spec);
    } catch (InvalidParameterException e) {
    // Could be that it's an invalid param for the found algorithm
    } catch (UnsupportedOperationException e) {
    // Could be that the operation is not supported
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) InvalidParameterException(java.security.InvalidParameterException) Signature(java.security.Signature)

Example 95 with InvalidParameterException

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

the class PKIXBuilderParametersTest method testSetMaxPathLength.

/**
     * Test for <code>setMaxPathLength()</code>
     */
public final void testSetMaxPathLength() throws Exception {
    KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
    keyTest.load(null, null);
    ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
    ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[2];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
    keyTest.setCertificateEntry("alias1", cert[0]);
    keyTest.setCertificateEntry("alias2", cert[0]);
    keyTest.setCertificateEntry("alias3", cert[1]);
    PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
    assertEquals(5, p.getMaxPathLength());
    p.setMaxPathLength(10);
    assertEquals(10, p.getMaxPathLength());
    p.setMaxPathLength(0);
    assertEquals(0, p.getMaxPathLength());
    p.setMaxPathLength(-1);
    assertEquals(-1, p.getMaxPathLength());
    int[] maxPathLength = { -2, -10, Integer.MIN_VALUE };
    for (int i = 0; i < maxPathLength.length; i++) {
        try {
            p.setMaxPathLength(maxPathLength[i]);
            fail("InvalidParameterException expected ");
        } catch (InvalidParameterException e) {
        // expected
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) ByteArrayInputStream(java.io.ByteArrayInputStream) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

InvalidParameterException (java.security.InvalidParameterException)135 SecureRandom (java.security.SecureRandom)15 ActionEvent (com.cloud.event.ActionEvent)11 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)9 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 Paint (android.graphics.Paint)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 DB (com.cloud.utils.db.DB)7 File (java.io.File)7 Properties (java.util.Properties)7 NimbusClient (backtype.storm.utils.NimbusClient)6 FirewallRule (com.cloud.network.rules.FirewallRule)6 InvalidKeyException (java.security.InvalidKeyException)6 Time (android.text.format.Time)4 FileNotFoundException (java.io.FileNotFoundException)4