This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-rampart.git

commit 9c9b4c19b7e711938801375b8a2f291c60f95a07
Author: Robert Lazarski <[email protected]>
AuthorDate: Wed Nov 18 04:05:35 2026 -1000

    Reference an endorsing SCT with the SCT value type in the transport binding
    
    The transport binding's SecureConversationToken signature without derived
    keys stamped the SAML 1.x assertion value type on the wsse:Reference to the
    wsc:SecurityContextToken. WSS4J resolves the already processed SCT by URI
    and ignores it, but a strict peer rejects a SAML reference to an SCT. The
    reference now carries the SCT value type of the conversation version, and
    the leading "#" of the stored id is only stripped when present.
    
    Co-Authored-By: Claude Fable 5.1 <[email protected]>
---
 .../rampart/builder/TransportBindingBuilder.java   | 14 +++-
 .../TransportSecureConversationReferenceTest.java  | 85 ++++++++++++++++++++++
 .../policy/rampart-transport-binding-sct.xml       | 63 ++++++++++++++++
 3 files changed, 160 insertions(+), 2 deletions(-)

diff --git 
a/modules/rampart-core/src/main/java/org/apache/rampart/builder/TransportBindingBuilder.java
 
b/modules/rampart-core/src/main/java/org/apache/rampart/builder/TransportBindingBuilder.java
index 27fd3a83..8fe5a09a 100644
--- 
a/modules/rampart-core/src/main/java/org/apache/rampart/builder/TransportBindingBuilder.java
+++ 
b/modules/rampart-core/src/main/java/org/apache/rampart/builder/TransportBindingBuilder.java
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.rahas.RahasConstants;
 import org.apache.rahas.TrustException;
+import org.apache.wss4j.common.derivedKey.ConversationConstants;
 import org.apache.rampart.RampartConstants;
 import org.apache.rampart.RampartException;
 import org.apache.rampart.RampartMessageData;
