Python错误SSL:ssl.SSLError:[SSL:SSLV3_ALERT_HANDSHAKE_FAILURE]SSLV3警报握手失败(_SSL.c:726)

2024-10-01 05:02:56 发布

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

我正在尝试使用python2.7.15从(IP,destport443)获取SNI,我使用的是OpenSSL的最新版本和ssl模块。在

这是我的代码:

import OpenSSL as OSsl #This two modules are imported for the only purpose of getting the SNI using function defined by us down here getSNI
import ssl



ip = "52.85.25.17"
dport = "443"


#With this function we get the Server Name Identification for the trasmissions with Secure Socket Layer identified by the port 443. We only care about the destinationIP and the destinationPort

def getSNI(ip, dport):
    if dport != "443":
        commonName = "Not SSL"
        print commonName
    else:   
        server_certificate = ssl.get_server_certificate((ip, dport))

        x509 = OSsl.crypto.load_certificate(OSsl.crypto.FILETYPE_PEM, server_certificate) #x509 is referred to the standard used for PKI (Public Key Infrastructure) used in this case for ciphering our informations about certificate

#FILETYPE_PEM serializes data to a Base64-Encoded

    #getting the informations about Certificate

        certInfo = x509.get_subject()
        commonName = certInfo.commonName
        print (commonName) 
    return commonName


getSNI(ip,dport)

这是可行的,但是对于指定的地址(在我发布的代码片段中),我得到以下错误:

^{pr2}$

我已经升级了所有的模块和包,我读了很多关于这个主题的问题,我不知道如何解决这个问题

编辑1:执行whois时,我发现这个IpAddress与Amazon相连,那么Amazon和SNI有什么特别的问题吗?在


Tags: theipsslforgetservercertificateabout
1条回答
网友
1楼 · 发布于 2024-10-01 05:02:56

SNI的重点是可能存在多个域,这些域被解析为具体的IP地址。所以,您提供的IP(52.85.25.17)就是这样的地址之一。服务器无法决定您请求的是哪个域的证书,因此它以错误的方式终止连接。在

附录1。捕捉SSLError异常

您可以通过以下方式捕获ssl.SSLError

try:
    server_certificate = ssl.get_server_certificate((ip, dport))
    ...
except ssl.SSLError as e:
    common_name = "Handshake Failed"

相关问题 更多 >