인터넷을 통해 X509 인증서를 사용하도록 WCF를 어떻게 구성하려면?

StackOverflow https://stackoverflow.com/questions/335719

  •  22-07-2019
  •  | 
  •  

문제

인터넷을 통해 풍부한 클라이언트에서 안전한 WCF 웹 서비스에 이르기까지 보안 메시지 수준 인증을 얻으려면 X509 인증서를 사용해야합니다.

특히, 'DEV'인증서 작성, 설치 및 프로덕션을위한 '실제'인증서를 얻는 등 설정, 구성, 코딩 및 배포에 대한 단계별 가이드를 찾고 있습니다.

도움이 되었습니까?

해결책

다음 단계는 시작하기위한 가이드입니다.

1) 첫째, 클라이언트 및 서버 인증서를 생성하려면 루트 권한이 필요합니다. 외부 기관 제공 업체 (예 : Verisign)를 사용하거나 Microsoft 인증서 서버와 같은 것을 사용하여 직접 생성 할 수 있습니다.

개발 루트 권한 인증서를 생성하려면 Visual Studio와 함께 제공되는 "Makecert"도구를 사용할 수 있습니다.

makecert -n "CN=MyRootCA" -r -sv RootCA.pvk RootCA.cer

2) 그런 다음 클라이언트 및 서버 인증서를 요청/생성해야합니다. 두 유형의 인증서는 로컬 머신 인증서로 설치할 수 있으며 동일한 루트 권한을 사용하여 서명해야합니다. Microsoft 인증서 서버의 웹 인터페이스에서 클라이언트 인증서를 요청할 수 있습니다. http://mycertserver/certsrv.

각 컴퓨터에 대한 개발 클라이언트 인증서를 생성하려면 "makecert"를 다시 사용할 수 있습니다. 클라이언트 인증서는 1 단계에서 생성 된 개발 루트 권한 인증서와 함께 서명됩니다.

makecert -pe -n "CN=MyCert" -ss my -sky exchange -sk MyCert 
         -iv MyRootCA.pvk -ic MyRootCA.cer -sr localmachine MyCert.cer

이렇게하면 명령이 실행되는 컴퓨터에 인증서가 로컬 머신 스토어의 개인 인증서 폴더에 설치됩니다.

서버가 클라이언트 인증서를 신뢰하려면 서버의 신뢰할 수있는 루트 인증서 당국 저장소에 개발 루트 당국 인증서를 설치해야합니다 (MMC 인증서 스냅을 사용하여이를 수행하십시오). 고객은 또한 동일한 방식으로 루트 인증서를 설치하여 자신의 인증서를 신뢰해야합니다.

3) 인증서를 사용하여 클라이언트 인증을 요구하도록 WCF 서비스를 구성하십시오 (예 : web.config).

<services>
  <service
    name="TestService"
    behaviorConfiguration="wsHttpCertificateBehavior">
    <endpoint name="TestEndPoint"
      address=""
      binding="wsHttpBinding"
      bindingConfiguration="wsHttpEndpointBinding"
      contract="TestService.IMyContract">
      <identity>
        <dns value=""/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
  </service>
</services>

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding">
      <security mode="Message">
        <message clientCredentialType="Certificate"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <behavior name="wsHttpCertificateBehavior">
    <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
    <serviceCredentials>
      <clientCertificate>
        <authentication 
          certificateValidationMode="PeerOrChainTrust" 
          revocationMode="NoCheck"/>
      </clientCertificate>
      <serverCertificate findValue="CN=MyCert"/>
    </serviceCredentials>
  </behavior>
</behaviors>

4) 이제 발신자를 구성하십시오 (예 : app.config를 통해).

<client>
  <endpoint name="wsHttpBinding"
    address="https://localhost/TestService/TestService.svc"
    binding="wsHttpBinding"
    bindingConfiguration="wsHttpBinding"
    behaviorConfiguration="wsHttpCertificateBehavior"
    contract="TestService.IMyContract">
    <identity>
      <dns value="MyCert"/>
    </identity>
  </endpoint>
</client>

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpBinding">
      <security mode="Message">
        <message clientCredentialType="Certificate"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
 <endpointBehaviors>
  <behavior name="wsHttpCertificateBehavior">
    <clientCredentials>
      <clientCertificate findValue="MyCert" storeLocation="LocalMachine"/>
      <serviceCertificate>
        <authentication 
          certificateValidationMode="PeerOrChainTrust" 
          revocationMode="NoCheck" 
          trustedStoreLocation="LocalMachine"/>
      </serviceCertificate>
    </clientCredentials>
  </behavior>
 </endpointBehaviors>
</behaviors>

다른 팁

Microsoft의 WCF 보안 지침을 읽는 것이 좋습니다

이것은이 시나리오뿐만 아니라 다른 많은 것들을 다룹니다.

http://www.codeplex.com/wcfsecurityguide/

편집 : 지금 https://archive.codeplex.com/?p=wcfsecurityGuide

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top