Search in sources :

Example 21 with InvalidAlgorithmParameterException

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

the class KeyManagerFactorySpiTest method test_engineInit_02.

/**
     * javax.net.ssl.KeyManagerFactorySpi#KengineInit(ManagerFactoryParameters spec)
     */
public void test_engineInit_02() {
    KeyManagerFactorySpiImpl kmf = new KeyManagerFactorySpiImpl();
    try {
        kmf.engineInit(null);
        fail("InvalidAlgorithmParameterException wasn't thrown");
    } catch (InvalidAlgorithmParameterException iape) {
    //expected
    } catch (Exception e) {
        fail(e + " was thrown instead of InvalidAlgorithmParameterException");
    }
    try {
        char[] psw = "password".toCharArray();
        Parameters pr = new Parameters(psw);
        kmf.engineInit(pr);
    } catch (Exception e) {
        fail(e + " unexpected exception was thrown");
    }
}
Also used : KeyManagerFactorySpiImpl(org.apache.harmony.xnet.tests.support.KeyManagerFactorySpiImpl) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ManagerFactoryParameters(javax.net.ssl.ManagerFactoryParameters) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException)

Example 22 with InvalidAlgorithmParameterException

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

the class KeyManagerFactory2Test method checkResult.

private void checkResult(KeyManagerFactory keyMF) throws Exception {
    KeyStore kStore = null;
    ManagerFactoryParameters mfp = null;
    char[] pass = { 'a', 'b', 'c' };
    try {
        keyMF.init(kStore, null);
        fail("KeyStoreException must be thrown");
    } catch (KeyStoreException e) {
    }
    try {
        keyMF.init(kStore, pass);
        fail("UnrecoverableKeyException must be thrown");
    } catch (UnrecoverableKeyException e) {
    }
    try {
        keyMF.init(mfp);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    }
    assertNull("getKeyManagers() should return null object", keyMF.getKeyManagers());
    try {
        kStore = KeyStore.getInstance(KeyStore.getDefaultType());
        kStore.load(null, null);
    } catch (KeyStoreException e) {
        fail("default keystore is not supported");
        return;
    }
    keyMF.init(kStore, pass);
    mfp = new MyKeyManagerFactorySpi.Parameters(kStore, null);
    try {
        keyMF.init(mfp);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    }
    mfp = new MyKeyManagerFactorySpi.Parameters(kStore, pass);
    keyMF.init(mfp);
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) MyKeyManagerFactorySpi(org.apache.harmony.xnet.tests.support.MyKeyManagerFactorySpi) ManagerFactoryParameters(javax.net.ssl.ManagerFactoryParameters)

Example 23 with InvalidAlgorithmParameterException

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

the class invalidParams method testCertPathValidator11.

/**
     * Test for <code>validate(CertPath certpath, CertPathParameters params)</code> method
     * Assertion: throws InvalidAlgorithmParameterException params is not
     * instance of PKIXParameters or null
     */
public void testCertPathValidator11() throws NoSuchAlgorithmException, NoSuchProviderException, CertPathValidatorException {
    if (!PKIXSupport) {
        fail(NotSupportMsg);
        return;
    }
    CertPathValidator[] certPV = createCPVs();
    assertNotNull("CertPathValidator objects were not created", certPV);
    MyCertPath mCP = new MyCertPath(new byte[0]);
    invalidParams mPar = new invalidParams();
    for (int i = 0; i < certPV.length; i++) {
        try {
            certPV[i].validate(mCP, mPar);
            fail("InvalidAlgorithmParameterException must be thrown");
        } catch (InvalidAlgorithmParameterException e) {
        }
        try {
            certPV[i].validate(mCP, null);
            fail("InvalidAlgorithmParameterException must be thrown");
        } catch (InvalidAlgorithmParameterException e) {
        }
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPathValidator(java.security.cert.CertPathValidator) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException)

Example 24 with InvalidAlgorithmParameterException

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

the class CertPathValidatorSpiTest method testCertPathValidatorSpi01.

/**
     * Test for <code>CertPathValidatorSpi</code> constructor Assertion:
     * constructs CertPathValidatorSpi
     */
public void testCertPathValidatorSpi01() throws CertPathValidatorException, InvalidAlgorithmParameterException {
    CertPathValidatorSpi certPathValid = new MyCertPathValidatorSpi();
    CertPathParameters params = null;
    CertPath certPath = null;
    CertPathValidatorResult cpvResult = certPathValid.engineValidate(certPath, params);
    assertNull("Not null CertPathValidatorResult", cpvResult);
    try {
        certPathValid.engineValidate(certPath, params);
        fail("CertPathValidatorException must be thrown");
    } catch (CertPathValidatorException e) {
    }
    try {
        certPathValid.engineValidate(certPath, params);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertPathParameters(java.security.cert.CertPathParameters) CertPath(java.security.cert.CertPath) CertPathValidatorResult(java.security.cert.CertPathValidatorResult) MyCertPathValidatorSpi(org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi) MyCertPathValidatorSpi(org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi) CertPathValidatorSpi(java.security.cert.CertPathValidatorSpi)

Example 25 with InvalidAlgorithmParameterException

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

the class CertStore2Test method testGetInstanceStringCertStoreParametersProvider.

public void testGetInstanceStringCertStoreParametersProvider() {
    try {
        CertStoreParameters parameters = new MyCertStoreParameters();
        CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, parameters, provider);
        assertNotNull(certStore);
        assertNotNull(certStore.getCertStoreParameters());
        assertNotSame(parameters, certStore.getCertStoreParameters());
        assertSame(provider, certStore.getProvider());
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore certStore = CertStore.getInstance(CERT_STORE_NAME, null, provider);
        assertNotNull(certStore);
        assertNull(certStore.getCertStoreParameters());
        assertSame(provider, certStore.getProvider());
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore.getInstance("UnknownCertStore", null, provider);
        fail("expected NoSuchAlgorithmException");
    } catch (NoSuchAlgorithmException e) {
    // ok
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    }
    try {
        CertStore.getInstance(CERT_STORE_NAME, new MyOtherCertStoreParameters(), provider);
        fail("expected InvalidAlgorithmParameterException");
    } catch (NoSuchAlgorithmException e) {
        fail("unexpected exception: " + e);
    } catch (InvalidAlgorithmParameterException e) {
    // ok
    }
}
Also used : CertStoreParameters(java.security.cert.CertStoreParameters) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertStore(java.security.cert.CertStore)

Aggregations

InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)394 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)216 InvalidKeyException (java.security.InvalidKeyException)206 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)130 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)114 BadPaddingException (javax.crypto.BadPaddingException)112 Cipher (javax.crypto.Cipher)101 IvParameterSpec (javax.crypto.spec.IvParameterSpec)100 IOException (java.io.IOException)74 SecretKeySpec (javax.crypto.spec.SecretKeySpec)58 NoSuchProviderException (java.security.NoSuchProviderException)56 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)49 CertificateException (java.security.cert.CertificateException)45 KeyStoreException (java.security.KeyStoreException)43 SecureRandom (java.security.SecureRandom)37 SecretKey (javax.crypto.SecretKey)34 BigInteger (java.math.BigInteger)31 KeyPairGenerator (java.security.KeyPairGenerator)27 UnrecoverableKeyException (java.security.UnrecoverableKeyException)27 X509Certificate (java.security.cert.X509Certificate)27