Search in sources :

Example 21 with ASN1Encodable

use of org.openecard.bouncycastle.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class X509Ext method getSubjectDirectoryAttributesStringValue.

private String getSubjectDirectoryAttributesStringValue(byte[] value) throws IOException {
    // @formatter:off
    /*
		 * SubjectDirectoryAttributes ::= ASN1Sequence SIZE (1..MAX) OF Attribute
		 *
		 * Attribute ::= ASN1Sequence
		 * {
		 *      type AttributeType,
		 *      values SET OF AttributeValue
		 * }
		 */
    // @formatter:on
    StringBuilder sb = new StringBuilder();
    SubjectDirectoryAttributes subjectDirectoryAttributes = SubjectDirectoryAttributes.getInstance(value);
    for (Object attribute : subjectDirectoryAttributes.getAttributes()) {
        ASN1ObjectIdentifier attributeType = ((Attribute) attribute).getAttrType();
        String attributeTypeStr = attributeType.getId();
        ASN1Encodable[] attributeValues = ((Attribute) attribute).getAttributeValues();
        for (ASN1Encodable attributeValue : attributeValues) {
            String attributeValueStr = getAttributeValueString(attributeType, attributeValue);
            sb.append(MessageFormat.format("{0}={1}", attributeTypeStr, attributeValueStr));
            sb.append(NEWLINE);
        }
    }
    return sb.toString();
}
Also used : Attribute(org.bouncycastle.asn1.x509.Attribute) SubjectDirectoryAttributes(org.bouncycastle.asn1.x509.SubjectDirectoryAttributes) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) DirectoryString(org.bouncycastle.asn1.x500.DirectoryString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERIA5String(org.bouncycastle.asn1.DERIA5String) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 22 with ASN1Encodable

use of org.openecard.bouncycastle.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class PolicyInformationUtil method toString.

/**
 * Get string representation of policy qualifier info.
 *
 * @param policyQualifierInfo
 *            Policy qualifier info
 * @return String representation of policy qualifier info
 * @throws IOException
 *             If policy qualifier info is invalid
 */
public static String toString(PolicyQualifierInfo policyQualifierInfo) throws IOException {
    StringBuffer sbPolicyQualifier = new StringBuffer();
    ASN1ObjectIdentifier policyQualifierId = policyQualifierInfo.getPolicyQualifierId();
    CertificatePolicyQualifierType certificatePolicyQualifierType = CertificatePolicyQualifierType.resolveOid(policyQualifierId.getId());
    if (certificatePolicyQualifierType == PKIX_CPS_POINTER_QUALIFIER) {
        DERIA5String cpsPointer = ((DERIA5String) policyQualifierInfo.getQualifier());
        sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.CpsPointer"), cpsPointer));
    } else if (certificatePolicyQualifierType == PKIX_USER_NOTICE_QUALIFIER) {
        ASN1Encodable userNoticeObj = policyQualifierInfo.getQualifier();
        UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
        sbPolicyQualifier.append(MessageFormat.format(res.getString("PolicyInformationUtil.UserNotice"), toString(userNotice)));
    }
    return sbPolicyQualifier.toString();
}
Also used : DERIA5String(org.bouncycastle.asn1.DERIA5String) UserNotice(org.bouncycastle.asn1.x509.UserNotice) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 23 with ASN1Encodable

use of org.openecard.bouncycastle.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class DPolicyQualifierInfoChooser method populate.

private void populate(PolicyQualifierInfo policyQualifierInfo) throws IOException {
    if (policyQualifierInfo == null) {
        jrbCps.setSelected(true);
    } else {
        ASN1ObjectIdentifier policyQualifierId = policyQualifierInfo.getPolicyQualifierId();
        if (policyQualifierId.equals(new ASN1ObjectIdentifier(PKIX_CPS_POINTER_QUALIFIER.oid()))) {
            jrbCps.setSelected(true);
            jtfCps.setText(((DERIA5String) policyQualifierInfo.getQualifier()).getString());
            jtfCps.setCaretPosition(0);
        } else if (policyQualifierId.equals(new ASN1ObjectIdentifier(PKIX_USER_NOTICE_QUALIFIER.oid()))) {
            jrbUserNotice.setSelected(true);
            ASN1Encodable userNoticeObj = policyQualifierInfo.getQualifier();
            UserNotice userNotice = UserNotice.getInstance(userNoticeObj);
            junUserNotice.setUserNotice(userNotice);
        } else {
            jrbCps.setSelected(true);
        }
    }
}
Also used : UserNotice(org.bouncycastle.asn1.x509.UserNotice) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 24 with ASN1Encodable

use of org.openecard.bouncycastle.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class PolicyMappingsTableModel method load.

/**
 * Load the PolicyMappingsTableModel with policy mappings.
 *
 * @param policyMappings
 *            The policy mappings
 */
public void load(PolicyMappings policyMappings) {
    ASN1Sequence policyMappingsSeq = (ASN1Sequence) policyMappings.toASN1Primitive();
    // convert and sort
    ASN1Encodable[] asn1EncArray = policyMappingsSeq.toArray();
    PolicyMapping[] policyMappingsArray = new PolicyMapping[asn1EncArray.length];
    for (int i = 0; i < asn1EncArray.length; i++) {
        policyMappingsArray[i] = PolicyMapping.getInstance(asn1EncArray[i]);
    }
    Arrays.sort(policyMappingsArray, new IssuerDomainPolicyComparator());
    data = new Object[policyMappingsArray.length][2];
    int i = 0;
    for (PolicyMapping policyMapping : policyMappingsArray) {
        data[i][0] = policyMapping;
        data[i][1] = policyMapping;
        i++;
    }
    fireTableDataChanged();
}
Also used : PolicyMapping(org.kse.crypto.x509.PolicyMapping) ASN1Sequence(org.bouncycastle.asn1.ASN1Sequence) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable)

