0

I am trying to connect to a third party web service. I have tried to do it in multiple ways, but I have been unable. They use java for service and for the client, and they have sent me what should be the correct header:

<soapenv:Header>
<wsse:Security 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-DF651A72BB4BD472F5149301750204095" 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="doc soapenv web" 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-DF651A72BB4BD472F5149301750203994">
                <ds:Transforms>
                    <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                        <ec:InclusiveNamespaces PrefixList="doc web" 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>iITj5pTonO3g052LVSnea1yZd0Q=</ds:DigestValue>
            </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue>DhsMfNnidlHk7QIRAWBrr44T6nMLLG00AN/1jnZSlV7pbrMZ3V/MrvW1S5hzQYGQXRH1U1bqzCw8wF2nGtizDtagWGR9UfBoq+wvFBktQy6f7B91DbN++q03a28i2iiSxiEOVWaCvZzCmwOOLdOIIvaD8c8YsJAIgzB+wGg1s6d14+0rk4zAEQrtu7hWvOtU3s6aKIMrX9JiP+1qVInI4RPWynZ9pIbB87vaZSMHsqkjexxKMBB7v5sZugDjl2gPsJeE4dbtC8pXrfZ4QhQ+HSsEYvMJ90J8zyoG2gLuOeCrcQDBe6RrdwpP20r2sTFMKpy2ADZnl1LkwbadvLvnQ==</ds:SignatureValue>
        <ds:KeyInfo Id="KI-DF651A72BB4BD472F5149301750203992">
            <wsse:SecurityTokenReference wsu:Id="STR-DF651A72BB4BD472F5149301750203993">
                <ds:X509Data>
                    <ds:X509IssuerSerial>
                        <ds:X509IssuerName>OU=yyy,O=xxx,C=ES</ds:X509IssuerName>
                        <ds:X509SerialNumber>a very long integer here</ds:X509SerialNumber>
                    </ds:X509IssuerSerial>
                </ds:X509Data>
            </wsse:SecurityTokenReference>
        </ds:KeyInfo>
    </ds:Signature>
</wsse:Security>
</soapenv:Header>

I tried different bindings, like this one:

        <basicHttpBinding>
            <binding name="GInsideCertificateWSSoapBinding"  >
              <security mode="TransportWithMessageCredential"    >
                <message clientCredentialType="Certificate"  />
              </security>
            </binding>
         </basicHttpBinding>

And this one:

      <customBinding>
        <binding name="CustomSoapBinding">
          <security includeTimestamp="true"
                    authenticationMode="CertificateOverTransport"
                    defaultAlgorithmSuite="Basic256"
                    requireDerivedKeys="false"
                    messageSecurityVersion="WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10"
                    >
          </security>
          <textMessageEncoding messageVersion="Soap11"></textMessageEncoding>
          <httpsTransport maxReceivedMessageSize="2000000000"/>
        </binding>
      </customBinding>

I also tried this code: https://msdn.microsoft.com/en-us/library/microsoft.web.services2.security.tokens.binarysecuritytoken.aspx

But no one generates a header like the one they sent me. What kind of security is implemented? They told me BinarySecurityToken, but I cannot connect to the service anyways.

Any ideas?

rasputino
  • 691
  • 1
  • 8
  • 24

1 Answers1

0

You need to load a X509Certificate2 before make a call as this :

X509Certificate2 certificat = null;
X509Store store = new X509Store("My", StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
foreach (X509Certificate2 cert in store.Certificates) {
    // Retrouve le certificat par son nom commun (CN)
    if (cert.GetNameInfo(X509NameType.SimpleName, false) == nomCertificat) {
        certificat = cert;
        break; 
    }
}

But provide C# code to see more in details.

User.Anonymous
  • 1,719
  • 1
  • 28
  • 51
  • I already did it in this way. What I want is a simple BinarySecurityToken signed like the SOAP message above, but the message generated is really different. The problem is not how to get the certificate, is the way how generate a SOAP like the one above. – rasputino Apr 27 '17 at 10:27
  • Oh ok. Then you'll do check this page https://msdn.microsoft.com/en-us/library/ms827738.aspx. It is about how create a custom token. It's pretty old (2003), so maybe some extensions or nugget package are now available. – User.Anonymous Apr 27 '17 at 11:40
  • Check this answers, it is the same issues.http://stackoverflow.com/questions/37594829/use-wsse-security-header-in-soap-message-visual-studio-2015-net-framework-4-5 or http://stackoverflow.com/questions/40671821/calling-a-java-ws-from-c-sharp – User.Anonymous Apr 27 '17 at 12:30