[WSS4J] wss4j/src/org/apache/ws/security/components/crypto Merlin.java,1.8,1.9

[email protected] Wed, 28 Jan 2004 01:17:13 -0800
Newsgroups gmane.text.xml.wss4j
Message-ID <[email protected]>
Update of /cvsroot/wss4j/wss4j/src/org/apache/ws/security/components/crypto
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28680/src/org/apache/ws/security/components/crypto

Modified Files:
	Merlin.java 
Log Message:
Insert bug fix reported by Jason Essington (NPE during
getCertificate() )

Index: Merlin.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/components/crypto/Merlin.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Merlin.java	27 Nov 2003 07:43:42 -0000	1.8
--- Merlin.java	28 Jan 2004 09:17:11 -0000	1.9
***************
*** 88,93 ****
      private static Log log = LogFactory.getLog(Merlin.class);
      private static CertificateFactory certFact;
-     protected PrivateKey key = null;
-     protected Certificate[] certs = null;
      private Properties properties = null;
      private KeyStore keystore = null;
--- 88,91 ----
***************
*** 233,253 ****
      }
  
!     private boolean equalsStringArray(String[] in1, String[] in2) {
! 	if (in1.length != in2.length) {
! 	    return false;
! 	}
! 	for (int i = 0; i < in1.length; i++) {
! 	    if (in1[i] != null) {
! 		if (!(in1[i].equals(in2[i]))) {
! 		    return false;
  		}
! 	    }
! 	    // come here if in1[i] is null, check in2[i]
! 	    else if (in2[i] != null) {
! 		return false;
! 	    }
  	}
- 	return true;
-     }
  
      /**
--- 231,251 ----
      }
  
! 	private boolean equalsStringArray(String[] in1, String[] in2) {
! 		if (in1.length != in2.length) {
! 			return false;
  		}
! 		for (int i = 0; i < in1.length; i++) {
! 			if (in1[i] != null) {
! 				if (!(in1[i].equals(in2[i]))) {
! 					return false;
! 				}
! 			}
! 			// come here if in1[i] is null, check in2[i]
! 			else if (in2[i] != null) {
! 				return false;
! 			}
! 		}
! 		return true;
  	}
  
      /**
***************
*** 274,299 ****
       * --- remains to be tested in several ways --
       */
!     public String getAliasForX509Cert(String issuer, BigInteger serialNumber) throws Exception {
! 	String issuerSplit[] = splitAndTrim(issuer);
! 	X509Certificate x509cert = null;
! 	String certIssuer[] = null;
!         for (Enumeration e = keystore.aliases(); e.hasMoreElements();) {
!             String alias = (String) e.nextElement();
!             Certificate[] certs = keystore.getCertificateChain(alias);
!             for (int i = 0; i < certs.length; i++) {
!                 if (!(certs[i] instanceof X509Certificate)) {
!                     continue;
!                 }
! 				x509cert = (X509Certificate)certs[i];
!                 if (x509cert.getSerialNumber().compareTo(serialNumber) == 0) {
! 		    		certIssuer = splitAndTrim(x509cert.getIssuerDN().getName());
! 		    		if (equalsStringArray(issuerSplit, certIssuer)) {
  						return alias;
! 		    		}
!                 }
!             }
!         }
!         return null;
!     }
  
      /**
--- 272,298 ----
       * --- remains to be tested in several ways --
       */
! 	public String getAliasForX509Cert(String issuer, BigInteger serialNumber)
! 		throws Exception {
! 		String issuerSplit[] = splitAndTrim(issuer);
! 		X509Certificate x509cert = null;
! 		String certIssuer[] = null;
! 		for (Enumeration e = keystore.aliases(); e.hasMoreElements();) {
! 			String alias = (String) e.nextElement();
! 			Certificate[] certs = keystore.getCertificateChain(alias);
! 			for (int i = 0; i < certs.length; i++) {
! 				if (!(certs[i] instanceof X509Certificate)) {
! 					continue;
! 				}
! 				x509cert = (X509Certificate) certs[i];
! 				if (x509cert.getSerialNumber().compareTo(serialNumber) == 0) {
! 					certIssuer = splitAndTrim(x509cert.getIssuerDN().getName());
! 					if (equalsStringArray(issuerSplit, certIssuer)) {
  						return alias;
! 					}
! 				}
! 			}
! 		}
! 		return null;
! 	}
  
      /**
***************
*** 321,335 ****
       *         null if this alias does not exist in the keystore
       */
!     public X509Certificate[] getCertificates(String alias) throws Exception {
!         certs = keystore.getCertificateChain(alias);
!         if (certs == null || certs.length == 0) {
!             return null;
!         }
!         X509Certificate[] x509certs = new X509Certificate[certs.length];
!         for (int i = 0; i < certs.length; i++) {
!             x509certs[i] = (X509Certificate) certs[i];
!         }
!         return x509certs;
!     }
  
      /**
--- 320,339 ----
       *         null if this alias does not exist in the keystore
       */
! 	public X509Certificate[] getCertificates(String alias) throws Exception {
! 		Certificate[] certs = keystore.getCertificateChain(alias);
! 		if (certs == null || certs.length == 0) {
! 			// no cert chain, so lets check if getCertificate gives us a result.
! 			Certificate cert = keystore.getCertificate(alias);
! 			if (cert == null) {
! 				return null;
! 			}
! 			certs = new Certificate[] { cert };
! 		}
! 		X509Certificate[] x509certs = new X509Certificate[certs.length];
! 		for (int i = 0; i < certs.length; i++) {
! 			x509certs[i] = (X509Certificate) certs[i];
! 		}
! 		return x509certs;
! 	}
  
      /**



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn