【问题标题】:WCF Client P12 certificate issue - Cannot resolve KeyInfo for verifying signature: KeyInfo 'SecurityKeyIdentifier'WCF 客户端 P12 证书问题 - 无法解析用于验证签名的 KeyInfo:KeyInfo 'SecurityKeyIdentifier'
【发布时间】:2019-09-23 03:14:59
【问题描述】:

我的 WCF 服务调用 java soap 服务时出现“无法解析用于验证签名的 KeyInfo:KeyInfo 'SecurityKeyIdentifier”。我做了很多研究,包括 Yaron 的建议,但我被困住了。我可以访问服务并获得响应,因为在提琴手或自定义 MessageEncoder 中我可以看到服务响应,但在接下来的身份验证步骤中失败。

所以这是我的第一个配置:

<system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="MyBinding">
          <textMessageEncoding messageVersion="Soap11WSAddressing10"/>
          <security authenticationMode="MutualCertificateDuplex" 
                    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"  
                    enableUnsecuredResponse="true"
                    requireDerivedKeys="false">
          </security>
          <httpsTransport requireClientCertificate="true" />
        </binding>
      </customBinding>
    </bindings>

    <behaviors>
      <endpointBehaviors>
        <behavior name="ClientCertificateBehavior">
          <clientCredentials>
            <clientCertificate findValue="******"
                              storeLocation="LocalMachine" storeName="My"
                              x509FindType="FindByThumbprint"/>

            <serviceCertificate>
              <defaultCertificate findValue="******"
                                  storeLocation="LocalMachine" storeName="My"
                                  x509FindType="FindByThumbprint"/>
              <authentication certificateValidationMode="None" />
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
      <endpoint address="***"
        binding="customBinding" bindingConfiguration="MyBinding"
        contract="****" name="***"
        behaviorConfiguration="ClientCertificateBehavior">
        <identity>
          <dns value="****"/>
        </identity>
      </endpoint>

    </client>
  </system.serviceModel>

为了比较两个信封,我用soapui 重现了通话。 因此,使用传出证书,我可以获得响应。这是信封:

<soapenv:Envelope xmlns:test="******" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <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">
         <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="X509-1FA551D8E45A2519671568974431972170">MIICpzCCAhCgAwIBAgIJAJx7RzEj5z6mMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAkJHMQwwCgYDVQQKDANPWksxDzANBgNVBAsMBkJyb2tXUzEgMB4GA1UEAwwXT1pLIEJyb2tXUyBSb290IFRlc3QgQ0EwHhcNMTkwMzI3MTQwNzMwWhcNMjQwMzI1MTQwNzMwWjBgMQswCQYDVQQGEwJCRzEbMBkGA1UEChMSVFQgQ29uc3VsdGluZyBFT09EMQ8wDQYDVQQLEwZCcm9rV1MxIzAhBgNVBAMUGk9aSyBDbGllbnRpIFRUS09OU19XU19URVNUMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHdLiR3OSjR5gyHClQ29bLS4bYXVXpBZ5vf2AneHWRKQToIjpFrZWss07Sk3xFOrvb6HZHfqfKLFkXQyiM0KmNOmzwvHLAEet3nbDsTqD9K36VokvGRjJ8FAzIB3QV/YkkKIb7GzCKWyLiZ1REIudVCXccudiff4bthQUHQjV8YwIDAQABo3sweTAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQU7jFfld64Xe0r31M6JzGsSUKuqD4wHwYDVR0jBBgwFoAUHqy+i9hdOuNkH1OhTmdNMX19kskwDQYJKoZIhvcNAQEFBQADgYEAE3oJL4KVGQRr2D8xz3HGFRGrM9fzwziMSLEWDnQuTFXeFf3u/KzFICjIFqtjyYh/lwRGTNiDjpQyFbca4iXR3spvC+/XOpqsi6qjFsPxApFtQpr9bIkkIN1s+XGccSHEkW26pY7Apf0lHdLZPjY4anB2aeH3bE3eLyXcTgLqOwY=</wsse:BinarySecurityToken>
         <ds:Signature Id="SIG-1FA551D8E45A2519671568974431981173" 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="wsa **** soapenv" 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-1FA551D8E45A251967156896582764876">
                  <ds:Transforms>
                     <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                        <ec:InclusiveNamespaces PrefixList="****" 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>09qV67e9HentqoNIEWQLkHmouOY=</ds:DigestValue>
               </ds:Reference>
            </ds:SignedInfo>
            <ds:SignatureValue>pj9pg4JuAzlHAdz5mZmZOy+Et5voEnEUTzawfql4Qa7st3O2dxpa7z3x8ktPUvQb5UTQe4R7izMH
v4O43ZI7D0Mez0N8SvfaXTlA/mudk1GsdqvFYuOhayYJs0xeDHq7hIoB5WKbh7uTdPts+XZYHc1y
8zJk7oZhnNvHpwChh3A=</ds:SignatureValue>
            <ds:KeyInfo Id="KI-1FA551D8E45A2519671568974431973171">
               <wsse:SecurityTokenReference wsu:Id="STR-1FA551D8E45A2519671568974431973172">
                  <wsse:Reference URI="#X509-1FA551D8E45A2519671568974431972170" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/>
               </wsse:SecurityTokenReference>
            </ds:KeyInfo>
         </ds:Signature>
      </wsse:Security>
      <wsa:Action>http://****/getserviceTest</wsa:Action>
      <wsa:MessageID>uuid:aeafa280-18af-4f27-83a5-a0103bb9ce17</wsa:MessageID>
      <wsa:To>https://********</wsa:To>
   </soapenv:Header>
   <soapenv:Body wsu:Id="id-1FA551D8E45A251967156896582764876" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <test:getserviceTestIn>
         <userInfo>
            <loginID>****</loginID>
            <passwordHash>dced489c01609dbfffc6c86461a69c629610dc1a</passwordHash>
         </userInfo>
      </test:getserviceTestIn>
   </soapenv:Body>
</soapenv:Envelope>

然后回应:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" 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" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:exc14n="http://www.w3.org/2001/10/xml-exc-c14n#">
   <S:Header>
      <Action S:mustUnderstand="1" xmlns="http://www.w3.org/2005/08/addressing">http://*****/getserviceTestResponse</Action>
      <MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:39624f81-e533-4cf4-b038-f05f40d2c17f</MessageID>
      <RelatesTo xmlns="http://www.w3.org/2005/08/addressing">uuid:aeafa280-18af-4f27-83a5-a0103bb9ce17</RelatesTo>
      <To xmlns="http://www.w3.org/2005/08/addressing">http://www.w3.org/2005/08/addressing/anonymous</To>
      <wsse:Security S:mustUnderstand="1">
         <wsu:Timestamp wsu:Id="_3" xmlns:ns16="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns15="http://www.w3.org/2003/05/soap-envelope">
            <wsu:Created>2019-09-23T02:53:44Z</wsu:Created>
            <wsu:Expires>2019-09-23T02:58:44Z</wsu:Expires>
         </wsu:Timestamp>
         <ds:Signature Id="_1" xmlns:ns16="http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" xmlns:ns15="http://www.w3.org/2003/05/soap-envelope">
            <ds:SignedInfo>
               <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                  <exc14n:InclusiveNamespaces PrefixList="wsse S"/>
               </ds:CanonicalizationMethod>
               <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
               <ds:Reference URI="#_5002">
                  <ds:Transforms>
                     <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                        <exc14n:InclusiveNamespaces PrefixList="S"/>
                     </ds:Transform>
                  </ds:Transforms>
                  <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                  <ds:DigestValue>cDxxSUo0sUft403D3ftiRJMju0Y=</ds:DigestValue>
               </ds:Reference>
               <ds:Reference URI="#_3">
                  <ds:Transforms>
                     <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                        <exc14n:InclusiveNamespaces PrefixList="wsu wsse S"/>
                     </ds:Transform>
                  </ds:Transforms>
                  <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                  <ds:DigestValue>dTHkdp73Z3Wyyk4yagzPUn3ON+E=</ds:DigestValue>
               </ds:Reference>
            </ds:SignedInfo>
            <ds:SignatureValue>VQo6HzqXDhVjK6su9JifYk6i+xNpCac0O9zmdCqQIJhQfBQlt5sCv4EuE6HveJPG4IjQpX9oKU5DYGCFtsYEmt+ClDrIORfsUbuXaQdvR8pA/t62vvGbcmAqsubqjz4uKKMnGJc5bOFvIPmkA5WIfieViutSQnGwA5xtK1PWt1k=</ds:SignatureValue>
            <ds:KeyInfo>
               <wsse:SecurityTokenReference>
                  <ds:X509Data>
                     <ds:X509IssuerSerial>
                        <ds:X509IssuerName>CN=***, OU=***, O=**, C=**</ds:X509IssuerName>
                        <ds:X509SerialNumber>SERIAL IS DIFFERENT THAN MINE???</ds:X509SerialNumber>
                     </ds:X509IssuerSerial>
                  </ds:X509Data>
               </wsse:SecurityTokenReference>
            </ds:KeyInfo>
         </ds:Signature>
      </wsse:Security>
   </S:Header>
   <S:Body wsu:Id="_5002">
      <ns2:GetserviceTestOut xmlns:ns2="http://******/">
         <reqID>d2f4c570-8a71-4d83-a427-fc0c40f150d4</reqID>
         <status>
            <status>0</status>
         </status>
         <node>
            <property1>*****</property1>
            <property2>*****</property2>
         </node>
         ...
      </ns2:GetserviceTestOut>
   </S:Body>
