2013-10-01 4 views
0

Я пытаюсь связаться с сервисом с фреймворком WCF. Только информационная безопасность У меня есть доступный:Исключение службы WCF: {«Не удалось разрешить идентификатор ключевой клавиши»}

Сертификат является сертификатом P12 с закрытым ключом, импортированным в локальный магазин ключей локального компьютера.

Я получил успешную сделку, работая в SoapUI, и мне удалось получить сообщение Soap XML:

SoapUI сообщение:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="*removed*"> 
    <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"> 
     <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-*removed*">*removed*</wsse:BinarySecurityToken> 
     <ds:Signature Id="SIG-37" 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 urn" 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-36"> 
      <ds:Transforms> 
       <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> 
       <ec:InclusiveNamespaces PrefixList="urn" 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>*removed*</ds:DigestValue> 
      </ds:Reference> 
     </ds:SignedInfo> 
     <ds:SignatureValue> 
      *removed* 
     </ds:SignatureValue> 
     <ds:KeyInfo Id="KI-*removed*"> 
      <wsse:SecurityTokenReference wsu:Id="STR-*removed*"> 
      <wsse:Reference URI="#X509-*removed*" 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> 
    </soapenv:Header> 
    <soapenv:Body wsu:Id="id-36" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <!--Not important--> 
    </soapenv:Body> 
</soapenv:Envelope> 

Я через многочисленные исключения и настройки безопасности, а также теперь я пришел к CustomBinding с помощью AsymmetricSecurityBindingElement. Это ближайшее я могу добраться до удачных сообщений SoapUI в WCF:

WCF сообщение:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
    <s:Header> 
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> 
     <SignedInfo> 
      <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></CanonicalizationMethod> 
      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></SignatureMethod> 
      <Reference URI="#_2"> 
      <Transforms> 
       <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform> 
      </Transforms> 
      <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod> 
      <DigestValue>*removed*</DigestValue> 
      </Reference> 
     </SignedInfo> 
     <SignatureValue>*removed*</SignatureValue> 
     <KeyInfo> 
      <o:SecurityTokenReference> 
      <o:KeyIdentifier ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509SubjectKeyIdentifier">*removed*</o:KeyIdentifier> 
      </o:SecurityTokenReference> 
     </KeyInfo> 
     </Signature> 
    </o:Security> 
    </s:Header> 
    <s:Body u:Id="_2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <!--Not important--> 
    </s:Body> 
</s:Envelope> 

SoapUI имеют некоторые настройки безопасности, которые необходимо Binary маркер безопасности, а не X509 сертификата. Я также изменил значение DNS конечной точки в app.config, так что не будет жаловаться на другой претензии DNS в сертификате: S

<identity> 
    <dns value="*IPv4-address*" /> 
</identity> 

Мое поведение EndPoint как это:

<behavior name="CustomBehavior"> 
    <clientCredentials> 
    <clientCertificate findValue="*IPv4-address*" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="Root"/> 
    <serviceCertificate> 
     <defaultCertificate findValue="*IPv4-address*" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="Root"/> 
    </serviceCertificate> 
    </clientCredentials> 
</behavior> 

customBinding в C#:

var asymmetricSecurityBindingElement = new AsymmetricSecurityBindingElement(); 
asymmetricSecurityBindingElement.InitiatorTokenParameters = new X509SecurityTokenParameters { InclusionMode = SecurityTokenInclusionMode.Never }; 
asymmetricSecurityBindingElement.RecipientTokenParameters = new X509SecurityTokenParameters { InclusionMode = SecurityTokenInclusionMode.Never }; 
asymmetricSecurityBindingElement.IncludeTimestamp = false; 

CustomBinding customBinding = new CustomBinding(); 
customBinding.Elements.Add(asymmetricSecurityBindingElement); 
customBinding.Elements.Add(new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8)); 

HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); 
httpsBindingElement.RequireClientCertificate = true; 
customBinding.Elements.Add(httpsBindingElement); 

Удаленная служба выдает исключение при выполнении метода WSDL: { «не удалось разрешить идентификатор ключа субъекта»} (в nerException) http://docs.oracle.com/html/E13983_01/troubleshooting.htm говорит, что сертификат открытого ключа может отсутствовать в хранилище ключей удаленной службы, но транзакция SoapUI работает. В нем также упоминается что-то об псевдониме, и я не уверен, что это значит.

Кажется, у меня нет подсказки для решения моей проблемы. Может кто-нибудь мне помочь?

ответ

0

Попробуйте this binding:

<customBinding> 
     <binding name="NewBinding0"> 
      <textMessageEncoding messageVersion="Soap11" /> 
      <security authenticationMode="MutualCertificate" includeTimestamp="false" 
       messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"> 
       <secureConversationBootstrap /> 
      </security> 
      <httpTransport /> 
     </binding> 
</customBinding> 

убедитесь, чтобы украсить свой контракт подписать только:

[System.ServiceModel.ServiceContractAttribute(ConfigurationName=..., ProtectionLevel=System.Net.Security.ProtectionLevel.Sign)] 

Больше информации here.

+0

Спасибо за быстрый ответ. И я действительно использовал ваш очень полезный блог о распространенных ошибках;).У меня установлен уровень защиты Sign Signed, и я попробовал ваш customBinding с помощью httpsTransport, что приводит к другому исключению: «Не удается найти аутентификатор токена для типа токена« System.IdentityModel.Tokens.X509SecurityToken ». Токены этого типа не могут быть приняты согласно текущие настройки безопасности ". Хотя моя привязка теперь настроена как последняя ошибка, упомянутая в вашем сообщении. – user1190841

+0

проверить это сообщение http://webservices20.blogspot.co.il/2010/10/wcf-cannot-find-token-authenticator.html –