use of org.gudy.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();
}
use of org.gudy.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();
}
use of org.gudy.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);
}
}
}
use of org.gudy.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();
}
use of org.gudy.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);
}
Aggregations