【问题标题】:Anonymous DH connection with Python SSL使用 Python SSL 的匿名 DH 连接
【发布时间】:2021-03-09 06:28:58
【问题描述】:

我正在尝试使用匿名 Diffie-Hellman (ADH-AES256-GCM-SHA384) 在 python 中包装 http 连接。我确实需要为我的应用程序使用这个特定的密码套件。所以这就是我要开始的内容。

服务器:

import ssl
from http.server import HTTPServer, SimpleHTTPRequestHandler

context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
context.set_ciphers("ADH-AES256-GCM-SHA384")

server = HTTPServer(("localhost", 8080), SimpleHTTPRequestHandler)
server.socket = context.wrap_socket(server.socket)
server.serve_forever()

客户:

import ssl
import http.client

context = ssl.SSLContext(protocol=ssl.PROTOCOL_TLSv1_2)
context.set_ciphers("ADH-AES256-GCM-SHA384")

connection = http.client.HTTPSConnection("localhost", "8080", context=context)
connection.connect()

这是我得到的错误:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    connection.connect()
  File "/usr/lib/python3.8/http/client.py", line 1424, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: NO_CIPHERS_AVAILABLE] no ciphers available (_ssl.c:1123)

如果我在客户端和服务器上都设置密码,为什么没有可用的密码?

编辑: 我已将客户端和服务器上的密码列表更改为“ADH-AES256-GCM-SHA384:@SECLEVEL=0”。现在有一个不同的错误:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
    connection.connect()
  File "/usr/lib/python3.8/http/client.py", line 1424, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1123)

【问题讨论】:

    标签: python ssl https diffie-hellman


    【解决方案1】:

    我在这里找到了解决方案:Python SSL Server - Client Hello w/ only Cipher Suite: TLS_DH_anon_WITH_AES_256_CBC_SHA (0x003a) Fails

    我的新服务器代码如下所示:

    sslContext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
    sslContext.set_ciphers("ADH-AES256-GCM-SHA384:@SECLEVEL=0")
    sslContext.load_dh_params("params.pem")
    server = socketserver.TCPServer(("localhost", 8080), SimpleHTTPRequestHandler)
    server.socket = sslContext.wrap_socket(server.socket, server_side=True)
    server.serve_forever()
    

    params.pem 包含 diffie hellman 参数,密钥长度为 3072 位,由 cryptography module 生成和序列化

    【讨论】:

      猜你喜欢
      • 2012-09-10
      • 1970-01-01
      • 2011-08-07
      • 2010-10-24
      • 2016-06-17
      • 2020-09-09
      • 1970-01-01
      • 2011-03-11
      • 2018-10-05
      相关资源
      最近更新 更多