2016-04-14 19 views
1

かなり基本的な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私は同様の問題で発見した以前の質問に基づいて追加しましたが、サイコロはありませんでした。どのようなアイデアが間違っている?

答えて

2

https://www.ssllabs.com/ssltest/

Protocols Supported 
TLS 1.2 Yes 
TLS 1.1 Yes 
TLS 1.0 No 
SSL 3  No 
SSL 2  No 

だから、そのサイトは、TLSバージョン1.1または1.2を使用できますが、TLS 1.0をサポートしていません。

以下を行う必要があります。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 
            | SecurityProtocolType.Tls12; 

これは、.NET 4.5+が必要です。

+0

これで解決しました。なぜ、それがデフォルトでTLSを試行しないのか不思議です.Windows 8でコンパイルするのはなぜでしょうか。 – Dendory

+0

'https:// www.ssllabs.com'というURLでコードを試してみてください。 SSL/TLSセキュアチャネルを作成できませんでした.' *はサポートしていないためうまく失敗します。 'healthstone.ca'のテスト結果を見ると、いくつかの" server closed connection "*メッセージが表示されるので、クライアントネゴシエーションフェーズを完了するのではなく、サポートされているプロトコルを実装していないハンマー接続であるように見えます。 –

+0

実際には、デフォルトのCentOS 7/Apache/LetsEncrypt設定を実行しているサーバーです。私はそれが優雅に失敗しない理由は分かりません。 – Dendory

0

古いWindows 2008サーバーでこの問題が発生しました。サーバー上のInternet ExplorerもURLを開くことができませんでした。 FirefoxがURLを開くことができました。

Windows 2008で、SchannelサービスはTLS 1.0のみをサポートしています.Titch 1.1のヒットTLSエンドポイントでは、TLS 1.1とTLS 1.2が有効でした。

エンドポイントでTLS 1.0を有効にして解決しました。

関連する問題