簡體   English   中英

如何明確地將Python的ldap3模塊告知TLS版本1.2?

[英]How to tell Python's ldap3 module to TLS version 1.2 explicitly?

我正在嘗試使用ldap3 Python模塊對ldap進行身份驗證,但是我想驗證我的連接是否使用TLS 1.2版。

相關代碼段:

tls = Tls(validate=ssl.CERT_REQUIRED, version=ssl.PROTOCOL_TLSv1_2)
server = Server(server_uri, use_ssl=True, tls=tls, get_info=ALL)
conn = Connection(server, user="domain\\myusername", password="password", authentication=NTLM, auto_referrals=False)
conn.bind()

我的連接對象的輸出:

Connection(server=Server(
host='domain.host.com', 
port=636, 
use_ssl=True, 
allowed_referral_hosts=[('*', True)], 
tls=Tls(validate=<VerifyMode.CERT_REQUIRED: 2>, 
version=<_SSLMethod.PROTOCOL_TLSv1_2: 5>), 
get_info='ALL', mode='IP_V6_PREFERRED'), 
version=3, 
authentication='NTLM', 
client_strategy='SYNC', ...truncated...)

我不確定版本屬性中的“ 5”是什么意思,但是最終我試圖驗證是否要使用TLS 1.2版進行身份驗證。

常量來自ssl stdlib模塊。 您可以使用該模塊為不同的SSL版本打印等值的常量,如下所示:

$ python -c "import ssl; print(ssl.PROTOCOL_SSLv3)"
1
$ python -c "import ssl; print(ssl.PROTOCOL_SSLv23)"
2
$ python -c "import ssl; print(ssl.PROTOCOL_TLSv1)"
3
$ python -c "import ssl; print(ssl.PROTOCOL_TLSv1_1)"     
4
$ python -c "import ssl; print(ssl.PROTOCOL_TLSv1_2)"
5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM