diff --git a/src/main/java/org/opensaml/xml/security/x509/X509Util.java b/src/main/java/org/opensaml/xml/security/x509/X509Util.java index bed3fda..47cac82 100644 --- a/src/main/java/org/opensaml/xml/security/x509/X509Util.java +++ b/src/main/java/org/opensaml/xml/security/x509/X509Util.java @@ -39,11 +39,12 @@ import javax.security.auth.x500.X500Principal; import org.apache.commons.ssl.TrustMaterial; import org.bouncycastle.asn1.ASN1InputStream; -import org.bouncycastle.asn1.DERObject; -import org.bouncycastle.asn1.DERObjectIdentifier; +import org.bouncycastle.asn1.ASN1Primitive; +import org.bouncycastle.asn1.ASN1Encoding; +import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.DERSequence; import org.bouncycastle.asn1.DERSet; -import org.bouncycastle.asn1.DERString; +import org.bouncycastle.asn1.ASN1String; import org.bouncycastle.asn1.x509.SubjectKeyIdentifier; import org.bouncycastle.asn1.x509.X509Extensions; import org.bouncycastle.util.Arrays; @@ -153,14 +154,14 @@ public class X509Util { List commonNames = new LinkedList(); try { ASN1InputStream asn1Stream = new ASN1InputStream(dn.getEncoded()); - DERObject parent = asn1Stream.readObject(); + ASN1Primitive parent = asn1Stream.readObject(); String cn = null; - DERObject dnComponent; + ASN1Primitive dnComponent; DERSequence grandChild; - DERObjectIdentifier componentId; + ASN1ObjectIdentifier componentId; for (int i = 0; i < ((DERSequence) parent).size(); i++) { - dnComponent = ((DERSequence) parent).getObjectAt(i).getDERObject(); + dnComponent = ((DERSequence) parent).getObjectAt(i).toASN1Primitive(); if (!(dnComponent instanceof DERSet)) { log.debug("No DN components."); continue; @@ -168,17 +169,17 @@ public class X509Util { // Each DN component is a set for (int j = 0; j < ((DERSet) dnComponent).size(); j++) { - grandChild = (DERSequence) ((DERSet) dnComponent).getObjectAt(j).getDERObject(); + grandChild = (DERSequence) ((DERSet) dnComponent).getObjectAt(j).toASN1Primitive(); if (grandChild.getObjectAt(0) != null - && grandChild.getObjectAt(0).getDERObject() instanceof DERObjectIdentifier) { - componentId = (DERObjectIdentifier) grandChild.getObjectAt(0).getDERObject(); + && grandChild.getObjectAt(0).toASN1Primitive() instanceof ASN1ObjectIdentifier) { + componentId = (ASN1ObjectIdentifier) grandChild.getObjectAt(0).toASN1Primitive(); if (CN_OID.equals(componentId.getId())) { // OK, this dn component is actually a cn attribute if (grandChild.getObjectAt(1) != null - && grandChild.getObjectAt(1).getDERObject() instanceof DERString) { - cn = ((DERString) grandChild.getObjectAt(1).getDERObject()).getString(); + && grandChild.getObjectAt(1).toASN1Primitive() instanceof ASN1String) { + cn = ((ASN1String) grandChild.getObjectAt(1).toASN1Primitive()).getString(); commonNames.add(cn); } } @@ -465,8 +466,15 @@ public class X509Util { if (EDI_PARTY_ALT_NAME.equals(nameType) || X400ADDRESS_ALT_NAME.equals(nameType) || OTHER_ALT_NAME.equals(nameType)) { - // these have no defined representation, just return a DER-encoded byte[] - return ((DERObject) nameValue).getDEREncoded(); + // these have no defined representation, just return a DER-encoded byte[] (or null if that fails) + byte [] x; + try { + x = ((ASN1Primitive) nameValue).getEncoded(ASN1Encoding.DER); + } catch (java.io.IOException e) { + x = null; + } + return x; + } log.warn("Encountered unknown alt name type '{}', adding as-is", nameType);