Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,13 @@ private String setupEncryptedKey(RampartMessageData rmd, Token sigToken)
throws RampartException {
try {
KeyGenerator keyGen;
try {
keyGen = KeyUtils.getKeyGenerator(WSConstants.AES_128);
} catch (WSSecurityException e) {
e.printStackTrace();
return null;
}
try {
String encrAlgo = rmd.getPolicyData().getAlgorithmSuite().getEncryption();
keyGen = KeyUtils.getKeyGenerator(encrAlgo != null ? encrAlgo : WSConstants.AES_128);
} catch (WSSecurityException e) {
e.printStackTrace();
return null;
}
SecretKey symmetricKey = keyGen.generateKey();
WSSecEncryptedKey encrKey = this.getEncryptedKeyBuilder(rmd,
sigToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import javax.xml.namespace.QName;

import org.apache.axis2.context.MessageContext;
import org.apache.rahas.TokenStorage;
import org.apache.rahas.TrustUtil;
import org.apache.neethi.Policy;
import org.apache.wss4j.dom.WSConstants;
import org.apache.wss4j.common.derivedKey.ConversationConstants;
Expand Down Expand Up @@ -49,6 +51,41 @@ public void testSymmBinding() throws Exception {
this.verifySecHeader(list.iterator(), ctx.getEnvelope());
}

/**
* RAMPART-462: the symmetric key generated for an X509 protection token must follow the
* encryption algorithm of the policy's AlgorithmSuite (here Basic256 = AES-256) instead of
* always being AES-128.
*/
public void testSymmBindingBasic256() throws Exception {
MessageContext ctx = getMsgCtx();

String policyXml = "test-resources/policy/rampart-symm-binding-6-basic256.xml";

Policy policy = this.loadPolicy(policyXml);

ctx.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);

MessageBuilder builder = new MessageBuilder();
builder.build(ctx);

ArrayList<QName> list = new ArrayList<QName>();

list.add(new QName(WSConstants.WSU_NS, WSConstants.TIMESTAMP_TOKEN_LN));
list.add(new QName(WSConstants.ENC_NS, WSConstants.ENC_KEY_LN));
list.add(new QName(WSConstants.ENC_NS, WSConstants.REF_LIST_LN));
list.add(new QName(WSConstants.SIG_NS, WSConstants.SIG_LN));

this.verifySecHeader(list.iterator(), ctx.getEnvelope());

// The session key generated by SymmetricBindingBuilder is kept in the token store
TokenStorage store = TrustUtil.getTokenStore(ctx);
String[] ids = store.getTokenIdentifiers();
assertEquals("Expected exactly one generated key", 1, ids.length);
byte[] secret = store.getToken(ids[0]).getSecret();
assertNotNull(secret);
assertEquals("Basic256 requires a 256-bit (32 byte) AES key", 32, secret.length);
}

// public void testSymmBindingServerSide() {
//
// try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<wsp:Policy wsu:Id="policy2" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl">
<wsp:ExactlyOne>
<wsp:All>
<sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:ProtectionToken>
<wsp:Policy>
<sp:X509Token sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
<wsp:Policy>
<sp:RequireThumbprintReference/>
<sp:WssX509V3Token10/>
</wsp:Policy>
</sp:X509Token>
</wsp:Policy>
</sp:ProtectionToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:OnlySignEntireHeadersAndBody/>
</wsp:Policy>
</sp:SymmetricBinding>
<sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:MustSupportRefKeyIdentifier/>
<sp:MustSupportRefIssuerSerial/>
<sp:MustSupportRefThumbprint/>
<sp:MustSupportRefEncryptedKey/>
</wsp:Policy>
</sp:Wss11>
<sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<sp:Body/>
<sp:Header Name="To" Namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>
<sp:Header Name="From" Namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>
<sp:Header Name="FaultTo" Namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>
<sp:Header Name="ReplyTo" Namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>
<sp:Header Name="MessageID" Namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>
<sp:Header Name="RelatesTo" Namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>
<sp:Header Name="Action" Namespace="http://schemas.xmlsoap.org/ws/2004/08/addressing"/>
</sp:SignedParts>
<sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<sp:Body/>
</sp:EncryptedParts>

<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy">
<ramp:user>alice</ramp:user>
<ramp:encryptionUser>bob</ramp:encryptionUser>
<ramp:passwordCallbackClass>org.apache.rampart.TestCBHandler</ramp:passwordCallbackClass>

<ramp:signatureCrypto>
<ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
<ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">pkcs12</ramp:property>
<ramp:property name="org.apache.ws.security.crypto.merlin.file">test-resources/keys/interop2024.pkcs12</ramp:property>
<ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">password</ramp:property>
</ramp:crypto>
</ramp:signatureCrypto>
<ramp:encryptionCypto>
<ramp:crypto provider="org.apache.ws.security.components.crypto.Merlin">
<ramp:property name="org.apache.ws.security.crypto.merlin.keystore.type">pkcs12</ramp:property>
<ramp:property name="org.apache.ws.security.crypto.merlin.file">test-resources/keys/interop2024.pkcs12</ramp:property>
<ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">password</ramp:property>
</ramp:crypto>
</ramp:encryptionCypto>
</ramp:RampartConfig>


</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>