Search in sources :

Example 66 with NoSuchProviderException

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

the class NoSuchProviderExceptionTest method testNoSuchProviderException03.

/**
     * Test for <code>NoSuchProviderException(String)</code> constructor
     * Assertion: constructs NoSuchProviderException when <code>msg</code> is
     * null
     */
public void testNoSuchProviderException03() {
    String msg = null;
    NoSuchProviderException tE = new NoSuchProviderException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException)

Example 67 with NoSuchProviderException

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

the class CertificateFactory2Test method GetInstance02.

/**
     * Test for <code>getInstance(String type, String provider)</code> method
     * Assertions:
     * throws NullPointerException when type is null
     * throws CertificateException when type is not available
     * throws IllegalArgumentException when provider is null or empty;
     * throws NoSuchProviderException when provider is available;
     * returns CertificateFactory object
     */
public void GetInstance02(boolean mode) throws CertificateException, NoSuchProviderException, IllegalArgumentException, CRLException {
    try {
        CertificateFactory.getInstance(null, mProv.getName());
        fail("NullPointerException or CertificateException must be thrown when type is null");
    } catch (CertificateException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            CertificateFactory.getInstance(invalidValues[i], mProv.getName());
            fail("CertificateException must be thrown (type: ".concat(invalidValues[i]).concat(")"));
        } catch (CertificateException e) {
        }
    }
    String prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            CertificateFactory.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (type: ".concat(validValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
        try {
            CertificateFactory.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 {
                CertificateFactory.getInstance(validValues[i], invalidValues[j]);
                fail("NoSuchProviderException must be thrown (type: ".concat(validValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
            } catch (NoSuchProviderException e) {
            }
        }
    }
    CertificateFactory cerF;
    for (int i = 0; i < validValues.length; i++) {
        cerF = CertificateFactory.getInstance(validValues[i], mProv.getName());
        assertEquals("Incorrect type", cerF.getType(), validValues[i]);
        assertEquals("Incorrect provider", cerF.getProvider().getName(), mProv.getName());
        checkResult(cerF, mode);
    }
}
Also used : CertificateException(java.security.cert.CertificateException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateFactory(java.security.cert.CertificateFactory)

Example 68 with NoSuchProviderException

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

the class CertificateTest method testVerifyPublicKey2.

/**
     * This test just calls <code>verify(PublicKey)</code> method<br>
     *
     * @throws InvalidKeyException
     * @throws CertificateException
     * @throws NoSuchAlgorithmException
     * @throws NoSuchProviderException
     * @throws SignatureException
     * @throws IOException
     * @throws InvalidAlgorithmParameterException
     */
public final void testVerifyPublicKey2() throws InvalidKeyException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException, InvalidAlgorithmParameterException, IOException {
    Certificate c1 = new MyCertificate("TEST_TYPE", testEncoding);
    c1.verify(null);
    cert.verify(cert.getPublicKey());
    PublicKey k = cert.getPublicKey();
    MyModifiablePublicKey changedEncoding = new MyModifiablePublicKey(k);
    changedEncoding.setEncoding(new byte[cert.getEncoded().length - 1]);
    try {
        cert.verify(c1.getPublicKey());
        fail();
    } catch (InvalidKeyException expected) {
    }
    try {
        cert.verify(changedEncoding);
        fail();
    } catch (Exception expected) {
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) PublicKey(java.security.PublicKey) InvalidKeyException(java.security.InvalidKeyException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ObjectStreamException(java.io.ObjectStreamException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateEncodingException(java.security.cert.CertificateEncodingException) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) MyFailingCertificate(org.apache.harmony.security.tests.support.cert.MyFailingCertificate)

Example 69 with NoSuchProviderException

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

the class CertStore2Test method testGetInstanceStringCertStoreParametersString.

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

Example 70 with NoSuchProviderException

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

the class myCertStore method testCertStore16.

/**
     * Test for <code>getType()</code> method
     */
public void testCertStore16() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    if (!initParams()) {
        return;
    }
    CertStore certS;
    for (int i = 0; i < dValid.length; i++) {
        certS = CertStore.getInstance(dValid[i], dParams);
        assertEquals("Incorrect type", certS.getType(), dValid[i]);
        try {
            certS = CertStore.getInstance(dValid[i], dParams, defaultProviderCol);
            assertEquals("Incorrect type", certS.getType(), dValid[i]);
        } catch (IllegalArgumentException e) {
            fail("Unexpected IllegalArgumentException " + e.getMessage());
        }
        try {
            certS = CertStore.getInstance(dValid[i], dParams, defaultProviderColName);
            assertEquals("Incorrect type", certS.getType(), dValid[i]);
        } catch (NoSuchProviderException e) {
            fail("Unexpected IllegalArgumentException " + e.getMessage());
        }
    }
}
Also used : NoSuchProviderException(java.security.NoSuchProviderException) CertStore(java.security.cert.CertStore)

Aggregations

NoSuchProviderException (java.security.NoSuchProviderException)93 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)67 InvalidKeyException (java.security.InvalidKeyException)30 IOException (java.io.IOException)28 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)18 CertificateException (java.security.cert.CertificateException)18 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)14 Cipher (javax.crypto.Cipher)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 BadPaddingException (javax.crypto.BadPaddingException)12 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)12 KeyStoreException (java.security.KeyStoreException)11 SignatureException (java.security.SignatureException)10 X509Certificate (java.security.cert.X509Certificate)10 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