重複の可能性:
C# 証明書エラーを無視しますか?
SSL 経由でリモート サーバーに接続するコードを書いています。私が現在使用しているコードを以下に示します。「検証手順に従って、リモート証明書が無効です」というメッセージが表示されました。
いくつかの調査の結果、SSL セットアップの証明書検証部分をスキップする必要があることがわかりました。証明書の検証をスキップするには、どのコードを記述すればよいですか?
System.Net.ServicePointManager.ServerCertificateValidationCallback =
(sender, certificate, chain, errors) => true;
TcpClient client = new TcpClient("IPADDDRESSHERE", 80);
Console.WriteLine("Client connected.");
SslStream sslStream = new SslStream(
client.GetStream(),
false,
ValidateServerCertificate,
null
);
try
{
sslStream.AuthenticateAsClient("IPADDDRESSHERE");
}
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;
}