</S:Envelope>

我在这个回复中看到的是证书 X509SerialNumber 与我的不同。

创建自定义文本编码器后,我进行了一些测试以生成 X509SerialNumber。我的结论是客户端证书 p12 有 2 个对等证书,一个用于服务器,一个用于客户端。

CipherSuite:
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
PeerPrincipal:
CN=XXXX, OU=XX, O=XX, C=XX
Peer Certificate 1:
[
Version: V3
Subject: CN=XXX Server, OU=XX, O=XX, C=XX
Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5
Key: Sun RSA public key, 1024 bits
public exponent: 65537
Validity: [From: Thu May 04 16:23:07 SGT 2017,
To: Sun May 02 16:23:07 SGT 2027]
Issuer: CN=XX Root Test CA, OU=XX, O=XX, C=XX
SerialNumber: [ 9c7b4731 23e73ea0]

]


Peer Certificate 2:
[
Version: V3
Subject: CN=XX Root Test CA, OU=BrokWS, O=OZK, C=BG
Signature Algorithm: SHA1withRSA, OID = 1.2.840.113549.1.1.5

Key: Sun RSA public key, 1024 bits
public exponent: 65537
Validity: [From: Thu May 04 16:17:56 SGT 2017,
To: Sun May 02 16:17:56 SGT 2027]
Issuer: CN=XX Root Test CA, OU=XX, O=XX, C=XX
SerialNumber: [ e30bccb6 ec893986]

]

但是 wcf 尝试使用客户端对等证书验证签名,而不是与服务器回复中正确的 X509SerialNumber 对应的服务器证书。

您知道如何使用 wcf 配置吗?或者如果可能的话,可以提取这个对等证书?

谢谢!

【问题讨论】:

  • 我自己通过从回复中删除安全标头找到了解决方案。因为他们只签署了时间戳和正文。而不是操作、to、replyto、messageid。

标签: c# wcf soap wcf-security ws-security


【解决方案1】:

我自己通过从回复中删除安全标头找到了解决方案。因为他们只签署了时间戳和正文。而不是操作、to、replyto、messageid。

我使用自定义 MessageEncoder 做到了:

public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
        {
            byte[] msgContents = new byte[buffer.Count];
            Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
            bufferManager.ReturnBuffer(buffer.Array);

            MemoryStream stream = new MemoryStream(msgContents);
            var doc = new XmlDocument {PreserveWhitespace = true};
            doc.Load(stream);

            XmlNode envNode = doc.GetElementsByTagName("S:Envelope")[0];
            XmlNode headerNode = doc.GetElementsByTagName("S:Header")[0];
            XmlNode bodyNode = doc.GetElementsByTagName("S:Body")[0];
            if (envNode.Attributes != null && bodyNode.Attributes != null)
            {
                envNode.Attributes.RemoveAll();
                headerNode.RemoveAll();
                bodyNode.Attributes.RemoveAll();
            }

            stream = new MemoryStream();
            doc.Save(stream);

            stream.Position = 0;
            return Message.CreateMessage(XmlReader.Create(stream), int.MaxValue, MessageVersion);
        }

【讨论】:

    猜你喜欢
    • 2015-06-04
    • 1970-01-01
    • 2013-07-14
    • 2012-02-27
    • 1970-01-01
    • 2011-04-09
    • 2013-10-07
    • 2018-02-12
    • 2021-04-07
    相关资源
    最近更新 更多