Search in sources :

Example 96 with DERObject

use of org.bouncycastle.asn1.DERObject in project XobotOS by xamarin.

the class X509Extensions method toASN1Object.

/**
     * <pre>
     *     Extensions        ::=   SEQUENCE SIZE (1..MAX) OF Extension
     *
     *     Extension         ::=   SEQUENCE {
     *        extnId            EXTENSION.&amp;id ({ExtensionSet}),
     *        critical          BOOLEAN DEFAULT FALSE,
     *        extnValue         OCTET STRING }
     * </pre>
     */
public DERObject toASN1Object() {
    ASN1EncodableVector vec = new ASN1EncodableVector();
    Enumeration e = ordering.elements();
    while (e.hasMoreElements()) {
        ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
        X509Extension ext = (X509Extension) extensions.get(oid);
        ASN1EncodableVector v = new ASN1EncodableVector();
        v.add(oid);
        if (ext.isCritical()) {
            // BEGIN android-changed
            v.add(DERBoolean.TRUE);
        // END android-changed
        }
        v.add(ext.getValue());
        vec.add(new DERSequence(v));
    }
    return new DERSequence(vec);
}
Also used : Enumeration(java.util.Enumeration) DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 97 with DERObject

use of org.bouncycastle.asn1.DERObject in project nhin-d by DirectProject.

the class SMIMECryptographerImpl method logDigests.

protected void logDigests(SignerInformation sigInfo) {
    // will fail
    if (this.m_logDigest && sigInfo != null) {
        try {
            //get the digests
            final Attribute digAttr = sigInfo.getSignedAttributes().get(CMSAttributes.messageDigest);
            final DERObject hashObj = digAttr.getAttrValues().getObjectAt(0).getDERObject();
            final byte[] signedDigest = ((ASN1OctetString) hashObj).getOctets();
            final String signedDigestHex = org.apache.commons.codec.binary.Hex.encodeHexString(signedDigest);
            LOGGER.info("Signed Message Digest: " + signedDigestHex);
            // should have the computed digest now
            final byte[] digest = sigInfo.getContentDigest();
            final String digestHex = org.apache.commons.codec.binary.Hex.encodeHexString(digest);
            LOGGER.info("Computed Message Digest: " + digestHex);
        } catch (Throwable t) {
        /* no-op.... logging digests is a quiet operation */
        }
    }
}
Also used : ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERObject(org.bouncycastle.asn1.DERObject) Attribute(org.bouncycastle.asn1.cms.Attribute) SMIMECapabilitiesAttribute(org.bouncycastle.asn1.smime.SMIMECapabilitiesAttribute) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString)

Example 98 with DERObject

use of org.bouncycastle.asn1.DERObject in project nhin-d by DirectProject.

the class AuthorityInfoAccessExtentionField method injectReferenceValue.

/**
	 * {@inheritDoc}
	 */
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
    this.certificate = value;
    final DERObject exValue = getExtensionValue(value);
    if (exValue == null) {
        if (isRequired())
            throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
        else {
            final Collection<String> coll = Collections.emptyList();
            this.policyValue = PolicyValueFactory.getInstance(coll);
            return;
        }
    }
    final AuthorityInformationAccess aia = AuthorityInformationAccess.getInstance(exValue);
    final Collection<String> retVal = new ArrayList<String>();
    for (AccessDescription accessDescription : aia.getAccessDescriptions()) {
        final String accessMethod = AuthorityInfoAccessMethodIdentifier.fromId(accessDescription.getAccessMethod().toString()).getName();
        retVal.add(accessMethod + ":" + accessDescription.getAccessLocation().getName().toString());
    }
    if (retVal.isEmpty() && isRequired())
        throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
    this.policyValue = PolicyValueFactory.getInstance(retVal);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) AuthorityInformationAccess(org.bouncycastle.asn1.x509.AuthorityInformationAccess) DERObject(org.bouncycastle.asn1.DERObject) AccessDescription(org.bouncycastle.asn1.x509.AccessDescription) ArrayList(java.util.ArrayList)

Example 99 with DERObject

