Search in sources :

Example 11 with AlgorithmSuite

use of org.apache.wss4j.policy.model.AlgorithmSuite in project cxf by apache.

the class PolicyBasedWSS4JStaxInInterceptor method configureProperties.

@Override
protected void configureProperties(SoapMessage msg, WSSSecurityProperties securityProperties) throws XMLSecurityException {
    AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
    checkAsymmetricBinding(aim, msg, securityProperties);
    checkSymmetricBinding(aim, msg, securityProperties);
    checkTransportBinding(aim, msg, securityProperties);
    // Allow for setting non-standard signature algorithms
    String asymSignatureAlgorithm = (String) msg.getContextualProperty(SecurityConstants.ASYMMETRIC_SIGNATURE_ALGORITHM);
    String symSignatureAlgorithm = (String) msg.getContextualProperty(SecurityConstants.SYMMETRIC_SIGNATURE_ALGORITHM);
    if (asymSignatureAlgorithm != null || symSignatureAlgorithm != null) {
        Collection<AssertionInfo> algorithmSuites = aim.get(SP12Constants.ALGORITHM_SUITE);
        if (algorithmSuites != null && !algorithmSuites.isEmpty()) {
            for (AssertionInfo algorithmSuite : algorithmSuites) {
                AlgorithmSuite algSuite = (AlgorithmSuite) algorithmSuite.getAssertion();
                if (asymSignatureAlgorithm != null) {
                    algSuite.setAsymmetricSignature(asymSignatureAlgorithm);
                }
                if (symSignatureAlgorithm != null) {
                    algSuite.setSymmetricSignature(symSignatureAlgorithm);
                }
            }
        }
    }
    super.configureProperties(msg, securityProperties);
}
Also used : AlgorithmSuite(org.apache.wss4j.policy.model.AlgorithmSuite) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 12 with AlgorithmSuite

use of org.apache.wss4j.policy.model.AlgorithmSuite in project cxf by apache.

the class TransportBindingHandler method doDerivedKeySignature.

private byte[] doDerivedKeySignature(boolean tokenIncluded, SecurityToken secTok, AbstractToken token, List<WSEncryptionPart> sigParts) throws Exception {
    // Do Signature with derived keys
    WSSecDKSign dkSign = new WSSecDKSign(secHeader);
    dkSign.setIdAllocator(wssConfig.getIdAllocator());
    dkSign.setCallbackLookup(callbackLookup);
    dkSign.setAttachmentCallbackHandler(new AttachmentCallbackHandler(message));
    dkSign.setStoreBytesInAttachment(storeBytesInAttachment);
    dkSign.setExpandXopInclude(isExpandXopInclude());
    dkSign.setWsDocInfo(wsDocInfo);
    AlgorithmSuite algorithmSuite = tbinding.getAlgorithmSuite();
    // Setting the AttachedReference or the UnattachedReference according to the flag
    Element ref;
    if (tokenIncluded) {
        ref = secTok.getAttachedReference();
    } else {
        ref = secTok.getUnattachedReference();
    }
    if (ref != null) {
        dkSign.setExternalKey(secTok.getSecret(), cloneElement(ref));
    } else {
        dkSign.setExternalKey(secTok.getSecret(), secTok.getId());
    }
    if (token instanceof UsernameToken) {
        dkSign.setCustomValueType(WSS4JConstants.WSS_USERNAME_TOKEN_VALUE_TYPE);
    }
    // Set the algo info
    dkSign.setSignatureAlgorithm(algorithmSuite.getSymmetricSignature());
    AlgorithmSuiteType algType = binding.getAlgorithmSuite().getAlgorithmSuiteType();
    dkSign.setDerivedKeyLength(algType.getSignatureDerivedKeyLength() / 8);
    if (token.getVersion() == SPConstants.SPVersion.SP11) {
        dkSign.setWscVersion(ConversationConstants.VERSION_05_02);
    }
    dkSign.prepare();
    addDerivedKeyElement(dkSign.getdktElement());
    dkSign.getParts().addAll(sigParts);
    List<Reference> referenceList = dkSign.addReferencesToSign(sigParts);
    // Do signature
    dkSign.computeSignature(referenceList, false, null);
    return dkSign.getSignatureValue();
}
Also used : WSSecDKSign(org.apache.wss4j.dom.message.WSSecDKSign) AlgorithmSuite(org.apache.wss4j.policy.model.AlgorithmSuite) AlgorithmSuiteType(org.apache.wss4j.policy.model.AlgorithmSuite.AlgorithmSuiteType) SecurityTokenReference(org.apache.wss4j.common.token.SecurityTokenReference) Reference(javax.xml.crypto.dsig.Reference) Element(org.w3c.dom.Element) AttachmentCallbackHandler(org.apache.cxf.ws.security.wss4j.AttachmentCallbackHandler) UsernameToken(org.apache.wss4j.policy.model.UsernameToken) WSSecUsernameToken(org.apache.wss4j.dom.message.WSSecUsernameToken)

Aggregations

AlgorithmSuite (org.apache.wss4j.policy.model.AlgorithmSuite)12 Policy (org.apache.neethi.Policy)4 AbstractToken (org.apache.wss4j.policy.model.AbstractToken)4 Element (org.w3c.dom.Element)4 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)3 AttachmentCallbackHandler (org.apache.cxf.ws.security.wss4j.AttachmentCallbackHandler)3 All (org.apache.neethi.All)3 ExactlyOne (org.apache.neethi.ExactlyOne)3 AlgorithmSuiteType (org.apache.wss4j.policy.model.AlgorithmSuite.AlgorithmSuiteType)3 IssuedToken (org.apache.wss4j.policy.model.IssuedToken)3 X509Token (org.apache.wss4j.policy.model.X509Token)3 QName (javax.xml.namespace.QName)2 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)2 StaxSerializer (org.apache.cxf.ws.security.wss4j.StaxSerializer)2 Crypto (org.apache.wss4j.common.crypto.Crypto)2 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)2 SecurityTokenReference (org.apache.wss4j.common.token.SecurityTokenReference)2 WSSecEncrypt (org.apache.wss4j.dom.message.WSSecEncrypt)2 WSSecUsernameToken (org.apache.wss4j.dom.message.WSSecUsernameToken)2 KerberosToken (org.apache.wss4j.policy.model.KerberosToken)2