You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2012/08/08 16:09:53 UTC
svn commit: r1370780 - in
/webservices/wss4j/branches/swssf/streaming-ws-security/src/main:
java/org/swssf/wss/ext/ java/org/swssf/wss/impl/processor/input/
java/org/swssf/wss/securityEvent/ resources/wss/
Author: coheigea
Date: Wed Aug 8 14:09:52 2012
New Revision: 1370780
URL: http://svn.apache.org/viewvc?rev=1370780&view=rev
Log:
Updates following Santuario revision 1370778
Added:
webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/WSSEncryptedKeyInputHandler.java
- copied, changed from r1370739, webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java
Removed:
webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java
webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/securityEvent/EncryptedKeyTokenSecurityEvent.java
Modified:
webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java
webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java
webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/securityEvent/WSSecurityEventConstants.java
webservices/wss4j/branches/swssf/streaming-ws-security/src/main/resources/wss/wss-config.xml
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java?rev=1370780&r1=1370779&r2=1370780&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSConstants.java Wed Aug 8 14:09:52 2012
@@ -264,8 +264,6 @@ public class WSSConstants extends XMLSec
}
//todo rename KeyUsage because C14N, etc are not keys...
- public static final KeyUsage Sym_Key_Wrap = new KeyUsage("Sym_Key_Wrap");
- public static final KeyUsage Asym_Key_Wrap = new KeyUsage("Asym_Key_Wrap");
public static final KeyUsage Comp_Key = new KeyUsage("Comp_Key");
public static final KeyUsage Enc_KD = new KeyUsage("Enc_KD");
public static final KeyUsage Sig_KD = new KeyUsage("Sig_KD");
@@ -273,7 +271,6 @@ public class WSSConstants extends XMLSec
public static final KeyUsage STR_Trans = new KeyUsage("STR_Trans");
public static final KeyUsage XPath = new KeyUsage("XPath");
- public static final TokenType EncryptedKeyToken = new TokenType("EncryptedKeyToken");
public static final TokenType UsernameToken = new TokenType("UsernameToken");
public static final TokenType SecurityContextToken = new TokenType("SecurityContextToken");
public static final TokenType Saml10Token = new TokenType("Saml10Token");
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java?rev=1370780&r1=1370779&r2=1370780&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/ext/WSSUtils.java Wed Aug 8 14:09:52 2012
@@ -23,12 +23,12 @@ import org.apache.xml.security.stax.ext.
import org.apache.xml.security.stax.ext.stax.XMLSecAttribute;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
import org.apache.xml.security.stax.ext.stax.XMLSecStartElement;
+import org.apache.xml.security.stax.securityEvent.EncryptedKeyTokenSecurityEvent;
import org.apache.xml.security.stax.securityEvent.KeyValueTokenSecurityEvent;
import org.apache.xml.security.stax.securityEvent.TokenSecurityEvent;
import org.apache.xml.security.stax.securityEvent.X509TokenSecurityEvent;
import org.swssf.wss.crypto.Merlin;
import org.swssf.wss.securityEvent.DerivedKeyTokenSecurityEvent;
-import org.swssf.wss.securityEvent.EncryptedKeyTokenSecurityEvent;
import org.swssf.wss.securityEvent.HttpsTokenSecurityEvent;
import org.swssf.wss.securityEvent.KerberosTokenSecurityEvent;
import org.swssf.wss.securityEvent.RelTokenSecurityEvent;
Copied: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/WSSEncryptedKeyInputHandler.java (from r1370739, webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java)
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/WSSEncryptedKeyInputHandler.java?p2=webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/WSSEncryptedKeyInputHandler.java&p1=webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java&r1=1370739&r2=1370780&rev=1370780&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/EncryptedKeyInputHandler.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/impl/processor/input/WSSEncryptedKeyInputHandler.java Wed Aug 8 14:09:52 2012
@@ -18,34 +18,18 @@
*/
package org.swssf.wss.impl.processor.input;
+import org.apache.xml.security.binding.xmldsig.KeyInfoType;
+import org.apache.xml.security.binding.xmlenc.EncryptedKeyType;
+import org.apache.xml.security.stax.ext.InputProcessorChain;
+import org.apache.xml.security.stax.ext.XMLSecurityException;
+import org.apache.xml.security.stax.ext.XMLSecurityProperties;
+import org.apache.xml.security.stax.impl.processor.input.XMLEncryptedKeyInputHandler;
import org.swssf.binding.wss10.ObjectFactory;
import org.swssf.binding.wss10.ReferenceType;
import org.swssf.binding.wss10.SecurityTokenReferenceType;
-import org.apache.xml.security.binding.xmldsig.KeyInfoType;
-import org.apache.xml.security.binding.xmlenc.EncryptedKeyType;
-import org.swssf.wss.ext.*;
-import org.swssf.wss.securityEvent.EncryptedKeyTokenSecurityEvent;
-import org.apache.xml.security.stax.config.JCEAlgorithmMapper;
-import org.apache.xml.security.stax.ext.*;
-import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
-import org.apache.xml.security.stax.impl.securityToken.AbstractSecurityToken;
-import org.apache.xml.security.stax.impl.securityToken.SecurityTokenFactory;
-import org.apache.xml.security.stax.impl.util.IDGenerator;
-import org.apache.xml.security.stax.securityEvent.TokenSecurityEvent;
-import org.xmlsecurity.ns.configuration.AlgorithmType;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.spec.SecretKeySpec;
-import javax.xml.bind.JAXBElement;
-import javax.xml.namespace.QName;
-import java.security.*;
-import java.util.Deque;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
+import org.swssf.wss.ext.WSSConstants;
+import org.swssf.wss.ext.WSSSecurityProperties;
+import org.swssf.wss.ext.WSSecurityContext;
/**
* Processor for the EncryptedKey XML Structure
@@ -53,185 +37,31 @@ import java.util.Map;
* @author $Author$
* @version $Revision$ $Date$
*/
-public class EncryptedKeyInputHandler extends AbstractInputSecurityHeaderHandler {
+public class WSSEncryptedKeyInputHandler extends XMLEncryptedKeyInputHandler {
+ //if this EncryptedKey structure contains a reference list, instantiate a new DecryptInputProcessor
+ //and add it to the chain
@Override
- public void handle(final InputProcessorChain inputProcessorChain, final XMLSecurityProperties securityProperties,
- final Deque<XMLSecEvent> eventQueue, final Integer index) throws XMLSecurityException {
-
- @SuppressWarnings("unchecked")
- final EncryptedKeyType encryptedKeyType =
- ((JAXBElement<EncryptedKeyType>) parseStructure(eventQueue, index, securityProperties)).getValue();
-
- if (encryptedKeyType.getEncryptionMethod() == null) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "noEncAlgo");
- }
-
- checkBSPCompliance(inputProcessorChain, encryptedKeyType);
-
- if (encryptedKeyType.getId() == null) {
- encryptedKeyType.setId(IDGenerator.generateID(null));
- }
-
- final List<QName> elementPath = getElementPath(eventQueue);
- final XMLSecEvent responsibleXMLSecStartXMLEvent = getResponsibleStartXMLEvent(eventQueue, index);
- final WSSecurityContext securityContext = (WSSecurityContext) inputProcessorChain.getSecurityContext();
-
- final SecurityTokenProvider securityTokenProvider = new SecurityTokenProvider() {
-
- private SecurityToken securityToken = null;
-
- public SecurityToken getSecurityToken() throws XMLSecurityException {
-
- if (this.securityToken != null) {
- return this.securityToken;
- }
-
- this.securityToken = new AbstractSecurityToken(
- securityContext, null, encryptedKeyType.getId(), null) {
-
- private final Map<String, Key> keyTable = new Hashtable<String, Key>();
-
- public boolean isAsymmetric() {
- return false;
- }
-
- public Key getKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage)
- throws XMLSecurityException {
- if (keyTable.containsKey(algorithmURI)) {
- return keyTable.get(algorithmURI);
- } else {
- String algoFamily = JCEAlgorithmMapper.getJCERequiredKeyFromURI(algorithmURI);
- Key key = new SecretKeySpec(getSecret(this), algoFamily);
- keyTable.put(algorithmURI, key);
- return key;
- }
- }
-
- @Override
- public PublicKey getPubKey(String algorithmURI, XMLSecurityConstants.KeyUsage keyUsage)
- throws XMLSecurityException {
- return null;
- }
-
- public SecurityToken getKeyWrappingToken() throws XMLSecurityException {
- return getWrappingSecurityToken(this);
- }
-
- public WSSConstants.TokenType getTokenType() {
- return WSSConstants.EncryptedKeyToken;
- }
-
- private SecurityToken wrappingSecurityToken = null;
-
- private SecurityToken getWrappingSecurityToken(SecurityToken wrappedSecurityToken)
- throws XMLSecurityException {
- if (wrappingSecurityToken != null) {
- return this.wrappingSecurityToken;
- }
- KeyInfoType keyInfoType = encryptedKeyType.getKeyInfo();
- this.wrappingSecurityToken = SecurityTokenFactory.getInstance().getSecurityToken(
- keyInfoType,
- SecurityToken.KeyInfoUsage.DECRYPTION,
- securityProperties,
- securityContext
- );
- this.wrappingSecurityToken.addWrappedToken(wrappedSecurityToken);
- return this.wrappingSecurityToken;
- }
-
- private byte[] getSecret(SecurityToken wrappedSecurityToken) throws XMLSecurityException {
-
- String algorithmURI = encryptedKeyType.getEncryptionMethod().getAlgorithm();
- if (algorithmURI == null) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "noEncAlgo");
- }
- AlgorithmType asyncEncAlgo = JCEAlgorithmMapper.getAlgorithmMapping(algorithmURI);
- if (asyncEncAlgo == null) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "noEncAlgo");
- }
-
- final SecurityToken wrappingSecurityToken = getWrappingSecurityToken(wrappedSecurityToken);
- try {
- WSSConstants.KeyUsage keyUsage;
- if (wrappingSecurityToken.isAsymmetric()) {
- keyUsage = WSSConstants.Asym_Key_Wrap;
- } else {
- keyUsage = WSSConstants.Sym_Key_Wrap;
- }
-
- Cipher cipher;
- if (asyncEncAlgo.getJCEProvider() == null) {
- cipher = Cipher.getInstance(asyncEncAlgo.getJCEName());
- } else {
- cipher = Cipher.getInstance(asyncEncAlgo.getJCEName(), asyncEncAlgo.getJCEProvider());
- }
- cipher.init(Cipher.DECRYPT_MODE, wrappingSecurityToken.getSecretKey(algorithmURI, keyUsage));
- if (encryptedKeyType.getCipherData() == null
- || encryptedKeyType.getCipherData().getCipherValue() == null) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, "noCipher");
- }
- return cipher.doFinal(encryptedKeyType.getCipherData().getCipherValue());
-
- } catch (NoSuchPaddingException e) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "unsupportedKeyTransp",
- e, "No such padding: " + algorithmURI
- );
- } catch (NoSuchAlgorithmException e) {
- throw new WSSecurityException(
- WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, "unsupportedKeyTransp",
- e, "No such algorithm: " + algorithmURI
- );
- } catch (BadPaddingException e) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (IllegalBlockSizeException e) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (InvalidKeyException e) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, e);
- } catch (NoSuchProviderException e) {
- throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "noSecProvider", e);
- }
- }
- };
- this.securityToken.setElementPath(elementPath);
- this.securityToken.setXMLSecEvent(responsibleXMLSecStartXMLEvent);
- return this.securityToken;
- }
-
- @Override
- public String getId() {
- return encryptedKeyType.getId();
- }
- };
-
- //register the key token for decryption:
- securityContext.registerSecurityTokenProvider(encryptedKeyType.getId(), securityTokenProvider);
-
- //fire a tokenSecurityEvent
- TokenSecurityEvent tokenSecurityEvent = new EncryptedKeyTokenSecurityEvent();
- tokenSecurityEvent.setSecurityToken(securityTokenProvider.getSecurityToken());
- securityContext.registerSecurityEvent(tokenSecurityEvent);
-
- //if this EncryptedKey structure contains a reference list, instantiate a new DecryptInputProcessor
- //and add it to the chain
- if (encryptedKeyType.getReferenceList() != null) {
- KeyInfoType keyInfoType = new KeyInfoType();
- SecurityTokenReferenceType securityTokenReferenceType = new SecurityTokenReferenceType();
- ReferenceType referenceType = new ReferenceType();
- referenceType.setURI("#" + encryptedKeyType.getId());
- ObjectFactory objectFactory = new ObjectFactory();
- securityTokenReferenceType.getAny().add(objectFactory.createReference(referenceType));
- keyInfoType.getContent().add(objectFactory.createSecurityTokenReference(securityTokenReferenceType));
- inputProcessorChain.addProcessor(
- new DecryptInputProcessor(keyInfoType, encryptedKeyType.getReferenceList(),
- (WSSSecurityProperties) securityProperties, securityContext)
- );
- }
+ protected void handleReferenceList(final InputProcessorChain inputProcessorChain,
+ final EncryptedKeyType encryptedKeyType,
+ final XMLSecurityProperties securityProperties) throws XMLSecurityException {
+ KeyInfoType keyInfoType = new KeyInfoType();
+ SecurityTokenReferenceType securityTokenReferenceType = new SecurityTokenReferenceType();
+ ReferenceType referenceType = new ReferenceType();
+ referenceType.setURI("#" + encryptedKeyType.getId());
+ ObjectFactory objectFactory = new ObjectFactory();
+ securityTokenReferenceType.getAny().add(objectFactory.createReference(referenceType));
+ keyInfoType.getContent().add(objectFactory.createSecurityTokenReference(securityTokenReferenceType));
+ inputProcessorChain.addProcessor(
+ new DecryptInputProcessor(keyInfoType, encryptedKeyType.getReferenceList(),
+ (WSSSecurityProperties) securityProperties,
+ (WSSecurityContext) inputProcessorChain.getSecurityContext())
+ );
}
- private void checkBSPCompliance(InputProcessorChain inputProcessorChain, EncryptedKeyType encryptedKeyType)
- throws WSSecurityException {
+ @Override
+ protected void checkBSPCompliance(InputProcessorChain inputProcessorChain, EncryptedKeyType encryptedKeyType)
+ throws XMLSecurityException {
final WSSecurityContext securityContext = (WSSecurityContext) inputProcessorChain.getSecurityContext();
if (encryptedKeyType.getType() != null) {
securityContext.handleBSPRule(WSSConstants.BSPRule.R3209);
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/securityEvent/WSSecurityEventConstants.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/securityEvent/WSSecurityEventConstants.java?rev=1370780&r1=1370779&r2=1370780&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/securityEvent/WSSecurityEventConstants.java (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/wss/securityEvent/WSSecurityEventConstants.java Wed Aug 8 14:09:52 2012
@@ -42,6 +42,5 @@ public abstract class WSSecurityEventCon
public static final Event UsernameToken = new Event("UsernameToken");
public static final Event HttpsToken = new Event("HttpsToken");
public static final Event DerivedKeyToken = new Event("DerivedKeyToken");
- public static final Event EncryptedKeyToken = new Event("EncryptedKeyToken");
}
Modified: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/resources/wss/wss-config.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/resources/wss/wss-config.xml?rev=1370780&r1=1370779&r2=1370780&view=diff
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/resources/wss/wss-config.xml (original)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/resources/wss/wss-config.xml Wed Aug 8 14:09:52 2012
@@ -11,7 +11,7 @@
JAVACLASS="org.swssf.wss.impl.processor.input.BinarySecurityTokenInputHandler"/>
<Handler NAME="EncryptedKey"
URI="http://www.w3.org/2001/04/xmlenc#"
- JAVACLASS="org.swssf.wss.impl.processor.input.EncryptedKeyInputHandler"/>
+ JAVACLASS="org.swssf.wss.impl.processor.input.WSSEncryptedKeyInputHandler"/>
<Handler NAME="ReferenceList"
URI="http://www.w3.org/2001/04/xmlenc#"
JAVACLASS="org.swssf.wss.impl.processor.input.ReferenceListInputHandler"/>