Search in sources :

Example 41 with ASN1InputStream

use of com.android.org.bouncycastle.asn1.ASN1InputStream in project keepass2android by PhilippC.

the class Dump method main.

public static void main(String[] args) throws Exception {
    FileInputStream fIn = new FileInputStream(args[0]);
    ASN1InputStream bIn = new ASN1InputStream(fIn);
    Object obj = null;
    while ((obj = bIn.readObject()) != null) {
        System.out.println(ASN1Dump.dumpAsString(obj));
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) FileInputStream(java.io.FileInputStream)

Example 42 with ASN1InputStream

use of com.android.org.bouncycastle.asn1.ASN1InputStream in project android_packages_apps_Settings by crdroidandroid.

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 43 with ASN1InputStream

use of com.android.org.bouncycastle.asn1.ASN1InputStream in project keystore-explorer by kaikramer.

the class DKeyUsage method prepopulateWithValue.

private void prepopulateWithValue(byte[] value) throws IOException {
    // we have a ByteArrayInputStream here which does not need to be closed
    @SuppressWarnings("resource") DERBitString keyUsage = DERBitString.getInstance(new ASN1InputStream(value).readObject());
    int keyUsageValue = keyUsage.intValue();
    jcbDigitalSignature.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.digitalSignature));
    jcbNonRepudiation.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.nonRepudiation));
    jcbKeyEncipherment.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.keyEncipherment));
    jcbDataEncipherment.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.dataEncipherment));
    jcbKeyAgreement.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.keyAgreement));
    jcbCertificateSigning.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.keyCertSign));
    jcbCrlSign.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.cRLSign));
    jcbEncipherOnly.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.encipherOnly));
    jcbDecipherOnly.setSelected(hasKeyUsage(keyUsageValue, KeyUsage.decipherOnly));
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERBitString(org.bouncycastle.asn1.DERBitString)

Example 44 with ASN1InputStream

use of com.android.org.bouncycastle.asn1.ASN1InputStream in project keystore-explorer by kaikramer.

the class DNetscapeCertificateType method prepopulateWithValue.

private void prepopulateWithValue(byte[] value) throws IOException {
    // we have a ByteArrayInputStream here which does not need to be closed
    @SuppressWarnings("resource") DERBitString netscapeCertType = DERBitString.getInstance(new ASN1InputStream(value).readObject());
    int netscapeCertTypes = netscapeCertType.intValue();
    jcbSslClient.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.sslClient));
    jcbSslServer.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.sslServer));
    jcbSmime.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.smime));
    jcbObjectSigning.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.objectSigning));
    jcbReserved.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.reserved));
    jcbSslCa.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.sslCA));
    jcbSmimeCa.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.smimeCA));
    jcbObjectSigningCa.setSelected(isCertType(netscapeCertTypes, NetscapeCertType.objectSigningCA));
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERBitString(org.bouncycastle.asn1.DERBitString)

Example 45 with ASN1InputStream

use of com.android.org.bouncycastle.asn1.ASN1InputStream in project webcert by sklintyg.

the class ASN1UtilImpl method getValue.

@Override
public String getValue(String identifier, InputStream asn1Signature) {
    ByteArrayInputStream bais = null;
    ASN1InputStream asn1InputStream = null;
    try {
        bais = convertStream(asn1Signature);
        asn1InputStream = new ASN1InputStream(bais);
        DERObject obj = asn1InputStream.readObject();
        ContentInfo contentInfo = ContentInfo.getInstance(obj);
        // Extract certificates
        SignedData signedData = SignedData.getInstance(contentInfo.getContent());
        return findInCertificate(identifier, (DERObject) signedData.getCertificates().getObjectAt(0));
    } catch (IOException e) {
        LOG.error("Error parsing signature: {}", e.getMessage());
        throw new IllegalStateException(e);
    } finally {
        IOUtils.closeQuietly(bais);
        IOUtils.closeQuietly(asn1InputStream);
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERObject(org.bouncycastle.asn1.DERObject) SignedData(org.bouncycastle.asn1.pkcs.SignedData) ByteArrayInputStream(java.io.ByteArrayInputStream) ContentInfo(org.bouncycastle.asn1.pkcs.ContentInfo) IOException(java.io.IOException)

Aggregations

ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)108 IOException (java.io.IOException)90 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)36 ByteArrayInputStream (java.io.ByteArrayInputStream)35 X509Certificate (java.security.cert.X509Certificate)25 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)25 BigInteger (java.math.BigInteger)21 DEROctetString (org.bouncycastle.asn1.DEROctetString)21 ASN1InputStream (com.android.org.bouncycastle.asn1.ASN1InputStream)20 CertificateException (java.security.cert.CertificateException)20 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)18 CertificateParsingException (java.security.cert.CertificateParsingException)18 Enumeration (java.util.Enumeration)17 CertificateEncodingException (java.security.cert.CertificateEncodingException)16 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)16 InvalidKeyException (java.security.InvalidKeyException)14 CRLException (java.security.cert.CRLException)14 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)14 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)12 NoSuchProviderException (java.security.NoSuchProviderException)11