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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations