我讀到客戶端身份驗證是可選的,因此我嘗試連接到我的SSL服務器而不在客戶端進行身份驗證。當我這樣做時,我在服務器上收到以下錯誤:, in accept_connection ssl_version=ssl.PROTOCOL_SSLv23 File "/usr/lib/python2.7/ssl.py", line 933, in wrap_socket ciphers=ciphers) File "/usr/lib/python2.7/ssl.py", line 601, in __init__ self.do_handshake() File "/usr/lib/python2.7/ssl.py", line 830, in do_handshake self._sslobj.do_handshake()SSLEOFError: EOF occurred in violation of protocol (_ssl.c:590)這是工作中的服務器和客戶端代碼,當我在客戶端上進行身份驗證時,一切正常,但是當我注釋掉該行時,就會顯示錯誤。服務器(python):def accept_connection(self, sock): client, (addr, port) = sock.accept() sslclient = ssl.wrap_socket( client, server_side=True, certfile=self.ssl_cert_file, keyfile=self.ssl_key_file, ssl_version=ssl.PROTOCOL_SSLv23 )客戶端(C#):public bool Connect() { try { client = new TcpClient(this.ServerAddress, this.ServerPort); sslStream = new SslStream( client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateCert), null ); try { sslStream.AuthenticateAsClient(this.ServerAddress); } catch (AuthenticationException e) { sslStream = null; client.Close(); client = null; return false; } } catch (Exception e) { return false; } return true; }以上是沒有錯誤的工作代碼。當我在客戶端上注釋掉以下代碼時://sslStream.AuthenticateAsClient(this.ServerAddress);上面提到的python錯誤出現了,并且客戶端連接不會引發任何異常,并且會繼續運行直到第一次讀取,然后失敗,并顯示以下信息:This operation is only allowed using a successfully authenticated context.如果我不打電話AuthenticateAsClient怎么辦?這就是我生成certfile和keyfile的方式openssl req -x509 -newkey rsa:1024 -keyout my.key -out my.crt -days 365 -nodes -subj "/C=US/ST=VA/L=Junk/O=None/OU=Junk/CN=example.local"Python是版本2。也許我只是被誤導了對的調用AuthenticateAsClient是可選的?
1 回答

天涯盡頭無女友
TA貢獻1831條經驗 獲得超9個贊
SSL客戶端證書身份驗證確實是可選的。客戶端將其證書發送到服務器,然后服務器驗證該證書是否有效,服務器期望的時間以及使用該證書對客戶端進行身份驗證的時間。
但是,這不是由
sslStream.AuthenticateAsClient(this.ServerAddress);
如文檔所述,此方法是
客戶端調用以認證服務器,并可選地通過客戶端-服務器連接對客戶端進行身份驗證。
在ssl握手過程中,必須對服務器進行身份驗證(驗證其證書是否有效,是否已為預期的域頒發,是否由受信任的權威機構頒發)。例如,使用此鏈接的描述,我們看到第3步是:
SSL或TLS客戶端驗證服務器的數字證書
服務器等待客戶端執行此步驟的結果。因此,如果您通過注釋調用來跳過此步驟,則您AuthenticateAsClient
的python服務器正確地抱怨協議違規。
要使用客戶端身份驗證,您將使用另一個重載:
X509CertificateCollection clientCerts = GetClientCerts(); sslStream.AuthenticateAsClient(this.ServerAddress, clientCerts, true);
由于您未執行此操作-您未在執行(可選)客戶端身份驗證。
- 1 回答
- 0 關注
- 403 瀏覽
添加回答
舉報
0/150
提交
取消