[libxmltooling-java] 03/05: Migrate to API from newer bouncycastle

Matthew Vernon matthew at moszumanska.debian.org
Thu Apr 10 17:08:22 UTC 2014


This is an automated email from the git hooks/post-receive script.

matthew pushed a commit to branch feature/newerbc
in repository libxmltooling-java.

commit d6d13bf61147e569bf0734e8288c4120db8383f8
Author: Matthew Vernon <matthew at debian.org>
Date:   Tue Feb 18 10:35:38 2014 +0000

    Migrate to API from newer bouncycastle
    
    The API changed from version 1.46 to 1.47 of bouncycastle. A porting
    guide is here:
    http://www.bouncycastle.org/wiki/display/JA1/Porting+from+earlier+BC+releases+to+1.47+and+later
    
    This is a fairly dumb application of that guide to the code.
---
 .../org/opensaml/xml/security/x509/X509Util.java   | 35 +++++++++++++---------
 1 file changed, 21 insertions(+), 14 deletions(-)

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..af9cb27 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,11 @@ 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.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 +153,14 @@ public class X509Util {
         List<String> commonNames = new LinkedList<String>();
         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 +168,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 +465,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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libxmltooling-java.git



More information about the pkg-java-commits mailing list