Forum Discussion

evilSteve's avatar
evilSteve
New Contributor
11 years ago

Encrypt the sign and the body

Hi,

i've a problem with the encryption of both sign and body of a soap message.

What i want to do is:
  • Includes a timestamp
  • All headers are signed along with the timestamp
  • Signature encrypted
  • Body encrypted

    But i'm stuck with an error..

    The others examples with only Username Token, Timestamp+signature, Timestamp+signature+encrypt works fine.

    I use SOAPUI 5.0, and i've configured it with this Outgoing WS-Security Config:
    - Timestamp (time to live 60)
    - Signature ( Keystore = client.keystore Alias = client )
    - Encryption ( Keystore = client.keystore Alias = server
    Part:
    Name = Signature
    NameSpace = http://www.w3.org/2000/09/xmldsig
    Encode = element
    - Encryption ( Keystore = client.keystore Alias = server
    Part:
    Name = Body
    NameSpace = http://www.w3.org/2003/05/soap-envelope/
    Encode = content



    There are 2 keystore, client.kestore and server.keystore.
    For the creation of the keystore i've follow this script:

    #!/bin/sh
    KEYTOOL=$JAVA_HOME/bin/keytool
    echo Generating the Server KeyStore in file server.keystore
    # The value of CN should be the IP address or host name on which web application will be deployed. Avoid specifying 'localhost'
    $KEYTOOL -genkey -alias tomcat-sv -dname "CN=tomcat-sv, OU=X, O=Y, L=Z, S=XY, C=YZ" -keyalg RSA -keypass *_KeyPass_* -storepass *_KeyPass_* -keystore server.keystore

    echo Exporting the certificate from keystore to an external file server.cer
    $KEYTOOL -export -alias tomcat-sv -storepass *_KeyPass_* -file server.cer -keystore server.keystore

    echo Generating the Client KeyStore in file client.keystore
    $KEYTOOL -genkey -alias tomcat-cl -dname "CN=tomcat-cl, OU=X, O=Y, L=Z, S=XY, C=YZ" -keyalg RSA -keypass *_KeyPass_* -storepass *_KeyPass_* -keystore client.keystore

    echo Exporting the certificate from keystore to external file client.cer
    $KEYTOOL -export -alias tomcat-cl -storepass *_KeyPass_* -file client.cer -keystore client.keystore

    echo metto la chiave pubblica del server nel keystore del client
    $KEYTOOL -import -alias tomcat-sv -file server.cer -keystore client.keystore -keypass *_KeyPass_* -storepass *_KeyPass_*

    echo metto la chiave pubblica del client nel keystore del server
    $KEYTOOL -import -alias tomcat-cl -file client.cer -keystore server.keystore -keypass *_KeyPass_* -storepass *_KeyPass_*



    This is the reply from the web services:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
    <soapenv:Fault xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <faultcode>wsse:InvalidSecurity</faultcode>
    <faultstring>Expected encrypted part missing</faultstring>
    <detail/>
    </soapenv:Fault>
    </soapenv:Body>
    </soapenv:Envelope>



    If i change the namespace of the body into "http://schemas.xmlsoap.org/soap/envelope/" then i get:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
    <soapenv:Fault xmlns:axis2ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <faultcode>axis2ns2:FailedCheck</faultcode>
    <faultstring>The signature or decryption was invalid</faultstring>
    <detail/>
    </soapenv:Fault>
    </soapenv:Body>
    </soapenv:Envelope>





    This is my request:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wam="http://wam.evil.it">
    <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <ds:Signature Id="SIG-CEF851598E4FD165791401812036719135" xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
    <ec:InclusiveNamespaces PrefixList="soapenv wam" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    </ds:CanonicalizationMethod>
    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
    <ds:Reference URI="#id-CEF851598E4FD165791401811316502106">
    <ds:Transforms>
    <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
    <ec:InclusiveNamespaces PrefixList="wam" xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"/>
    </ds:Transform>
    </ds:Transforms>
    <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
    <ds:DigestValue>jmmralKJDd9Ijc8J3FtmfZUzMOU=</ds:DigestValue>
    </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>MHPlIcmkOb3HbE/uOnTBl3RtoNF0QvYU9vA1diUMTpjwTW+AxzROfwcte9qHb1yyTLtoOj1Wft+t
    aEmtfBG7igW1U/sF5RAOJY8w+Kkl1adueR5WFqoPAZafJEUFQ5qrYTPLqbSvpf/kGQOqdxHZ4J18
    Pxu0px4qieAo+ZEa1ZBwuS82zURCtYZ7ZzGfB4u1KgX8VRRO48bTF76LZdmWD3nMSzPjE/W/dux+
    XsM16GRLXw67zt8G3s4TjGV7UFL44Cvo+RBXoXwjknzSjIBuhrGnJUK2H6EsnTYL9d/ZeKqnsarQ
    9zc6+tQOAQC3R0bzZLGc5hwp51pznzNUHuhInA==</ds:SignatureValue>
    <ds:KeyInfo Id="KI-CEF851598E4FD165791401812036718133">
    <wsse:SecurityTokenReference wsu:Id="STR-CEF851598E4FD165791401812036718134">
    <ds:X509Data>
    <ds:X509IssuerSerial>
    <ds:X509IssuerName>CN=tomcat-cl,OU=X,O=Y,L=Z,ST=XY,C=YZ</ds:X509IssuerName>
    <ds:X509SerialNumber>798547597</ds:X509SerialNumber>
    </ds:X509IssuerSerial>
    </ds:X509Data>
    </wsse:SecurityTokenReference>
    </ds:KeyInfo>
    </ds:Signature>
    <wsu:Timestamp wsu:Id="TS-CEF851598E4FD165791401812036717131">
    <wsu:Created>2014-06-03T16:13:56.716Z</wsu:Created>
    <wsu:Expires>2014-06-03T17:53:56.716Z</wsu:Expires>
    </wsu:Timestamp>
    </wsse:Security>
    </soapenv:Header>
    <soapenv:Body wsu:Id="id-CEF851598E4FD165791401811316502106" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <xenc:EncryptedData Id="ED-CEF851598E4FD165791401812036741138" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">
    <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc"/>
    <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <wsse:SecurityTokenReference wsse11:TokenType="http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#EncryptedKey" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd">
    <wsse:Reference URI="#EK-CEF851598E4FD165791401812036740137"/>
    </wsse:SecurityTokenReference>
    </ds:KeyInfo>
    <xenc:CipherData>
    <xenc:CipherValue>GRdNc2+Y94efqhBZz3BMNb9Cx792t5UdliCtTzKR4Q+aT4RCbwdrxa6bbQQ0MtM74FifCsk7IC5a2IKFTRiYn48VbnLqQ/RdRIjcy6gAEoRv0UtIU7eEHE/AXARXcRTC3ILydEe2KsEqggNNH8cpswCvxaFy2wFbL3mZryu6csWcHFnwhZTnvWd5mErRgKtUOCwrhpqFxrNPBWcmxMi6m9GQ2zyWOT7gKDOnbzKPqLo5NCfu10m+Nyjr5Kmc52puRohZzBe58Zks/5l2EtGrnKqKtWy+j9luRMQNw734aX950WTfW3++9dciLnS7XxojybTfkr9eoqlGaD1sQmlw9UNvzKgDf9rQdM/BAPhlhthI+O/DX+sJHKMFSAib3uuu4g3+eUE/EYk75qcJdxuEk0E6hk8z5WFFAnOci8y4cvdTRX0Ew3cAQ2SG4H7kCaGd</xenc:CipherValue>
    </xenc:CipherData>
    </xenc:EncryptedData>
    </soapenv:Body>
    </soapenv:Envelope>




    If you need additional log/printscreen answer me, I'll upload them immediately.



    Kind Regards,

    Stefano.
    • evilSteve's avatar
      evilSteve
      New Contributor
      I almost forgot to post the services.xml


      <parameter name="useOriginalwsdl">false</parameter>
      <parameter name="modifyUserWSDLPortAddress">true</parameter>
      <operation name="getDeviceTEST">
      <module ref="rampart" />
      <module ref="rahas" />
      <module ref="addressing" />

      <wsp:Policy
      wsu:Id="SecConvPolicy"
      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:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
      <wsp:Policy>

      <sp:ProtectionToken>
      <wsp:Policy>
      <sp:SecureConversationToken
      sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
      <wsp:Policy>
      <sp:RequireDerivedKeys />
      <sp:BootstrapPolicy>
      <wsp:Policy>

      <sp:EncryptedParts>
      <sp:Body />
      </sp:EncryptedParts>

      <sp:SymmetricBinding>
      <wsp:Policy>
      <sp:ProtectionToken>
      <wsp:Policy>
      <sp:X509Token
      sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
      <wsp:Policy>
      <sp:RequireDerivedKeys />
      <sp:RequireThumbprintReference />
      <sp:WssX509V3Token10 />
      </wsp:Policy>
      </sp:X509Token>
      </wsp:Policy>
      </sp:ProtectionToken>
      <sp:AlgorithmSuite>
      <wsp:Policy>
      <sp:Basic128Rsa15 />
      </wsp:Policy>
      </sp:AlgorithmSuite>
      <sp:Layout>
      <wsp:Policy>
      <sp:Strict />
      </wsp:Policy>
      </sp:Layout>
      <sp:IncludeTimestamp />
      <sp:EncryptSignature />
      <sp:OnlySignEntireHeadersAndBody />
      </wsp:Policy>
      </sp:SymmetricBinding>

      <sp:EndorsingSupportingTokens>
      <wsp:Policy>
      <sp:X509Token
      sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
      <wsp:Policy>
      <sp:RequireThumbprintReference />
      <sp:WssX509V3Token10 />
      </wsp:Policy>
      </sp:X509Token>
      </wsp:Policy>
      </sp:EndorsingSupportingTokens>

      <sp:Wss11>
      <wsp:Policy>
      <sp:MustSupportRefKeyIdentifier />
      <sp:MustSupportRefIssuerSerial />
      <sp:MustSupportRefThumbprint />
      <sp:MustSupportRefEncryptedKey />
      <sp:RequireSignatureConfirmation />
      </wsp:Policy>
      </sp:Wss11>

      <sp:Trust10>
      <wsp:Policy>
      <sp:MustSupportIssuedTokens />
      <sp:RequireClientEntropy />
      <sp:RequireServerEntropy />
      </wsp:Policy>
      </sp:Trust10>

      </wsp:Policy>
      </sp:BootstrapPolicy>
      </wsp:Policy>
      </sp:SecureConversationToken>
      </wsp:Policy>
      </sp:ProtectionToken>

      <sp:AlgorithmSuite>
      <wsp:Policy>
      <sp:Basic128Rsa15 />
      </wsp:Policy>
      </sp:AlgorithmSuite>

      <sp:Layout>
      <wsp:Policy>
      <sp:Strict />
      </wsp:Policy>
      </sp:Layout>

      <sp:IncludeTimestamp />
      <sp:EncryptSignature />
      <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:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
      <wsp:Policy>
      <sp:MustSupportIssuedTokens />
      <sp:RequireClientEntropy />
      <sp:RequireServerEntropy />
      </wsp:Policy>
      </sp:Trust10>

      <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>tomcat-sv</ramp:user>
      <ramp:encryptionUser>tomcat-cl</ramp:encryptionUser>
      <ramp:passwordCallbackClass>it.evil.wam.PWCallback</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">JKS</ramp:property>
      <ramp:property name="org.apache.ws.security.crypto.merlin.file">/home/evil/server.keystore</ramp:property>
      <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">*_KeyPass_*</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">JKS</ramp:property>
      <ramp:property name="org.apache.ws.security.crypto.merlin.file">/home/evil/server.keystore</ramp:property>
      <ramp:property name="org.apache.ws.security.crypto.merlin.keystore.password">*_KeyPass_*</ramp:property>
      </ramp:crypto>
      </ramp:encryptionCypto>
      </ramp:RampartConfig>

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

      <parameter name="sct-issuer-config">
      <sct-issuer-config>
      <cryptoProperties>
      <crypto provider="org.apache.ws.security.components.crypto.Merlin">
      <property name="org.apache.ws.security.crypto.merlin.keystore.type">JKS</property>
      <property name="org.apache.ws.security.crypto.merlin.file">/home/evil/server.keystore</property>
      <property name="org.apache.ws.security.crypto.merlin.keystore.password">*_KeyPass_*</property>
      </crypto>
      </cryptoProperties>
      <addRequestedAttachedRef />
      <addRequestedUnattachedRef />

      <!--
      Key computation mechanism
      1 - Use Request Entropy
      2 - Provide Entropy
      3 - Use Own Key
      -->
      <keyComputation>3</keyComputation>

      <!--
      proofKeyType element is valid only if the keyComputation is set to 3
      i.e. Use Own Key

      Valid values are: EncryptedKey & BinarySecret
      -->
      <proofKeyType>BinarySecret</proofKeyType>
      </sct-issuer-config>
      </parameter>

      <parameter name="token-canceler-config">
      <token-canceler-config>

      </token-canceler-config>
      </parameter>
      </operation>


      maybe i'm using the wrong namespace for the signature?