2014-02-24 116 views
1

我寫了一個WebSocket服務器,它目前只適用於ws://連接。
使用http://www.websocket.org/echo.html(在Chrome上)和http://websocket4net.codeplex.com/進行測試。C#WebSocketServer wss://連接失敗

現在我想也支持wss://連接(TLS)。
我已經將它與WebSocket4Net一起使用,但是當使用回顯測試時,
在C#代碼中執行SslStream.AuthenticateAsServer();後,javascript立即引發異常。

它進行TLS協商,但Chrome拒絕連接。
SslStream讀,寫操作(服務器端通過AuthenticateAsServer完成):

Read(5, 0, 5) == 5 
Read(517, 5, 512) == 512 
Write(887, 0, 887) 
Read(887, 0, 5) == 5 
Read(887, 5, 262) == 262 
Read(5, 0, 5) == 5 
Read(6, 5, 1) == 1 
Read(5, 0, 5) == 5 
Read(53, 5, 48) == 48 
Write(59, 0, 59) 

我用下面的步驟來添加證書:由new SslStream(new NetworkStream(clientSocket), true)
創造了AuthenticateAsServer

makecert -sv CA.pvk -r -n "CN=Dev" -a sha256 -len 2048 -sky signature -cy authority CA.cer 
makecert -ic CA.cer -iv CA.pvk -n "CN=localhost, CN=127.0.0.1" -a sha256 -len 2048 -sky exchange -sv CA_localhost.pvk -pe CA_localhost.cer 
cert2spc CA_localhost.cer CA_localhost.spc 
pvkimprt -pfx CA_localhost.spc CA_localhost.pvk //Select export 
//Import CA.cer into your Computer store's Trusted Root Certification Authorities (certmgr.msc) 
//Import the private key that the server is going to use into the server machine's Personal store. 
//This is achieved by importing the .pfx file that you generated earlier. 

SslStream我使用「CA_localhost.cer」證書。

確保後的證書顯示在certmgr.msc我的Chrome中打開 http://www.websocket.org/echo.html和使用wss://localhost:12345的地址(其中我的服務器正在監聽),並勾選複選框。
點擊Connect後我只得到:

ERROR: undefined 
DISCONNECTED 

JavaScript控制檯顯示:
WebSocket連接到 'WSS://127.0.0.1:12345 /編碼=文本' 失敗:連接關閉接收之前握手響應

在服務器端後AuthenticateAsServer屬性IsAuthenticatedIsEncrypted被設置爲真,但立即之後我接收零長度的數據,關閉連接。

我假設我在證書創建和/或安裝期間犯了一個錯誤,但我不知道我可能做錯了什麼。
任何想法?

回答

0

測試和放棄的幾個小時後,我給它另一個去:
原來(或至少對我來說,它看起來像吧)只有最後一個共同的名字取爲驗證對WS-URI 。

使用wss://127.0.0.1:12345工作。