You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by di...@apache.org on 2004/03/06 05:21:59 UTC

cvs commit: ws-fx/wss4j/src/org/apache/ws/security/message WSSignEnvelope.java

dims        2004/03/05 20:21:59

  Modified:    wss4j/src/org/apache/ws/security WSConstants.java
               wss4j/src/org/apache/ws/security/message WSSignEnvelope.java
  Log:
  Patch from "Rami Jaamour" <rj...@parasoft.com>
  for "setting the sig algorithm and canonicalization"
  
  Revision  Changes    Path
  1.6       +23 -0     ws-fx/wss4j/src/org/apache/ws/security/WSConstants.java
  
  Index: WSConstants.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/wss4j/src/org/apache/ws/security/WSConstants.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- WSConstants.java	3 Mar 2004 20:44:51 -0000	1.5
  +++ WSConstants.java	6 Mar 2004 04:21:59 -0000	1.6
  @@ -17,6 +17,8 @@
   
   package org.apache.ws.security;
   
  +import org.apache.xml.security.c14n.Canonicalizer;
  +import org.apache.xml.security.signature.XMLSignature;
   import org.apache.xml.security.utils.EncryptionConstants;
   
   /**
  @@ -148,6 +150,27 @@
   	 * This is a optional method as defined by XML encryption.
   	 */
       public static final String AES_192 = EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES192;
  +
  +    /**
  +     * Sets the {@link org.apache.ws.security.message.WSSignEnvelope#build(Document, Crypto) signature}
  +     * method to use DSA with SHA1 (DSS) to sign data.
  +     * <p/>
  +     * This is a required method as defined by XML signature. 
  +     */
  +    public static final String DSA = XMLSignature.ALGO_ID_SIGNATURE_DSA;
  +
  +    /**
  +     * Sets the {@link org.apache.ws.security.message.WSSignEnvelope#build(Document, Crypto) signature}
  +     * method to use RSA with SHA to sign data.
  +     * <p/>
  +     * This is a recommended method as defined by XML signature. 
  +     */
  +    public static final String RSA = XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1;
  +
  +    public static final String C14N_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
  +    public static final String C14N_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
  +    public static final String C14N_EXCL_OMIT_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
  +    public static final String C14N_EXCL_WITH_COMMENTS = Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
   
       /**
        * Sets the {@link org.apache.ws.security.message.WSSignEnvelope#build(Document, Crypto) signing} 
  
  
  
  1.4       +61 -2     ws-fx/wss4j/src/org/apache/ws/security/message/WSSignEnvelope.java
  
  Index: WSSignEnvelope.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/wss4j/src/org/apache/ws/security/message/WSSignEnvelope.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WSSignEnvelope.java	29 Feb 2004 12:30:35 -0000	1.3
  +++ WSSignEnvelope.java	6 Mar 2004 04:21:59 -0000	1.4
  @@ -59,6 +59,8 @@
   
       
   	protected boolean useSingleCert = true;
  +    protected String sigAlgo = XMLSignature.ALGO_ID_SIGNATURE_RSA;
  +    protected String canonAlgo = Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS; 
   
   	static {
   		Transform.init();
  @@ -117,6 +119,64 @@
   	public boolean isUseSingleCertificate() {
   		return this.useSingleCert;
   	}
  +    
  +    /**
  +     * Set the name of the signature encryption algorithm to use
  +     * <p/>
  +     * If the algorithm is not set then Triple RSA is used.
  +     * Refer to WSConstants which algorithms are supported.
  +     * <p/>
  +     * 
  +     * @param algo Is the name of the signature algorithm
  +     * @see WSConstants#RSA
  +     * @see WSConstants#DSA
  +     */
  +    public void setSignatureAlgorithm(String algo) {
  +        sigAlgo = algo;
  +    }
  +    
  +    /**
  +     * Get the name of the signature algorithm that is being used
  +     * <p/>
  +     * If the algorithm is not set then RSA is default.
  +     * <p/>
  +     * 
  +     * @return
  +     */
  +    public String getSignatureAlgorithm() {
  +        return sigAlgo;
  +    }
  +
  +    /**
  +     * Set the canonicalization method to use.
  +     * <p/>
  +     * If the canonicalization method is not set then the recommended
  +     * Exclusive XML Canonicalization is used by default
  +     * Refer to WSConstants which algorithms are supported.
  +     * <p/>
  +     * 
  +     * @param algo Is the name of the signature algorithm
  +     * @see WSConstants#C14N_OMIT_COMMENTS
  +     * @see WSConstants#C14N_WITH_COMMENTS
  +     * @see WSConstants#C14N_EXCL_OMIT_COMMENTS
  +     * @see WSConstants#C14N_EXCL_WITH_COMMENTS
  +     */
  +    public void setSigCanonicalization(String algo) {
  +        canonAlgo = algo;
  +    }
  +    
  +    /**
  +     * Get the canonicalization method.
  +     * <p/>
  +     * If the canonicalization method was not set then
  +     * Exclusive XML Canonicalization is used by default.
  +     * <p/>
  +     * 
  +     * @return
  +     */
  +    public String getSigCanonicalization() {
  +        return canonAlgo;
  +    }
   
       /**
        * Builds a signed soap envelope.
  @@ -156,8 +216,7 @@
           // Set the id of the elements to be used as digest source
   		// String id = setBodyID(doc);
           XMLSignature sig = null;
  -        sig = new XMLSignature(doc, null, XMLSignature.ALGO_ID_SIGNATURE_RSA,
  -                Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
  +        sig = new XMLSignature(doc, null, sigAlgo, canonAlgo);
           /*
            * If we don't generate a new Transforms for each addDocument
            * here, then only the last Transforms is put into the