Search in sources :

Example 1 with ParsingException

use of org.conscrypt.OpenSSLX509CertificateFactory.ParsingException in project robovm by robovm.

the class OpenSSLX509CertPath method fromPkcs7Encoding.

private static CertPath fromPkcs7Encoding(InputStream inStream) throws CertificateException {
    try {
        if (inStream == null || inStream.available() == 0) {
            return new OpenSSLX509CertPath(Collections.<X509Certificate>emptyList());
        }
    } catch (IOException e) {
        throw new CertificateException("Problem reading input stream", e);
    }
    final boolean markable = inStream.markSupported();
    if (markable) {
        inStream.mark(PUSHBACK_SIZE);
    }
    /* Attempt to see if this is a PKCS#7 bag. */
    final PushbackInputStream pbis = new PushbackInputStream(inStream, PUSHBACK_SIZE);
    try {
        final byte[] buffer = new byte[PKCS7_MARKER.length];
        final int len = pbis.read(buffer);
        if (len < 0) {
            /* No need to reset here. The stream was empty or EOF. */
            throw new ParsingException("inStream is empty");
        }
        pbis.unread(buffer, 0, len);
        if (len == PKCS7_MARKER.length && Arrays.equals(PKCS7_MARKER, buffer)) {
            return new OpenSSLX509CertPath(OpenSSLX509Certificate.fromPkcs7PemInputStream(pbis));
        }
        return new OpenSSLX509CertPath(OpenSSLX509Certificate.fromPkcs7DerInputStream(pbis));
    } catch (Exception e) {
        if (markable) {
            try {
                inStream.reset();
            } catch (IOException ignored) {
            }
        }
        throw new CertificateException(e);
    }
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 2 with ParsingException

use of org.conscrypt.OpenSSLX509CertificateFactory.ParsingException in project robovm by robovm.

the class OpenSSLX509Certificate method fromPkcs7DerInputStream.

public static List<OpenSSLX509Certificate> fromPkcs7DerInputStream(InputStream is) throws ParsingException {
    @SuppressWarnings("resource") OpenSSLBIOInputStream bis = new OpenSSLBIOInputStream(is);
    final long[] certRefs;
    try {
        certRefs = NativeCrypto.d2i_PKCS7_bio(bis.getBioContext(), NativeCrypto.PKCS7_CERTS);
    } catch (Exception e) {
        throw new ParsingException(e);
    } finally {
        NativeCrypto.BIO_free(bis.getBioContext());
    }
    if (certRefs == null) {
        return Collections.emptyList();
    }
    final List<OpenSSLX509Certificate> certs = new ArrayList<OpenSSLX509Certificate>(certRefs.length);
    for (int i = 0; i < certRefs.length; i++) {
        if (certRefs[i] == 0) {
            continue;
        }
        certs.add(new OpenSSLX509Certificate(certRefs[i]));
    }
    return certs;
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) ArrayList(java.util.ArrayList) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateParsingException(java.security.cert.CertificateParsingException) CertificateExpiredException(java.security.cert.CertificateExpiredException) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) SignatureException(java.security.SignatureException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 3 with ParsingException

use of org.conscrypt.OpenSSLX509CertificateFactory.ParsingException in project robovm by robovm.

the class OpenSSLX509CRL method fromPkcs7DerInputStream.

public static List<OpenSSLX509CRL> fromPkcs7DerInputStream(InputStream is) throws ParsingException {
    OpenSSLBIOInputStream bis = new OpenSSLBIOInputStream(is);
    final long[] certRefs;
    try {
        certRefs = NativeCrypto.d2i_PKCS7_bio(bis.getBioContext(), NativeCrypto.PKCS7_CRLS);
    } catch (Exception e) {
        throw new ParsingException(e);
    } finally {
        NativeCrypto.BIO_free(bis.getBioContext());
    }
    final List<OpenSSLX509CRL> certs = new ArrayList<OpenSSLX509CRL>(certRefs.length);
    for (int i = 0; i < certRefs.length; i++) {
        if (certRefs[i] == 0) {
            continue;
        }
        certs.add(new OpenSSLX509CRL(certRefs[i]));
    }
    return certs;
}
Also used : ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) ArrayList(java.util.ArrayList) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) SignatureException(java.security.SignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CRLException(java.security.cert.CRLException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 4 with ParsingException

use of org.conscrypt.OpenSSLX509CertificateFactory.ParsingException in project robovm by robovm.

the class OpenSSLX509CRL method fromPkcs7PemInputStream.

public static List<OpenSSLX509CRL> fromPkcs7PemInputStream(InputStream is) throws ParsingException {
    OpenSSLBIOInputStream bis = new OpenSSLBIOInputStream(is);
    final long[] certRefs;
    try {
        certRefs = NativeCrypto.PEM_read_bio_PKCS7(bis.getBioContext(), NativeCrypto.PKCS7_CRLS);
    } catch (Exception e) {
        throw new ParsingException(e);
    } finally {
        NativeCrypto.BIO_free(bis.getBioContext());
    }
    final List<OpenSSLX509CRL> certs = new ArrayList<OpenSSLX509CRL>(certRefs.length);
    for (int i = 0; i < certRefs.length; i++) {
        if (certRefs[i] == 0) {
            continue;
        }
        certs.add(new OpenSSLX509CRL(certRefs[i]));
    }
    return certs;
}
Also used : ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) ArrayList(java.util.ArrayList) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) SignatureException(java.security.SignatureException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CRLException(java.security.cert.CRLException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 5 with ParsingException

use of org.conscrypt.OpenSSLX509CertificateFactory.ParsingException in project robovm by robovm.

the class OpenSSLX509Certificate method fromPkcs7PemInputStream.

public static List<OpenSSLX509Certificate> fromPkcs7PemInputStream(InputStream is) throws ParsingException {
    @SuppressWarnings("resource") OpenSSLBIOInputStream bis = new OpenSSLBIOInputStream(is);
    final long[] certRefs;
    try {
        certRefs = NativeCrypto.PEM_read_bio_PKCS7(bis.getBioContext(), NativeCrypto.PKCS7_CERTS);
    } catch (Exception e) {
        throw new ParsingException(e);
    } finally {
        NativeCrypto.BIO_free(bis.getBioContext());
    }
    final List<OpenSSLX509Certificate> certs = new ArrayList<OpenSSLX509Certificate>(certRefs.length);
    for (int i = 0; i < certRefs.length; i++) {
        if (certRefs[i] == 0) {
            continue;
        }
        certs.add(new OpenSSLX509Certificate(certRefs[i]));
    }
    return certs;
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) ArrayList(java.util.ArrayList) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) CertificateParsingException(java.security.cert.CertificateParsingException) CertificateExpiredException(java.security.cert.CertificateExpiredException) ParsingException(org.conscrypt.OpenSSLX509CertificateFactory.ParsingException) SignatureException(java.security.SignatureException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Aggregations

ParsingException (org.conscrypt.OpenSSLX509CertificateFactory.ParsingException)5 InvalidKeyException (java.security.InvalidKeyException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 NoSuchProviderException (java.security.NoSuchProviderException)4 SignatureException (java.security.SignatureException)4 ArrayList (java.util.ArrayList)4 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 CertificateException (java.security.cert.CertificateException)3 CRLException (java.security.cert.CRLException)2 CertificateExpiredException (java.security.cert.CertificateExpiredException)2 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)2 CertificateParsingException (java.security.cert.CertificateParsingException)2 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)2 IOException (java.io.IOException)1 PushbackInputStream (java.io.PushbackInputStream)1