use of org.bouncycastle.asn1.DERObject in project nhin-d by DirectProject.

the class IssuerAttributeField method injectReferenceValue.

/**
	 * {@inheritDoc}
	 */
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
    this.certificate = value;
    if (rdnAttributeId.equals(RDNAttributeIdentifier.DISTINGUISHED_NAME)) {
        final Collection<String> str = Arrays.asList(certificate.getIssuerX500Principal().getName(X500Principal.RFC2253));
        this.policyValue = PolicyValueFactory.getInstance(str);
        return;
    }
    DERObject tbsValue = null;
    try {
        tbsValue = this.getDERObject(certificate.getTBSCertificate());
    }///CLOVER:OFF
     catch (Exception e) {
        throw new PolicyProcessException("Exception parsing TBS certificate fields.", e);
    }
    ///CLOVER:ON
    final TBSCertificateStructure tbsStruct = TBSCertificateStructure.getInstance(tbsValue);
    final X509Name x509Name = getX509Name(tbsStruct);
    @SuppressWarnings("unchecked") final Vector<String> values = x509Name.getValues(new DERObjectIdentifier(getRDNAttributeFieldId().getId()));
    if (values.isEmpty() && this.isRequired())
        throw new PolicyRequiredException(getFieldName() + " field attribute " + rdnAttributeId.getName() + " is marked as required but is not present.");
    final Collection<String> retVal = values;
    this.policyValue = PolicyValueFactory.getInstance(retVal);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) X509Name(org.bouncycastle.asn1.x509.X509Name) TBSCertificateStructure(org.bouncycastle.asn1.x509.TBSCertificateStructure) DERObjectIdentifier(org.bouncycastle.asn1.DERObjectIdentifier) PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException) PolicyProcessException(org.nhindirect.policy.PolicyProcessException)

Example 100 with DERObject

use of org.bouncycastle.asn1.DERObject in project nhin-d by DirectProject.

the class SubjectAltNameExtensionField method injectReferenceValue.

/**
	 * {@inheritDoc}
	 */
@Override
public void injectReferenceValue(X509Certificate value) throws PolicyProcessException {
    this.certificate = value;
    final DERObject exValue = getExtensionValue(value);
    if (exValue == null) {
        if (isRequired())
            throw new PolicyRequiredException("Extention " + getExtentionIdentifier().getDisplay() + " is marked as required by is not present.");
        else {
            final Collection<String> emptyList = Collections.emptyList();
            this.policyValue = PolicyValueFactory.getInstance(emptyList);
            return;
        }
    }
    final Collection<String> names = new ArrayList<String>();
    final GeneralNames generalNames = GeneralNames.getInstance(exValue);
    for (GeneralName name : generalNames.getNames()) {
        final GeneralNameType type = GeneralNameType.fromTag(name.getTagNo());
        if (type != null) {
            names.add(type.getDisplay() + ":" + name.getName().toString());
        }
    }
    this.policyValue = PolicyValueFactory.getInstance(names);
}
Also used : PolicyRequiredException(org.nhindirect.policy.PolicyRequiredException) DERObject(org.bouncycastle.asn1.DERObject) GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) ArrayList(java.util.ArrayList) GeneralName(org.bouncycastle.asn1.x509.GeneralName)

Aggregations

ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)58 DERSequence (org.bouncycastle.asn1.DERSequence)56 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)42 DERObject (org.bouncycastle.asn1.DERObject)37 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)20 IOException (java.io.IOException)17 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)17 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)17 DERInteger (org.bouncycastle.asn1.DERInteger)16 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)13 DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)13 DEROctetString (org.bouncycastle.asn1.DEROctetString)13 PolicyRequiredException (org.nhindirect.policy.PolicyRequiredException)12 BERSequence (org.bouncycastle.asn1.BERSequence)9 DERBitString (org.bouncycastle.asn1.DERBitString)9 DEREncodable (org.bouncycastle.asn1.DEREncodable)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ArrayList (java.util.ArrayList)8 BigInteger (java.math.BigInteger)7 Enumeration (java.util.Enumeration)7