Search in sources :

Example 31 with NoSuchProviderException

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

the class CertPathValidator2Test method testGetInstance02.

/**
     * Test for <code>getInstance(String algorithm, String provider)</code>
     * method Assertions: throws NullPointerException when algorithm is null
     * throws NoSuchAlgorithmException when algorithm is not available throws
     * IllegalArgumentException when provider is null or empty; throws
     * NoSuchProviderException when provider is available; returns
     * CertPathValidator object
     */
public void testGetInstance02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException, CertPathValidatorException {
    try {
        CertPathValidator.getInstance(null, mProv.getName());
        fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null");
    } catch (NullPointerException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            CertPathValidator.getInstance(invalidValues[i], mProv.getName());
            fail("NoSuchAlgorithmException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
        } catch (NoSuchAlgorithmException e) {
        }
    }
    String prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertPathValidator.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (type: ".concat(validValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
        try {
            CertPathValidator.getInstance(validValues[i], "");
            fail("IllegalArgumentException must be thrown when provider is empty (type: ".concat(validValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
    }
    for (int i = 0; i < validValues.length; i++) {
        for (int j = 1; j < invalidValues.length; j++) {
            try {
                CertPathValidator.getInstance(validValues[i], invalidValues[j]);
                fail("NoSuchProviderException must be thrown (type: ".concat(validValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
            } catch (NoSuchProviderException e) {
            }
        }
    }
    CertPathValidator cerPV;
    for (int i = 0; i < validValues.length; i++) {
        cerPV = CertPathValidator.getInstance(validValues[i], mProv.getName());
        assertEquals("Incorrect type", cerPV.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", cerPV.getProvider().getName(), mProv.getName());
        checkResult(cerPV);
    }
}
Also used : CertPathValidator(java.security.cert.CertPathValidator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 32 with NoSuchProviderException

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

the class myCertificateFactory method testCertificateFactory18.

/**
     * Test for <code>getType()</code> method
     */
public void testCertificateFactory18() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertificateFactory certF = CertificateFactory.getInstance(validValues[i]);
            assertEquals("Incorrect type: ", validValues[i], certF.getType());
            certF = CertificateFactory.getInstance(validValues[i], defaultProviderName);
            assertEquals("Incorrect type", certF.getType(), validValues[i]);
            certF = CertificateFactory.getInstance(validValues[i], defaultProvider);
            assertEquals("Incorrect provider", certF.getProvider(), defaultProvider);
            assertEquals("Incorrect type", certF.getType(), validValues[i]);
        } catch (NoSuchProviderException e) {
            fail("Unexpected NoSuchProviderException " + e.getMessage());
        }
    }
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) CertificateFactory(java.security.cert.CertificateFactory)

Example 33 with NoSuchProviderException

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

the class invalidParams method testCertPathValidator14.

/**
     * Test for <code>getProvider()</code> method
     */
public void testCertPathValidator14() throws NoSuchAlgorithmException {
    if (!PKIXSupport) {
        fail(NotSupportMsg);
        return;
    }
    CertPathValidator certPV;
    for (int i = 0; i < validValues.length; i++) {
        try {
            certPV = CertPathValidator.getInstance(validValues[i], defaultProviderName);
            assertEquals("Incorrect provider", certPV.getProvider(), defaultProvider);
        } catch (NoSuchProviderException e) {
            fail("Unexpected NoSuchProviderException " + e.getMessage());
        }
        certPV = CertPathValidator.getInstance(validValues[i], defaultProvider);
        assertEquals("Incorrect provider", certPV.getProvider(), defaultProvider);
    }
}
Also used : CertPathValidator(java.security.cert.CertPathValidator) NoSuchProviderException(java.security.NoSuchProviderException)

Example 34 with NoSuchProviderException

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

the class KeyFactoryTest method testGetInstanceStringString.

@SuppressWarnings("unchecked")
public void testGetInstanceStringString() {
    try {
        KeyFactory factory = KeyFactory.getInstance(TEST_KEYFACTORY_NAME, TEST_PROVIDER_NAME);
        assertNotNull(factory);
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (NoSuchProviderException e) {
        fail("unexpected exception: " + e);
    }
    String[][] combinations = { { "UnknownKeyFactory", TEST_PROVIDER_NAME }, { TEST_KEYFACTORY_NAME, "UnknownProvider" }, { TEST_KEYFACTORY_NAME, existingProvider.getName() }, { null, TEST_PROVIDER_NAME }, { TEST_KEYFACTORY_NAME, null }, { null, null } };
    Class[] exceptions = { NoSuchAlgorithmException.class, NoSuchProviderException.class, NoSuchAlgorithmException.class, NullPointerException.class, IllegalArgumentException.class, IllegalArgumentException.class };
    for (int i = 0; i < combinations.length; i++) {
        String[] combination = combinations[i];
        String message = "getInstance(\"" + combination[0] + "\", \"" + combination[1] + "\")";
        exceptionThrown = false;
        try {
            KeyFactory.getInstance(combination[0], combination[1]);
        } catch (Exception e) {
            checkException(message, e, exceptions[i]);
        } finally {
            checkException(message, null, exceptions[i]);
        }
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) KeyFactory(java.security.KeyFactory) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 35 with NoSuchProviderException

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

the class CertPathBuilder2Test method testGetInstance02.

/**
     * Test for <code>getInstance(String algorithm, String provider)</code> method
     * Assertions:
     * throws NullPointerException when algorithm is null
     * throws NoSuchAlgorithmException when algorithm  is not correct
     * throws IllegalArgumentException when provider is null or empty;
     * throws NoSuchProviderException when provider is available;
     * returns CertPathBuilder object
     */
public void testGetInstance02() throws NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException, InvalidAlgorithmParameterException, CertPathBuilderException {
    try {
        CertPathBuilder.getInstance(null, mProv.getName());
        fail("NullPointerException or NoSuchAlgorithmException must be thrown when algorithm is null");
    } catch (NullPointerException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            CertPathBuilder.getInstance(invalidValues[i], mProv.getName());
            fail("NoSuchAlgorithmException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
        } catch (NoSuchAlgorithmException e) {
        }
    }
    String prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertPathBuilder.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (type: ".concat(validValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
        try {
            CertPathBuilder.getInstance(validValues[i], "");
            fail("IllegalArgumentException must be thrown when provider is empty (type: ".concat(validValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
    }
    for (int i = 0; i < validValues.length; i++) {
        for (int j = 1; j < invalidValues.length; j++) {
            try {
                CertPathBuilder.getInstance(validValues[i], invalidValues[j]);
                fail("NoSuchProviderException must be thrown (type: ".concat(validValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
            } catch (NoSuchProviderException e) {
            }
        }
    }
    CertPathBuilder cerPB;
    for (int i = 0; i < validValues.length; i++) {
        cerPB = CertPathBuilder.getInstance(validValues[i], mProv.getName());
        assertEquals("Incorrect type", cerPB.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", cerPB.getProvider().getName(), mProv.getName());
        checkResult(cerPB);
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertPathBuilder(java.security.cert.CertPathBuilder) NoSuchProviderException(java.security.NoSuchProviderException)

Aggregations

NoSuchProviderException (java.security.NoSuchProviderException)97 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)70 InvalidKeyException (java.security.InvalidKeyException)31 IOException (java.io.IOException)29 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)20 CertificateException (java.security.cert.CertificateException)19 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)14 Cipher (javax.crypto.Cipher)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 KeyStoreException (java.security.KeyStoreException)12 X509Certificate (java.security.cert.X509Certificate)12 BadPaddingException (javax.crypto.BadPaddingException)12 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)12 SignatureException (java.security.SignatureException)11 SecretKey (javax.crypto.SecretKey)10 CertificateFactory (java.security.cert.CertificateFactory)9 CertificateEncodingException (java.security.cert.CertificateEncodingException)8 IvParameterSpec (javax.crypto.spec.IvParameterSpec)8 KeyStore (java.security.KeyStore)7 Provider (java.security.Provider)7