在ssl握手期间,我收到“ [SSL:SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3警报握手失败(_ssl.c:579)”。我在这里想念什么? Python版本是:
Python 2.7.5
Python正在使用:
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.2k-fips 2017年1月26日'
这是我的代码
sock = socket.socket()
sock.settimeout(2)
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.verify_mode = ssl.CERT_REQUIRED
context.check_hostname = True
context.load_default_certs()
s = ssl.wrap_socket(sock,ssl_version=ssl.PROTOCOL_TLSv1_2, cert_reqs=ssl.CERT_REQUIRED, ca_certs="/etc/ssl/certs/ca-bundle.crt" )
hostStr = ("{host}:{port}").format(host=host,port=port)
try:
s.connect((host, port))
s.do_handshake()
checks.append({"host":hostStr,"canConnect":"true","canNegotiateSSL":"true"})
except ssl.SSLError as e:
error = ("Connectivity passed with SSL error: {error}").format(error=e)
if "CERTIFICATE_VERIFY_FAILED" not in error:
checks.append({"host":hostStr,"canConnect":"true","canNegotiateSSL":"false","message":error})
else:
checks.append({"host":hostStr,"canConnect":"false","canNegotiateSSL":"false","message":error})
except Exception as e:
error = ("Failed: {error}").format(error=e)
checks.append({"host":hostStr,"canConnect":"false","canNegotiateSSL":"false","message":error})
logging.debug(error)
finally:
s.close()