@@ -698,8 +699,17 @@ public class TransportBindingBuilder extends 
BindingBuilder {
         } else {
             try {
                 WSSecSignature sig = new WSSecSignature(rmd.getSecHeader());
-                sig.setCustomTokenId(tok.getId().substring(1));
-                
sig.setCustomTokenValueType(RampartUtil.getSAML10AssertionNamespace());
+                String tokId = tok.getId();
+                if (tokId.startsWith("#")) {
+                    tokId = tokId.substring(1);
+                }
+                sig.setCustomTokenId(tokId);
+                // The wsse:Reference to a wsc:SecurityContextToken carries 
the SCT value
+                // type of the conversation version in use. This used to be 
the SAML 1.x
+                // assertion value type, which a strict peer rejects for an 
SCT.
+                sig.setCustomTokenValueType(
+                        ConversationConstants.VERSION_05_12 == 
rmd.getSecConvVersion()
+                                ? WSConstants.WSC_SCT_05_12 : 
WSConstants.WSC_SCT);
                 sig.setSecretKey(tok.getSecret());
                 
sig.setSignatureAlgorithm(algorithmSuite.getAsymmetricSignature());
                 
sig.setSignatureAlgorithm(algorithmSuite.getSymmetricSignature());
diff --git 
a/modules/rampart-tests/src/test/java/org/apache/rampart/TransportSecureConversationReferenceTest.java
 
b/modules/rampart-tests/src/test/java/org/apache/rampart/TransportSecureConversationReferenceTest.java
new file mode 100644
index 00000000..92f4a23e
--- /dev/null
+++ 
b/modules/rampart-tests/src/test/java/org/apache/rampart/TransportSecureConversationReferenceTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.rampart;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axis2.context.MessageContext;
+import org.apache.neethi.Policy;
+import org.apache.rahas.Token;
+import org.apache.rahas.TrustUtil;
+import org.apache.rampart.util.RampartUtil;
+import org.apache.wss4j.dom.WSConstants;
+
+/**
+ * A transport binding endorsed by a SecureConversationToken without derived 
keys
+ * references the wsc:SecurityContextToken from ds:KeyInfo with the SCT value 
type of
+ * the conversation version in use. It used to carry the SAML 1.x assertion 
value type.
+ */
+public class TransportSecureConversationReferenceTest extends 
MessageBuilderTestBase {
+
+    private static final String WSC_NS = 
"http://schemas.xmlsoap.org/ws/2005/02/sc";;
+    private static final String SCT_ID = "sct-1";
+
+    @SuppressWarnings("unchecked")
+    public void testEndorsingSctReferencedWithSctValueType() throws Exception {
+        MessageContext ctx = getMsgCtx();
+        Policy policy = 
loadPolicy("test-resources/policy/rampart-transport-binding-sct.xml");
+        ctx.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policy);
+
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace wsc = fac.createOMNamespace(WSC_NS, "wsc");
+        OMElement sct = fac.createOMElement("SecurityContextToken", wsc);
+        sct.addAttribute("Id", SCT_ID, 
fac.createOMNamespace(WSConstants.WSU_NS, "wsu"));
+        fac.createOMElement("Identifier", wsc, sct).setText("urn:uuid:sct-1");
+
+        // An SCT obtained through an attached wsse:Reference is stored under 
"#" + wsu:Id
+        Token token = new Token("#" + SCT_ID, sct, new Date(),
+                new Date(System.currentTimeMillis() + 300000));
+        token.setSecret(new byte[16]);
+        token.setState(Token.ISSUED);
+        TrustUtil.getTokenStore(ctx).add(token);
+        
RampartUtil.getContextMap(ctx).put(RampartUtil.getContextIdentifierKey(ctx), 
"#" + SCT_ID);
+
+        new MessageBuilder().build(ctx);
+
+        List<QName> expected = new ArrayList<QName>();
+        expected.add(new QName(WSConstants.WSU_NS, 
WSConstants.TIMESTAMP_TOKEN_LN));
+        expected.add(sct.getQName());
+        expected.add(new QName(WSConstants.SIG_NS, WSConstants.SIG_LN));
+        verifySecHeader(expected.iterator(), ctx.getEnvelope());
+
+        OMElement signature = ctx.getEnvelope().getHeader()
+                .getFirstChildWithName(new QName(WSConstants.WSSE_NS, 
WSConstants.WSSE_LN))
+                .getFirstChildWithName(new QName(WSConstants.SIG_NS, 
WSConstants.SIG_LN));
+        OMElement reference = signature
+                .getFirstChildWithName(new QName(WSConstants.SIG_NS, 
WSConstants.KEYINFO_LN))
+                .getFirstChildWithName(new QName(WSConstants.WSSE_NS, 
"SecurityTokenReference"))
+                .getFirstChildWithName(new QName(WSConstants.WSSE_NS, 
"Reference"));
+        assertNotNull("wsse:Reference to the SCT missing", reference);
+        assertEquals("#" + SCT_ID, reference.getAttributeValue(new 
QName("URI")));
+        assertEquals(WSConstants.WSC_SCT, reference.getAttributeValue(new 
QName("ValueType")));
+    }
+}
diff --git 
a/modules/rampart-tests/test-resources/policy/rampart-transport-binding-sct.xml 
b/modules/rampart-tests/test-resources/policy/rampart-transport-binding-sct.xml
new file mode 100644
index 00000000..b9051848
--- /dev/null
+++ 
b/modules/rampart-tests/test-resources/policy/rampart-transport-binding-sct.xml
@@ -0,0 +1,63 @@
+<wsp:Policy wsu:Id="transportSct" 
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";>
+<wsp:ExactlyOne>
+  <wsp:All>
+       <sp:TransportBinding 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+         <wsp:Policy>
+               <sp:TransportToken>
+                 <wsp:Policy>
+                       <sp:HttpsToken RequireClientCertificate="false"/>
+                 </wsp:Policy>
+               </sp:TransportToken>
+               <sp:AlgorithmSuite>
+                 <wsp:Policy>
+                       <sp:Basic128/>
+                 </wsp:Policy>
+               </sp:AlgorithmSuite>
+               <sp:Layout>
+                 <wsp:Policy>
+                       <sp:Lax/>
+                 </wsp:Policy>
+               </sp:Layout>
+               <sp:IncludeTimestamp/>
+         </wsp:Policy>
+       </sp:TransportBinding>
+       <sp:EndorsingSupportingTokens 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+         <wsp:Policy>
+               <sp:SecureConversationToken 
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient";>
+                 <wsp:Policy>
+                       <sp:RequireExternalUriReference/>
+                 </wsp:Policy>
+               </sp:SecureConversationToken>
+         </wsp:Policy>
+       </sp:EndorsingSupportingTokens>
+       <sp:Wss10 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+         <wsp:Policy>
+               <sp:MustSupportRefKeyIdentifier/>
+               <sp:MustSupportRefIssuerSerial/>
+         </wsp:Policy>
+       </sp:Wss10>
+       <sp:Trust10 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+         <wsp:Policy>
+               <sp:MustSupportIssuedTokens/>
+               <sp:RequireClientEntropy/>
+               <sp:RequireServerEntropy/>
+         </wsp:Policy>
+       </sp:Trust10>
+
+       <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:RampartConfig>
+
+  </wsp:All>
+</wsp:ExactlyOne>
+</wsp:Policy>

Reply via email to