Return-Path: Delivered-To: apmail-ws-wss4j-dev-archive@www.apache.org Received: (qmail 89086 invoked from network); 2 May 2006 09:50:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 May 2006 09:50:37 -0000 Received: (qmail 19538 invoked by uid 500); 2 May 2006 09:49:48 -0000 Delivered-To: apmail-ws-wss4j-dev-archive@ws.apache.org Received: (qmail 19240 invoked by uid 500); 2 May 2006 09:49:46 -0000 Mailing-List: contact wss4j-dev-help@ws.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list wss4j-dev@ws.apache.org Received: (qmail 19036 invoked by uid 500); 2 May 2006 09:49:45 -0000 Delivered-To: apmail-ws-wss4j-cvs@ws.apache.org Received: (qmail 19013 invoked by uid 99); 2 May 2006 09:49:45 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 May 2006 02:49:45 -0700 X-ASF-Spam-Status: No, hits=-8.6 required=10.0 tests=ALL_TRUSTED,INFO_TLD,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 02 May 2006 02:49:41 -0700 Received: (qmail 88357 invoked by uid 65534); 2 May 2006 09:49:15 -0000 Message-ID: <20060502094915.88313.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r398880 [4/10] - in /webservices/wss4j/site/xref-test: ./ components/ interop/ policy/ sandbox/ secconv/ secconv/components/ secconv/scenarios/ secconv/scenarios/ping/ secconv/scenarios/ping/impl/ wssec/ Date: Tue, 02 May 2006 09:36:30 -0000 To: wss4j-cvs@ws.apache.org From: ruchithf@apache.org X-Mailer: svnmailer-1.0.8 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: webservices/wss4j/site/xref-test/wssec/TestBase64.html URL: http://svn.apache.org/viewcvs/webservices/wss4j/site/xref-test/wssec/TestBase64.html?rev=398880&view=auto ============================================================================== --- webservices/wss4j/site/xref-test/wssec/TestBase64.html (added) +++ webservices/wss4j/site/xref-test/wssec/TestBase64.html Tue May 2 02:36:22 2006 @@ -0,0 +1,134 @@ + + + +TestBase64 xref + + + +
+
+1   /*
+2    * Created on 09.09.2005
+3    *
+4    * To change the template for this generated file go to
+5    * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+6    */
+7   package wssec;
+8   
+9   import java.util.Arrays;
+10  import junit.framework.TestCase;
+11  import org.apache.ws.security.util.Base64;
+12  import org.apache.ws.security.WSSecurityException;
+13  
+14  public class TestBase64 extends TestCase {
+15  
+16      private byte[] dataBinary = null;
+17      
+18      /*
+19       * The following String is the value "This is a test\n" encoded
+20       * in Base64
+21       */
+22      private String thisIsATestEnc = "VGhpcyBpcyBhIHRlc3QK";
+23      private String thisIsATestClear = "This is a test\n";
+24      private String thisIsATestEnc4group = "VGhp\ncyBp\ncyBh\nIHRl\nc3QK";
+25      
+26      private String encodedBinary;
+27      
+28      public static void main(String[] args) {
+29          junit.textui.TestRunner.run(TestBase64.class);
+30      }
+31  
+32      public TestBase64(String arg0) {
+33          super(arg0);
+34      }
+35  
+36      protected void setUp() throws Exception {
+37          super.setUp();
+38          dataBinary = new byte[256];
+39          for (int i = 0; i < 256; i++) {
+40              dataBinary[i] = (byte)i;
+41          }
+42      }
+43  
+44      /*
+45       * Class under test for String encode(byte[])
+46       */
+47      public void testEncodebyteArray() {
+48          String isATestEnc = Base64.encode(thisIsATestClear.getBytes());
+49          assertEquals(isATestEnc, thisIsATestEnc);
+50  
+51          encodedBinary = Base64.encode(dataBinary);
+52          byte[] outBinary = null;
+53          try {
+54              outBinary = Base64.decode(encodedBinary);
+55          } catch (WSSecurityException ex) {
+56  
+57          }
+58          assertTrue(Arrays.equals(outBinary, dataBinary));
+59      }
+60  
+61      /*
+62       * Class under test for String encode(byte[], int, boolean)
+63       */
+64      public void testEncodebyteArrayintboolean() {
+65          String isATestEnc = Base64.encode(thisIsATestClear.getBytes(), 4, false);
+66          assertEquals(isATestEnc, thisIsATestEnc);
+67  
+68          isATestEnc = Base64.encode(thisIsATestClear.getBytes(), 76, false);
+69          assertEquals(isATestEnc, thisIsATestEnc);
+70  
+71          isATestEnc = Base64.encode(thisIsATestClear.getBytes(), 4, true);
+72          assertEquals(isATestEnc, thisIsATestEnc4group);
+73  
+74          isATestEnc = Base64.encode(thisIsATestClear.getBytes(), 76, true);
+75          assertEquals(isATestEnc, thisIsATestEnc);
+76          
+77          encodedBinary = Base64.encode(dataBinary, 4, false);
+78          byte[] outBinary = null;
+79          try {
+80              outBinary = Base64.decode(encodedBinary);
+81          } catch (WSSecurityException ex) {
+82          }
+83          assertTrue(Arrays.equals(outBinary, dataBinary));   
+84          
+85          encodedBinary = Base64.encode(dataBinary, 76, false);
+86          outBinary = null;
+87          try {
+88              outBinary = Base64.decode(encodedBinary);
+89          } catch (WSSecurityException ex) {
+90          }
+91          assertTrue(Arrays.equals(outBinary, dataBinary));        
+92          
+93          encodedBinary = Base64.encode(dataBinary, 4, true);
+94          outBinary = null;
+95          try {
+96              outBinary = Base64.decode(encodedBinary);
+97          } catch (WSSecurityException ex) {
+98          }
+99          assertTrue(Arrays.equals(outBinary, dataBinary));    
+100         
+101         encodedBinary = Base64.encode(dataBinary, 76, true);
+102         outBinary = null;
+103         try {
+104             outBinary = Base64.decode(encodedBinary);
+105         } catch (WSSecurityException ex) {
+106         }
+107         assertTrue(Arrays.equals(outBinary, dataBinary));        
+108     }
+109 
+110     public void testDecode() {
+111         byte[] out = null;
+112         byte[] outBinary = null;
+113         try {
+114             out = Base64.decode(thisIsATestEnc);
+115         } catch (WSSecurityException ex) {
+116 
+117         }
+118         assertEquals(new String(out), thisIsATestClear);
+119     }
+120 
+121 }
+
+
+ + Added: webservices/wss4j/site/xref-test/wssec/TestWSSecurity4.html URL: http://svn.apache.org/viewcvs/webservices/wss4j/site/xref-test/wssec/TestWSSecurity4.html?rev=398880&view=auto ============================================================================== --- webservices/wss4j/site/xref-test/wssec/TestWSSecurity4.html (added) +++ webservices/wss4j/site/xref-test/wssec/TestWSSecurity4.html Tue May 2 02:36:22 2006 @@ -0,0 +1,187 @@ + + + +TestWSSecurity4 xref + + + +
+
+1   /*
+2    * Copyright  2003-2004 The Apache Software Foundation.
+3    *
+4    *  Licensed under the Apache License, Version 2.0 (the "License");
+5    *  you may not use this file except in compliance with the License.
+6    *  You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   *  Unless required by applicable law or agreed to in writing, software
+11   *  distributed under the License is distributed on an "AS IS" BASIS,
+12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   *  See the License for the specific language governing permissions and
+14   *  limitations under the License.
+15   *
+16   */
+17  package wssec;
+18  
+19  import junit.framework.Test;
+20  import junit.framework.TestCase;
+21  import junit.framework.TestSuite;
+22  import org.apache.axis.Message;
+23  import org.apache.axis.MessageContext;
+24  import org.apache.axis.client.AxisClient;
+25  import org.apache.axis.configuration.NullProvider;
+26  import org.apache.axis.message.SOAPEnvelope;
+27  import org.apache.commons.logging.Log;
+28  import org.apache.commons.logging.LogFactory;
+29  import org.apache.ws.security.WSSecurityEngine;
+30  import org.apache.ws.security.components.crypto.Crypto;
+31  import org.apache.ws.security.components.crypto.CryptoFactory;
+32  import org.w3c.dom.Document;
+33  
+34  import java.io.ByteArrayInputStream;
+35  import java.io.InputStream;
+36  
+37  
+38  
+39  /***
+40   * WS-Security Test Case
+41   * <p/>
+42   * 
+43   * @author Davanum Srinivas (dims@yahoo.com)
+44   * @author Werner Dittmann (Werner.Dittmann@t-online.de)
+45   */
+46  public class TestWSSecurity4 extends TestCase {
+47      private static Log log = LogFactory.getLog(TestWSSecurity4.class);
+48      static final String NS = "http://www.w3.org/2000/09/xmldsig#";
+49      static final String soapMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<SOAP-ENV:Body>" + "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\">" + "<value xmlns=\"\">15</value>" + "</add>" + "</SOAP-ENV:Body>\r\n       \r\n" + "</SOAP-ENV:Envelope>";
+50      static final WSSecurityEngine secEngine = new WSSecurityEngine();
+51      static final Crypto crypto = CryptoFactory.getInstance("cryptoSKI.properties");
+52  
+53      MessageContext msgContext;
+54      SOAPEnvelope unsignedEnvelope;
+55  
+56      /***
+57       * TestWSSecurity constructor
+58       * <p/>
+59       * 
+60       * @param name name of the test
+61       */
+62      public TestWSSecurity4(String name) {
+63          super(name);
+64      }
+65  
+66      /***
+67       * JUnit suite
+68       * <p/>
+69       * 
+70       * @return a junit test suite
+71       */
+72      public static Test suite() {
+73          return new TestSuite(TestWSSecurity4.class);
+74      }
+75  
+76      /***
+77       * Main method
+78       * <p/>
+79       * 
+80       * @param args command line args
+81       */
+82      public static void main(String[] args) {
+83          junit.textui.TestRunner.run(suite());
+84      }
+85  
+86      /***
+87       * Setup method
+88       * <p/>
+89       * 
+90       * @throws java.lang.Exception Thrown when there is a problem in setup
+91       */
+92      protected void setUp() throws Exception {
+93          AxisClient tmpEngine = new AxisClient(new NullProvider());
+94          msgContext = new MessageContext(tmpEngine);
+95          unsignedEnvelope = getSOAPEnvelope();
+96      }
+97  
+98      /***
+99       * Constructs a soap envelope
+100      * <p/>
+101      * 
+102      * @return soap envelope
+103      * @throws java.lang.Exception if there is any problem constructing the soap envelope
+104      */
+105     protected SOAPEnvelope getSOAPEnvelope() throws Exception {
+106         InputStream in = new ByteArrayInputStream(soapMsg.getBytes());
+107         Message msg = new Message(in);
+108         msg.setMessageContext(msgContext);
+109         return msg.getSOAPEnvelope();
+110     }
+111 
+112     /***
+113      * Test that signs and verifies a WS-Security envelope using SubjectKeyIdentifier.
+114      * This test uses the SubjectKeyIdentifier to identify the certificate. It
+115      * uses the Direct version, that is it embedds the certificate in the message.
+116      * <p/>
+117      * 
+118      * @throws java.lang.Exception Thrown when there is any problem in signing or verification
+119      */
+120 //    public void testX509SignatureSKIDirect() throws Exception {
+121 //        SOAPEnvelope envelope = null;
+122 //        WSSignEnvelope builder = new WSSignEnvelope();
+123 //        builder.setUserInfo("wss4jcert", "security");
+124 //        builder.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER_DIRECT);
+125 //
+126 //        // builder.setUserInfo("john", "keypass");
+127 //        log.info("Before Signing....");
+128 //        Document doc = unsignedEnvelope.getAsDocument();
+129 //        Document signedDoc = builder.build(doc, crypto);
+130 //
+131 //        /*
+132 //         * convert the resulting document into a message first. The toSOAPMessage()
+133 //         * mehtod performs the necessary c14n call to properly set up the signed
+134 //         * document and convert it into a SOAP message. After that we extract it
+135 //         * as a document again for further processing.
+136 //         */
+137 //
+138 //        Message signedMsg = (Message) SOAPUtil.toSOAPMessage(signedDoc);
+139 //        XMLUtils.PrettyElementToWriter(signedMsg.getSOAPEnvelope().getAsDOM(), new PrintWriter(System.out));
+140 //
+141 //        signedDoc = signedMsg.getSOAPEnvelope().getAsDocument();
+142 //        log.info("After Signing....");
+143 //        verify(signedDoc);
+144 //    }
+145 
+146     /***
+147      * Test that signs (twice) and verifies a WS-Security envelope
+148      * <p/>
+149      * 
+150      * @throws java.lang.Exception Thrown when there is any problem in signing or verification
+151      */
+152 //    public void testDoubleX509SignatureSKIDirect() throws Exception {
+153 //        SOAPEnvelope envelope = null;
+154 //        WSSignEnvelope builder = new WSSignEnvelope();
+155 //        builder.setUserInfo("wss4jcert", "security");
+156 //        builder.setKeyIdentifierType(WSConstants.SKI_KEY_IDENTIFIER_DIRECT);
+157 //
+158 //        // builder.setUserInfo("john", "keypass");
+159 //        Document doc = unsignedEnvelope.getAsDocument();
+160 //        Document signedDoc = builder.build(doc, crypto);
+161 //        Document signedDoc1 = builder.build(signedDoc, crypto);
+162 //        verify(signedDoc1);
+163 //    }
+164 
+165     /***
+166      * Verifies the soap envelope
+167      * 
+168      * @param env soap envelope
+169      * @throws java.lang.Exception Thrown when there is a problem in verification
+170      */
+171     private void verify(Document doc) throws Exception {
+172         secEngine.processSecurityHeader(doc, null, null, crypto);
+173     }
+174 }
+
+
+ + Added: webservices/wss4j/site/xref-test/wssec/TestWSSecurityHooks.html URL: http://svn.apache.org/viewcvs/webservices/wss4j/site/xref-test/wssec/TestWSSecurityHooks.html?rev=398880&view=auto ============================================================================== --- webservices/wss4j/site/xref-test/wssec/TestWSSecurityHooks.html (added) +++ webservices/wss4j/site/xref-test/wssec/TestWSSecurityHooks.html Tue May 2 02:36:22 2006 @@ -0,0 +1,282 @@ + + + +TestWSSecurityHooks xref + + + +
+
+1   /*
+2    * Copyright  2003-2004 The Apache Software Foundation.
+3    *
+4    *  Licensed under the Apache License, Version 2.0 (the "License");
+5    *  you may not use this file except in compliance with the License.
+6    *  You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   *  Unless required by applicable law or agreed to in writing, software
+11   *  distributed under the License is distributed on an "AS IS" BASIS,
+12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   *  See the License for the specific language governing permissions and
+14   *  limitations under the License.
+15   *
+16   */
+17  
+18  package wssec;
+19  
+20  import junit.framework.Test;
+21  import junit.framework.TestCase;
+22  import junit.framework.TestSuite;
+23  import org.apache.axis.AxisFault;
+24  import org.apache.axis.Message;
+25  import org.apache.axis.MessageContext;
+26  import org.apache.axis.client.AxisClient;
+27  import org.apache.axis.configuration.NullProvider;
+28  import org.apache.commons.logging.Log;
+29  import org.apache.commons.logging.LogFactory;
+30  import org.apache.ws.axis.security.WSDoAllReceiver;
+31  import org.apache.ws.axis.security.WSDoAllSender;
+32  import org.apache.ws.security.WSPasswordCallback;
+33  import org.apache.ws.security.components.crypto.BouncyCastle;
+34  import org.apache.ws.security.components.crypto.Crypto;
+35  import org.apache.ws.security.handler.WSHandlerConstants;
+36  
+37  import javax.security.auth.callback.Callback;
+38  import javax.security.auth.callback.CallbackHandler;
+39  import javax.security.auth.callback.UnsupportedCallbackException;
+40  import java.io.ByteArrayInputStream;
+41  import java.io.FileInputStream;
+42  import java.io.IOException;
+43  import java.io.InputStream;
+44  import java.security.KeyStore;
+45  
+46  /***
+47   * <dl>
+48   * <dt><b>Title: </b><dd>WS Security Hooks Test Case</dd>
+49   * <p>
+50   * <dt><b>Description: </b><dd>Test Case to verify the load...Crypto hooks work properly. 
+51   * Also tests the setKeyStore method of Merlin </dd>
+52   * </dl>
+53   * 
+54   * @see org.apache.ws.security.components.crypto.Merlin#setKeyStore
+55   * @see org.apache.ws.axis.security.WSDoAllReceiver#loadSignatureCrypto
+56   * @see org.apache.ws.axis.security.WSDoAllReceiver#loadDecryptionCrypto
+57   * @see org.apache.ws.axis.security.WSDoAllSender#loadSignatureCrypto
+58   * @see org.apache.ws.axis.security.WSDoAllSender#loadEncryptionCrypto
+59   * 
+60   * @author <a href="mailto:jasone@greenrivercomputing.com>Jason Essington</a>
+61   * @version $Revision: 289252 $
+62   */
+63  public class TestWSSecurityHooks extends TestCase implements CallbackHandler
+64  {
+65     private static Log log = LogFactory.getLog(TestWSSecurityHooks.class);
+66     private static final String soapMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+
+67           "<soapenv:Envelope " +
+68                 "xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\" " +
+69                 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
+70                 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
+71              "<soapenv:Header>" +
+72              "</soapenv:Header>" +
+73              "<soapenv:Body>" +
+74                 "<ns1:echo " +
+75                       "xmlns:ns1=\"http://org.apache.wss4j.wssec/TESTCASE\" " +
+76                       "soapenv:encodingStyle=\"http://www.w3.org/2003/05/soap-encoding\">" +
+77                    "<inStr xsi:type=\"xsd:string\">ECHO ECHo ECho Echo echo echO ecHO eCHO ECHO</inStr>" +
+78                 "</ns1:echo>" +
+79              "</soapenv:Body>" +
+80           "</soapenv:Envelope>";
+81  
+82     KeyStore keystore = null;
+83     MessageContext mc = null;
+84     
+85     public TestWSSecurityHooks(String name) {
+86        super(name);
+87     }
+88     
+89     protected void setUp() throws Exception {
+90        AxisClient tmpEngine = new AxisClient(new NullProvider());
+91        mc = new MessageContext(tmpEngine);
+92        mc.setCurrentMessage(getSOAPMessage(soapMessage));
+93        mc.setProperty(WSHandlerConstants.PW_CALLBACK_REF, this);
+94        keystore = loadKeyStore();
+95     }
+96  
+97     public static Test suite() {
+98        return new TestSuite(TestWSSecurityHooks.class);
+99     }
+100 
+101    public static void main(String[] args) {
+102       junit.textui.TestRunner.run(suite());
+103    }
+104    
+105    //
+106    //
+107    // Tests
+108    //
+109    //
+110    
+111    public void testCryptoHook() throws Exception {
+112       assertNotNull("", keystore);
+113       Crypto crypto = new TestCryptoImpl(keystore);
+114       assertNotNull(PrivilegedAccessor.getValue(crypto, "keystore"));
+115    }
+116    public void testSenderLoadSignatureHook() throws Exception {
+117       TestSenderImpl sender = new TestSenderImpl();
+118       // we have to coerce a value into this field or we'll get a bunch of NPEs when calling decodeSignatureParameter
+119       PrivilegedAccessor.setValue(sender, "msgContext", mc);
+120       PrivilegedAccessor.invokeMethod(sender, "decodeSignatureParameter", new Object[] {});
+121       assertNotNull(PrivilegedAccessor.getValue(sender, "sigCrypto"));
+122    }
+123    public void testSenderLoadEncryptionHook() throws Exception {
+124       TestSenderImpl sender = new TestSenderImpl();
+125       // decodeEcnryptionParameter() is rather insistant on having a user (anyUser)
+126       sender.setOption(WSHandlerConstants.ENCRYPTION_USER, "anyUserWillDo");
+127       // we have to coerce a value into this field or we'll get a bunch of NPEs when calling decodeSignatureParameter
+128       PrivilegedAccessor.setValue(sender, "msgContext", mc);
+129       PrivilegedAccessor.invokeMethod(sender, "decodeEncryptionParameter", new Object[] {});
+130       assertNotNull(PrivilegedAccessor.getValue(sender, "encCrypto"));
+131    }
+132    public void testReceiverLoadSignatureHook() throws Exception {
+133       TestReceiverImpl receiver = new TestReceiverImpl();
+134       PrivilegedAccessor.invokeMethod(receiver, "decodeSignatureParameter", new Object[] {});
+135       assertNotNull(PrivilegedAccessor.getValue(receiver, "sigCrypto"));
+136    }
+137    public void testReceiverLoadDecryptionHook() throws Exception {
+138       TestReceiverImpl receiver = new TestReceiverImpl();
+139       PrivilegedAccessor.invokeMethod(receiver, "decodeDecryptionParameter", new Object[] {});
+140       assertNotNull(PrivilegedAccessor.getValue(receiver, "decCrypto"));
+141    }
+142    
+143    public void testRoundTripWithHooks() throws Exception {
+144       // Setup our sender to Encrypt and Sign a soap message
+145       TestSenderImpl sender = new TestSenderImpl();
+146       sender.setOption(WSHandlerConstants.ACTOR, "test");
+147       sender.setOption(WSHandlerConstants.USER, "16c73ab6-b892-458f-abf5-2f875f74882e");
+148       sender.setOption(WSHandlerConstants.ACTION, "Encrypt Signature");
+149       sender.setOption(WSHandlerConstants.SIG_KEY_ID, "DirectReference");
+150       sender.setOption(WSHandlerConstants.ENC_KEY_ID, "X509KeyIdentifier");
+151       sender.invoke(mc);
+152       
+153       // Make sure that at least SOMETHING happened
+154       String soapPart = mc.getCurrentMessage().getSOAPPartAsString();
+155       assertNotSame("The message has not been Encrypted or Signed", soapPart, soapMessage);
+156       
+157       // Prepare the message context for the response
+158       Message message = getSOAPMessage(soapPart);
+159       mc.setPastPivot(true);
+160       mc.setCurrentMessage(message);
+161       
+162       // Setup our receiver for the decryption / signature validation
+163       TestReceiverImpl receiver = new TestReceiverImpl();
+164       receiver.setOption(WSHandlerConstants.ACTOR, "test");
+165       receiver.setOption(WSHandlerConstants.ACTION, "Encrypt Signature");
+166       receiver.invoke(mc);
+167    }
+168    
+169    //
+170    //
+171    // Test Utility Classes
+172    //
+173    //
+174       
+175    /***
+176     * This is a subclass of Merlin that uses the setKeyStore() method rather than the 
+177     * load(is) method to set the private keystore field.
+178     */
+179    public class TestCryptoImpl extends BouncyCastle {
+180       TestCryptoImpl(KeyStore ks) throws Exception {
+181          super(null);
+182          assertNotNull(ks);
+183          setKeyStore(ks);
+184       }
+185    }
+186    
+187    /***
+188     * Subclass of WSDoAllReceiver that creates the Crypto's directly
+189     */
+190    public class TestReceiverImpl extends WSDoAllReceiver
+191    {
+192       protected Crypto loadDecryptionCrypto() throws AxisFault {
+193          try {
+194             return new TestCryptoImpl(keystore);
+195          } catch(Exception e) {
+196             fail("Failed to create a Crypto instance.");
+197             throw new AxisFault("Failed to create a Crypto instance.", e);
+198          }
+199       }
+200       protected Crypto loadSignatureCrypto() throws AxisFault {
+201          try {
+202             return new TestCryptoImpl(keystore);
+203          } catch(Exception e) {
+204             fail("Failed to create a Crypto instance.");
+205             throw new AxisFault("Failed to create a Crypto instance.", e);
+206          }
+207       }
+208    }
+209    
+210    /***
+211     * Subclass of WSDoAllSender that creates the Crypto's directly
+212     */
+213    public class TestSenderImpl extends WSDoAllSender
+214    {
+215       protected Crypto loadEncryptionCrypto() throws AxisFault {
+216          try {
+217             return new TestCryptoImpl(keystore);
+218          } catch(Exception e) {
+219             fail("Failed to create a Crypto instance.");
+220             throw new AxisFault("Failed to create a Crypto instance.", e);
+221          }
+222       }
+223       protected Crypto loadSignatureCrypto() throws AxisFault {
+224          try {
+225             return new TestCryptoImpl(keystore);
+226          } catch(Exception e) {
+227             fail("Failed to create a Crypto instance.");
+228             throw new AxisFault("Failed to create a Crypto instance.", e);
+229          }
+230       }
+231    }
+232    
+233    
+234    //
+235    //
+236    // test utility methods
+237    //
+238    //
+239    
+240    protected Message getSOAPMessage(String message) throws Exception {
+241       InputStream in = new ByteArrayInputStream(message.getBytes());
+242       Message msg = new Message(in);
+243       msg.setMessageContext(mc);
+244       return msg;
+245    }
+246    
+247    protected KeyStore loadKeyStore() throws Exception {
+248       KeyStore ks = null;
+249       FileInputStream is = null;
+250       is = new FileInputStream("keys/x509.PFX.MSFT");
+251       ks = KeyStore.getInstance("pkcs12");
+252       String password = "security";
+253       ks.load(is, password.toCharArray());
+254       return ks;
+255    }
+256    
+257    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+258       for (int i = 0; i < callbacks.length; i++) {
+259          if (callbacks[i] instanceof WSPasswordCallback) {
+260             WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
+261             pc.setPassword("security");
+262             
+263          } else {
+264             throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
+265          }
+266       }
+267    }
+268    
+269 }
+
+
+ + Added: webservices/wss4j/site/xref-test/wssec/TestWSSecurityNew.html URL: http://svn.apache.org/viewcvs/webservices/wss4j/site/xref-test/wssec/TestWSSecurityNew.html?rev=398880&view=auto ============================================================================== --- webservices/wss4j/site/xref-test/wssec/TestWSSecurityNew.html (added) +++ webservices/wss4j/site/xref-test/wssec/TestWSSecurityNew.html Tue May 2 02:36:22 2006 @@ -0,0 +1,196 @@ + + + +TestWSSecurityNew xref + + + +
+
+1   /*
+2    * Copyright  2003-2004 The Apache Software Foundation.
+3    *
+4    *  Licensed under the Apache License, Version 2.0 (the "License");
+5    *  you may not use this file except in compliance with the License.
+6    *  You may obtain a copy of the License at
+7    *
+8    *      http://www.apache.org/licenses/LICENSE-2.0
+9    *
+10   *  Unless required by applicable law or agreed to in writing, software
+11   *  distributed under the License is distributed on an "AS IS" BASIS,
+12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+13   *  See the License for the specific language governing permissions and
+14   *  limitations under the License.
+15   *
+16   */
+17  
+18  package wssec;
+19  
+20  import junit.framework.Test;
+21  import junit.framework.TestCase;
+22  import junit.framework.TestSuite;
+23  import org.apache.axis.Message;
+24  import org.apache.axis.MessageContext;
+25  import org.apache.axis.client.AxisClient;
+26  import org.apache.axis.utils.XMLUtils;
+27  import org.apache.axis.configuration.NullProvider;
+28  import org.apache.axis.message.SOAPEnvelope;
+29  import org.apache.commons.logging.Log;
+30  import org.apache.commons.logging.LogFactory;
+31  import org.apache.ws.security.WSSecurityEngine;
+32  import org.apache.ws.security.WSConstants;
+33  import org.apache.ws.security.components.crypto.Crypto;
+34  import org.apache.ws.security.components.crypto.CryptoFactory;
+35  import org.apache.ws.security.message.WSSecSignature;
+36  import org.apache.ws.security.message.WSSecHeader;
+37  import org.w3c.dom.Document;
+38  
+39  import java.io.ByteArrayInputStream;
+40  import java.io.InputStream;
+41  import java.io.PrintWriter;
+42  
+43  
+44  /***
+45   * WS-Security Test Case
+46   * <p/>
+47   * 
+48   * @author Davanum Srinivas (dims@yahoo.com)
+49   */
+50  public class TestWSSecurityNew extends TestCase {
+51      private static Log log = LogFactory.getLog(TestWSSecurityNew.class);
+52      static final String NS = "http://www.w3.org/2000/09/xmldsig#";
+53      static final String soapMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + "<SOAP-ENV:Body>" + "<add xmlns=\"http://ws.apache.org/counter/counter_port_type\">" + "<value xmlns=\"\">15</value>" + "</add>" + "</SOAP-ENV:Body>\r\n       \r\n" + "</SOAP-ENV:Envelope>";
+54      static final WSSecurityEngine secEngine = new WSSecurityEngine();
+55      static final Crypto crypto = CryptoFactory.getInstance();
+56  
+57      MessageContext msgContext;
+58      SOAPEnvelope unsignedEnvelope;
+59  
+60      /***
+61       * TestWSSecurity constructor
+62       * <p/>
+63       * 
+64       * @param name name of the test
+65       */
+66      public TestWSSecurityNew(String name) {
+67          super(name);
+68      }
+69  
+70      /***
+71       * JUnit suite
+72       * <p/>
+73       * 
+74       * @return a junit test suite
+75       */
+76      public static Test suite() {
+77          return new TestSuite(TestWSSecurityNew.class);
+78      }
+79  
+80      /***
+81       * Main method
+82       * <p/>
+83       * 
+84       * @param args command line args
+85       */
+86      public static void main(String[] args) {
+87          junit.textui.TestRunner.run(suite());
+88      }
+89  
+90      /***
+91       * Setup method
+92       * <p/>
+93       * 
+94       * @throws java.lang.Exception Thrown when there is a problem in setup
+95       */
+96      protected void setUp() throws Exception {
+97          AxisClient tmpEngine = new AxisClient(new NullProvider());
+98          msgContext = new MessageContext(tmpEngine);
+99          unsignedEnvelope = getSOAPEnvelope();
+100     }
+101 
+102     /***
+103      * Constructs a soap envelope
+104      * <p/>
+105      * 
+106      * @return soap envelope
+107      * @throws java.lang.Exception if there is any problem constructing the soap envelope
+108      */
+109     protected SOAPEnvelope getSOAPEnvelope() throws Exception {
+110         InputStream in = new ByteArrayInputStream(soapMsg.getBytes());
+111         Message msg = new Message(in);
+112         msg.setMessageContext(msgContext);
+113         return msg.getSOAPEnvelope();
+114     }
+115 
+116     /***
+117      * Test that signs and verifies a WS-Security envelope.
+118      * The test uses the ThumbprintSHA1 key identifier type. 
+119      * 
+120      * <p/>
+121      * 
+122      * @throws java.lang.Exception Thrown when there is any problem in signing or verification
+123      */
+124     public void testX509SignatureIS() throws Exception {
+125         WSSecSignature builder = new WSSecSignature();
+126         builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+127         builder.setKeyIdentifierType(WSConstants.ISSUER_SERIAL);
+128         log.info("Before Signing IS....");
+129         Document doc = unsignedEnvelope.getAsDocument();
+130         WSSecHeader secHeader = new WSSecHeader();
+131         secHeader.insertSecurityHeader(doc);
+132         Document signedDoc = builder.build(doc, crypto, secHeader);
+133 
+134         /*
+135          * convert the resulting document into a message first. The toSOAPMessage()
+136          * mehtod performs the necessary c14n call to properly set up the signed
+137          * document and convert it into a SOAP message. After that we extract it
+138          * as a document again for further processing.
+139          */
+140 
+141         if (log.isDebugEnabled()) {
+142             log.debug("Signed message with IssuerSerial key identifier:");
+143             XMLUtils.PrettyElementToWriter(signedDoc.getDocumentElement(), new PrintWriter(System.out));
+144         }
+145         Message signedMsg = (Message) SOAPUtil.toSOAPMessage(signedDoc);
+146         if (log.isDebugEnabled()) {
+147             log.debug("Signed message with IssuerSerial key identifier(1):");
+148             XMLUtils.PrettyElementToWriter(signedMsg.getSOAPEnvelope().getAsDOM(), new PrintWriter(System.out));
+149         }
+150         signedDoc = signedMsg.getSOAPEnvelope().getAsDocument();
+151         log.info("After Signing IS....");
+152         verify(signedDoc);
+153     }
+154 
+155 
+156     /***
+157      * Test that signs (twice) and verifies a WS-Security envelope.
+158      * <p/>
+159      * 
+160      * @throws java.lang.Exception Thrown when there is any problem in signing or verification
+161      */
+162     public void testDoubleX509SignatureIS() throws Exception {
+163         WSSecSignature builder = new WSSecSignature();
+164         builder.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security");
+165         Document doc = unsignedEnvelope.getAsDocument();
+166         WSSecHeader secHeader = new WSSecHeader();
+167         secHeader.insertSecurityHeader(doc);
+168         Document signedDoc = builder.build(doc, crypto, secHeader);
+169         Document signedDoc1 = builder.build(signedDoc, crypto, secHeader);
+170         verify(signedDoc1);
+171     }
+172 
+173     /***
+174      * Verifies the soap envelope.
+175      * This method verfies all the signature generated. 
+176      * 
+177      * @param env soap envelope
+178      * @throws java.lang.Exception Thrown when there is a problem in verification
+179      */
+180     private void verify(Document doc) throws Exception {
+181         secEngine.processSecurityHeader(doc, null, null, crypto);
+182     }
+183 }
+
+
+ + --------------------------------------------------------------------- To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org For additional commands, e-mail: wss4j-dev-help@ws.apache.org