Search in sources :

Example 46 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class X509CertificateTest method generateCertificates_X509_PEM_TrailingData.

private void generateCertificates_X509_PEM_TrailingData(CertificateFactory f) throws Exception {
    byte[] certBytes = getResourceAsBytes(CERTS_X509_PEM);
    byte[] certsPlusExtra = new byte[certBytes.length + 4096];
    System.arraycopy(certBytes, 0, certsPlusExtra, 0, certBytes.length);
    ByteArrayInputStream bais = new ByteArrayInputStream(certsPlusExtra);
    assertEquals(certsPlusExtra.length, bais.available());
    // RI is broken
    try {
        Collection<? extends X509Certificate> certs = (Collection<? extends X509Certificate>) f.generateCertificates(bais);
        if (StandardNames.IS_RI) {
            fail("RI fails on this test.");
        }
    } catch (CertificateParsingException e) {
        if (StandardNames.IS_RI) {
            return;
        }
        throw e;
    }
    // Bouncycastle is broken
    if ("BC".equals(f.getProvider().getName())) {
        assertEquals(0, bais.available());
    } else {
        assertEquals(4096, bais.available());
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) ByteArrayInputStream(java.io.ByteArrayInputStream) Collection(java.util.Collection) X509Certificate(java.security.cert.X509Certificate)

Example 47 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class CertificateParsingExceptionTest method testCertificateParsingException09.

/**
     * Test for <code>CertificateParsingException(String, Throwable)</code>
     * constructor Assertion: constructs CertificateParsingException when
     * <code>cause</code> is not null <code>msg</code> is not null
     */
public void testCertificateParsingException09() {
    CertificateParsingException tE;
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertificateParsingException(msgs[i], tCause);
        String getM = tE.getMessage();
        String toS = tCause.toString();
        if (msgs[i].length() > 0) {
            assertTrue("getMessage() must contain ".concat(msgs[i]), getM.indexOf(msgs[i]) != -1);
            if (!getM.equals(msgs[i])) {
                assertTrue("getMessage() should contain ".concat(toS), getM.indexOf(toS) != -1);
            }
        }
        assertNotNull("getCause() must not return null", tE.getCause());
        assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException)

Example 48 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class CertificateParsingExceptionTest method testCertificateParsingException02.

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

Example 49 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project robovm by robovm.

the class CertificateParsingExceptionTest method testCertificateParsingException04.

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

Example 50 with CertificateParsingException

use of java.security.cert.CertificateParsingException in project XobotOS by xamarin.

the class X509V3CertificateGenerator method generate.

/**
     * generate an X509 certificate, based on the current issuer and subject,
     * using the passed in provider for the signing and the supplied source
     * of randomness, if required.
     */
public X509Certificate generate(PrivateKey key, String provider, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    TBSCertificateStructure tbsCert = generateTbsCert();
    byte[] signature;
    try {
        signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, provider, key, random, tbsCert);
    } catch (IOException e) {
        throw new ExtCertificateEncodingException("exception encoding TBS cert", e);
    }
    try {
        return generateJcaObject(tbsCert, signature);
    } catch (CertificateParsingException e) {
        throw new ExtCertificateEncodingException("exception producing certificate object", e);
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) TBSCertificateStructure(org.bouncycastle.asn1.x509.TBSCertificateStructure) IOException(java.io.IOException)

Aggregations

CertificateParsingException (java.security.cert.CertificateParsingException)75 List (java.util.List)27 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 X509Certificate (java.security.cert.X509Certificate)16 CertificateException (java.security.cert.CertificateException)14 Collection (java.util.Collection)13 X500Principal (javax.security.auth.x500.X500Principal)13 BigInteger (java.math.BigInteger)8 InvalidKeyException (java.security.InvalidKeyException)7 HashMap (java.util.HashMap)7 DERIA5String (org.bouncycastle.asn1.DERIA5String)7 DEROctetString (org.bouncycastle.asn1.DEROctetString)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 NoSuchProviderException (java.security.NoSuchProviderException)6 SignatureException (java.security.SignatureException)6 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 CertificateExpiredException (java.security.cert.CertificateExpiredException)6 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)6 GeneralName (org.bouncycastle.asn1.x509.GeneralName)6