Search in sources :

Example 86 with InvalidParameterException

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

the class KeyPairGenerator2Test method checkResult.

private void checkResult(KeyPairGenerator keyPairGen, int mode) throws InvalidAlgorithmParameterException {
    AlgorithmParameterSpec pp = null;
    switch(mode) {
        case 1:
            try {
                keyPairGen.initialize(pp, new SecureRandom());
                fail("InvalidAlgorithmParameterException must be thrown");
            } catch (InvalidAlgorithmParameterException e) {
            }
            keyPairGen.initialize(1000, new SecureRandom());
            try {
                keyPairGen.initialize(-1024, new SecureRandom());
                fail("InvalidParameterException must be thrown");
            } catch (InvalidParameterException e) {
                assertEquals("Incorrect exception", e.getMessage(), "Incorrect keysize parameter");
            }
            try {
                keyPairGen.initialize(100, null);
                fail("InvalidParameterException must be thrown");
            } catch (InvalidParameterException e) {
                assertEquals("Incorrect exception", e.getMessage(), "Incorrect random");
            }
            keyPairGen.generateKeyPair();
            keyPairGen.genKeyPair();
            break;
        case 2:
            try {
                keyPairGen.initialize(pp, new SecureRandom());
            } catch (UnsupportedOperationException e) {
            // js2e does not throw this exception
            }
            keyPairGen.initialize(1000, new SecureRandom());
            try {
                keyPairGen.initialize(63, new SecureRandom());
                fail("InvalidParameterException must be thrown");
            } catch (InvalidParameterException e) {
            }
            keyPairGen.initialize(100, null);
            assertNull("Not null KeyPair", keyPairGen.generateKeyPair());
            assertNull("Not null KeyPair", keyPairGen.genKeyPair());
            break;
        case 3:
            keyPairGen.initialize(pp, new SecureRandom());
            keyPairGen.initialize(pp);
            keyPairGen.initialize(1000, new SecureRandom());
            keyPairGen.initialize(100);
            assertNotNull("Null KeyPair", keyPairGen.generateKeyPair());
            assertNotNull("Null KeyPair", keyPairGen.genKeyPair());
            break;
        case 4:
            try {
                keyPairGen.initialize(pp, null);
                fail("UnsupportedOperationException must be thrown");
            } catch (UnsupportedOperationException e) {
            }
            keyPairGen.initialize(pp, new SecureRandom());
            keyPairGen.initialize(101, new SecureRandom());
            keyPairGen.initialize(10000);
            try {
                keyPairGen.initialize(101, null);
                fail("IllegalArgumentException must be thrown for null random");
            } catch (IllegalArgumentException e) {
            }
            try {
                keyPairGen.initialize(99, new SecureRandom());
                fail("InvalidParameterException must be thrown for invalid key");
            } catch (InvalidParameterException e) {
            }
            try {
                keyPairGen.initialize(99);
                fail("InvalidParameterException must be thrown for invalid key");
            } catch (InvalidParameterException e) {
            }
            try {
                keyPairGen.initialize(199, null);
                fail("IllegalArgumentException must be thrown for null random");
            } catch (IllegalArgumentException e) {
            }
            assertNull("Not null KeyPair", keyPairGen.generateKeyPair());
            assertNull("Not null KeyPair", keyPairGen.genKeyPair());
            break;
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) SecureRandom(java.security.SecureRandom) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 87 with InvalidParameterException

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

the class InvalidParameterExceptionTest method testInvalidParameterException02.

/**
     * Test for <code>InvalidParameterException(String)</code> constructor
     * Assertion: constructs InvalidParameterException with detail message msg.
     * Parameter <code>msg</code> is not null.
     */
public void testInvalidParameterException02() {
    InvalidParameterException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new InvalidParameterException(msgs[i]);
        assertEquals("getMessage() must return: ".concat(msgs[i]), tE.getMessage(), msgs[i]);
        assertNull("getCause() must return null", tE.getCause());
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException)

Example 88 with InvalidParameterException

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

the class DSAKeyPairGeneratorTest method test_DSAKeyPairGenerator01.

/**
     * java.security.interfaces.DSAKeyPairGenerator
     * #initialize(DSAParams params, SecureRandom random)
     */
public void test_DSAKeyPairGenerator01() {
    DSAParams dsaParams = new DSAParameterSpec(p, q, g);
    SecureRandom random = null;
    MyDSA dsa = new MyDSA(dsaParams);
    try {
        random = SecureRandom.getInstance("SHA1PRNG");
    } catch (Exception e) {
        fail("Unexpected exception for SecureRandom: " + e);
    }
    try {
        dsa.initialize(dsaParams, random);
    } catch (Exception e) {
        fail("Unexpected exception: " + e);
    }
    try {
        dsa.initialize(dsaParams, null);
        fail("InvalidParameterException was not thrown");
    } catch (InvalidParameterException ipe) {
    //expected
    } catch (Exception e) {
        fail(e + " was thrown instead of InvalidParameterException");
    }
    try {
        dsa.initialize(null, random);
        fail("InvalidParameterException was not thrown");
    } catch (InvalidParameterException ipe) {
    //expected
    } catch (Exception e) {
        fail(e + " was thrown instead of InvalidParameterException");
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) InvalidParameterException(java.security.InvalidParameterException) SecureRandom(java.security.SecureRandom) DSAParams(java.security.interfaces.DSAParams) InvalidParameterException(java.security.InvalidParameterException)

Example 89 with InvalidParameterException

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

the class DSAKeyPairGeneratorTest method test_DSAKeyPairGenerator02.

/**
     * java.security.interfaces.DSAKeyPairGenerator
     * #initialize(int modlen, boolean genParams, SecureRandom randomm)
     */
public void test_DSAKeyPairGenerator02() {
    int[] invalidLen = { -1, 0, 511, 513, 650, 1023, 1025 };
    DSAParams dsaParams = new DSAParameterSpec(p, q, g);
    SecureRandom random = null;
    MyDSA dsa = new MyDSA(null);
    try {
        random = SecureRandom.getInstance("SHA1PRNG");
    } catch (Exception e) {
        fail("Unexpected exception for SecureRandom: " + e);
    }
    //exception case
    try {
        dsa.initialize(520, false, random);
        fail("InvalidParameterException was not thrown");
    } catch (InvalidParameterException ipe) {
        String str = ipe.getMessage();
        if (!str.equals("there are not precomputed parameters")) {
            fail("Incorrect exception's message: " + str);
        }
    } catch (Exception e) {
        fail(e + " was thrown instead of InvalidParameterException");
    }
    //exception case
    for (int i = 0; i < invalidLen.length; i++) {
        try {
            dsa.initialize(invalidLen[i], true, random);
            fail("InvalidParameterException was not thrown");
        } catch (InvalidParameterException ipe) {
            String str = ipe.getMessage();
            if (!str.equals("Incorrect modlen")) {
                fail("Incorrect exception's message: " + str);
            }
        } catch (Exception e) {
            fail(e + " was thrown instead of InvalidParameterException");
        }
    }
    //positive case
    dsa = new MyDSA(dsaParams);
    try {
        dsa.initialize(520, true, random);
    } catch (Exception e) {
        fail(e + " was thrown for subcase 1");
    }
    //positive case
    try {
        dsa.initialize(520, false, random);
    } catch (Exception e) {
        fail(e + " was thrown for subcase 1");
    }
}
Also used : DSAParameterSpec(java.security.spec.DSAParameterSpec) InvalidParameterException(java.security.InvalidParameterException) SecureRandom(java.security.SecureRandom) DSAParams(java.security.interfaces.DSAParams) InvalidParameterException(java.security.InvalidParameterException)

Example 90 with InvalidParameterException

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

the class myKeyGenerator method test_initILjava_security_SecureRandom.

public void test_initILjava_security_SecureRandom() throws NoSuchAlgorithmException {
    SecureRandom random = null;
    KeyGenerator kg = null;
    for (int i = 0; i < validAlgorithmsKeyGenerator.length; i++) {
        kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[i]);
        random = new SecureRandom();
        kg.init(validKeySizes[i], random);
        assertNotNull(kg.getProvider());
    }
    kg = KeyGenerator.getInstance(validAlgorithmsKeyGenerator[0]);
    try {
        kg.init(5, random);
        fail("InvalidParameterException expected");
    } catch (InvalidParameterException e) {
    //expected
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) SecureRandom(java.security.SecureRandom) KeyGenerator(javax.crypto.KeyGenerator)

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