Search in sources :

Example 36 with DERUTF8String

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);
                        }
                    }
                }
            }
        }
    }
}
Also used : DEROctetString(org.bouncycastle.asn1.DEROctetString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) HashMap(java.util.HashMap) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERSet(org.bouncycastle.asn1.DERSet) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERSequence(org.bouncycastle.asn1.DERSequence) DLSequence(org.bouncycastle.asn1.DLSequence) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive)

Example 37 with DERUTF8String

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());
    }
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String)

Example 38 with DERUTF8String

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);
            }
        }
    }
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String) Attribute(org.bouncycastle.asn1.pkcs.Attribute) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 39 with DERUTF8String

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 "";
    }
}
Also used : ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) IOException(java.io.IOException)

Example 40 with DERUTF8String

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);
    }
}
Also used : BigInteger(java.math.BigInteger) ASN1InputStream(org.bouncycastle.asn1.ASN1InputStream) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERSequence(org.bouncycastle.asn1.DERSequence) CertificateParsingException(java.security.cert.CertificateParsingException) ASN1TaggedObject(org.bouncycastle.asn1.ASN1TaggedObject) List(java.util.List) DEROctetString(org.bouncycastle.asn1.DEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Aggregations

DERUTF8String (org.bouncycastle.asn1.DERUTF8String)42 DERSequence (org.bouncycastle.asn1.DERSequence)25 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)19 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)17 DEROctetString (org.bouncycastle.asn1.DEROctetString)17 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)15 IOException (java.io.IOException)14 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)14 DERIA5String (org.bouncycastle.asn1.DERIA5String)14 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)13 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)13 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)12 X500Name (org.bouncycastle.asn1.x500.X500Name)11 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)9 GeneralName (org.bouncycastle.asn1.x509.GeneralName)9 X509Certificate (java.security.cert.X509Certificate)8 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)8 GeneralNames (org.bouncycastle.asn1.x509.GeneralNames)7 BigInteger (java.math.BigInteger)6 Date (java.util.Date)6