다음을 통해 공유


방법: SSL 인증서를 사용하여 포트 구성

전송 보안을 사용하는 WSHttpBinding 클래스를 사용하여 자체 호스팅 WCF(Windows Communication Foundation) 서비스를 만드는 경우 X.509 인증서를 사용하여 포트도 구성해야 합니다. 자체 호스팅 서비스를 만들지 않는 경우 IIS(인터넷 정보 서비스)에서 서비스를 호스트할 수 있습니다. 자세한 내용은 http 전송 보안 참조하세요.

포트를 구성하기 위해 사용하는 도구는 컴퓨터에서 실행되는 운영 체제에 따라 달라집니다.

Windows Server 2003을 실행하는 경우 HttpCfg.exe 도구를 사용합니다. Windows Server 2003에서 이 도구가 설치됩니다. 자세한 내용은 Httpcfg 개요참조하세요. Windows 지원 도구 설명서 Httpcfg.exe 도구의 구문을 설명합니다.

Windows Vista를 실행하는 경우 이미 설치된 Netsh.exe 도구를 사용합니다.

비고

컴퓨터에 저장된 인증서를 수정하려면 관리 권한이 필요합니다.

포트 구성 방법 결정

  1. 다음 예제와 같이 Windows Server 2003 또는 Windows XP에서 HttpCfg.exe 도구를 사용하여 쿼리ssl 스위치를 사용하여 현재 포트 구성을 봅니다.

    httpcfg query ssl  
    
  2. Windows Vista에서 Netsh.exe 도구를 사용하여 다음 예제와 같이 현재 포트 구성을 봅니다.

    netsh http show sslcert  
    

인증서의 지문 가져오기

  1. 인증서 MMC 스냅인을 사용하여 클라이언트 인증의 목적이 있는 X.509 인증서를 찾습니다. 자세한 내용은 방법: MMC 스냅인을 사용하여 인증서를 보는 방법을 참조하십시오.

  2. 인증서의 지문에 액세스합니다. 자세한 내용은 방법: 인증서의 지문 검색을 참조하세요.

  3. 인증서의 지문을 메모장과 같은 텍스트 편집기에 복사합니다.

  4. 16진수 문자 사이의 모든 공백을 제거합니다. 이를 수행하는 한 가지 방법은 텍스트 편집기 찾기 및 바꾸기 기능을 사용하고 각 공간을 null 문자로 바꾸는 것입니다.

포트 번호에 SSL 인증서 바인딩

  1. Windows Server 2003 또는 Windows XP에서 SSL(Secure Sockets Layer) 저장소의 "설정" 모드에서 HttpCfg.exe 도구를 사용하여 인증서를 포트 번호에 바인딩합니다. 도구는 다음 예제와 같이 지문을 사용하여 인증서를 식별합니다.

    httpcfg set ssl -i 0.0.0.0:8012 -h 0000000000003ed9cd0c315bbb6dc1c08da5e6  
    
    • -i 스위치에는 IP:port 구문이 있으며 컴퓨터의 포트 8012로 인증서를 설정하도록 도구에 지시합니다. 필요에 따라 숫자 앞에 오는 4개의 0을 컴퓨터의 실제 IP 주소로 바꿀 수도 있습니다.

    • -h 스위치는 인증서의 지문을 지정합니다.

  2. Windows Vista에서 다음 예제와 같이 Netsh.exe 도구를 사용합니다.

    netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00001111-aaaa-2222-bbbb-3333cccc4444}
    
    • certhash 매개 변수는 인증서의 지문을 지정합니다.

    • ipport 매개 변수는 설명된 Httpcfg.exe 도구의 -i 스위치와 마찬가지로 IP 주소와 포트 및 함수를 지정합니다.

    • appid 매개 변수는 소유 애플리케이션을 식별하는 데 사용할 수 있는 GUID입니다.

포트 번호에 SSL 인증서 바인딩 및 클라이언트 인증서 지원

  1. Windows Server 2003 또는 Windows XP에서 전송 계층에서 X.509 인증서로 인증하는 클라이언트를 지원하려면 다음 예제와 같이 이전 절차에 따라 HttpCfg.exe추가 명령줄 매개 변수를 전달합니다.

    httpcfg set ssl -i 0.0.0.0:8012 -h 0000000000003ed9cd0c315bbb6dc1c08da5e6 -f 2  
    

    -f 스위치에는 n이 1에서 7 사이의 숫자인 n 구문이 있습니다. 앞의 예제와 같이 값 2는 전송 계층에서 클라이언트 인증서를 사용하도록 설정합니다. 값 3은 클라이언트 인증서를 사용하도록 설정하고 해당 인증서를 Windows 계정에 매핑합니다. 다른 값의 동작은 HttpCfg.exe 도움말을 참조하세요.

  2. Windows Vista에서 전송 계층에서 X.509 인증서로 인증하는 클라이언트를 지원하려면 다음 예제와 같이 이전 절차를 수행하지만 추가 매개 변수를 사용합니다.

    netsh http add sslcert ipport=0.0.0.0:8000 certhash=0000000000003ed9cd0c315bbb6dc1c08da5e6 appid={00001111-aaaa-2222-bbbb-3333cccc4444} clientcertnegotiation=enable  
    

