程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用 Python SSL 的匿名 DH 连接大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决使用 Python SSL 的匿名 DH 连接?

开发过程中遇到使用 Python SSL 的匿名 DH 连接的问题如何解决?下面主要结合日常开发的经验,给出你关于使用 Python SSL 的匿名 DH 连接的解决方法建议,希望对你解决使用 Python SSL 的匿名 DH 连接有所启发或帮助;

我正在尝试使用匿名 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",in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:1123)

解决方法

我在这里找到了解决方案: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 生成并序列化

大佬总结

以上是大佬教程为你收集整理的使用 Python SSL 的匿名 DH 连接全部内容,希望文章能够帮你解决使用 Python SSL 的匿名 DH 连接所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。