From commits-return-17841-apmail-cxf-commits-archive=cxf.apache.org@cxf.apache.org Wed Jan 25 14:48:56 2012 Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 54306966F for ; Wed, 25 Jan 2012 14:48:56 +0000 (UTC) Received: (qmail 34473 invoked by uid 500); 25 Jan 2012 14:48:56 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 34365 invoked by uid 500); 25 Jan 2012 14:48:55 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 34358 invoked by uid 99); 25 Jan 2012 14:48:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jan 2012 14:48:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Jan 2012 14:48:49 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4A1D523888FD for ; Wed, 25 Jan 2012 14:48:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1235775 - in /cxf/trunk/systests/ws-security: ./ src/test/java/org/apache/cxf/systest/ws/gcm/ src/test/java/org/apache/cxf/systest/ws/gcm/server/ src/test/resources/org/apache/cxf/systest/ws/gcm/ src/test/resources/org/apache/cxf/systest/w... Date: Wed, 25 Jan 2012 14:48:26 -0000 To: commits@cxf.apache.org From: coheigea@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120125144827.4A1D523888FD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: coheigea Date: Wed Jan 25 14:48:26 2012 New Revision: 1235775 URL: http://svn.apache.org/viewvc?rev=1235775&view=rev Log: Adding tests that show how to use AES-GCM algorithms for encryption using custom WS-SecurityPolicy AlgorithmSuites - @Ignore'd until we pick up WSS4J 1.6.5 Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuite.java cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuiteLoader.java cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMTest.java cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/server/ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/server/Server.java cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/DoubleItGCM.wsdl cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/client/ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/client/client.xml cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/server/ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/server/server.xml Modified: cxf/trunk/systests/ws-security/pom.xml Modified: cxf/trunk/systests/ws-security/pom.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/pom.xml?rev=1235775&r1=1235774&r2=1235775&view=diff ============================================================================== --- cxf/trunk/systests/ws-security/pom.xml (original) +++ cxf/trunk/systests/ws-security/pom.xml Wed Jan 25 14:48:26 2012 @@ -194,7 +194,13 @@ com.sun.xml.fastinfoset FastInfoset - + + + + org.bouncycastle + bcprov-jdk15 + test + Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuite.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuite.java?rev=1235775&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuite.java (added) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuite.java Wed Jan 25 14:48:26 2012 @@ -0,0 +1,72 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.systest.ws.gcm; + +import org.apache.cxf.ws.security.policy.SP12Constants; +import org.apache.cxf.ws.security.policy.SPConstants; +import org.apache.cxf.ws.security.policy.WSSPolicyException; +import org.apache.cxf.ws.security.policy.model.AlgorithmSuite; + +/** + * This AlgorithmSuite supports GCM security policies. + */ +public class GCMAlgorithmSuite extends AlgorithmSuite { + + public GCMAlgorithmSuite(SPConstants version) { + super(version); + } + + public GCMAlgorithmSuite() { + super(SP12Constants.INSTANCE); + } + + /** + * Set the algorithm suite + * + * @param algoSuite + * @throws WSSPolicyException + */ + @Override + public void setAlgorithmSuite(String algoSuite) throws WSSPolicyException { + this.algoSuiteString = algoSuite; + + if ("Basic128GCM".equals(algoSuite)) { + this.digest = SPConstants.SHA1; + this.encryption = "http://www.w3.org/2009/xmlenc11#aes128-gcm"; + this.symmetricKeyWrap = SPConstants.KW_AES128; + this.asymmetricKeyWrap = SPConstants.KW_RSA_OAEP; + this.encryptionKeyDerivation = SPConstants.P_SHA1_L128; + this.signatureKeyDerivation = SPConstants.P_SHA1_L128; + this.encryptionDerivedKeyLength = 128; + this.signatureDerivedKeyLength = 128; + this.minimumSymmetricKeyLength = 128; + } else if ("Basic256GCM".equals(algoSuite)) { + this.digest = SPConstants.SHA1; + this.encryption = "http://www.w3.org/2009/xmlenc11#aes256-gcm"; + this.symmetricKeyWrap = SPConstants.KW_AES256; + this.asymmetricKeyWrap = SPConstants.KW_RSA_OAEP; + this.encryptionKeyDerivation = SPConstants.P_SHA1_L256; + this.signatureKeyDerivation = SPConstants.P_SHA1_L192; + this.encryptionDerivedKeyLength = 256; + this.signatureDerivedKeyLength = 192; + this.minimumSymmetricKeyLength = 256; + this.encryptionDerivedKeyLength = 256; + } + } +} Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuiteLoader.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuiteLoader.java?rev=1235775&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuiteLoader.java (added) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMAlgorithmSuiteLoader.java Wed Jan 25 14:48:26 2012 @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.systest.ws.gcm; + +import org.w3c.dom.Element; + +import org.apache.cxf.Bus; +import org.apache.cxf.helpers.DOMUtils; +import org.apache.cxf.ws.security.policy.SPConstants; +import org.apache.cxf.ws.security.policy.custom.AlgorithmSuiteLoader; +import org.apache.cxf.ws.security.policy.model.AlgorithmSuite; + +/** + * This class retrieves a custom AlgorithmSuite for use with security policies that require GCM + * algorithms. + */ +public class GCMAlgorithmSuiteLoader implements AlgorithmSuiteLoader { + + public GCMAlgorithmSuiteLoader(Bus bus) { + bus.setExtension(this, AlgorithmSuiteLoader.class); + } + + public AlgorithmSuite getAlgorithmSuite(Element policyElement, SPConstants consts) { + if (policyElement != null) { + GCMAlgorithmSuite algorithmSuite = new GCMAlgorithmSuite(consts); + String algorithmSuiteName = DOMUtils.getFirstElement(policyElement).getLocalName(); + algorithmSuite.setAlgorithmSuite(algorithmSuiteName); + return algorithmSuite; + } + return null; + } + +} Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMTest.java?rev=1235775&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMTest.java (added) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/GCMTest.java Wed Jan 25 14:48:26 2012 @@ -0,0 +1,125 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.systest.ws.gcm; + +import java.net.URL; + +import javax.crypto.Cipher; +import javax.crypto.SecretKey; +import javax.crypto.spec.SecretKeySpec; +import javax.xml.namespace.QName; +import javax.xml.ws.Service; + +import org.apache.cxf.Bus; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.systest.ws.gcm.server.Server; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; + +import org.example.contract.doubleit.DoubleItPortType; + +import org.junit.BeforeClass; + +/** + * A set of tests for GCM algorithms using custom WS-SecurityPolicy expressions. + */ +public class GCMTest extends AbstractBusClientServerTestBase { + static final String PORT = allocatePort(Server.class); + + private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt"; + private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService"); + + private boolean unrestrictedPoliciesInstalled = checkUnrestrictedPoliciesInstalled(); + + @BeforeClass + public static void startServers() throws Exception { + assertTrue( + "Server failed to launch", + // run the server in the same process + // set this to false to fork + launchServer(Server.class, true) + ); + } + + @org.junit.Test + @org.junit.Ignore + public void testAESGCM128() throws Exception { + if (!unrestrictedPoliciesInstalled) { + return; + } + + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = GCMTest.class.getResource("client/client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL wsdl = GCMTest.class.getResource("DoubleItGCM.wsdl"); + Service service = Service.create(wsdl, SERVICE_QNAME); + QName portQName = new QName(NAMESPACE, "DoubleItGCM128Port"); + DoubleItPortType gcmPort = + service.getPort(portQName, DoubleItPortType.class); + updateAddressPort(gcmPort, PORT); + gcmPort.doubleIt(25); + } + + @org.junit.Test + @org.junit.Ignore + public void testAESGCM256() throws Exception { + if (!unrestrictedPoliciesInstalled) { + return; + } + + SpringBusFactory bf = new SpringBusFactory(); + URL busFile = GCMTest.class.getResource("client/client.xml"); + + Bus bus = bf.createBus(busFile.toString()); + SpringBusFactory.setDefaultBus(bus); + SpringBusFactory.setThreadDefaultBus(bus); + + URL wsdl = GCMTest.class.getResource("DoubleItGCM.wsdl"); + Service service = Service.create(wsdl, SERVICE_QNAME); + QName portQName = new QName(NAMESPACE, "DoubleItGCM256Port"); + DoubleItPortType gcmPort = + service.getPort(portQName, DoubleItPortType.class); + updateAddressPort(gcmPort, PORT); + gcmPort.doubleIt(25); + } + + private boolean checkUnrestrictedPoliciesInstalled() { + try { + byte[] data = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; + + SecretKey key192 = new SecretKeySpec( + new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17}, + "AES"); + Cipher c = Cipher.getInstance("AES"); + c.init(Cipher.ENCRYPT_MODE, key192); + c.doFinal(data); + return true; + } catch (Exception e) { + // + } + return false; + } + +} Added: cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/server/Server.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/server/Server.java?rev=1235775&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/server/Server.java (added) +++ cxf/trunk/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/gcm/server/Server.java Wed Jan 25 14:48:26 2012 @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.systest.ws.gcm.server; + +import java.net.URL; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; + +public class Server extends AbstractBusTestServerBase { + + public Server() { + + } + + protected void run() { + URL busFile = Server.class.getResource("server.xml"); + Bus busLocal = new SpringBusFactory().createBus(busFile); + BusFactory.setDefaultBus(busLocal); + setBus(busLocal); + + try { + new Server(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} Added: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/DoubleItGCM.wsdl URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/DoubleItGCM.wsdl?rev=1235775&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/DoubleItGCM.wsdl (added) +++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/DoubleItGCM.wsdl Wed Jan 25 14:48:26 2012 @@ -0,0 +1,193 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/client/client.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/client/client.xml?rev=1235775&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/client/client.xml (added) +++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/client/client.xml Wed Jan 25 14:48:26 2012 @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/server/server.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/server/server.xml?rev=1235775&view=auto ============================================================================== --- cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/server/server.xml (added) +++ cxf/trunk/systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/gcm/server/server.xml Wed Jan 25 14:48:26 2012 @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +