Search in sources :

Example 6 with ASN1InputStream

use of com.github.zhenwei.core.asn1.ASN1InputStream in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CertInstallerHelper method isCa.

private boolean isCa(X509Certificate cert) {
    try {
        byte[] asn1EncodedBytes = cert.getExtensionValue("2.5.29.19");
        if (asn1EncodedBytes == null) {
            return false;
        }
        DEROctetString derOctetString = (DEROctetString) new ASN1InputStream(asn1EncodedBytes).readObject();
        byte[] octets = derOctetString.getOctets();
        ASN1Sequence sequence = (ASN1Sequence) new ASN1InputStream(octets).readObject();
        return BasicConstraints.getInstance(sequence).isCA();
    } catch (IOException e) {
        return false;
    }
}
Also used : ASN1InputStream(com.android.org.bouncycastle.asn1.ASN1InputStream) ASN1Sequence(com.android.org.bouncycastle.asn1.ASN1Sequence) IOException(java.io.IOException) DEROctetString(com.android.org.bouncycastle.asn1.DEROctetString)

Example 7 with ASN1InputStream

use of com.github.zhenwei.core.asn1.ASN1InputStream in project nhin-d by DirectProject.

the class TrustChainValidator method getObject.

private DERObject getObject(byte[] ext) {
    ASN1InputStream aIn = null;
    try {
        aIn = new ASN1InputStream(ext);
        ASN1OctetString octs = (ASN1OctetString) aIn.readObject();
        IOUtils.closeQuietly(aIn);
        aIn = new ASN1InputStream(octs.getOctets());
        return aIn.readObject();
    } catch (Exception e) {
        throw new IllegalArgumentException("Exception processing data ", e);
    } finally {
        IOUtils.closeQuietly(aIn);
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) CertificateParsingException(java.security.cert.CertificateParsingException) AddressException(javax.mail.internet.AddressException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) NHINDException(org.nhindirect.stagent.NHINDException)

Example 8 with ASN1InputStream

use of com.github.zhenwei.core.asn1.ASN1InputStream in project nhin-d by DirectProject.

the class MessageSigInspector method getObject.

protected static DERObject getObject(byte[] ext) throws PolicyProcessException {
    ASN1InputStream aIn = null;
    try {
        aIn = new ASN1InputStream(ext);
        ASN1OctetString octs = (ASN1OctetString) aIn.readObject();
        IOUtils.closeQuietly(aIn);
        aIn = new ASN1InputStream(octs.getOctets());
        return aIn.readObject();
    } catch (Exception e) {
        throw new PolicyProcessException("Exception processing data ", e);
    } finally {
        IOUtils.closeQuietly(aIn);
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) CMSException(org.bouncycastle.cms.CMSException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Example 9 with ASN1InputStream

use of com.github.zhenwei.core.asn1.ASN1InputStream in project nhin-d by DirectProject.

the class AbstractX509Field method getObject.

/**
	 * Converts an encoded internal octet string object to a DERObject
	 * @param ext The encoded octet string as a byte array
	 * @return The converted DERObject
	 * @throws PolicyProcessException
	 */
protected DERObject getObject(byte[] ext) throws PolicyProcessException {
    ASN1InputStream aIn = null;
    try {
        aIn = new ASN1InputStream(ext);
        ASN1OctetString octs = (ASN1OctetString) aIn.readObject();
        IOUtils.closeQuietly(aIn);
        aIn = new ASN1InputStream(octs.getOctets());
        return aIn.readObject();
    } catch (Exception e) {
        throw new PolicyProcessException("Exception processing data ", e);
    } finally {
        IOUtils.closeQuietly(aIn);
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Example 10 with ASN1InputStream

use of com.github.zhenwei.core.asn1.ASN1InputStream in project nhin-d by DirectProject.

the class AbstractX509Field method getDERObject.

/**
	 * Converts an encoded internal sequence object to a DERObject
	 * @param ext The encoded sequence as a byte array
	 * @return The converted DERObject
	 * @throws PolicyProcessException
	 */
protected DERObject getDERObject(byte[] ext) throws PolicyProcessException {
    ASN1InputStream aIn = null;
    try {
        aIn = new ASN1InputStream(ext);
        DERSequence seq = (DERSequence) aIn.readObject();
        IOUtils.closeQuietly(aIn);
        aIn = new ASN1InputStream(seq.getDEREncoded());
        return aIn.readObject();
    } catch (Exception e) {
        throw new PolicyProcessException("Exception processing data ", e);
    } finally {
        IOUtils.closeQuietly(aIn);
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERSequence(org.bouncycastle.asn1.DERSequence) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Aggregations

ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)171 IOException (java.io.IOException)142 ByteArrayInputStream (java.io.ByteArrayInputStream)76 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)64 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)42 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)38 DEROctetString (org.bouncycastle.asn1.DEROctetString)38 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)33 ASN1InputStream (com.github.zhenwei.core.asn1.ASN1InputStream)32 BigInteger (java.math.BigInteger)32 CertificateException (java.security.cert.CertificateException)31 X509Certificate (java.security.cert.X509Certificate)29 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)28 CertificateParsingException (java.security.cert.CertificateParsingException)27 Enumeration (java.util.Enumeration)27 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)26 InvalidKeyException (java.security.InvalidKeyException)25 CertificateEncodingException (java.security.cert.CertificateEncodingException)25 CRLException (java.security.cert.CRLException)24 NoSuchProviderException (java.security.NoSuchProviderException)22