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 mu...@apache.org on 2004/10/16 08:05:00 UTC

cvs commit: ws-fx/wss4j/test/secconv/components PWCallback.java TestDkEncrypt.java TestRSTR.java TestDkSign.java

muthulee    2004/10/15 23:05:00

  Modified:    wss4j/test/secconv/components TestDkEncrypt.java
                        TestRSTR.java TestDkSign.java
  Added:       wss4j/test/secconv/components PWCallback.java
  Log:
  Updating test cases for new changes.
  
  Revision  Changes    Path
  1.3       +13 -12    ws-fx/wss4j/test/secconv/components/TestDkEncrypt.java
  
  Index: TestDkEncrypt.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/wss4j/test/secconv/components/TestDkEncrypt.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestDkEncrypt.java	30 Aug 2004 09:22:57 -0000	1.2
  +++ TestDkEncrypt.java	16 Oct 2004 06:05:00 -0000	1.3
  @@ -17,11 +17,15 @@
   package secconv.components;
   
   import java.io.ByteArrayInputStream;
  +import java.io.IOException;
   import java.io.InputStream;
   import java.io.PrintWriter;
   import java.util.HashMap;
   import java.util.Vector;
   
  +import javax.security.auth.callback.Callback;
  +import javax.security.auth.callback.CallbackHandler;
  +import javax.security.auth.callback.UnsupportedCallbackException;
   import javax.xml.parsers.DocumentBuilderFactory;
   
   import junit.framework.Test;
  @@ -32,12 +36,14 @@
   import org.apache.axis.MessageContext;
   import org.apache.axis.client.AxisClient;
   import org.apache.axis.configuration.NullProvider;
  +//import org.apache.axis.encoding.Callback;
   import org.apache.axis.message.SOAPEnvelope;
   import org.apache.axis.utils.XMLUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.ws.axis.security.conversation.ConvHandlerConstants;
   import org.apache.ws.axis.security.util.AxisUtil;
  +import org.apache.ws.security.WSPasswordCallback;
   import org.apache.ws.security.WSSConfig;
   import org.apache.ws.security.conversation.ConvEngineResult;
   import org.apache.ws.security.conversation.ConversationEngine;
  @@ -57,7 +63,7 @@
    * @author Dimuthu Leelarathne. (muthulee@yahoo.com)
    *
    */
  -public class TestDkEncrypt extends TestCase {
  +public class TestDkEncrypt extends TestCase{
   	/*TODO:: Fix the bug and remove the dktoken from DkTokenInfo
   	 * Effectng changes : ConversationManger, ConversationClientHandler, ConversationServerHandler.
   	 * 
  @@ -205,13 +211,15 @@
           ConversationManager manager = new ConversationManager();
   
   		DerivedKeyInfo dkInfo =
  -					manager.addDerivedKeyToken(doc, uuid, dkcbHandler);
  +					manager.createDerivedKeyToken(doc, uuid, dkcbHandler, null, 24);
   		
   		
   		SecurityTokenReference secTokRef = dkInfo.getSecTokRef2DkToken();
   		
  -		manager.performDK_ENCR(ConversationUtil.generateIdentifier(uuid, dkInfo.getId()), "", true, doc, secTokRef, dkcbHandler);
  -	
  +		//manager.performDK_ENCR(ConversationUtil.generateIdentifier(uuid, dkInfo.getId()), "", true, doc, secTokRef, dkcbHandler);
  +	    manager.performDK_ENCR(ConversationUtil.generateIdentifier(uuid, dkInfo.getId()), "", true, doc, secTokRef, dkcbHandler, null, "http://www.w3.org/2001/04/xmlenc#tripledes-cbc");
  +	    
  +	    manager.addDkToken(doc, dkInfo);
   	    
           /*
            * convert the resulting document into a message first. The toSOAPMessage()
  @@ -239,14 +247,7 @@
           throws Exception {
          log.info("Before verifying the derived key signature");
   	   ConversationEngine engine = new ConversationEngine(config);
  -	   Vector results = engine.processSecConvHeader(doc, "", dkcbHandler,"secconv.scenarios.ping.PWCallback");
  -	   ConvEngineResult res = (ConvEngineResult)results.get(0);
  -	   if(res.getAction()==ConvEngineResult.ENCRYPT_DERIVED_KEY){
  -			log.info("Verifying the derived key signature Done");
  -	   }else{
  -	       throw new Exception("ConvResult is not set. Something is wrotn");
  -	   }
  -	   
  +	   Vector results = engine.processSecConvHeader(doc, "", dkcbHandler,null);
   	
       }
   
  
  
  
  1.3       +27 -11    ws-fx/wss4j/test/secconv/components/TestRSTR.java
  
  Index: TestRSTR.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/wss4j/test/secconv/components/TestRSTR.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestRSTR.java	30 Aug 2004 09:22:57 -0000	1.2
  +++ TestRSTR.java	16 Oct 2004 06:05:00 -0000	1.3
  @@ -18,11 +18,15 @@
   package secconv.components;
   
   import java.io.ByteArrayInputStream;
  +import java.io.IOException;
   import java.io.InputStream;
   import java.io.PrintWriter;
   import java.util.HashMap;
   import java.util.Vector;
   
  +import javax.security.auth.callback.Callback;
  +import javax.security.auth.callback.CallbackHandler;
  +import javax.security.auth.callback.UnsupportedCallbackException;
   import javax.xml.parsers.DocumentBuilderFactory;
   
   import junit.framework.Test;
  @@ -39,6 +43,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.ws.axis.security.conversation.ConvHandlerConstants;
   import org.apache.ws.axis.security.util.AxisUtil;
  +import org.apache.ws.security.WSPasswordCallback;
   import org.apache.ws.security.WSSConfig;
   import org.apache.ws.security.components.crypto.Crypto;
   import org.apache.ws.security.components.crypto.CryptoFactory;
  @@ -52,6 +57,7 @@
   import org.apache.ws.security.conversation.message.token.RequestSecurityTokenResponse;
   import org.apache.ws.security.conversation.message.token.RequestedProofToken;
   import org.apache.ws.security.conversation.message.token.SecurityContextToken;
  +import org.apache.ws.security.handler.WSHandlerConstants;
   import org.apache.ws.security.util.WSSecurityUtil;
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
  @@ -60,7 +66,7 @@
    * @author Dimuthu Leelarathne. (muthulee@yahoo.com)
    *
    */
  -public class TestRSTR extends TestCase {
  +public class TestRSTR extends TestCase implements CallbackHandler{
   	/*TODO:: Fix the bug and remove the dktoken from DkTokenInfo
   	 * Effectng changes : ConversationManger, ConversationClientHandler, ConversationServerHandler.
   	 * 
  @@ -147,7 +153,7 @@
   					   
   		this.config.put(ConvHandlerConstants.USE_FIXED_KEYLEN, new Boolean(true));
   		this.config.put(ConvHandlerConstants.KEY_LEGNTH, new Long(24));		
  -		
  +		this.config.put(WSHandlerConstants.DEC_PROP_FILE,"crypto.properties");
           
   	}
   
  @@ -240,16 +246,26 @@
   		throws Exception {
   	   log.info("Before verifying RSTR............");
   	   ConversationEngine engine = new ConversationEngine(config);
  -	   Vector results = engine.processSecConvHeader(doc, "", dkcbHandler,"secconv.scenarios.ping.PWCallback");
  -	   ConvEngineResult res = (ConvEngineResult)results.get(0);
  -	   if(res.getAction()==ConvEngineResult.SECURITY_TOKEN_RESPONSE){
  -			log.info("Verified successfully, RSTR ............");
  -	   }else{
  -		   throw new Exception("ConvResult is not set properly. Something is wrong");
  -	   }
  -	   
  -	
  +	   Vector results = engine.processSecConvHeader(doc, "", dkcbHandler, "secconv.components.PWCallback");
   	}
  +	
  +	public void handle(Callback[] callbacks)
  +				   throws IOException, UnsupportedCallbackException {
  +			   for (int i = 0; i < callbacks.length; i++) {
  +				   if (callbacks[i] instanceof WSPasswordCallback) {
  +					   WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
  +					   /*
  +						* here call a function/method to lookup the password for
  +						* the given identifier (e.g. a user name or keystore alias)
  +						* e.g.: pc.setPassword(passStore.getPassword(pc.getIdentfifier))
  +						* for Testing we supply a fixed name here.
  +						*/
  +					   pc.setPassword("secret");
  +				   } else {
  +					   throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
  +				   }
  +			   }
  +   }
   
   
   
  
  
  
  1.4       +19 -25    ws-fx/wss4j/test/secconv/components/TestDkSign.java
  
  Index: TestDkSign.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/wss4j/test/secconv/components/TestDkSign.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestDkSign.java	30 Aug 2004 09:22:57 -0000	1.3
  +++ TestDkSign.java	16 Oct 2004 06:05:00 -0000	1.4
  @@ -17,11 +17,15 @@
   package secconv.components;
   
   import java.io.ByteArrayInputStream;
  +import java.io.IOException;
   import java.io.InputStream;
   import java.io.PrintWriter;
   import java.util.HashMap;
   import java.util.Vector;
   
  +import javax.security.auth.callback.Callback;
  +import javax.security.auth.callback.CallbackHandler;
  +import javax.security.auth.callback.UnsupportedCallbackException;
   import javax.xml.parsers.DocumentBuilderFactory;
   
   import junit.framework.Test;
  @@ -38,10 +42,12 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.ws.axis.security.conversation.ConvHandlerConstants;
   import org.apache.ws.axis.security.util.AxisUtil;
  +import org.apache.ws.security.WSPasswordCallback;
   import org.apache.ws.security.WSSConfig;
   import org.apache.ws.security.conversation.ConvEngineResult;
   import org.apache.ws.security.conversation.ConversationEngine;
   import org.apache.ws.security.conversation.ConversationManager;
  +import org.apache.ws.security.conversation.ConversationUtil;
   import org.apache.ws.security.conversation.DerivedKeyCallbackHandler;
   import org.apache.ws.security.conversation.DerivedKeyTokenAdder;
   import org.apache.ws.security.conversation.message.info.DerivedKeyInfo;
  @@ -55,7 +61,7 @@
    * @author Dimuthu Leelarathne. (muthulee@yahoo.com)
    *
    */
  -public class TestDkSign extends TestCase {
  +public class TestDkSign extends TestCase{
       /*TODO:: Fix the bug and remove the dktoken from DkTokenInfo
        * Effectng changes : ConversationManger, ConversationClientHandler, ConversationServerHandler.
        * 
  @@ -202,14 +208,17 @@
   
           ConversationManager manager = new ConversationManager();
   
  -        DerivedKeyInfo dkInfo =
  -                    manager.addDerivedKeyToken(doc, uuid, dkcbHandler);
  -        
  -        
  -    
  +		DerivedKeyInfo dkInfo =
  +					 manager.createDerivedKeyToken(doc, uuid, dkcbHandler, null, 24);
  +		
  +		
  +		System.out.println("he"+uuid+"$$$$$$$$$" +dkInfo.getId());
  +		
  +		
           String genID = dkInfo.getId();
  -        manager.performDK_Sign(doc, dkcbHandler, uuid, dkInfo);
  +        manager.performDK_Sign(doc, dkcbHandler, uuid, dkInfo,null);
       
  +        manager.addDkToken(doc, dkInfo);
           
           /*
            * convert the resulting document into a message first. The toSOAPMessage()
  @@ -237,24 +246,9 @@
           throws Exception {
          log.info("Before verifying the derived key signature");
          ConversationEngine engine = new ConversationEngine(config);
  -       Vector results = engine.processSecConvHeader(doc, "", dkcbHandler,"secconv.scenarios.ping.PWCallback");
  -       ConvEngineResult res = (ConvEngineResult)results.get(0);
  -       if(res.getAction()==ConvEngineResult.SIGN_DERIVED_KEY){
  -            log.info("Verifying the derived key signature Done");
  -       }else{
  -           throw new Exception("ConvResult is not set. Something is wrotn");
  -       }
  -       
  -    
  +       Vector results = engine.processSecConvHeader(doc, "", dkcbHandler, null);
  +       System.out.println("Success");
       }
   
  -    public static void main(String[] args) throws Exception {
  -        TestDkSign test = new TestDkSign("TestWSSecurity10");
  -        test.setUp();
  -        test.testPerformDkSign();
  -
  -    }
  -
  -
  -
  +  
   }
  
  
  
  1.1                  ws-fx/wss4j/test/secconv/components/PWCallback.java
  
  Index: PWCallback.java
  ===================================================================
  /*
   * Copyright  2003-2004 The Apache Software Foundation.
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   *
   */
  
  /**
   * @author Werner Dittmann (Werner.Dittmann@siemens.com)
   */
  package secconv.components;
  
  import org.apache.ws.security.WSPasswordCallback;
  
  import javax.security.auth.callback.Callback;
  import javax.security.auth.callback.CallbackHandler;
  import javax.security.auth.callback.UnsupportedCallbackException;
  import java.io.IOException;
  
  /**
   * Class PWCallback
   */
  public class PWCallback implements CallbackHandler {
  
      /** Field key */
      private static final byte[] key = {
          (byte) 0x31, (byte) 0xfd, (byte) 0xcb, (byte) 0xda, (byte) 0xfb,
          (byte) 0xcd, (byte) 0x6b, (byte) 0xa8, (byte) 0xe6, (byte) 0x19,
          (byte) 0xa7, (byte) 0xbf, (byte) 0x51, (byte) 0xf7, (byte) 0xc7,
          (byte) 0x3e, (byte) 0x80, (byte) 0xae, (byte) 0x98, (byte) 0x51,
          (byte) 0xc8, (byte) 0x51, (byte) 0x34, (byte) 0x04,
      };
  
      /*
       * (non-Javadoc)
       * @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[])
       */
  
      /**
       * Method handle
       * 
       * @param callbacks 
       * @throws IOException                  
       * @throws UnsupportedCallbackException 
       */
      public void handle(Callback[] callbacks)
              throws IOException, UnsupportedCallbackException {
  
          for (int i = 0; i < callbacks.length; i++) {
              if (callbacks[i] instanceof WSPasswordCallback) {
                  WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
  
                  /*
                   * here call a function/method to lookup the password for
                   * the given identifier (e.g. a user name or keystore alias)
                   * e.g.: pc.setPassword(passStore.getPassword(pc.getIdentfifier))
                   * for Testing we supply a fixed name here.
                   */
                  if (pc.getUsage() == WSPasswordCallback.KEY_NAME) {
                      pc.setKey(key);
                  } else {
                      pc.setPassword("security");
                  }
              } else {
                  throw new UnsupportedCallbackException(callbacks[i],
                          "Unrecognized Callback");
              }
          }
      }
  }