포트 번호에서 SSL 인증서 삭제

  1. HttpCfg.exe 또는 Netsh.exe 도구를 사용하여 컴퓨터의 모든 바인딩의 포트와 지문을 볼 수 있습니다. 디스크에 정보를 인쇄하려면 다음 예제와 같이 리디렉션 문자 ">"를 사용합니다.

    httpcfg query ssl>myMachinePorts.txt  
    
  2. Windows Server 2003 또는 Windows XP에서 HttpCfg.exe 도구를 사용하여 삭제,ssl 키워드를 사용합니다. -i 스위치를 사용하여 IP:port 번호 및 -h 스위치를 사용하여 지문을 지정합니다.

    httpcfg delete ssl -i 0.0.0.0:8005 -h 0000000000003ed9cd0c315bbb6dc1c08da5e6  
    
  3. Windows Vista에서 다음 예제와 같이 Netsh.exe 도구를 사용합니다.

    Netsh http delete sslcert ipport=0.0.0.0:8005  
    

예시

다음 코드는 보안을 전송하도록 설정된 WSHttpBinding 클래스를 사용하여 자체 호스팅 서비스를 만드는 방법을 보여줍니다. 애플리케이션을 만들 때 주소에 포트 번호를 지정합니다.

// This string uses a function to prepend the computer name at run time.
string addressHttp = String.Format(
    "http://{0}:8080/Calculator",
    System.Net.Dns.GetHostEntry("").HostName);

WSHttpBinding b = new WSHttpBinding();
b.Security.Mode = SecurityMode.Transport;
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

// You must create an array of URI objects to have a base address.
Uri a = new Uri(addressHttp);
Uri[] baseAddresses = new Uri[] { a };

// Create the ServiceHost. The service type (Calculator) is not
// shown here.
ServiceHost sh = new ServiceHost(typeof(Calculator), baseAddresses);

// Add an endpoint to the service. Insert the thumbprint of an X.509
// certificate found on your computer.
Type c = typeof(ICalculator);
sh.AddServiceEndpoint(c, b, "MyCalculator");
sh.Credentials.ServiceCertificate.SetCertificate(
    StoreLocation.LocalMachine,
    StoreName.My,
    X509FindType.FindBySubjectName,
    "contoso.com");

// This next line is optional. It specifies that the client's certificate
// does not have to be issued by a trusted authority, but can be issued
// by a peer if it is in the Trusted People store. Do not use this setting
// for production code. The default is PeerTrust, which specifies that
// the certificate must originate from a trusted certificate authority.

// sh.Credentials.ClientCertificate.Authentication.CertificateValidationMode =
// X509CertificateValidationMode.PeerOrChainTrust;
try
{
    sh.Open();

    string address = sh.Description.Endpoints[0].ListenUri.AbsoluteUri;
    Console.WriteLine($"Listening @ {address}");
    Console.WriteLine("Press enter to close the service");
    Console.ReadLine();
    sh.Close();
}
catch (CommunicationException ce)
{
    Console.WriteLine($"A communication error occurred: {ce.Message}");
    Console.WriteLine();
}
catch (System.Exception exc)
{
    Console.WriteLine($"An unforeseen error occurred: {exc.Message}");
    Console.ReadLine();
}
' This string uses a function to prepend the computer name at run time.
Dim addressHttp As String = String.Format("http://{0}:8080/Calculator", _
System.Net.Dns.GetHostEntry("").HostName)

Dim b As New WSHttpBinding()
b.Security.Mode = SecurityMode.Transport
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate

' You must create an array of URI objects to have a base address.
Dim a As New Uri(addressHttp)
Dim baseAddresses() As Uri = {a}

' Create the ServiceHost. The service type (Calculator) is not
' shown here.
Dim sh As New ServiceHost(GetType(Calculator), baseAddresses)

' Add an endpoint to the service. Insert the thumbprint of an X.509 
' certificate found on your computer. 
Dim c As Type = GetType(ICalculator)
sh.AddServiceEndpoint(c, b, "MyCalculator")
sh.Credentials.ServiceCertificate.SetCertificate( _
                StoreLocation.LocalMachine, _
                StoreName.My, _
                X509FindType.FindBySubjectName, _
                "contoso.com")

' This next line is optional. It specifies that the client's certificate
' does not have to be issued by a trusted authority, but can be issued
' by a peer if it is in the Trusted People store. Do not use this setting
' for production code. The default is PeerTrust, which specifies that 
' the certificate must originate from a trusted certificate authority.
' sh.Credentials.ClientCertificate.Authentication.CertificateValidationMode =
' X509CertificateValidationMode.PeerOrChainTrust
Try
    sh.Open()

    Dim address As String = sh.Description.Endpoints(0).ListenUri.AbsoluteUri
    Console.WriteLine("Listening @ {0}", address)
    Console.WriteLine("Press enter to close the service")
    Console.ReadLine()
    sh.Close()
Catch ce As CommunicationException
    Console.WriteLine("A communication error occurred: {0}", ce.Message)
    Console.WriteLine()
Catch exc As System.Exception
    Console.WriteLine("An unforeseen error occurred: {0}", exc.Message)
    Console.ReadLine()
End Try

참고하십시오

  • HTTP 전송 보안