如何解决socket通信中的握手失败和无共享密码错误

2024-04-24 07:39:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我想写一个程序,其中两个系统通过SSL封装的socket通信相互通信。你知道吗

但是客户端系统和服务器/主机系统给了我握手失败错误和共享密码。你知道吗

这是服务器代码-

from socket import *
import ssl 
import time
context = ssl.create_default_context()     
while(1):    
    HOST = '192.168.1.172'
    PORT = 8000
    sock = socket(AF_INET,SOCK_STREAM)
    sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

    sock.bind((HOST,PORT))
    print ("here0")
    sock.listen(5)
    print ("here1")
    sock1 = ssl.wrap_socket(sock, ssl_version=ssl.PROTOCOL_TLSv1, 
            ciphers="ADH-AES256-SHA")
    conn,addr = sock1.accept()
    print ("here2")
    i=0
    while(i<10):
        print ("here---")
        conn.send(b'$$$')
        time.sleep(.1)
    sock.close()

错误-

line 18, in <module>
    conn,addr = sock1.accept()
  File "/usr/lib/python2.7/ssl.py", line 882, in accept
    server_side=True)
  File "/usr/lib/python2.7/ssl.py", line 353, in wrap_socket
    _context=self)
  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()
SSLError: [SSL: NO_SHARED_CIPHER] no shared cipher (_ssl.c:590)

客户机代码

from socket import *

import ssl

while(1):        

    HOST = '192.168.1.172'
    PORT = 8000
    socket = socket(AF_INET,SOCK_STREAM)
    socket.connect((HOST,PORT))

    print ("here0")
    #ssl_sock = ssl.wrap_socket(socket)
    #ssl_sock.connect((HOST,PORT))
    socket1 = ssl.wrap_socket(socket, ssl_version=ssl.PROTOCOL_TLSv1, ciphers="ADH-AES256-SHA")

    i=0
    while(i<10):
        print ("here---")
        recv = socket1.recv(20)
        print ("here1")
        print recv
        i = i +1

    socket.close()

----------------------你知道吗

错误-

line 14, in <module>
    socket1 = ssl.wrap_socket(socket, ssl_version=ssl.PROTOCOL_TLSv1)#, ciphers="ADH-AES256-SHA")
  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()
SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)

如果有人知道怎么解决,请帮忙。你知道吗

我需要两台计算机之间的加密套接字连接来传输一些文本


Tags: inpyimporthostssllibusrline