trebor iksrazal | 2 Mar 2004 22:28
Picon
Favicon

[WSS4J] More ldap

First, thanks for the help so far. 

I can now create, store and retrieve X509 Certificates
 via java and openldap. I also am storing the keystore
as a serialized object. Could someone please evaluate
some of the decisions I've made? 

1) I only access the keystore to create the
certificates when storing them in ldap. 

2) Each client has their own certificate, retrieved
via ldap when sending the message. The web service has
its own certificate, placed in the return. Each cert
is cached after the first ldap call via something
like: 

Map cache; 
cache = Collections.synchronizedMap(new HashMap());

X509Certificate cert = null;
if (cache.containsKey(certDistigushedName))
{
  cert (X509Certificate) =  
cache.get(certDistigushedName);
}
else
{
  cert = (X509Certificate)
getCertFromLDAP(dataSourceName);
  cache.put(certDistigushedName, cert);
(Continue reading)

Nachiappan Narayanan | 2 Mar 2004 16:29

[WSS4J] XML Encryption

All,
 
  Im exploring XML Encryption. Im not sure whether my approach towards XML Encryption is correct:
 
1. Client Sends the public key to the Server
2. Server Generates the Shared Secret Key
3. Server Encrypts the Shared Secret Key with the Client's Public Key
4. Server Sends the Encrypted Shared Secret Key to the Client
5. Client Decrypts & fetches the Shared Secret Key
6. For each and every SOAP Request, the Client encrypts the SOAP Request with the Shared Secret Key
7. The Server upon receiving the Encrypted SOAP Request, the server decrypts with the Shared Secret Key and obtains the original Request.
8. Similarly, the Server Response is encrypted with Shared Secret Key
9. The Server Response is decrypted by the client using the Shared Secret Key.
 
  Is this the one and only mechanisms by which XML Encryption can be achieved? I think the above procedure is symmetric key XML Encryption. If so, is there any steps such as this for Asymmetric Key XML Encryption?
 
  Here the Key generation should be automated rite? If i convert any string into byte array, i get Invalid Key Size exception. Is there any standard to generate such shared key?
 
  Can anyone please help me out?
 
Regards,
Nachiappan.N
Nachiappan Narayanan | 2 Mar 2004 15:35

[WSS4J] XML Encryption

All,
 
  Im exploring XML Encryption. Im not sure whether my approach towards XML Encryption is this:
 
1. Client Sends the public key to the Server
2. Server Generates the Shared Secret Key
3. Server Encrypts the Shared Secret Key with the Client's Public Key
4. Server Sends the Encrypted Shared Secret Key to the Client
5. Client Decrypts & fetches the Shared Secret Key
6. For each and every SOAP Request, the Client encrypts the SOAP Request with the Shared Secret Key
7. The Server upon receiving the Encrypted SOAP Request, the server decrypts with the Shared Secret Key and obtains the original Request.
8. Similarly, the Server Response is encrypted with Shared Secret Key
9. The Server Response is decrypted by the client using the Shared Secret Key.
 
  Is this the one and only mechanisms by which XML Encryption can be achieved? I think the above procedure is symmetric key XML Encryption. If so, is there any steps such as this for Asymmetric Key XML Encryption?
 
  Here the Key generation should be automated rite? If i convert any string into byte array, i get Invalid Key Size exception. Is there any standard to generate such shared key?
 
  Can anyone please help me out?
 
Regards,
Nachiappan.N
Nithya | 21 Feb 2004 08:11

[WSS4J] How to verify XML Signature in SeverSide Handler

All,
 
   Here is the code snippet, which is part of my ClientSide Handler.
 
 
 
 
   WSSignEnvelope wsSignBuilder = new WSSignEnvelope();
   wsSignBuilder.setUserInfo("d9a7bb54-ab27-43b5-b59e-50e7bfc1d343", "pfxpass");
   Document signedDoc = wsSignBuilder.build(utDoc, crypto);
   Message signedWSSignEnvMsg = (Message)AxisUtil.toSOAPMessage(signedDoc);
 
   msgContext.setCurrentMessage(signedWSSignEnvMsg);
 
 
 
 
   Basically im trying to add XML Signature to the SOAP Request in the client side handler and in the server side handler, i want to verify it. How do i verify the same in the server side?
 
   Can anyone please help me?
 
Regards,
Nithya.M
Nadadur | 20 Feb 2004 01:22

[WSS4J] ant test

Hi,

When running ant test, I get the following error.

        unitTests:

        BUILD FAILED
        /home/ws-sec/wss4j/build.xml:462: Could not create task or type
        of type: junit.

There is a junit jar file in lib (junit-3.8.1.jar).
I am using ant 1.6. ant compile works fine.

Any ideas on what the problem might be.
Nadadur

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
Dittmann Werner | 19 Feb 2004 15:28
Picon

AW: [WSS4J] Unable to initialize Crypto Factory

Hi,
 
the message "unknown attr1.3.6.1.4.1.311.17.1" always shows up.
We didn't fix it yet, however, the crypto is initialized. The message
is printed by Bouncycastle classes (AFAIK).
 
Regards,
Werner

-----Ursprüngliche Nachricht-----
Von: wss4j-devel-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org [mailto:wss4j-devel-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] Im Auftrag von Nachiappan Narayanan
Gesendet: Donnerstag, 19. Februar 2004 14:35
An: wss-comment-sDuHXQ4OtrM4h7I2RyI4rWD2FQJk+8+b@public.gmane.org; wss4j-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org; Rajesh Koilpillai; Mukund Balasubramanian; Nithya
Betreff: [WSS4J] Unable to initialize Crypto Factory

All,
 
  Im unable to get the instance of the Crypto. The following line itself fails.
 
 static final Crypto crypto = CryptoFactory.getInstance();
  When i compile and run the following program as,
        c:\test> java -Dlog4j.configuration=log.config TestWSSecurity
 
  I get the following info. on the console,
 
C:\test>java -Dlog4j.configuration=log.config TestWSSecurity
2004-02-19 18:42:28,312 [DEBUG] util.Loader          - Trying to find [crypto.properties] using sun.misc.Launcher$AppClassLoader-KeHM6iR8k4I@public.gmane.org class loader.
2004-02-19 18:42:28,359 [INFO] crypto.CryptoFactory - Using Crypto Engine [org.apache.ws.security.components.crypto.Merlin]
unknown attr1.3.6.1.4.1.311.17.1
 
  How do i resolve this?
 
  Am i doing any mistake?
 
Regards,
Nachiappan.N
Nachiappan Narayanan | 19 Feb 2004 14:34

[WSS4J] Unable to initialize Crypto Factory

All,
 
  Im unable to get the instance of the Crypto. The following line itself fails.
 
 static final Crypto crypto = CryptoFactory.getInstance();
  When i compile and run the following program as,
        c:\test> java -Dlog4j.configuration=log.config TestWSSecurity
 
  I get the following info. on the console,
 
C:\test>java -Dlog4j.configuration=log.config TestWSSecurity
2004-02-19 18:42:28,312 [DEBUG] util.Loader          - Trying to find [crypto.properties] using sun.misc.Launcher$AppClassLoader-KeHM6iR8k4I@public.gmane.org class loader.
2004-02-19 18:42:28,359 [INFO] crypto.CryptoFactory - Using Crypto Engine [org.apache.ws.security.components.crypto.Merlin]
unknown attr1.3.6.1.4.1.311.17.1
 
  How do i resolve this?
 
  Am i doing any mistake?
 
Regards,
Nachiappan.N
Attachment (TestWSSecurity.java): text/java, 4707 bytes
Attachment (log.config): application/octet-stream, 2699 bytes
Attachment (crypto.properties): text/properties, 420 bytes
Nachiappan Narayanan | 19 Feb 2004 14:26

nithya@...>

All,
 
  Im unable to get the instance of the Crypto. The following line itself fails.
 
 static final Crypto crypto = CryptoFactory.getInstance();
  When i compile and run the following program as,
        c:\test> java -Dlog4j.configuration=log.config TestWSSecurity
 
  I get the following info. on the console,
 
C:\test>java -Dlog4j.configuration=log.config TestWSSecurity
2004-02-19 18:42:28,312 [DEBUG] util.Loader          - Trying to find [crypto.properties] using sun.misc.Launcher$AppClassLoader-KeHM6iR8k4I@public.gmane.org class loader.
2004-02-19 18:42:28,359 [INFO] crypto.CryptoFactory - Using Crypto Engine [org.apache.ws.security.components.crypto.Merlin]
unknown attr1.3.6.1.4.1.311.17.1
 
  How do i resolve this?
 
  Am i doing any mistake?
 
Regards,
Nachiappan.N
Attachment (log.config): application/octet-stream, 2699 bytes
Attachment (TestWSSecurity.java): text/java, 4707 bytes
Attachment (crypto.properties): text/properties, 420 bytes
Pravir Ramtekkar | 16 Feb 2004 20:20

[WSS4J] WSS4J

Hi,
I was just wondering when will the project files be available on apache?
We are planning to use this with Axis.
thanx,
Pravir

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
Davanum Srinivas | 13 Feb 2004 20:39
Picon
Favicon

[WSS4J] Moving to Apache.

Werner, Team,

I will be checking in a version of wss4j in Apache's CVS. only diff is the LICENSE has been
updated to Apache 2.0 License as per ASF mandate. 

Thanks,
dims

PS: Please hold off any new check-in's in sf.net cvs till we get the project up and running at
Apache.

=====
Davanum Srinivas - http://webservices.apache.org/~dims/

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
wernerd | 13 Feb 2004 17:11
Picon

[WSS4J] wss4j/src/org/apache/ws/security/message/token SecurityTokenReference.java,1.8,1.9

Update of /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/token
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10700/src/org/apache/ws/security/message/token

Modified Files:
	SecurityTokenReference.java 
Log Message:
Add some functions to support SKI KeyIdentifier. Not tested yet, but
doesn't break existing functions.

Index: SecurityTokenReference.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/token/SecurityTokenReference.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- SecurityTokenReference.java	22 Dec 2003 13:36:29 -0000	1.8
+++ SecurityTokenReference.java	13 Feb 2004 16:11:05 -0000	1.9
 <at>  <at>  -54,19 +54,26  <at>  <at> 
  */
 package org.apache.ws.security.message.token;

+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.components.crypto.Crypto;
 import org.apache.ws.security.util.DOM2Writer;
 import org.apache.xml.security.keys.content.x509.XMLX509IssuerSerial;
+import org.apache.xml.security.keys.content.x509.XMLX509SKI;
 import org.apache.xml.security.utils.Base64;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Text;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;

 import javax.xml.namespace.QName;
 import java.security.cert.X509Certificate;

+
 /**
  * Security Token Reference.
  * <p/>
 <at>  <at>  -74,8 +81,15  <at>  <at> 
  *  <at> author Davanum Srinivas (dims@...).
  */
 public class SecurityTokenReference {
+	private static Log log = LogFactory.getLog(SecurityTokenReference.class.getName());
+	private static Log tlog =
+		LogFactory.getLog("org.apache.ws.security.TIME");
+
+	
     public static final QName TOKEN = new QName(WSConstants.WSSE_NS, "SecurityTokenReference");
     protected Element element = null;
+    
+    private boolean doDebug = false;

     /**
      * Constructor.
 <at>  <at>  -85,6 +99,7  <at>  <at> 
      *  <at> throws WSSecurityException 
      */
     public SecurityTokenReference(Element elem) throws WSSecurityException {
+		doDebug = log.isDebugEnabled();
         this.element = elem;
         QName el = new QName(this.element.getNamespaceURI(), this.element.getLocalName());
         if (!el.equals(TOKEN)) {
 <at>  <at>  -99,6 +114,7  <at>  <at> 
      *  <at> param doc 
      */
     public SecurityTokenReference(Document doc) {
+		doDebug = log.isDebugEnabled();
         this.element = doc.createElementNS(WSConstants.WSSE_NS, "wsse:SecurityTokenReference");
     }

 <at>  <at>  -140,7 +156,7  <at>  <at> 
     public void setKeyIdentifier(X509Certificate cert) throws Exception {
         Document doc = this.element.getOwnerDocument();
         byte data[] = cert.getEncoded();
-        org.w3c.dom.Text certText = doc.createTextNode(Base64.encode(data));
+        Text certText = doc.createTextNode(Base64.encode(data));
         Element keyId = doc.createElementNS(WSConstants.WSSE_NS, "wsse:KeyIdentifier");
 		keyId.setAttributeNS(null, "ValueType", "wsse:X509v3");
 		keyId.setAttributeNS(null, "EncodingType", "wsse:Base64Binary");
 <at>  <at>  -152,6 +168,29  <at>  <at> 
             this.element.appendChild(keyId);
         }
     }
+	/**
+	 * Sets the KeyIdentifer Element as a X509 Subject-Key-Identifier (SKI).
+	 * Takes a X509 certificate, gets it SKI data, converts into base 64 and
+	 * inserts it into a <code>wsse:KeyIdentifier</code> element, which is placed
+	 * in the <code>wsse:SecurityTokenReference</code> element.
+	 * 
+	 *  <at> param cert is the X509 certficate to get the SKI
+	 */
+	public void setKeyIdentifierSKI(X509Certificate cert) throws Exception {
+		Document doc = this.element.getOwnerDocument();
+		byte data[] = XMLX509SKI.getSKIBytesFromCert(cert);
+		org.w3c.dom.Text skiText = doc.createTextNode(Base64.encode(data));
+		Element keyId = doc.createElementNS(WSConstants.WSSE_NS, "wsse:KeyIdentifier");
+		keyId.setAttributeNS(null, "ValueType", "wsse:X509SubjectKeyIdentifier");
+		keyId.setAttributeNS(null, "EncodingType", "wsse:Base64Binary");
+		keyId.appendChild(skiText);
+		Element elem = getFirstElement();
+		if (elem != null) {
+			this.element.replaceChild(keyId, elem);
+		} else {
+			this.element.appendChild(keyId);
+		}
+	}

 	/**
 	 * Gets the KeyIdentifer.
 <at>  <at>  -162,15 +201,85  <at>  <at> 
 	 * 			certificate or zero if a unknown key identifier
 	 * 			type was detected.
 	 */
-	public BinarySecurity getKeyIdentifier() throws Exception {
+	public BinarySecurity getKeyIdentifier(Crypto crypto) throws Exception {
 		X509Security cert = null;
 		Element elem = getFirstElement();
 		String value = elem.getAttribute("ValueType");
 		if (value.equals("wsse:X509v3")) {
 			cert = new X509Security(elem);
 		}
+		else if (value.equals("wsse:X509SubjectKeyIdentifier")) {
+			cert = getCertFromSKI(elem, crypto);
+		}
 		return cert;
 	}
+	
+	private X509Security getCertFromSKI(Element elem, Crypto crypto) throws Exception {
+		
+		if (doDebug) {
+			log.debug("getCertFromSKI: enter");
+		}
+		X509Security found = null;
+		
+		byte[] skiBytes = null;
+		Node node = elem.getFirstChild();
+		if (node == null) {
+			return null;
+		}
+		if (node.getNodeType() == Node.TEXT_NODE) {
+			try {
+				skiBytes = Base64.decode(((Text) node).getData());
+			} catch (Exception e) {
+				return null;
+			}
+		}
+		if (doDebug) {
+			log.debug("Cert SKI: got SKI bytes");
+		}
+		NodeList nl =
+			elem.getOwnerDocument().getElementsByTagNameNS(
+				WSConstants.WSSE_NS,
+				"BinarySecurityToken");
+
+		int nlLength = nl.getLength();
+		for (int i = 0; i < nlLength; i++) {
+			if (doDebug) {
+				log.debug("Cert SKI: processing BST " + i);
+			}
+			X509Security token = null;
+			Element bstElement = (Element)nl.item(i);
+			String value = bstElement.getAttribute("ValueType");
+			if (!value.equals("wsse:X509v3")
+				|| ((token = new X509Security(bstElement)) == null)) {
+				continue;
+			}
+			X509Certificate cert = token.getX509Certificate(crypto);
+			if (cert == null) {
+				continue;
+			}
+			if (doDebug) {
+				log.debug("Cert SKI: got cert from BST");
+			}			
+			byte data[] = XMLX509SKI.getSKIBytesFromCert(cert);
+			if (data.length != skiBytes.length) {
+				continue;
+			}
+			if (doDebug) {
+				log.debug("Cert SKI: got SKI bytes from embedded cert");
+			}			
+			for (int ii = 0; ii < data.length; ii++) {
+				if (data[ii] != skiBytes[ii]) {
+					continue;
+				}
+			}
+			if (doDebug) {
+				log.debug("Cert SKI: found embedded BST");
+			}
+			found = token;
+		}
+		return found;
+	}
+	
     /**
      * Sets the X509 IssuerSerial data.
      * 

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

Gmane