RemoteCertificateValidationCallback 대리자

정의

인증에 사용되는 원격 SSL(Secure Sockets Layer) 인증서를 확인합니다.

public delegate bool RemoteCertificateValidationCallback(System::Object ^ sender, X509Certificate ^ certificate, X509Chain ^ chain, SslPolicyErrors sslPolicyErrors);
public delegate bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors);
type RemoteCertificateValidationCallback = delegate of obj * X509Certificate * X509Chain * SslPolicyErrors -> bool
Public Delegate Function RemoteCertificateValidationCallback(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) As Boolean 

매개 변수

sender
Object

이 유효성 검사에 대한 상태 정보를 포함하는 개체입니다.

certificate
X509Certificate

원격 파티를 인증하는 데 사용되는 인증서입니다.

chain
X509Chain

원격 인증서와 연결된 인증 기관의 체인입니다.

sslPolicyErrors
SslPolicyErrors

원격 인증서와 연결된 하나 이상의 오류입니다.

반환 값

Boolean 지정된 인증서가 인증에 허용되는지 여부를 결정하는 값입니다.

예제

다음 코드 예제에서는 클래스의 인스턴스에 의해 호출 되는 메서드를 구현 합니다 RemoteCertificateValidationCallback . 유효성 검사 오류가 있는 경우 이 메서드는 오류를 표시하고 반환 false하여 인증되지 않은 서버와의 통신을 차단합니다.


// The following method is invoked by the RemoteCertificateValidationDelegate.
public static bool ValidateServerCertificate(
      object sender,
      X509Certificate certificate,
      X509Chain chain,
      SslPolicyErrors sslPolicyErrors)
{
   if (sslPolicyErrors == SslPolicyErrors.None)
        return true;

    Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

    // Do not allow this client to communicate with unauthenticated servers.
    return false;
}

다음 코드 예제에서는 앞의 코드 예제에 정의된 메서드를 사용하여 대리자를 만듭니다.

// Create a TCP/IP client socket.
// machineName is the host running the server application.
TcpClient client = new TcpClient(machineName,5000);
Console.WriteLine("Client connected.");
// Create an SSL stream that will close the client's stream.
SslStream sslStream = new SslStream(
    client.GetStream(),
    false,
    new RemoteCertificateValidationCallback (ValidateServerCertificate),
    null
    );
// The server name must match the name on the server certificate.
try
{
    sslStream.AuthenticateAsClient(serverName);
}
catch (AuthenticationException e)
{
    Console.WriteLine("Exception: {0}", e.Message);
    if (e.InnerException != null)
    {
        Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
    }
    Console.WriteLine ("Authentication failed - closing the connection.");
    client.Close();
    return;
}

설명

대리자의 sslPolicyErrors 인수에는 클라이언트 또는 서버를 인증하는 동안 SSPI에서 반환된 인증서 오류가 포함됩니다. 이 Boolean 대리자가 호출한 메서드에서 반환되는 값은 인증이 성공할 수 있는지 여부를 결정합니다.

이 대리자는 클래스와 SslStream 함께 사용됩니다.

확장명 메서드

Name Description
GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보