Search in sources :

Example 81 with Provider

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

the class invalidParams method testCertPathValidator08.

/**
     * Test for <code>getInstance(String algorithm, Provider provider)</code> method
     * Assertion: throws IllegalArgumentException when provider is null
     */
public void testCertPathValidator08() throws NoSuchAlgorithmException {
    if (!PKIXSupport) {
        fail(NotSupportMsg);
        return;
    }
    Provider prov = null;
    for (int t = 0; t < validValues.length; t++) {
        try {
            CertPathValidator.getInstance(validValues[t], prov);
            fail("IllegalArgumentException must be thrown");
        } catch (IllegalArgumentException e1) {
        }
    }
}
Also used : Provider(java.security.Provider)

Example 82 with Provider

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

the class CertPathValidator2Test method testGetInstance03.

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

Example 83 with Provider

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

the class myCertificateFactory method testCertificateFactory06.

/**
     * Test for <code>getInstance(String type, Provider provider)</code>
     * method
     * Assertion: throws IllegalArgumentException when provider is null
     */
public void testCertificateFactory06() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    Provider provider = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertificateFactory.getInstance(validValues[i], provider);
            fail("IllegalArgumentException must be thrown  when provider is null");
        } catch (IllegalArgumentException e) {
        }
    }
}
Also used : Provider(java.security.Provider)

Example 84 with Provider

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

the class ECDHKeyAgreementTest method invokeCallingMethodForEachKeyAgreementProvider.

private void invokeCallingMethodForEachKeyAgreementProvider() throws Exception {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String callingMethodName = null;
    for (int i = 0; i < stackTrace.length; i++) {
        if ("invokeCallingMethodForEachKeyAgreementProvider".equals(stackTrace[i].getMethodName())) {
            callingMethodName = stackTrace[i + 1].getMethodName();
        }
    }
    if (callingMethodName == null) {
        throw new RuntimeException("Failed to deduce calling method name from stack trace");
    }
    String invokedMethodName = callingMethodName;
    Method method;
    try {
        method = getClass().getDeclaredMethod(invokedMethodName, Provider.class);
    } catch (NoSuchMethodError e) {
        throw new AssertionFailedError("Failed to find per-Provider test method " + getClass().getSimpleName() + "." + invokedMethodName + "(Provider)");
    }
    for (Provider provider : getKeyAgreementProviders()) {
        try {
            method.invoke(this, provider);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(getClass().getSimpleName() + "." + invokedMethodName + "(provider: " + provider.getName() + ") failed", e.getCause());
        }
    }
}
Also used : Method(java.lang.reflect.Method) AssertionFailedError(junit.framework.AssertionFailedError) InvocationTargetException(java.lang.reflect.InvocationTargetException) Provider(java.security.Provider)

Example 85 with Provider

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

the class SSLContextTest method test_SSLContext_getProvider.

public void test_SSLContext_getProvider() throws Exception {
    Provider provider = SSLContext.getDefault().getProvider();
    assertNotNull(provider);
    assertEquals(StandardNames.JSSE_PROVIDER_NAME, provider.getName());
}
Also used : 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