Search in sources :

Example 11 with CertificateParsingException

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

the class CertificateParsingExceptionTest method testCertificateParsingException05.

/**
     * Test for <code>CertificateParsingException(Throwable)</code>
     * constructor Assertion: constructs CertificateParsingException when
     * <code>cause</code> is not null
     */
public void testCertificateParsingException05() {
    CertificateParsingException tE = new CertificateParsingException(tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        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 12 with CertificateParsingException

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

the class CertificateParsingExceptionTest method testCertificateParsingException01.

/**
     * Test for <code>CertificateParsingException()</code> constructor
     * Assertion: constructs CertificateParsingException with no detail message
     */
public void testCertificateParsingException01() {
    CertificateParsingException tE = new CertificateParsingException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException)

Example 13 with CertificateParsingException

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

the class X509CertificateTest method generateCertificates_X509_DER_TrailingData.

private void generateCertificates_X509_DER_TrailingData(CertificateFactory f) throws Exception {
    byte[] certBytes = getResourceAsBytes(CERTS_X509_DER);
    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 14 with CertificateParsingException

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

the class X509V3CertificateGenerator method generate.

/**
     * generate an X509 certificate, based on the current issuer and subject
     * using the default provider, and the passed in source of randomness
     * (if required).
     * <p>
     * <b>Note:</b> this differs from the deprecated method in that the default provider is
     * used - not "BC".
     * </p>
     */
public X509Certificate generate(PrivateKey key, SecureRandom random) throws CertificateEncodingException, IllegalStateException, NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    TBSCertificate tbsCert = generateTbsCert();
    byte[] signature;
    try {
        signature = X509Util.calculateSignature(sigOID, signatureAlgorithm, 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) IOException(java.io.IOException) TBSCertificate(org.bouncycastle.asn1.x509.TBSCertificate)

Example 15 with CertificateParsingException

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

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 {
    TBSCertificate 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) IOException(java.io.IOException) TBSCertificate(org.bouncycastle.asn1.x509.TBSCertificate)

Aggregations

CertificateParsingException (java.security.cert.CertificateParsingException)72 List (java.util.List)25 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)18 X509Certificate (java.security.cert.X509Certificate)15 CertificateException (java.security.cert.CertificateException)13 Collection (java.util.Collection)12 X500Principal (javax.security.auth.x500.X500Principal)11 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