[WSS4J] wss4j/src/org/apache/ws/security WSDocInfoStore.java,NONE,1.1 WSDocInfo.java,NONE,1.1 WSSecurityEngine.java,1.33,1.34
[email protected] Mon, 09 Feb 2004 08:10:30 -0800
| Newsgroups | gmane.text.xml.wss4j |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/wss4j/wss4j/src/org/apache/ws/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8146/src/org/apache/ws/security Modified Files: WSSecurityEngine.java Added Files: WSDocInfoStore.java WSDocInfo.java Log Message: Add some more hooks for STRTransform. In particular a way to exchange/publish some more information about the document and its environment as it is processed during signature and verfication. These hooks are working, but there is only a dummy STRTransform only. --- NEW FILE: WSDocInfoStore.java --- /* * Created on Feb 9, 2004 */ package org.apache.ws.security; /** * WSDocInfoStore store WSDocInfo structure in a static Hash. * * Also the access methods are static. Thus it is possible to exchange * WSDocInfo between otherwise unrelated functions/methods. * The main usage for this is (are) the transformation functions that * are called during Signature/Verfication process. * * @author Werner Dittmann ([email protected]) */ import java.util.Hashtable; public class WSDocInfoStore { static Hashtable storage = new Hashtable(10); public static WSDocInfo lookup (int hash) { Integer intObj = new Integer(hash); return (WSDocInfo)storage.get(intObj); } public static void store (WSDocInfo info) { Integer intObj = new Integer(info.getHash()); if (storage.containsKey(intObj)) { return; } storage.put(intObj, info); } public static void delete(int hash) { Integer intObj = new Integer(hash); WSDocInfo wsInfo = (WSDocInfo)storage.get(intObj); if (wsInfo != null) { wsInfo.clear(); storage.remove(intObj); } } public static void delete(WSDocInfo info) { delete(info.getHash()); } } --- NEW FILE: WSDocInfo.java --- /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2001-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Axis" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact [email protected] * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * Created on Feb 9, 2004 * */ package org.apache.ws.security; /** * WSDocInfo holds information about the document to process. Together * with the WSDocInfoStore it provides a method to store access document * information about BinarySecurityToken, used Crypto, and others. * </p> * Using the Document's hash a caller can identify a document and get * the stored information that me be necessary to process the document. * The main usage for this is (are) the transformation functions that * are called during Signature/Verfication process. * * @author Werner Dittmann ([email protected]) * */ import org.apache.ws.security.components.crypto.Crypto; import org.w3c.dom.Element; import java.util.Vector; import java.util.Enumeration; public class WSDocInfo { int hash; Crypto crypto = null; Vector bst = null; public WSDocInfo(int hash) { this.hash = hash; } /** * Clears the info data except the hash code * */ public void clear() { crypto = null; if (bst != null && bst.size() > 0) { bst.removeAllElements(); } bst = null; } /** * Get a BinarySecurityToken for the given Id * * @param uri is the relative uri (starts with #) of the id * @return the BST element or null if nothing found */ public Element getBst(String uri) { String id = uri.substring(1); Element elem = null; if (bst != null) { for (Enumeration e = bst.elements(); e.hasMoreElements();) { elem = (Element) e.nextElement(); String cId = elem.getAttribute("Id"); if (id.equals(cId)) { break; } } } return elem; } /** * @return the signature crypto class used to process * the signature/verfiy */ public Crypto getCrypto() { return crypto; } /** * @return the hash value of the document */ public int getHash() { return hash; } /** * @param elem is the BinarySecurityToken to store */ public void setBst(Element elem) { if (bst == null) { bst = new Vector(); } bst.add(elem); } /** * @param crypto is the signature crypto class used to * process signature/verify */ public void setCrypto(Crypto crypto) { this.crypto = crypto; } } Index: WSSecurityEngine.java =================================================================== RCS file: /cvsroot/wss4j/wss4j/src/org/apache/ws/security/WSSecurityEngine.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- WSSecurityEngine.java 21 Jan 2004 12:14:42 -0000 1.33 +++ WSSecurityEngine.java 9 Feb 2004 16:10:28 -0000 1.34 @@ -64,14 +64,17 @@ import org.apache.ws.security.message.token.SecurityTokenReference; import org.apache.ws.security.message.token.UsernameToken; import org.apache.ws.security.message.token.X509Security; +import org.apache.ws.security.transform.STRTransform; import org.apache.ws.security.util.WSSecurityUtil; import org.apache.xml.security.encryption.XMLCipher; +import org.apache.xml.security.transforms.Transform; import org.apache.xml.security.keys.KeyInfo; import org.apache.xml.security.keys.content.X509Data; import org.apache.xml.security.keys.content.x509.XMLX509Certificate; import org.apache.xml.security.keys.content.x509.XMLX509IssuerSerial; import org.apache.xml.security.signature.XMLSignature; import org.apache.xml.security.utils.Base64; + import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -150,6 +153,12 @@ } tokenImpl.put(PKIPathSecurity.TYPE, PKIPathSecurity.class); tokenImpl.put(X509Security.TYPE, X509Security.class); + Transform.init(); + try { + Transform.register(STRTransform.implementedTransformURI, + "org.apache.ws.security.transform.STRTransform"); + } catch (Exception ex) { + }; } /** @@ -280,6 +289,12 @@ if( tlog.isDebugEnabled() ) { t0=System.currentTimeMillis(); } + /* + * Gather some info about the document to process and store + * it for retrival. Store the implemenation of signature crypto + * (no need for encryption --- yet) + */ + NodeList list = securityHeader.getChildNodes(); int len = list.getLength(); Node elem; @@ -318,7 +333,23 @@ throw new WSSecurityException(WSSecurityException.FAILURE, "noSigCryptoFile"); } - lastPrincipalFound = verifyXMLSignature(sig, sigCrypto); + /* + * Gather some info about the document to process and store + * it for retrival. Store the implemenation of signature crypto + * (no need for encryption --- yet) + */ + WSDocInfo wsDocInfo = new WSDocInfo(securityHeader.getOwnerDocument().hashCode()); + wsDocInfo.setCrypto(sigCrypto); + WSDocInfoStore.store(wsDocInfo); + try { + lastPrincipalFound = verifyXMLSignature(sig, sigCrypto); + } + catch (Exception ex) { + throw ex; + } + finally { + WSDocInfoStore.delete(wsDocInfo); + } actions.add(0, new Integer(WSConstants.SIGN)); principals.add(0, lastPrincipalFound); } else if (el.equals(ENCRYPTED_KEY)) { ------------------------------------------------------- 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