かなり基本的なSSL接続をしようとしています。なぜ動作しないのかについては、 HTTP経由では正常に接続されますが、HTTPSでは正常に接続されません。 これは、一連のサイトでのみ発生します。たとえば、google.comでは問題なく動作しますが、この特定のサーバーではLetsEncrypt証明書が実行されています。それが原因かもしれませんか?C#と.NET 4.5を使用してSSLサーバーに接続する際にエラーが発生しました
コードssltest.csのために:
using System;
using System.Net;
using System.Net.Sockets;
namespace SSLTest
{
public class Program
{
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
WebClient wc = new WebClient();
string result = wc.DownloadString("https://healthstone.ca/");
Console.WriteLine(result);
}
}
}
コンパイル:
%SYSTEMROOT%\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:ssltest.exe ssltest.cs
ラン:私はHTTPにサイトを変更した場合
Unhandled Exception: System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.ConnectStream.WriteHeaders(Boolean async)
--- End of inner exception stack trace ---
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at SSLTest.Program.Main(String[] args)
それは正常に動作します。サイトはブラウザで正常に読み込まれます。 2 ServicePointManager
私は同様の問題で発見した以前の質問に基づいて追加しましたが、サイコロはありませんでした。どのようなアイデアが間違っている?
これで解決しました。なぜ、それがデフォルトでTLSを試行しないのか不思議です.Windows 8でコンパイルするのはなぜでしょうか。 – Dendory
'https:// www.ssllabs.com'というURLでコードを試してみてください。 SSL/TLSセキュアチャネルを作成できませんでした.' *はサポートしていないためうまく失敗します。 'healthstone.ca'のテスト結果を見ると、いくつかの" server closed connection "*メッセージが表示されるので、クライアントネゴシエーションフェーズを完了するのではなく、サポートされているプロトコルを実装していないハンマー接続であるように見えます。 –
実際には、デフォルトのCentOS 7/Apache/LetsEncrypt設定を実行しているサーバーです。私はそれが優雅に失敗しない理由は分かりません。 – Dendory