如何解决握手故障和套接字通信中没有共享密码错误

时间:2019-05-08 09:22:35

标签: python sockets ssl encryption handshake

我想编写一个程序,其中2个系统通过SSL包装的套接字通信相互通信。

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

这是服务器代码-

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)

如果有人知道如何解决,请提供帮助。

我希望两台计算机之间的加密套接字连接能够传输一些文本

0 个答案:

没有答案