首页 > 解决方案 > Python 3.6 中使用客户端获取服务器证书时的问题

问题描述

我正在尝试使用客户端获取服务器证书。下面是我用 Python 3.6 编写的代码的相关部分:

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((mailhost, int(port)))
ctx = ssl.create_default_context()
ctx.check_hostname = True
ctx.verify_mode = ssl.CERT_REQUIRED
s = ctx.wrap_socket(s, server_hostname=mailhost)
cert_bin = s.getpeercert(True)

运行此代码后,调用“wrap_socket”方法时出现以下错误:

[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:847)

客户端具有 2017 年 11 月 2 日的 OpenSSL 1.1.0g 并运行 Ubuntu 18.04,服务器具有 2017 年 1 月 26 日的 OpenSSL 1.0.2k-fips 并运行 CentOS 7.6。

这个问题是否与不同版本的 OpenSSL 有关?

标签: pythonubuntuopensslcentos

解决方案


推荐阅读