Example 25 with ASN1Encodable

use of org.openecard.bouncycastle.asn1.ASN1Encodable in project keystore-explorer by kaikramer.

the class EccUtil method convertToECPrivateKeyStructure.

/**
 * Converts PKCS#8 EC private key (RFC 5208 ASN.1 PrivateKeyInfo structure) to "traditional" OpenSSL
 * ASN.1 structure ECPrivateKey from RFC 5915. As ECPrivateKey is already in the PrivateKey field of PrivateKeyInfo,
 * this must only be extracted:
 *
 * SEQUENCE {
 *	  INTEGER 0
 *	  SEQUENCE {
 *	    OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)
 *	    OBJECT IDENTIFIER prime256v1 (1 2 840 10045 3 1 7)
 *	    }
 *	  OCTET STRING, encapsulates {
 *	    SEQUENCE {
 *	      INTEGER 1
 *	      OCTET STRING
 *	        17 12 CA 42 16 79 1B 45    ...B.y.E
 *	        ...
 *	        C8 B2 66 0A E5 60 50 0B
 *	      [0] {
 *	        OBJECT IDENTIFIER prime256v1 (1 2 840 10045 3 1 7)
 *	        }
 *	      [1] {
 *	        BIT STRING
 *	          04 61 C0 08 B4 89 A0 50    .a.....P
 *            ...
 *	          AE D5 ED C3 4D 0E 47 91    ....M.G.
 *	          89                         .
 *	        }
 *	      }
 *	    }
 *	  }
 *
 * @param ecPrivateKey An EC key
 * @return Object holding ASN1 ECPrivateKey structure
 * @throws IOException When ECPrivateKey structure in PrivateKeyInfo's PrivateKey field cannot be parsed
 */
public static org.bouncycastle.asn1.sec.ECPrivateKey convertToECPrivateKeyStructure(ECPrivateKey ecPrivateKey) throws IOException {
    byte[] encoded = ecPrivateKey.getEncoded();
    PrivateKeyInfo privateKeyInfo = PrivateKeyInfo.getInstance(encoded);
    ASN1Encodable privateKey = privateKeyInfo.parsePrivateKey();
    return org.bouncycastle.asn1.sec.ECPrivateKey.getInstance(privateKey);
}
Also used : ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) PrivateKeyInfo(org.bouncycastle.asn1.pkcs.PrivateKeyInfo)

Aggregations

ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)129 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)71 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)56 IOException (java.io.IOException)32 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)31 DEROctetString (org.bouncycastle.asn1.DEROctetString)29 DERIA5String (org.bouncycastle.asn1.DERIA5String)25 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)23 DERSequence (org.bouncycastle.asn1.DERSequence)22 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)21 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)21 ArrayList (java.util.ArrayList)20 GeneralName (org.bouncycastle.asn1.x509.GeneralName)19 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)17 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)17 X509Certificate (java.security.cert.X509Certificate)15 HashSet (java.util.HashSet)15 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)15 DirectoryString (org.bouncycastle.asn1.x500.DirectoryString)15 DERBMPString (org.bouncycastle.asn1.DERBMPString)14