@@ -129,12 +129,13 @@ def connection(
129
129
l .set_option (ldap .OPT_X_TLS_REQUIRE_CERT , ldap .OPT_X_TLS_NEVER ) # type: ignore
130
130
# Disable TLS1 and TLS1.1
131
131
# 0x304 = TLS1.3, 0x303 = TLS1.2, 0x302 = TLS1.1, 0x301 = TLS1.0, but use ldap module constants
132
- tls_version = {
133
- '1.2' : ldap .OPT_X_TLS_PROTOCOL_TLS1_2 , # type: ignore
134
- '1.3' : getattr (ldap , 'OPT_X_TLS_PROTOCOL_TLS1_3' , ldap .OPT_X_TLS_PROTOCOL_TLS1_2 ), # type: ignore
135
- }.get (getattr (settings , 'SECURE_MIN_TLS_VERSION' , '1.2' ), ldap .OPT_X_TLS_PROTOCOL_TLS1_2 ) # type: ignore
136
-
137
- l .set_option (ldap .OPT_X_TLS_PROTOCOL_MIN , tls_version ) # type: ignore
132
+ if hasattr (ldap , 'OPT_X_TLS_PROTOCOL_TLS1_3' ):
133
+ tls_version = {
134
+ '1.2' : ldap .OPT_X_TLS_PROTOCOL_TLS1_2 , # type: ignore
135
+ '1.3' : getattr (ldap , 'OPT_X_TLS_PROTOCOL_TLS1_3' , ldap .OPT_X_TLS_PROTOCOL_TLS1_2 ), # type: ignore
136
+ }.get (getattr (settings , 'SECURE_MIN_TLS_VERSION' , '1.2' ), ldap .OPT_X_TLS_PROTOCOL_TLS1_2 ) # type: ignore
137
+
138
+ l .set_option (ldap .OPT_X_TLS_PROTOCOL_MIN , tls_version ) # type: ignore
138
139
# Cipher suites are from GNU TLS, not OpenSSL
139
140
# https://gnutls.org/manual/html_node/Priority-Strings.html for more info
140
141
# i.e.:
@@ -143,8 +144,14 @@ def connection(
143
144
# * PFS
144
145
# * SECURE256
145
146
#
146
- l .set_option (ldap .OPT_X_TLS_CIPHER_SUITE , cipher_suite ) # type: ignore
147
- l .set_option (ldap .OPT_X_TLS_NEWCTX , 0 ) # type: ignore
147
+ # Note: Your distro could have compiled libldap with OpenSSL, so this will not work
148
+ # You can simply use OpenSSL cipher suites, but you will need to test them
149
+ try :
150
+ l .set_option (ldap .OPT_X_TLS_CIPHER_SUITE , cipher_suite ) # type: ignore
151
+ l .set_option (ldap .OPT_X_TLS_NEWCTX , 0 ) # type: ignore
152
+ except Exception :
153
+ logger .info ('Cipher suite %s not supported by libldap' , cipher_suite )
154
+
148
155
149
156
l .simple_bind_s (who = username , cred = password )
150
157
except ldap .SERVER_DOWN as e : # type: ignore
0 commit comments