[WSS4J] wss4j/src/org/apache/ws/security/message WSSignEnvelope.java,1.23,1.24

[email protected] Thu, 15 Jan 2004 04:25:35 -0800
Newsgroups gmane.text.xml.wss4j
Message-ID <[email protected]>
Update of /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message
In directory sc8-pr-cvs1:/tmp/cvs-serv31504/src/org/apache/ws/security/message

Modified Files:
	WSSignEnvelope.java 
Log Message:
Start STR-Transform implementation. Only the first hooks in WSSignEnvelope,
a specific package, and a STRTransform source that is just a standard
c14n transformation as yet. Further refinements of the code follow.

Index: WSSignEnvelope.java
===================================================================
RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/message/WSSignEnvelope.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** WSSignEnvelope.java	7 Jan 2004 15:23:28 -0000	1.23
--- WSSignEnvelope.java	15 Jan 2004 12:25:33 -0000	1.24
***************
*** 60,63 ****
--- 60,64 ----
  import org.apache.ws.security.WSEncryptionPart;
  import org.apache.ws.security.WSSecurityException;
+ import org.apache.ws.security.transform.STRTransform;
  import org.apache.ws.security.components.crypto.Crypto;
  import org.apache.ws.security.message.token.BinarySecurity;
***************
*** 72,75 ****
--- 73,77 ----
  import org.apache.xml.security.signature.XMLSignature;
  import org.apache.xml.security.transforms.Transforms;
+ import org.apache.xml.security.transforms.Transform;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
***************
*** 93,96 ****
--- 95,107 ----
  	protected boolean useSingleCert = true;
  
+ 	static {
+ 		Transform.init();
+ 		try {
+ 			Transform.register(STRTransform.implementedTransformURI,
+ 				"org.apache.ws.security.transform.STRTransform");
+ 		} catch (Exception ex) {
+ 		};
+ 	}
+ 
      /**
       * Constructor.
***************
*** 180,183 ****
--- 191,197 ----
  
          KeyInfo info = sig.getKeyInfo();
+ 		String keyInfoUri = "id-" + info.hashCode();
+ 		info.setId(keyInfoUri);
+ 
          X509Certificate[] certs = crypto.getCertificates(user);
          if (certs.length <= 0) {
***************
*** 195,201 ****
  		}
  
  		Element envelope = doc.getDocumentElement();
  		Transforms transforms = null;
- 		String tokenUri = "id-" + info.hashCode();
  		
  		for (int part = 0; part < parts.size(); part++) {
--- 209,216 ----
  		}
  
+ 		String certUri = "id-" + certs[0].hashCode();
+ 		
  		Element envelope = doc.getDocumentElement();
  		Transforms transforms = null;
  		
  		for (int part = 0; part < parts.size(); part++) {
***************
*** 203,211 ****
  			String elemName = encPart.getName();
  			String nmSpace = encPart.getNamespace();
! 			
  			if (elemName.equals("Token")) {
  				transforms = new Transforms(doc);
  				transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
! 				sig.addDocument("#" + tokenUri, transforms);
  			}
  			else {
--- 218,247 ----
  			String elemName = encPart.getName();
  			String nmSpace = encPart.getNamespace();
! 
! 		/*
! 	 	 * Set up the elements to sign. 
! 	 	 * There are two resevered element names: "Token" and "STRTransform"
! 	 	 * "Token": Setup the Signature to either sign the information that 
! 	 	 * 			points to the security token or the token itself. If 
! 	 	 * 			its a direct reference sign the token, otherwise sign
! 	 	 * 			the KeyInfo Element.
! 	 	 * "STRTransform": Setup the de:Reference to use STR Transform
! 	 	 * 
! 	 	 */			
  			if (elemName.equals("Token")) {
  				transforms = new Transforms(doc);
  				transforms.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
! 				if (keyIdentifierType == WSConstants.BST_DIRECT_REFERENCE) {
! 					sig.addDocument("#" + certUri, transforms);
! 				}
! 				else {
! 					sig.addDocument("#" + keyInfoUri, transforms);
! 				}
! 			}
! 			else if (elemName.equals("STRTransform")) {
! 				Element ctx = null;
! 				transforms = new Transforms(doc);
! 				transforms.addTransform(STRTransform.implementedTransformURI /*, ctx */);
! 				sig.addDocument("#" + keyInfoUri, transforms);
  			}
  			else {
***************
*** 233,237 ****
          if (keyIdentifierType == WSConstants.BST_DIRECT_REFERENCE) {
              Reference ref = new Reference(doc);
!             ref.setURI("#" + tokenUri);
              secRef.setReference(ref);
              BinarySecurity token = null;
--- 269,273 ----
          if (keyIdentifierType == WSConstants.BST_DIRECT_REFERENCE) {
              Reference ref = new Reference(doc);
!             ref.setURI("#" + certUri);
              secRef.setReference(ref);
              BinarySecurity token = null;
***************
*** 243,247 ****
                  ((X509Security) token).setX509Certificate(certs[0]);
              }
!             token.setID(tokenUri);
              WSSecurityUtil.prependChildElement(doc, securityHeader, token.getElement(), false);
          } else if (keyIdentifierType == WSConstants.ISSUER_SERIAL) {
--- 279,283 ----
                  ((X509Security) token).setX509Certificate(certs[0]);
              }
!             token.setID(certUri);
              WSSecurityUtil.prependChildElement(doc, securityHeader, token.getElement(), false);
          } else if (keyIdentifierType == WSConstants.ISSUER_SERIAL) {
***************
*** 250,254 ****
                      certs[0].getSerialNumber());
              secRef.setX509IssuerSerial(data);
-             info.setId(tokenUri);
          } else if (keyIdentifierType == WSConstants.X509_KEY_IDENTIFIER) {
  			secRef.setKeyIdentifier(certs[0]);
--- 286,289 ----




-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html