簡體   English   中英

C#WebSocketServer wss://連接失敗

[英]C# WebSocketServer wss:// connection fail

我編寫了一個WebSocket服務器,該服務器當前僅與ws://連接一起使用。
經過http://www.websocket.org/echo.html (在Chrome上)和http://websocket4net.codeplex.com/進行了測試

現在,我還希望支持wss://連接(TLS)。
我已經將其與WebSocket4Net一起使用,但是在使用回聲測試時,
javascript在SslStream.AuthenticateAsServer();之后立即引發異常SslStream.AuthenticateAsServer(); 用C#代碼執行。

它進行TLS協商,但Chrome拒絕該連接。
SslStream讀寫(ServerSide由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)

我使用以下步驟添加證書:

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.

new SslStream(new NetworkStream(clientSocket), true) SslStream創建的new SslStream(new NetworkStream(clientSocket), true)
對於AuthenticateAsServer,我使用的是“ 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 /?encoding = text'的連接失敗:在收到握手響應之前,連接已關閉

AuthenticateAsServer之后的服務器端,屬性IsAuthenticatedIsEncrypted設置為true,但是此后立即收到長度為零的數據,關閉了連接。

我假設我在證書創建和/或安裝過程中出錯,但是我不知道自己做錯了什么。
有任何想法嗎?

經過幾個小時的測試並放棄了,我還是放棄了:
事實證明(或者至少對我而言,它看起來像這樣)僅采用了姓氏來驗證ws-uri。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM