use of org.bouncycastle.asn1.DERUTF8String in project signer by demoiselle.
the class PolicyIssuerName method parse.
@Override
public void parse(ASN1Primitive primitive) {
if (primitive instanceof DLSequence) {
DLSequence sequence = (DLSequence) primitive;
ASN1Encodable asn1Encodable = sequence.getObjectAt(0);
if (asn1Encodable instanceof DERTaggedObject) {
DERTaggedObject derTaggedObject = (DERTaggedObject) asn1Encodable;
ASN1Primitive object = derTaggedObject.getObject();
if (object instanceof DEROctetString) {
OctetString octetString = new OctetString();
octetString.parse(object);
this.issuerName = octetString.getValueUTF8();
} else if (object instanceof DERSequence) {
DERSequence sequence2 = (DERSequence) object;
for (int i = 0; i < sequence2.size(); i++) {
ASN1Encodable obj = sequence2.getObjectAt(i);
if (obj instanceof DERSet) {
DERSet set = (DERSet) obj;
ASN1Encodable object2 = set.getObjectAt(0);
if (object2 instanceof DERSequence) {
DERSequence sequence3 = (DERSequence) object2;
ObjectIdentifier objectIdendifier = new ObjectIdentifier();
objectIdendifier.parse(sequence3.getObjectAt(0).toASN1Primitive());
String name = null;
ASN1Encodable object3 = sequence3.getObjectAt(1);
if (object3 instanceof DERPrintableString) {
name = ((DERPrintableString) object3).getString();
} else if (object3 instanceof DERUTF8String) {
name = ((DERUTF8String) object3).getString();
} else {
System.out.println(policyMessagesBundle.getString("error.not.recognized.object", object3.getClass(), object3.toString()));
}
if (this.issuerNames == null) {
this.issuerNames = new HashMap<ObjectIdentifier, String>();
}
this.issuerNames.put(objectIdendifier, name);
}
}
}
}
}
}
}
use of org.bouncycastle.asn1.DERUTF8String in project signer by demoiselle.
the class FieldOfApplication method parse.
@Override
public void parse(ASN1Primitive derObject) {
if (derObject instanceof DERUTF8String) {
DERUTF8String derUTF8String = (DERUTF8String) derObject;
this.setValue(derUTF8String.getString());
} else {
this.setValue(derObject.toString());
}
}
use of org.bouncycastle.asn1.DERUTF8String in project keystore-explorer by kaikramer.
the class DialogHelper method populateTextField.
private static void populateTextField(Attribute[] attrs, JTextField textField, ASN1ObjectIdentifier pkcs9Attr) {
if (attrs != null) {
for (Attribute attribute : attrs) {
ASN1ObjectIdentifier attributeOid = attribute.getAttrType();
if (attributeOid.equals(pkcs9Attr)) {
ASN1Encodable challenge = attribute.getAttributeValues()[0];
// data type can be one of IA5String or UTF8String
if (challenge instanceof DERPrintableString) {
textField.setText(((DERPrintableString) challenge).getString());
} else if (challenge instanceof DERUTF8String) {
textField.setText(((DERUTF8String) challenge).getString());
}
textField.setCaretPosition(0);
}
}
}
}
use of org.bouncycastle.asn1.DERUTF8String in project ddf by codice.
the class SignerCondition method getIdentifyFromBytes.
// this code was grabbed online and should be correct
// we don't have any tests for this so be wary of changing this code
private String getIdentifyFromBytes(byte[] itemBytes) {
try (ASN1InputStream decoder = new ASN1InputStream(itemBytes)) {
ASN1Encodable encoded = decoder.readObject();
encoded = ((DERSequence) encoded).getObjectAt(1);
encoded = ((DERTaggedObject) encoded).getObject();
encoded = ((DERTaggedObject) encoded).getObject();
return ((DERUTF8String) encoded).getString();
} catch (IOException e) {
return "";
}
}
use of org.bouncycastle.asn1.DERUTF8String in project zm-mailbox by Zimbra.
the class CertUtil method printSubjectAlternativeNames.
private void printSubjectAlternativeNames(PrintStream outStream) throws Exception {
final String UPN_DISPLAY = "Principal Name";
final String RFC822NAME_DISPLAY = "RFC822 Name";
final String DNSNAME_DISPLAY = "DNS Name";
outStream.format("X509v3 Subject Alternative Name: \n");
ASN1InputStream decoder = null;
try {
Collection<List<?>> generalNames = cert.getSubjectAlternativeNames();
// Check that the certificate includes the SubjectAltName extension
if (generalNames == null) {
return;
}
for (List<?> generalName : generalNames) {
Integer tag = (Integer) generalName.get(0);
if (GeneralName.otherName == tag.intValue()) {
// Value is encoded using ASN.1
decoder = new ASN1InputStream((byte[]) generalName.toArray()[1]);
ASN1Encodable encoded = decoder.readObject();
DERSequence derSeq = (DERSequence) encoded;
ASN1ObjectIdentifier typeId = ASN1ObjectIdentifier.getInstance(derSeq.getObjectAt(0));
String oid = typeId.getId();
String value = null;
ASN1TaggedObject otherNameValue = ASN1TaggedObject.getInstance(derSeq.getObjectAt(1));
if (OID_UPN.equals(oid)) {
ASN1TaggedObject upnValue = ASN1TaggedObject.getInstance(otherNameValue.getObject());
DERUTF8String str = DERUTF8String.getInstance(upnValue.getObject());
value = str.getString();
}
outStream.format(" [%d] %s(%s) = %s\n", tag, oid, UPN_DISPLAY, value);
} else if (GeneralName.rfc822Name == tag.intValue()) {
String value = (String) generalName.get(1);
outStream.format(" [%d] %s = %s\n", tag, RFC822NAME_DISPLAY, value);
} else if (GeneralName.dNSName == tag.intValue()) {
String value = (String) generalName.get(1);
outStream.format(" [%d] %s = %s\n", tag, DNSNAME_DISPLAY, value);
} else {
outStream.format(" [%d] - not yet supported\n", tag);
}
}
} catch (CertificateParsingException e) {
e.printStackTrace();
} finally {
ByteUtil.closeStream(decoder);
}
}
Aggregations