You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tsik-dev@ws.apache.org by ha...@apache.org on 2005/08/08 22:03:01 UTC
svn commit: r230871 [58/61] - in /incubator/tsik/trunk: ./ data/
data/schema/ resources/ resources/junit/ src/ src/org/ src/org/apache/
src/org/apache/tsik/ src/org/apache/tsik/c14n/
src/org/apache/tsik/c14n/elements/ src/org/apache/tsik/common/ src/or...
Added: incubator/tsik/trunk/test/src/org/apache/tsik/util/test/UtilTestSuite.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/util/test/UtilTestSuite.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/util/test/UtilTestSuite.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/util/test/UtilTestSuite.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,47 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.util.test;
+
+import org.apache.tsik.test.BaseTestSuite;
+import junit.framework.Test;
+
+public class UtilTestSuite
+{
+ public static final String MODULE = "util";
+
+ public static void main(String[] args)
+ throws Exception
+ {
+ org.apache.tsik.test.Runner.runTextUI(suite(), args);
+ }
+
+ public static Test suite()
+ throws Exception
+ {
+ BaseTestSuite suite = new BaseTestSuite(MODULE);
+ suite.addTest(org.apache.tsik.resource.test.XMLResourceTest.suite());
+ suite.addTest(ShowEnvironment.suite());
+ suite.addTest(NamespacesTest.suite());
+ suite.addTest(Base64Test.suite());
+ suite.addTest(DateTimeTest.suite());
+ suite.addTest(org.apache.tsik.xpath.test.XPathTestSuite.suite());
+ suite.addTest(org.apache.tsik.domutil.test.DOMCursorTest.suite());
+ return suite;
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/util/test/UtilTestSuite.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/util/test/package.html
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/util/test/package.html?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/util/test/package.html (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/util/test/package.html Mon Aug 8 12:58:58 2005
@@ -0,0 +1,8 @@
+<html>
+<!-- $Id: package.html,v 1.1 2002/08/30 14:53:24 mark Exp $ -->
+<body>
+
+(TESTS) Tests the org.apache.tsik.util package.
+
+</body>
+</html>
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/util/test/package.html
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/AndOrNotTests.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/AndOrNotTests.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/AndOrNotTests.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/AndOrNotTests.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,216 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.verifier.test;
+
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+import junit.framework.Test;
+
+import org.apache.tsik.test.BaseTestCase;
+import org.apache.tsik.test.BaseTestSuite;
+import org.apache.tsik.verifier.AndTrustVerifier;
+import org.apache.tsik.verifier.NotTrustVerifier;
+import org.apache.tsik.verifier.OrTrustVerifier;
+import org.apache.tsik.verifier.TrustVerificationException;
+import org.apache.tsik.verifier.TrustVerifier;
+
+public class AndOrNotTests extends BaseTestCase
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ org.apache.tsik.test.Runner.runTextUI(suite(), args);
+ }
+
+ public static Test suite()
+ throws Exception
+ {
+ BaseTestSuite suite = new BaseTestSuite(VerifierTests.MODULE);
+
+ // Basic boolean logic
+ suite.addTest(new AndOrNotTests(true, "true"));
+ suite.addTest(new AndOrNotTests(false, "false"));
+ suite.addTest(new AndOrNotTests(true, "not(false)"));
+ suite.addTest(new AndOrNotTests(false, "not(true)"));
+ suite.addTest(new AndOrNotTests(true, "and(true)"));
+ suite.addTest(new AndOrNotTests(false, "and(false)"));
+ suite.addTest(new AndOrNotTests(true, "or(true)"));
+ suite.addTest(new AndOrNotTests(false, "or(false)"));
+ suite.addTest(new AndOrNotTests(true, "and(true,true)"));
+ suite.addTest(new AndOrNotTests(false, "and(true,false)"));
+ suite.addTest(new AndOrNotTests(false, "and(false,true)"));
+ suite.addTest(new AndOrNotTests(false, "and(false,false)"));
+ suite.addTest(new AndOrNotTests(true, "or(true,true)"));
+ suite.addTest(new AndOrNotTests(true, "or(true,false)"));
+ suite.addTest(new AndOrNotTests(true, "or(false,true)"));
+ suite.addTest(new AndOrNotTests(false, "or(false,false)"));
+
+ // A few larger expressions
+ suite.addTest(new AndOrNotTests(true, "and(true,true,true)"));
+ suite.addTest(new AndOrNotTests(false, "and(true,true,false)"));
+ suite.addTest(new AndOrNotTests(false, "and(false,true,true)"));
+ suite.addTest(new AndOrNotTests(true, "or(true,true,false)"));
+ suite.addTest(new AndOrNotTests(true, "or(false,true,true)"));
+ suite.addTest(new AndOrNotTests(true, "and(and(true),or(true))"));
+ suite.addTest(new AndOrNotTests(true, "and(or(true),not(false))"));
+ suite.addTest(new AndOrNotTests(true, "or(and(false),or(true))"));
+
+ return suite;
+ }
+
+ // --- end static members, begin instance members ---
+
+ private String expr;
+ private boolean expectValue;
+ private TrustVerifier verifier;
+
+ private AndOrNotTests(boolean expectValue, String expr)
+ {
+ super(AndOrNotTests.class.getName() + ' ' +
+ String.valueOf(expectValue) + ':' + expr,
+ VerifierTests.MODULE);
+
+ this.expr = expr;
+ this.expectValue = expectValue;
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ StringTokenizer tokens = new StringTokenizer(expr, ",()", true);
+ verifier = makeVerifier(tokens);
+ }
+
+ private TrustVerifier makeVerifier(StringTokenizer tokens)
+ {
+ if (!tokens.hasMoreTokens())
+ throwIllegal();
+ return makeVerifier(tokens, tokens.nextToken());
+ }
+
+ private TrustVerifier makeVerifier(StringTokenizer tokens, String token)
+ {
+ if (token.equals("and"))
+ return new AndTrustVerifier(makeVerifierList(tokens));
+ else if (token.equals("or"))
+ return new OrTrustVerifier(makeVerifierList(tokens));
+ else if (token.equals("not"))
+ return new NotTrustVerifier(makeVerifierListOfOne(tokens));
+ else if (token.equals("true"))
+ return new BooleanVerifier(true);
+ else if (token.equals("false"))
+ return new BooleanVerifier(false);
+ else
+ throwIllegal();
+ return null; // never gets here
+ }
+
+ private TrustVerifier makeVerifierListOfOne(StringTokenizer tokens)
+ {
+ TrustVerifier[] a = makeVerifierList(tokens);
+ if (a.length != 1)
+ throwIllegal();
+ return a[0];
+ }
+
+ private TrustVerifier[] makeVerifierList(StringTokenizer tokens)
+ {
+ if (!tokens.hasMoreTokens())
+ throwIllegal();
+ String token = tokens.nextToken();
+ if (!token.equals("("))
+ throwIllegal();
+ ArrayList list = new ArrayList();
+ while (true) {
+ if (!tokens.hasMoreTokens())
+ throwIllegal();
+ token = tokens.nextToken();
+ if (token.equals(")"))
+ break;
+ else if (!token.equals(","))
+ list.add(makeVerifier(tokens, token));
+ }
+ TrustVerifier[] a = new TrustVerifier[list.size()];
+ list.toArray(a);
+ return a;
+ }
+
+ private void throwIllegal()
+ {
+ throw new IllegalArgumentException("Illegal expression [" +
+ expr + "]");
+ }
+
+ public void runTest()
+ throws Exception
+ {
+ for (int i = 0; i < 4; i += 1) {
+ try {
+ switch (i) {
+ case 0: verifier.verifyTrust(); break;
+ case 1: verifier.verifyTrust((PublicKey) null); break;
+ case 2: verifier.verifyTrust((PublicKey) null, null); break;
+ case 3: verifier.verifyTrust((X509Certificate[]) null); break;
+ }
+ assertTrue("Expected failure but got success", expectValue);
+ } catch (TrustVerificationException e) {
+ assertTrue("Expected success but got failure", !expectValue);
+ }
+ }
+ }
+
+ private static class BooleanVerifier implements TrustVerifier
+ {
+ private boolean whetherToPass;
+
+ BooleanVerifier(boolean whetherToPass)
+ {
+ this.whetherToPass = whetherToPass;
+ }
+
+ public void verifyTrust()
+ throws TrustVerificationException
+ {
+ if (!whetherToPass) {
+ throw new TrustVerificationException();
+ }
+ }
+
+ public void verifyTrust(PublicKey key)
+ throws TrustVerificationException
+ {
+ verifyTrust();
+ }
+
+ public void verifyTrust(PublicKey key, String keyName)
+ throws TrustVerificationException
+ {
+ verifyTrust();
+ }
+
+ public void verifyTrust(X509Certificate[] chain)
+ throws TrustVerificationException
+ {
+ verifyTrust();
+ }
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/AndOrNotTests.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/CachingTests.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/CachingTests.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/CachingTests.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/CachingTests.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,333 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.verifier.test;
+
+import org.apache.tsik.verifier.CachingTrustVerifier;
+import org.apache.tsik.verifier.TrustVerificationException;
+import org.apache.tsik.verifier.TrustVerifier;
+import org.apache.tsik.test.BaseTestCase;
+import org.apache.tsik.test.BaseTestSuite;
+import java.io.FileInputStream;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import junit.framework.Test;
+
+public class CachingTests extends BaseTestCase
+{
+ public static void main(String[] args)
+ throws Exception
+ {
+ org.apache.tsik.test.Runner.runTextUI(suite(), args);
+ }
+
+ public static Test suite()
+ throws Exception
+ {
+ BaseTestSuite suite = new BaseTestSuite(VerifierTests.MODULE);
+ suite.addTest(new CachingTests());
+ return suite;
+ }
+
+ private static final int CACHE_INTERVAL = 100;
+ private static final int TOTAL_TIME = 1000;
+ private static final int EXPECT_MAX = TOTAL_TIME / CACHE_INTERVAL;
+ private static final int EXPECT_MIN = EXPECT_MAX - 1;
+
+ // --- end static members, begin instance members ---
+
+ private TrustVerifier cacheVerifier;
+ private X509Certificate cert1;
+ private X509Certificate cert2;
+
+ private CachingTests()
+ {
+ super(CachingTests.class.getName(), VerifierTests.MODULE);
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ // load two arbitary certs from the cacerts file for lack of any others
+ String f = System.getProperty("java.home") + "/lib/security/cacerts";
+ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
+ ks.load(new FileInputStream(f), null);
+ Enumeration aliases = ks.aliases();
+ while (aliases.hasMoreElements()) {
+ String alias = (String) aliases.nextElement();
+ if (ks.isCertificateEntry(alias)) {
+ X509Certificate cert =
+ (X509Certificate) ks.getCertificate(alias);
+ assertNotNull(cert);
+ if (cert1 == null) {
+ cert1 = cert;
+ } else if (cert2 == null) {
+ cert2 = cert;
+ } else {
+ break;
+ }
+ }
+ }
+ }
+
+ public void runTest()
+ throws Exception
+ {
+ boolTests();
+ certTests();
+ }
+
+ private void boolTests()
+ throws Exception
+ {
+ BooleanVerifier boolVerifier = new BooleanVerifier(true);
+ cacheVerifier = new CachingTrustVerifier(boolVerifier, CACHE_INTERVAL);
+
+ // prime the pump to avoid timing issues
+ int count = countVerifications(null, boolVerifier);
+
+ // Verifier should only be called once per cache interval
+ //
+ count = countVerifications(null, boolVerifier);
+ assertTrue("unexpected count " + count,
+ count >= EXPECT_MIN && count <= EXPECT_MAX);
+
+ // Unless it always fails, in which case it should be always called.
+ //
+ boolVerifier.setValue(false);
+ count = countVerifications(null, boolVerifier);
+ assertTrue(count > TOTAL_TIME);
+
+ // But caching should start again when verifications succeed.
+ //
+ boolVerifier.setValue(true);
+ count = countVerifications(null, boolVerifier);
+ assertTrue("unexpected count " + count,
+ count >= EXPECT_MIN && count <= EXPECT_MAX);
+ }
+
+ private void certTests()
+ throws Exception
+ {
+ CertVerifier certVerifier = new CertVerifier(cert1);
+ cacheVerifier = new CachingTrustVerifier(certVerifier, CACHE_INTERVAL);
+
+ // Should fail for cert2 and pass for cert1
+ //
+ X509Certificate[] cert1Chain = {cert1};
+ X509Certificate[] cert2Chain = {cert2};
+ cacheVerifier.verifyTrust(cert1Chain);
+ assertTrue(certVerifier.checkAndReset());
+ cacheVerifier.verifyTrust(cert1Chain);
+ assertTrue(!certVerifier.checkAndReset());
+ try {
+ cacheVerifier.verifyTrust(cert2Chain);
+ fail();
+ } catch (TrustVerificationException expected) {}
+ assertTrue(certVerifier.checkAndReset());
+ try {
+ cacheVerifier.verifyTrust(cert2Chain);
+ fail();
+ } catch (TrustVerificationException expected) {}
+ assertTrue(certVerifier.checkAndReset());
+ cacheVerifier.verifyTrust(cert1Chain);
+ assertTrue(!certVerifier.checkAndReset());
+ try {
+ cacheVerifier.verifyTrust(cert2Chain);
+ fail();
+ } catch (TrustVerificationException expected) {}
+ assertTrue(certVerifier.checkAndReset());
+
+ // prime the pump to avoid timing issues
+ int count = countVerifications(cert1, certVerifier);
+
+ // Verifier should only be called once per cache interval
+ //
+ count = countVerifications(cert1, certVerifier);
+ assertTrue("unexpected count " + count,
+ count >= EXPECT_MIN && count <= EXPECT_MAX);
+
+ // Unless it always fails, in which case it should be always called.
+ //
+ count = countVerifications(cert2, certVerifier);
+ assertTrue(count > TOTAL_TIME);
+
+ // But caching should start again when verifications succeed.
+ //
+ certVerifier.setValue(cert2);
+ count = countVerifications(cert2, certVerifier);
+ assertTrue("unexpected count " + count,
+ count >= EXPECT_MIN && count <= EXPECT_MAX);
+ }
+
+ private int countVerifications(X509Certificate cert,
+ TestVerifier testVerifier)
+ {
+ int count = 0;
+ long time = System.currentTimeMillis();
+ long endTime = time + TOTAL_TIME;
+ while (time < endTime) {
+ try {
+ if (cert != null) {
+ cacheVerifier.verifyTrust(new X509Certificate[] {cert});
+ } else {
+ cacheVerifier.verifyTrust();
+ }
+ } catch (TrustVerificationException ignored) { }
+ if (testVerifier.checkAndReset()) {
+ count += 1;
+ }
+ time = System.currentTimeMillis();
+ }
+ return count;
+ }
+
+ private static class TestVerifier
+ {
+ boolean wasCalled;
+
+ boolean checkAndReset()
+ {
+ boolean b = wasCalled;
+ wasCalled = false;
+ return b;
+ }
+ }
+
+ private static class BooleanVerifier
+ extends TestVerifier implements TrustVerifier
+ {
+ private boolean whetherToPass;
+
+ BooleanVerifier(boolean whetherToPass)
+ {
+ this.whetherToPass = whetherToPass;
+ }
+
+ void setValue(boolean whetherToPass)
+ {
+ this.whetherToPass = whetherToPass;
+ }
+
+ boolean getValue()
+ {
+ return whetherToPass;
+ }
+
+ public void verifyTrust()
+ throws TrustVerificationException
+ {
+ wasCalled = true;
+
+ if (!whetherToPass) {
+ throw new TrustVerificationException("expected failure");
+ }
+ }
+
+ public void verifyTrust(PublicKey key)
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void verifyTrust(PublicKey key, String keyName)
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void verifyTrust(X509Certificate[] chain)
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ private static class CertVerifier
+ extends TestVerifier implements TrustVerifier
+ {
+ private X509Certificate certToPass;
+ private boolean wasCalled;
+
+ CertVerifier(X509Certificate certToPass)
+ {
+ this.certToPass = certToPass;
+ }
+
+ void setValue(X509Certificate certToPass)
+ {
+ this.certToPass = certToPass;
+ }
+
+ X509Certificate getValue()
+ {
+ return certToPass;
+ }
+
+ boolean checkAndReset()
+ {
+ boolean b = wasCalled;
+ wasCalled = false;
+ return b;
+ }
+
+ public void verifyTrust()
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void verifyTrust(PublicKey key)
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void verifyTrust(PublicKey key, String keyName)
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void verifyTrust(X509Certificate[] chain)
+ throws TrustVerificationException
+ {
+ wasCalled = true;
+ boolean failed;
+ if (certToPass != null) {
+ try {
+ failed = !Arrays.equals(chain[0].getEncoded(),
+ certToPass.getEncoded());
+ } catch (GeneralSecurityException e) {
+ throw new RuntimeException(e.toString());
+ }
+ } else {
+ failed = true;
+ }
+ if (failed) {
+ throw new TrustVerificationException("expected failure");
+ }
+ }
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/CachingTests.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/SSLAndHttpsTests.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/SSLAndHttpsTests.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/SSLAndHttpsTests.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/SSLAndHttpsTests.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,350 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.verifier.test;
+
+import org.apache.tsik.verifier.AllPermissiveTrustVerifier;
+import org.apache.tsik.verifier.HttpsTrustAdapter;
+import org.apache.tsik.verifier.SSLTrustAdapter;
+import org.apache.tsik.verifier.TrustVerificationException;
+import org.apache.tsik.verifier.TrustVerifier;
+import org.apache.tsik.domutil.DOMCursor;
+import org.apache.tsik.test.DataDrivenTestCase;
+import org.apache.tsik.test.DataDrivenTestSuite;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.HttpURLConnection;
+import javax.net.ssl.SSLSocket;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.SSLException;
+import java.security.PublicKey;
+import java.security.cert.X509Certificate;
+import junit.framework.Test;
+
+public class SSLAndHttpsTests extends DataDrivenTestCase
+{
+ static {
+ try {
+ Class.forName("javax.net.ssl.HttpsURLConnection");
+ // don't need to set https handler for JDK 1.4 and above
+ } catch (ClassNotFoundException e) {
+ // set https handler for JSSE 1.0.2
+ System.setProperty("java.protocol.handler.pkgs",
+ "com.sun.net.ssl.internal.www.protocol");
+ }
+ }
+
+ public static void main(String[] args)
+ throws Exception
+ {
+ org.apache.tsik.test.Runner.runTextUI(suite(), args);
+ }
+
+ public static Test suite()
+ throws Exception
+ {
+ DataDrivenTestSuite ddSuite =
+ new DataDrivenTestSuite(VerifierTests.MODULE);
+ String file = "tbd...";
+ // We are not using DataDriven capabilities just yet...
+ ddSuite.addTest(new SSLAndHttpsTests(true, true, true));
+ ddSuite.addTest(new SSLAndHttpsTests(true, true, false));
+ ddSuite.addTest(new SSLAndHttpsTests(true, false, true));
+ ddSuite.addTest(new SSLAndHttpsTests(true, false, false));
+ ddSuite.addTest(new SSLAndHttpsTests(false, true, true));
+ ddSuite.addTest(new SSLAndHttpsTests(false, true, false));
+ ddSuite.addTest(new SSLAndHttpsTests(false, false, true));
+ ddSuite.addTest(new SSLAndHttpsTests(false, false, false));
+ return ddSuite;
+ }
+
+ // --- end static members, begin instance members ---
+
+ private URL url;
+ private String subject;
+ private boolean testSSLorHttps;
+ private boolean testBindOrDirect;
+ private boolean testFailure;
+
+ private SSLAndHttpsTests(boolean testSSLorHttps, boolean testBindOrDirect,
+ boolean testFailure)
+ {
+ super(makeTestName(testSSLorHttps, testBindOrDirect, testFailure),
+ VerifierTests.MODULE);
+
+ this.testSSLorHttps = testSSLorHttps;
+ this.testBindOrDirect = testBindOrDirect;
+ this.testFailure = testFailure;
+ }
+
+ private static String makeTestName(boolean testSSLorHttps,
+ boolean testBindOrDirect,
+ boolean testFailure)
+ {
+ StringBuffer buf = new StringBuffer(SSLAndHttpsTests.class.getName());
+ buf.append(' ');
+ buf.append(testSSLorHttps ? "SSL" : "Https");
+ buf.append('.');
+ buf.append(testBindOrDirect
+ ? (testSSLorHttps ? "getSocketFactory" : "bindToConnection")
+ : (testSSLorHttps ? "verifySession" : "verifyConnection"));
+ buf.append('.');
+ buf.append(testFailure ? "fail" : "pass");
+ return buf.toString();
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ // We are not using DataDriven capabilities just yet...
+ url = new URL("https://www.verisign.com/index.html");
+ if (testFailure) {
+ subject = "xxx";
+ } else {
+ subject =
+"CN=www.verisign.com, OU=Terms of use at www.verisign.com/rpa (c)00, OU=Production Services, O=\"VeriSign, Inc.\", L=Mountain View, ST=California, C=US";
+ }
+
+ // get query value
+ //
+ DOMCursor c = getInputData();
+
+ // get expected result
+ //
+ c = getExpectData();
+ }
+
+ public void runTest()
+ throws Exception
+ {
+ if (testSSLorHttps) {
+ testSSL();
+ } else {
+ testHttps();
+ }
+ }
+
+ private void testHttps()
+ throws Exception
+ {
+ boolean bindToConnection = testBindOrDirect;
+
+ // Create verifier and adapter
+ //
+ TestVerifier verifier = new TestVerifier(subject);
+
+ // Open connection
+ //
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ if (bindToConnection) {
+ HttpsTrustAdapter adapter = new HttpsTrustAdapter(verifier,
+ HttpsTrustAdapter.VERIFIER_AND);
+ adapter.bindToConnection(conn);
+ }
+ conn.setRequestMethod("GET");
+ conn.setDoInput(true);
+
+ try {
+ conn.connect();
+ if (bindToConnection) {
+ assertTrue("expected TrustVerificationException",
+ !testFailure);
+ assertTrue("Verifier was never called", verifier.wasCalled());
+ }
+ } catch (SSLException e) {
+ if (bindToConnection) {
+ if (!testFailure) {
+ throw e;
+ }
+ return; // socket already closed
+ } else {
+ throw e;
+ }
+ }
+
+ // Call verifier directly
+ //
+ if (!bindToConnection) {
+ try {
+ HttpsTrustAdapter.verifyConnection(conn, verifier);
+ assertTrue("expected TrustVerificationException",
+ !testFailure);
+ } catch (TrustVerificationException e) {
+ if (!testFailure) {
+ throw e;
+ }
+ }
+ assertTrue("Verifier was never called", verifier.wasCalled());
+ }
+
+ // Be polite
+ //
+ readAllInput(conn.getInputStream());
+ }
+
+ private void testSSL()
+ throws Exception
+ {
+ boolean useSocketFactory = testBindOrDirect;
+
+ // Create verifier and adapter
+ //
+ TestVerifier verifier = new TestVerifier(subject);
+
+ // Create socket
+ //
+ int port = url.getPort();
+ if (port == -1) port = 443;
+ SSLSocketFactory factory;
+ if (useSocketFactory) {
+ SSLTrustAdapter adapter = new SSLTrustAdapter(verifier,
+ HttpsTrustAdapter.VERIFIER_AND);
+ factory = adapter.getSocketFactory();
+ } else {
+ factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
+ }
+ SSLSocket socket =
+ (SSLSocket) factory.createSocket(url.getHost(), port);
+
+ // Start handshake
+ //
+ try {
+ socket.startHandshake();
+ if (useSocketFactory) {
+ assertTrue("expected TrustVerificationException",
+ !testFailure);
+ assertTrue("Verifier was never called", verifier.wasCalled());
+ }
+ } catch (SSLException e) {
+ if (useSocketFactory) {
+ if (!testFailure) {
+ throw e;
+ }
+ return; // socket already closed
+ } else {
+ throw e;
+ }
+ }
+
+ // Call verifier directly
+ //
+ if (!useSocketFactory) {
+ try {
+ SSLTrustAdapter.verifySession(socket.getSession(), verifier);
+ assertTrue("expected TrustVerificationException",
+ !testFailure);
+ } catch (TrustVerificationException e) {
+ if (!testFailure) {
+ throw e;
+ }
+ }
+ assertTrue("Verifier was never called", verifier.wasCalled());
+ }
+
+ // Write HTTP request
+ //
+ BufferedWriter out =
+ new BufferedWriter(
+ new OutputStreamWriter(socket.getOutputStream()));
+
+ URL requestUrl = new URL("http", url.getHost(),
+ url.getPort(), url.getFile());
+ String line ="GET " + requestUrl + " HTTP/1.1";
+ out.write(line, 0, line.length());
+ out.newLine();
+ out.newLine();
+ out.flush();
+
+ // Be polite
+ //
+ readAllInput(socket.getInputStream());
+ out.close();
+ socket.close();
+ }
+
+ private void readAllInput(InputStream stream)
+ throws IOException
+ {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(stream));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ //System.out.println(inputLine);
+ }
+ in.close();
+ }
+
+ private static class TestVerifier implements TrustVerifier
+ {
+ private boolean called;
+ private String expectSubject;
+
+ TestVerifier(String expectSubject)
+ {
+ this.expectSubject = expectSubject;
+ }
+
+ boolean wasCalled()
+ {
+ return called;
+ }
+
+ void reset()
+ {
+ called = false;
+ }
+
+ public void verifyTrust()
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException("wrong call");
+ }
+
+ public void verifyTrust(PublicKey key)
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException("wrong call");
+ }
+
+ public void verifyTrust(PublicKey key, String keyName)
+ throws TrustVerificationException
+ {
+ throw new UnsupportedOperationException("wrong call");
+ }
+
+ public void verifyTrust(X509Certificate[] chain)
+ throws TrustVerificationException
+ {
+ called = true;
+ //if (true) return;
+ String gotSubject = chain[0].getSubjectDN().getName();
+ if (!expectSubject.equals(gotSubject)) {
+ throw new TrustVerificationException("expected subject " +
+ expectSubject +
+ " but got " + gotSubject);
+ }
+ //System.out.println("Trusted cert subject: " + gotSubject);
+ }
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/SSLAndHttpsTests.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/VerifierTests.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/VerifierTests.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/VerifierTests.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/VerifierTests.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,54 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.verifier.test;
+
+import org.apache.tsik.test.BaseTestSuite;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class VerifierTests
+{
+ public static final String MODULE =
+ org.apache.tsik.util.test.UtilTestSuite.MODULE;
+
+
+ public static void main(String[] args)
+ throws Exception
+ {
+ org.apache.tsik.test.Runner.runTextUI(suite(), args);
+ }
+
+ public static Test suite()
+ throws Exception
+ {
+ TestSuite suite = new BaseTestSuite(MODULE);
+ suite.addTest(AndOrNotTests.suite());
+ suite.addTest(CachingTests.suite());
+ try {
+ Class.forName("javax.net.ssl.SSLSocket");
+ Class.forName(
+ "com.sun.net.ssl.internal.www.protocol.https.Handler");
+ suite.addTest(SSLAndHttpsTests.suite());
+ } catch (ClassNotFoundException e) {
+ System.out.println(
+ "*** SSLAndHttpsTests not run: SSL not available");
+ }
+ return suite;
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/VerifierTests.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/package.html
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/package.html?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/package.html (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/package.html Mon Aug 8 12:58:58 2005
@@ -0,0 +1,8 @@
+<html>
+<!-- $Id: package.html,v 1.1 2002/08/30 14:53:25 mark Exp $ -->
+<body>
+
+(TESTS) Tests the org.apache.tsik.verifier package.
+
+</body>
+</html>
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/verifier/test/package.html
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CheckUsernameTokenAction.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CheckUsernameTokenAction.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CheckUsernameTokenAction.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CheckUsernameTokenAction.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,83 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import org.apache.tsik.domutil.DOMCursor;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wsp.DependencyGraph;
+import org.apache.tsik.wss.elements.Security;
+import org.apache.tsik.wss.elements.UsernameToken;
+import org.apache.tsik.xpath.XPath;
+import org.w3c.dom.Document;
+
+class CheckUsernameTokenAction extends Action
+{
+ String username;
+ String password;
+
+ private XPath xpath;
+
+ public CheckUsernameTokenAction()
+ {
+ String soapUri = Namespaces.SOAPENV.getUri();
+ String[] ns = {"s", soapUri, "wsse", Security.uri};
+ String s = "/s:Envelope/s:Header/wsse:Security/wsse:UsernameToken";
+ this.xpath = new XPath(s, ns);
+ }
+
+
+ // Expects:
+ // username expected username
+ // password expected password
+ //
+ private boolean checkInvariants()
+ {
+ username = (String) map.get("username");
+ if (username == null) {
+ violations.add(new ActionViolation("Username missing"));
+ return false;
+ }
+ password = (String) map.get("password");
+ if (password == null) {
+ violations.add(new ActionViolation("Password missing"));
+ return false;
+ }
+ return true;
+ }
+
+ public void execute()
+ {
+ if (!checkInvariants()){
+ violations.add(new ActionViolation("Invariance check failed"));
+ return;
+ }
+ if (!(input.moveToXPath(xpath))){
+ violations.add(new ActionViolation("Cannot find " + xpath));
+ }
+ UsernameToken ut = UsernameToken.fromXml(input);
+ if (!(ut.getUsername().equals(username))){
+ violations.add(new ActionViolation("Bad username"));
+ }
+ if (!(ut.getPassword().equals(password))){
+ violations.add(new ActionViolation("Bad password"));
+ }
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CheckUsernameTokenAction.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CreateUsernameTokenAction.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CreateUsernameTokenAction.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CreateUsernameTokenAction.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CreateUsernameTokenAction.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,68 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import org.apache.tsik.domutil.DOMWriteCursor;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wss.elements.UsernameToken;
+import org.apache.tsik.xpath.XPath;
+
+public class CreateUsernameTokenAction extends Action
+{
+ private XPath outputXpath;
+
+ // Expects:
+ // output where to put the username token (xpath)
+ //
+ private boolean checkInvariants()
+ {
+ outputXpath = (XPath) map.get("output");
+ if (outputXpath == null){
+ violations.add(new ActionViolation("Output missing"));
+ return false;
+ }
+ boolean b = output.moveToXPath(outputXpath);
+ if (!b){
+ violations.
+ add(new ActionViolation("Couldn't evaluate output xpath"));
+ return false;
+ }
+ return true;
+ }
+
+ // Sets:
+ // output to point to the created username token (xpath)
+ //
+ public void execute()
+ {
+ if (!checkInvariants()){
+ violations.add(new ActionViolation("Invariance check failed"));
+ return;
+ }
+ UsernameToken ut = new UsernameToken("valid", "valid", null, null);
+// System.out.println("will add ut to "+output);
+// DOMWriteCursor wc = new DOMWriteCursor();
+ ut.toXml(output);
+ output.moveToChild(1);
+ map.put("output", output.createXPath());
+ }
+}
+
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/CreateUsernameTokenAction.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedDataAction.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedDataAction.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedDataAction.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedDataAction.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,113 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.X509Certificate;
+import javax.crypto.KeyGenerator;
+import org.apache.tsik.common.Logger;
+import org.apache.tsik.common.LoggerFactory;
+import org.apache.tsik.domutil.DOMCursor;
+import org.apache.tsik.domutil.DOMWriteCursor;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wss.DefaultTokenResolver;
+import org.apache.tsik.wss.Id;
+import org.apache.tsik.wss.TokenResolver;
+import org.apache.tsik.wss.elements.EncryptedData;
+import org.apache.tsik.wss.elements.EncryptedKey;
+import org.apache.tsik.wss.elements.KeyIdentifier;
+import org.apache.tsik.wss.elements.KeyInfo;
+import org.apache.tsik.wss.elements.ReferenceList;
+import org.apache.tsik.wss.elements.SecurityTokenReference;
+import org.apache.tsik.wss.elements.UsernameToken;
+import org.apache.tsik.xmlenc.AlgorithmType;
+import org.apache.tsik.xmlenc.Encryptor;
+import org.apache.tsik.xmlenc.tools.ConversionException;
+import org.apache.tsik.xpath.XPath;
+
+public class DecryptEncryptedDataAction extends Action
+{
+ private Logger log = LoggerFactory
+ .getLogger(DecryptEncryptedDataAction.class);
+
+ EncryptedKey ek;
+ X509Certificate cert;
+ XPath location;
+
+ // Expects:
+ // decryptedkey the key that decrypts the data (EncryptedKey)
+ // location location of the encrypted data (xpath)
+ //
+ private boolean checkInvariants()
+ {
+ ek = (EncryptedKey) map.get("decryptedkey");
+ if (ek == null){
+ violations.add(new ActionViolation("Decrypted key missing"));
+ }
+ location = (XPath) map.get("location");
+ if (location == null){
+ violations.add(new ActionViolation("Location missing"));
+ }
+ if (ek == null || location == null){
+ return false;
+ }
+
+ DOMCursor tmp = output.cloneCursor();
+ if (!tmp.moveToXPath(location)){
+ violations.
+ add(new ActionViolation("Couldn't evaluate location xpath"));
+ return false;
+ }
+ return true;
+ }
+
+ // Sets:
+ // output the decrypted data (Xpath)
+ //
+ public void execute()
+ {
+ if (!checkInvariants()){
+ violations.add(new ActionViolation("Invariance check failed"));
+ return;
+ }
+ ek = (EncryptedKey) map.get("decryptedkey");
+ ReferenceList refList = ek.getReferenceList();
+ String refId = refList.getDataReference();
+ log.debug("Decrypted key decrypts id "+refId);
+ if (refId == null){
+ String s = "No reference ID in EncryptedKey";
+ violations.add(new ActionViolation(s));
+ return;
+ }
+ TokenResolver res = new DefaultTokenResolver();
+ if (refId != null){
+ res.map(refId, ek.getDekKey());
+ }
+ output.moveToXPath(location);
+ EncryptedData ed = EncryptedData.fromXml(output);
+ ed.decrypt(res);
+ DOMCursor c = ed.getDecryptedData();
+ output.copyOver(c);
+ map.put("output", output.createXPath());
+ }
+}
+
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedDataAction.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedKeyAction.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedKeyAction.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedKeyAction.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedKeyAction.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,94 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+import java.util.Map;
+import org.apache.tsik.domutil.DOMCursor;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wss.DefaultTokenResolver;
+import org.apache.tsik.wss.TokenResolver;
+import org.apache.tsik.wss.elements.EncryptedKey;
+import org.apache.tsik.xpath.XPath;
+
+
+public class DecryptEncryptedKeyAction extends Action
+{
+ PrivateKey key;
+ X509Certificate cert;
+ XPath location;
+
+ // Expects:
+ // key the key to decrypt temp key with (PrivateKey)
+ // cert the cert corresponding to key (X509Certificate)
+ // location location of the encrypted key (xpath)
+ //
+ private boolean checkInvariants()
+ {
+ cert = (X509Certificate) map.get("cert");
+ if (cert == null){
+ violations.add(new ActionViolation("Certificate missing"));
+ }
+ key = (PrivateKey) map.get("key");
+ if (key == null){
+ violations.add(new ActionViolation("Key missing"));
+ }
+ location = (XPath) map.get("location");
+ if (location == null){
+ violations.add(new ActionViolation("Location missing"));
+ }
+ if (cert == null || key == null || location == null){
+ return false;
+ }
+
+ DOMCursor tmp = output.cloneCursor();
+ if (!tmp.moveToXPath(location)){
+ violations.
+ add(new ActionViolation("Couldn't evaluate location xpath"));
+ return false;
+ }
+ return true;
+ }
+
+ // Sets:
+ // decryptedkey the decryptedkey (EncryptedKey)
+ //
+ public void execute()
+ {
+ if (!checkInvariants()){
+ violations.add(new ActionViolation("Invariance check failed"));
+ return;
+ }
+ output.moveToXPath(location);
+ EncryptedKey ek = EncryptedKey.fromXml(output);
+ TokenResolver res = new DefaultTokenResolver();
+ res.map(cert, key);
+ try {
+ ek.decrypt(res);
+ } catch (NoSuchAlgorithmException e){
+ violations.add(new ActionViolation(e));
+ return;
+ }
+ map.put("decryptedkey",ek);
+ }
+}
+
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/DecryptEncryptedKeyAction.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/EncryptTokenAction.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/EncryptTokenAction.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/EncryptTokenAction.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/EncryptTokenAction.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,132 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import org.apache.tsik.domutil.DOMWriteCursor;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wss.elements.UsernameToken;
+import java.security.cert.X509Certificate;
+import java.security.Key;
+import org.apache.tsik.xpath.XPath;
+import org.apache.tsik.wss.elements.KeyIdentifier;
+import org.apache.tsik.wss.elements.SecurityTokenReference;
+import org.apache.tsik.wss.elements.ReferenceList;
+import org.apache.tsik.wss.elements.KeyInfo;
+import org.apache.tsik.wss.elements.EncryptedKey;
+import org.apache.tsik.wss.Id;
+import org.apache.tsik.xmlenc.Encryptor;
+import org.apache.tsik.xmlenc.AlgorithmType;
+import javax.crypto.KeyGenerator;
+import java.security.NoSuchAlgorithmException;
+
+
+public class EncryptTokenAction extends Action
+{
+ X509Certificate cert;
+ XPath keyOutputXpath;
+ XPath tokenXpath;
+
+ // Expects:
+ // cert the certificate to encrypt temp key with (X509Cert)
+ // keyoutput where to put the encrypted key (xpath)
+ // token the token to encrypt in situ (xpath)
+ //
+ private boolean checkInvariants()
+ {
+ cert = (X509Certificate) map.get("cert");
+ if (cert == null){
+ violations.add(new ActionViolation("Certificate missing"));
+ }
+ keyOutputXpath = (XPath) map.get("keyoutput");
+ if (keyOutputXpath == null){
+ violations.add(new ActionViolation("Key output missing"));
+ }
+ tokenXpath = (XPath) map.get("token");
+ if (tokenXpath == null){
+ violations.add(new ActionViolation("Token missing"));
+ }
+ if (cert == null || keyOutputXpath == null || tokenXpath == null){
+ return false;
+ }
+
+ boolean b = output.moveToXPath(keyOutputXpath);
+ if (!b){
+ violations.
+ add(new ActionViolation("Couldn't evaluate key output xpath"));
+ }
+ boolean b2 = input.moveToXPath(tokenXpath);
+ if (!b2){
+ violations.
+ add(new ActionViolation("Couldn't evaluate token xpath"));
+ }
+
+ return (b && b2);
+ }
+
+ public void execute()
+ {
+ if (!checkInvariants()){
+ violations.add(new ActionViolation("Invariance check failed"));
+ return;
+ }
+ // encrypted key
+ KeyIdentifier kid = new KeyIdentifier(cert);
+ SecurityTokenReference str = new SecurityTokenReference(kid);
+ KeyInfo keyInfo = new KeyInfo(str);
+ String id = Id.generateId();
+ ReferenceList refList = new ReferenceList("#"+ id);
+
+ KeyGenerator keyGen = null;
+ try {
+ keyGen = KeyGenerator.getInstance("DESede");
+ } catch (NoSuchAlgorithmException ex){
+ violations.add(new ActionViolation(ex));
+ return;
+ }
+ Key key = keyGen.generateKey();
+
+ EncryptedKey ek = new EncryptedKey(keyInfo, refList);
+ try {
+ ek.encrypt(key);
+ } catch (NoSuchAlgorithmException ex){
+ violations.add(new ActionViolation(ex));
+ return;
+ }
+ output.moveToXPath(keyOutputXpath);
+ ek.toXml(output);
+
+ // encrypted data
+ Encryptor e = null;
+ try {
+ e = new Encryptor(input.getDocument(),
+ ek.getDekKey(),
+ AlgorithmType.TRIPLEDES);
+ } catch (NoSuchAlgorithmException ex){
+ violations.add(new ActionViolation(ex));
+ return;
+ }
+ //e.setContentEncryption(true);
+ e.encryptInPlace(tokenXpath);
+ output.moveToChild(1);
+ output.setAttribute("Id", id);
+ }
+}
+
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/EncryptTokenAction.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1ReadDepGraph.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1ReadDepGraph.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1ReadDepGraph.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1ReadDepGraph.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,90 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wsp.DependencyGraph;
+import org.apache.tsik.wsp.actions.MapAction;
+import org.w3c.dom.Document;
+import org.apache.tsik.wsp.actions.CheckSecurityHeader;
+import org.apache.tsik.wsp.actions.CheckMustUnderstand;
+
+
+class Test1ReadDepGraph implements DependencyGraph
+{
+ Action[] actions;
+
+ public Test1ReadDepGraph()
+ {
+ Map map = new HashMap();
+
+ actions = new Action[4];
+
+ actions[0] = new CheckSecurityHeader();
+ actions[1] = new CheckMustUnderstand();
+ actions[2] = createMapAction(map);
+ actions[3] = new CheckUsernameTokenAction();
+
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].setMap(map);
+ }
+ }
+
+ private Action createMapAction(Map map)
+ {
+ MapAction mapAction = new MapAction(map);
+ mapAction.map("username","valid");
+ mapAction.map("password","valid");
+ return mapAction;
+ }
+
+ public void setInput(Document doc)
+ {
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].setInput(doc);
+ }
+ }
+
+ public void execute()
+ {
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].execute();
+ if (actions[i].getViolations().length != 0) {
+ return;
+ }
+ }
+ }
+
+ public Action.Violation[] getViolations()
+ {
+ List l = new ArrayList();
+ for (int i = 0; i < actions.length; i += 1){
+ Action.Violation[] v = actions[i].getViolations();
+ for (int j = 0; j < v.length; j += 1){
+ l.add(v[j]);
+ }
+ }
+ return (Action.Violation[]) l.toArray(new Action.Violation[0]);
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1ReadDepGraph.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1WriteDepGraph.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1WriteDepGraph.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1WriteDepGraph.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1WriteDepGraph.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,96 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import org.apache.tsik.common.Logger;
+import org.apache.tsik.common.LoggerFactory;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.actions.CreateSoapHeader;
+import org.apache.tsik.wsp.actions.CreateSecurityHeader;
+import org.apache.tsik.wsp.DependencyGraph;
+import org.apache.tsik.wss.elements.UsernameToken;
+import org.apache.tsik.xpath.XPath;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.ActionViolation;
+import org.w3c.dom.Document;
+import org.apache.tsik.wsp.OutputDependencyGraph;
+import java.util.Map;
+import java.util.HashMap;
+import org.apache.tsik.resource.ResourceFactory;
+import org.apache.tsik.resource.XMLResource;
+import org.apache.tsik.domutil.DOMCursor;
+import org.apache.tsik.wss.elements.Security;
+import org.apache.tsik.domutil.DOMWriteCursor;
+
+class Test1WriteDepGraph implements OutputDependencyGraph
+{
+ Document doc;
+ Action soap;
+ Action sec;
+ Action uname;
+
+ Map map = new HashMap();
+
+ public Test1WriteDepGraph()
+ {
+ soap = new CreateSoapHeader();
+ sec = new CreateSecurityHeader();
+ uname = new CreateUsernameTokenAction();
+
+ soap.setMap(map);
+ sec.setMap(map);
+ uname.setMap(map);
+ }
+
+ public void setInput(Document doc)
+ {
+ this.doc = doc;
+
+ soap.setInput(doc);
+ sec.setInput(doc);
+ uname.setInput(doc);
+ }
+
+ public Document getOutput()
+ {
+ return doc;
+ }
+
+ public void execute()
+ {
+ soap.execute();
+ sec.execute();
+ uname.execute();
+ }
+
+ public Action.Violation[] getViolations()
+ {
+ Action.Violation[] v1 = soap.getViolations();
+ Action.Violation[] v2 = sec.getViolations();
+ Action.Violation[] v3 = uname.getViolations();
+
+ Action.Violation[] v = new Action.Violation[v1.length + v2.length
+ + v3.length];
+ System.arraycopy(v1, 0, v, 0, v1.length);
+ System.arraycopy(v2, 0, v, v1.length, v2.length);
+ System.arraycopy(v3, 0, v, v1.length + v2.length, v3.length);
+
+ return v;
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test1WriteDepGraph.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2ReadDepGraph.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2ReadDepGraph.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2ReadDepGraph.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2ReadDepGraph.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,143 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.actions.MapAction;
+import org.apache.tsik.wsp.actions.CheckSecurityHeader;
+import org.apache.tsik.wsp.actions.CheckMustUnderstand;
+import org.apache.tsik.wsp.DependencyGraph;
+import org.apache.tsik.wss.elements.EncryptedKey;
+import org.apache.tsik.wss.elements.Security;
+import org.apache.tsik.xpath.XPath;
+import org.w3c.dom.Document;
+
+
+class Test2ReadDepGraph implements DependencyGraph
+{
+ Document doc;
+
+ private Action[] actions;
+
+ // Expects:
+ // key the key to decrypt temp key with (PrivateKey)
+ // cert the cert corresponding to key (X509Certificate)
+ //
+ public Test2ReadDepGraph(PrivateKey key, X509Certificate cert)
+ {
+ Map map = new HashMap();
+
+ actions = new Action[8];
+
+ actions[0] = new CheckSecurityHeader();
+ actions[1] = new CheckMustUnderstand();
+
+ actions[2] = createKeyMap(cert, key, map);
+ actions[3] = new DecryptEncryptedKeyAction();
+
+ actions[4] = createDataMap(map);
+ actions[5] = new DecryptEncryptedDataAction();
+
+ actions[6] = createUtMap(map);
+ actions[7] = new CheckUsernameTokenAction();
+
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].setMap(map);
+ }
+ }
+
+ private Action createKeyMap(X509Certificate cert, PrivateKey key, Map map)
+ {
+ MapAction mapAction = new MapAction(map);
+ mapAction.map("key", key);
+ mapAction.map("cert", cert);
+
+ String[] ns = {"s", Namespaces.SOAPENV.getUri(), "wsse", Security.uri,
+ "xenc", EncryptedKey.uri};
+ String s = "/s:Envelope/s:Header/wsse:Security/xenc:EncryptedKey";
+ XPath xpath = new XPath(s, ns);
+ mapAction.map("location", xpath);
+
+ return mapAction;
+ }
+
+ private Action createDataMap(Map map)
+ {
+ MapAction mapAction = new MapAction(map);
+
+ String[] ns = {"s", Namespaces.SOAPENV.getUri(), "wsse", Security.uri,
+ "xenc", EncryptedKey.uri};
+ String s = "/s:Envelope/s:Header/wsse:Security/xenc:EncryptedData";
+ XPath xpath = new XPath(s, ns);
+ mapAction.map("location", xpath);
+
+ return mapAction;
+ }
+
+ private Action createUtMap(Map map)
+ {
+ MapAction mapAction = new MapAction(map);
+ mapAction.map("username","valid");
+ mapAction.map("password","valid");
+ return mapAction;
+ }
+
+ public void setInput(Document doc)
+ {
+ this.doc = doc;
+
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].setInput(doc);
+ }
+ }
+
+ public Document getOutput()
+ {
+ return doc;
+ }
+
+ public void execute()
+ {
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].execute();
+ if (actions[i].getViolations().length != 0) {
+ return;
+ }
+ }
+ }
+
+ public Action.Violation[] getViolations()
+ {
+ List l = new ArrayList();
+ for (int i = 0; i < actions.length; i += 1){
+ Action.Violation[] v = actions[i].getViolations();
+ for (int j = 0; j < v.length; j += 1){
+ l.add(v[j]);
+ }
+ }
+ return (Action.Violation[]) l.toArray(new Action.Violation[0]);
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2ReadDepGraph.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2WriteDepGraph.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2WriteDepGraph.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2WriteDepGraph.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2WriteDepGraph.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,131 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tsik.common.Logger;
+import org.apache.tsik.common.LoggerFactory;
+import org.apache.tsik.domutil.DOMCursor;
+import org.apache.tsik.domutil.DOMWriteCursor;
+import org.apache.tsik.resource.ResourceFactory;
+import org.apache.tsik.resource.XMLResource;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wsp.DependencyGraph;
+import org.apache.tsik.wsp.actions.MapAction;
+import org.apache.tsik.wsp.actions.CreateSoapHeader;
+import org.apache.tsik.wsp.actions.CreateSecurityHeader;
+import org.apache.tsik.wsp.OutputDependencyGraph;
+import org.apache.tsik.wss.DefaultTokenResolver;
+import org.apache.tsik.wss.TokenResolver;
+import org.apache.tsik.wss.elements.Security;
+import org.apache.tsik.wss.elements.UsernameToken;
+import org.apache.tsik.xpath.XPath;
+
+import org.w3c.dom.Document;
+
+
+class Test2WriteDepGraph implements OutputDependencyGraph
+{
+ Document doc;
+
+ private Action[] actions;
+
+ // Expects:
+ // cert the certificate to encrypt temp key with (X509Cert)
+ // keyoutput where to put the encrypted key (xpath)
+ // token the token to encrypt in situ (xpath)
+ //
+ public Test2WriteDepGraph(X509Certificate cert)
+ {
+ Map map = new HashMap();
+
+ actions = new Action[5];
+
+ actions[0] = new CreateSoapHeader();
+ actions[1] = new CreateSecurityHeader();
+ actions[2] = new CreateUsernameTokenAction();
+ actions[3] = createMapAction(cert, map);
+ actions[4] = new EncryptTokenAction();
+
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].setMap(map);
+ }
+ }
+
+ private Action createMapAction(X509Certificate cert, Map map)
+ {
+ // the action should be one that could be modeled
+ // in the graph, one that a) remaps and b) maps
+ // text to xpaths
+ MapAction mapAction = new MapAction(map);
+ mapAction.map("cert", cert);
+ mapAction.remap("output","token");
+
+ String soapUri = Namespaces.SOAPENV.getUri();
+ String[] ns = {"s", soapUri, "wsse", Security.uri};
+ String s = "/s:Envelope/s:Header/wsse:Security";
+ XPath xpath = new XPath(s, ns);
+ mapAction.map("keyoutput", xpath);
+ return mapAction;
+ }
+
+ public void setInput(Document doc)
+ {
+ this.doc = doc;
+
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].setInput(doc);
+ }
+ }
+
+ public Document getOutput()
+ {
+ return doc;
+ }
+
+ public void execute()
+ {
+ for (int i = 0; i < actions.length; i += 1){
+ actions[i].execute();
+ if (actions[i].getViolations().length != 0) {
+ return;
+ }
+ }
+ }
+
+ public Action.Violation[] getViolations()
+ {
+ List l = new ArrayList();
+ for (int i = 0; i < actions.length; i += 1){
+ Action.Violation[] v = actions[i].getViolations();
+ for (int j = 0; j < v.length; j += 1){
+ l.add(v[j]);
+ }
+ }
+ return (Action.Violation[]) l.toArray(new Action.Violation[0]);
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/Test2WriteDepGraph.java
------------------------------------------------------------------------------
svn:executable =
Added: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/WspTest.java
URL: http://svn.apache.org/viewcvs/incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/WspTest.java?rev=230871&view=auto
==============================================================================
--- incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/WspTest.java (added)
+++ incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/WspTest.java Mon Aug 8 12:58:58 2005
@@ -0,0 +1,220 @@
+// $Id$
+
+//
+// (C) Copyright 2005 VeriSign, Inc. All Rights Reserved.
+//
+// VeriSign, Inc. shall have no responsibility, financial or
+// otherwise, for any consequences arising out of the use of
+// this material. The program material is provided on an "AS IS"
+// BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+// express or implied. The user is responsible for determining
+// any necessary third party rights or authorizations that may
+// be required for the use of the materials. Users are advised
+// that they may need authorizations under certain patents from
+// Microsoft and IBM, or others. Please see notice.txt file.
+// VeriSign disclaims any obligation to notify the user of any
+// such third party rights.
+//
+
+package org.apache.tsik.wsp.test;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.tsik.common.Logger;
+import org.apache.tsik.common.LoggerFactory;
+import org.apache.tsik.domutil.DOMCursor;
+import org.apache.tsik.messaging.SoapMessage;
+import org.apache.tsik.resource.ResourceFactory;
+import org.apache.tsik.resource.XMLResource;
+import org.apache.tsik.util.Namespaces;
+import org.apache.tsik.wsp.Action;
+import org.apache.tsik.wsp.graphs.SignAndEncryptBody;
+import org.apache.tsik.wsp.graphs.DecryptAndVerifyBody;
+import org.apache.tsik.wsp.ActionViolation;
+import org.apache.tsik.wsp.DependencyGraph;
+import org.apache.tsik.wsp.OutputDependencyGraph;
+import org.apache.tsik.wss.elements.Security;
+import org.apache.tsik.wss.elements.UsernameToken;
+import org.apache.tsik.xpath.XPath;
+import org.w3c.dom.Document;
+import java.io.File;
+
+
+public class WspTest extends TestCase
+{
+ private static XMLResource xmlres = ResourceFactory.getXMLResource();
+ private Logger logger = LoggerFactory.getLogger(WspTest.class);
+
+ public static void main(String[] args) throws Exception
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+
+ public static Test suite() throws Exception
+ {
+ org.apache.log4j.PropertyConfigurator.configure("log4j/log4j.props");
+
+ return new TestSuite(WspTest.class);
+ }
+
+ public WspTest(String name) throws Exception
+ {
+ super(name);
+ }
+
+ private Document read(String in) throws IOException
+ {
+ return xmlres.parseXML(new FileInputStream(in), false);
+ }
+
+ private SoapMessage readSoap(String in) throws IOException
+ {
+ return new SoapMessage(read(in));
+ }
+
+
+ public void testa() throws Exception
+ {
+ byte[] byteArray = new byte[30];
+ for(int i = 0;i<byteArray.length;i++) {
+ byteArray[i] = '0';
+ }
+ }
+
+ public void xtest1() throws Exception
+ {
+ SoapMessage soap = readSoap("wss/ping.xml");
+
+ OutputDependencyGraph odg = new Test1WriteDepGraph();
+ odg.setInput(soap.getDocument());
+ odg.execute();
+ Action.Violation[] violations = odg.getViolations();
+ if (violations.length != 0){
+ for (int i = 0; i < violations.length; i += 1){
+ System.out.println(violations[i]);
+ }
+ }
+ assertTrue(violations.length == 0);
+ DOMCursor out = new DOMCursor(odg.getOutput());
+
+ File tmp = File.createTempFile("wsptest", null);
+ String path = tmp.getCanonicalPath();
+ out.publish(new FileOutputStream(path, false), false);
+
+ Document doc = read(path);
+ DependencyGraph dg = new Test1ReadDepGraph();
+ dg.setInput(doc);
+ dg.execute();
+ violations = dg.getViolations();
+ if (violations.length != 0){
+ for (int i = 0; i < violations.length; i += 1){
+ System.out.println(violations[i]);
+ }
+ }
+ assertTrue(violations.length == 0);
+ }
+
+ public void xtest2() throws Exception
+ {
+ setupKeys();
+ SoapMessage soap = readSoap("wss/ping.xml");
+
+ OutputDependencyGraph odg = new Test2WriteDepGraph(recipientCert);
+ odg.setInput(soap.getDocument());
+ odg.execute();
+ Action.Violation[] violations = odg.getViolations();
+ if (violations.length != 0){
+ for (int i = 0; i < violations.length; i += 1){
+ System.out.println(violations[i]);
+ }
+ }
+ assertTrue(violations.length == 0);
+ DOMCursor out = new DOMCursor(odg.getOutput());
+
+ File tmp = File.createTempFile("wsptest", null);
+ String path = tmp.getCanonicalPath();
+ out.publish(new FileOutputStream(path, false), false);
+
+ Document doc = read(path);
+ DependencyGraph dg
+ = new Test2ReadDepGraph(recipientKey, recipientCert);
+ dg.setInput(doc);
+ dg.execute();
+ violations = dg.getViolations();
+ if (violations.length != 0){
+ for (int i = 0; i < violations.length; i += 1){
+ System.out.println(violations[i]);
+ }
+ }
+ assertTrue(violations.length == 0);
+ }
+
+ private PrivateKey senderKey;
+ private X509Certificate senderCert;
+ private PrivateKey recipientKey;
+ private X509Certificate recipientCert;
+
+ private void setupKeys() throws Exception
+ {
+ KeyStore ks = KeyStore.getInstance("JKS");
+ ks.load(new FileInputStream("wss/oasis.jks"),
+ "password".toCharArray());
+
+ senderKey = (PrivateKey) ks.getKey("alice", "password".toCharArray());
+ senderCert = (X509Certificate) ks.getCertificate("alice");
+ recipientKey = (PrivateKey) ks.getKey("bob", "password".toCharArray());
+ recipientCert = (X509Certificate) ks.getCertificate("bob");
+
+ assertTrue(senderKey != null);
+ assertTrue(senderCert != null);
+ assertTrue(recipientKey != null);
+ assertTrue(recipientCert != null);
+ }
+
+ public void xtestSignAndDecrypt() throws Exception
+ {
+ setupKeys();
+ SoapMessage soap = readSoap("wss/ping.xml");
+
+ OutputDependencyGraph odg
+ = new SignAndEncryptBody(senderKey, senderCert, recipientCert);
+ odg.setInput(soap.getDocument());
+ executeGraph(odg);
+ DOMCursor out = new DOMCursor(odg.getOutput());
+
+ File tmp = File.createTempFile("wsptest", null);
+ String path = tmp.getCanonicalPath();
+ out.publish(new FileOutputStream(path, false), false);
+
+
+ Document doc = read(path);
+ odg = new DecryptAndVerifyBody(recipientKey, recipientCert,
+ senderCert);
+ odg.setInput(doc);
+ executeGraph(odg);
+ out = new DOMCursor(odg.getOutput());
+ }
+
+ private void executeGraph(OutputDependencyGraph odg)
+ {
+ odg.execute();
+ Action.Violation[] violations = odg.getViolations();
+ if (violations.length != 0){
+ for (int i = 0; i < violations.length; i += 1){
+ System.out.println(violations[i]);
+ }
+ }
+ assertTrue(violations.length == 0);
+ }
+}
Propchange: incubator/tsik/trunk/test/src/org/apache/tsik/wsp/test/WspTest.java
------------------------------------------------------------------------------
svn:executable =
---------------------------------------------------------------------
To unsubscribe, e-mail: tsik-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tsik-dev-help@ws.apache.org