2013-08-15 2 views
2

클라이언트 인증서와 사용자 이름/암호가 필요한 서버에 연결하는 WCF 클라이언트를 가져 오는 데 문제가 있습니다.WCF 클라이언트 인증서 및 사용자 이름 자격 증명 금지

 var binding = new WSHttpBinding(SecurityMode.Transport); 
     binding.Security.Transport = new HttpTransportSecurity(); 
     binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; 

     var ea = new EndpointAddress(EndpointUrl); 

     using (var p = new ServiceReference1.AAAClient(binding, ea)) 
     { 
      try 
      { 
       p.ClientCredentials.ClientCertificate.SetCertificate(
         System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser, 
         System.Security.Cryptography.X509Certificates.StoreName.My, 
         System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName, 
         CertificateSubject); 

       var x = p.RequiresClientCertificateOnly(); 
       Console.WriteLine("Status: " + x.status); 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex.ToString()); 
      } 

      Console.WriteLine(); 
     } 

다음 논리적 단계는 사용자 이름/암호 부분을 추가했지만, 그것은 다시 허가받지 않은 403와 함께 제공 :

이 나는 ​​이것을 사용 JUST 클라이언트 인증서의 작품을 사용하는 것을 확인했습니다. 클라이언트 인증서 및 사용자 이름/암호를 제공하기 위해 중간에 피 들러를 사용 했으므로 자격 증명과 인증서가 유효하다는 사실을 알고 WCF를 통해 모두 사용하면 제대로 작동하지 않거나 클라이언트 인증서 및 사용자 이름/암호.

모두 같습니다 사용하려고 코드 (WsHttpBinding과와은 BasicHttpBinding으로 시도 - 모두 같은 결과)

:

 var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential); 
     binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; 
     binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; 

     var ea = new EndpointAddress(EndpointUrl); 

     using (var p = new ServiceReference1.PingPortTypeClient(binding, ea)) 
     { 
      try 
      { 
       p.ClientCredentials.ClientCertificate.SetCertificate(
         System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser, 
         System.Security.Cryptography.X509Certificates.StoreName.My, 
         System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName, 
         CertificateSubject); 

       p.ClientCredentials.UserName.UserName = Username; 
       p.ClientCredentials.UserName.Password = Password; 

       var x = p.pingDatabase(); 
       Console.WriteLine("Status: " + x.status); 
      } 
      catch (Exception ex) 
      { 
       Console.WriteLine(ex.ToString()); 
      } 

      Console.WriteLine(); 

나는 브라우저에서 직접 URL 고토 때 - 나는 오류 얻을 :

HTTP Error 403.7 - Forbidden The page you are attempting to access requires your browser to have a Secure Sockets Layer (SSL) client certificate that the Web server recognizes.

이는 동일한 오류 (403)가 수신되었으므로 위의 두 번째 예에서 인증서가 전송되지 않았 음을 나타냅니다.

누군가가 WCF가 클라이언트 인증서와 사용자 이름/암호를 제공하도록 구성 할 수 있습니까? 나는 웹을 뒤흔들었고 여기에있는 '비슷한 질문'은 전혀 도움이되지 못했다. 그걸로 지금 매우 좌절감을 느끼고 있습니다 - 나는 무엇을 놓치고 있습니까?

+0

내게 web.config를 보여 주실 수 있습니까? – rauts

+0

또한 WCF 서비스를 만들거나 아니면 해당 서비스를 사용하고 있습니까? WCF 서비스를 만드는 경우 동일한 끝점에 클라이언트 인증서와 사용자 이름/암호 인증이 없어야합니다. 각 인증 모드 (관심사 원칙의 분리)로 두 개의 다른 종단점을 만듭니다. – rauts

+0

좋아, 문제는 보이지만 쉽게 해결되지는 않습니다. SSL이 작동 중입니다. 코드를 기반으로 SSL을 사용하여 메시지를 암호화하지만 메시지 수준 암호화를 사용하여 호스트에 전달할 클라이언트 인증 사용자 자격 증명을 보존합니다. 호스트와의 인증에 UserName/ID와 클라이언트 인증서 자격 증명을 함께 사용하고 있습니까? WCF, 암호화 및 클라이언트 자격 증명을 사용하여 잠시 동안 작업 해본 적이 있으며 누구도이 두 가지를 모두 사용하려고 본 적이 없습니다. – Brian

답변

5

사용자 이름 (메시지 수준)과 인증서 (전송 수준)가 모두 필요한 경우 사용자 지정 바인딩을 사용해야합니다. 예 :

 <customBinding> 
      <binding name="NewBinding0"> 
       <textMessageEncoding messageVersion="Default" /> 
       <security authenticationMode="UserNameOverTransport"> 
        <secureConversationBootstrap /> 
       </security> 
       <httpsTransport requireClientCertificate="true" /> 
      </binding> 
     </customBinding> 

WSHttp 또는 BasicHttp를 사용하려는 경우 messageVersion의 값이 다릅니다. 현재 WSHttp 인 "Default"로 설정했습니다. Basic에서는 "Soap11"로 설정했습니다.

+0

고맙습니다, 저에게 95 %가 있고 지금 일하고 있습니다. 놀랍게도이 같은 예제를 찾기가 어려웠습니다! – Rosstified

+0

@RM 100 % 어떻게 만들었는지에 대해 의견을 말할 수 있습니까? 귀하의 질문이 거의 똑같이 내가하려는 일을 거울처럼 ... 바로 코드에 이르기까지. 또한이 바인딩은 WCF 서비스뿐만 아니라 클라이언트에도 적용됩니까? – Bensonius

+0

또한이 바인딩 외에도 코드 또는 다른 WCF web.config 값을 변경해야합니까? – Bensonius

관련 문제