Skip to content

Commit 6b77946

Browse files
committed
Improve TLS documentation
See: #55 Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 63058a0 commit 6b77946

File tree

5 files changed

+137
-5
lines changed

5 files changed

+137
-5
lines changed

Doc/reference/ldap.rst

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ This module defines the following functions:
8383
This function sets the value of the global option specified by *option* to
8484
*invalue*.
8585

86+
.. note::
87+
88+
Most global settings do not affect existing :py:class:`LDAPObject`
89+
connections. Applications should call :py:func:`set_option()` before
90+
they establish connections with :py:func:`initialize`.
91+
8692
.. versionchanged:: 3.1
8793

8894
The deprecated functions ``ldap.init()`` and ``ldap.open()`` were removed.
@@ -221,34 +227,156 @@ SASL options
221227
TLS options
222228
:::::::::::
223229

230+
.. warning::
231+
232+
libldap does not materialize all TLS settings immediately. You must use
233+
:py:const:`OPT_X_TLS_NEWCTX` with value ``0`` to instruct libldap to
234+
apply pending TLS settings and create a new internal TLS context::
235+
236+
conn = ldap.initialize("ldap://ldap.example")
237+
conn.set_option(ldap.OPT_X_TLS_CACERTFILE, '/path/to/ca.pem')
238+
conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
239+
conn.start_tls_s()
240+
conn.simple_bind_s(dn, password)
241+
224242
.. py:data:: OPT_X_TLS
225243
244+
.. deprecated:: 3.0
245+
The option is deprecated in OpenLDAP and should no longer be used. It
246+
will be removed in the future.
247+
248+
.. py:data:: OPT_X_TLS_ALL
249+
250+
Value for :py:const:`OPT_X_TLS_CRLCHECK`
251+
226252
.. py:data:: OPT_X_TLS_ALLOW
227253
254+
Value for :py:const:`OPT_X_TLS_REQUIRE_CERT`
255+
228256
.. py:data:: OPT_X_TLS_CACERTDIR
229257
258+
get/set path to directory with CA certs
259+
230260
.. py:data:: OPT_X_TLS_CACERTFILE
231261
262+
get/set path to PEM file with CA certs
263+
232264
.. py:data:: OPT_X_TLS_CERTFILE
233265
266+
get/set path to file with PEM encoded cert for client cert authentication,
267+
requires :py:const:`OPT_X_TLS_KEYFILE`.
268+
269+
.. py:data:: OPT_X_TLS_CIPHER
270+
271+
get cipher suite name from TLS session
272+
234273
.. py:data:: OPT_X_TLS_CIPHER_SUITE
235274
275+
get/set allowed cipher suites
276+
277+
.. py:data:: OPT_X_TLS_CRLCHECK
278+
279+
get/set CRL check mode. CRL validation needs :py:const:`OPT_X_TLS_CRLFILE`
280+
281+
:py:const:`OPT_X_TLS_NONE`
282+
Don't perform CRL checks
283+
284+
:py:const:`OPT_X_TLS_PEER`
285+
Perform CRL check for peer's end entity cert.
286+
287+
:py:const:`OPT_X_TLS_ALL`
288+
Perform CRL checks for the whole cert chain
289+
290+
.. py:data:: OPT_X_TLS_CRLFILE
291+
292+
get/set path to CRL file
293+
236294
.. py:data:: OPT_X_TLS_CTX
237295
296+
get address of internal memory address of TLS context (**DO NOT USE**)
297+
238298
.. py:data:: OPT_X_TLS_DEMAND
239299
300+
Value for :py:const:`OPT_X_TLS_REQUIRE_CERT`
301+
240302
.. py:data:: OPT_X_TLS_HARD
241303
304+
Value for :py:const:`OPT_X_TLS_REQUIRE_CERT`
305+
242306
.. py:data:: OPT_X_TLS_KEYFILE
243307
308+
get/set path to file with PEM encoded key for client cert authentication,
309+
requires :py:const:`OPT_X_TLS_CERTFILE`.
310+
244311
.. py:data:: OPT_X_TLS_NEVER
245312
313+
Value for :py:const:`OPT_X_TLS_REQUIRE_CERT`
314+
315+
.. py:data:: OPT_X_TLS_NEWCTX
316+
317+
set and apply TLS settings to internal TLS context. Value ``0`` creates
318+
a new client-side context.
319+
320+
.. py:data:: OPT_X_TLS_NONE
321+
322+
Value for :py:const:`OPT_X_TLS_CRLCHECK`
323+
324+
.. py:data:: OPT_X_TLS_PACKAGE
325+
326+
Get TLS implementation, known values are
327+
328+
* ``GnuTLS``
329+
* ``MozNSS`` (Mozilla NSS)
330+
* ``OpenSSL``
331+
332+
.. py:data:: OPT_X_TLS_PEER
333+
334+
Value for :py:const:`OPT_X_TLS_CRLCHECK`
335+
336+
.. py:data:: OPT_X_TLS_PEERCERT
337+
338+
Get peer's certificate as BER/DER data structure (not supported)
339+
340+
.. py:data:: OPT_X_TLS_PROTOCOL_MIN
341+
342+
get/set minimum protocol version (wire protocol version as int)
343+
344+
* ``0x300`` for SSL 3.0
345+
* ``0x301`` for TLS 1.0
346+
* ``0x302`` for TLS 1.1
347+
* ``0x303`` for TLS 1.2
348+
* ``0x304`` for TLS 1.3
349+
246350
.. py:data:: OPT_X_TLS_RANDOM_FILE
247351
352+
get/set path to /dev/urandom (**DO NOT USE**)
353+
248354
.. py:data:: OPT_X_TLS_REQUIRE_CERT
249355
356+
get/set validation strategy for server cert.
357+
358+
:py:const:`OPT_X_TLS_NEVER`
359+
Don't check server cert and host name
360+
361+
:py:const:`OPT_X_TLS_ALLOW`
362+
Ignore cert validation errors and don't check host name
363+
364+
:py:const:`OPT_X_TLS_DEMAND`
365+
Validate peer cert chain and host name
366+
367+
:py:const:`OPT_X_TLS_HARD`
368+
Same as :py:const:`OPT_X_TLS_DEMAND`
369+
250370
.. py:data:: OPT_X_TLS_TRY
251371
372+
.. deprecated:: 3.0
373+
This value is only used by slapd server internally. It will be removed
374+
in the future.
375+
376+
.. py:data:: OPT_X_TLS_VERSION
377+
378+
Get negotiated TLS protocol version as string
379+
252380
.. _ldap-keepalive-options:
253381

254382
Keepalive options
@@ -561,6 +689,8 @@ The above exceptions are raised when a result code from an underlying API
561689
call does not indicate success.
562690

563691

692+
.. _ldap-warnings:
693+
564694
Warnings
565695
========
566696

Doc/spelling_wordlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ defresult
3939
dereferenced
4040
dereferencing
4141
desc
42+
dev
4243
directoryOperation
4344
distinguished
4445
distributedOperation
@@ -145,6 +146,7 @@ UDP
145146
Umich
146147
unparsing
147148
unsigend
149+
urandom
148150
uri
149151
urlPrefix
150152
urlscheme

Lib/ldap/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ class Str(Constant):
281281
TLSInt('OPT_X_TLS_DEMAND'),
282282
TLSInt('OPT_X_TLS_ALLOW'),
283283
TLSInt('OPT_X_TLS_TRY'),
284-
TLSInt('OPT_X_TLS_PEERCERT', optional=True),
285284

286285
TLSInt('OPT_X_TLS_VERSION', optional=True),
287286
TLSInt('OPT_X_TLS_CIPHER', optional=True),

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ AUTOPEP8_OPTS=--aggressive
1212
.PHONY: all
1313
all:
1414

15+
Modules/constants_generated.h: Lib/ldap/constants.py
16+
$(PYTHON) $^ > $@
17+
indent Modules/constants_generated.h
18+
rm -f Modules/constants_generated.h~
19+
1520
.PHONY: clean
1621
clean:
1722
rm -rf build dist *.egg-info .tox MANIFEST

Modules/constants_generated.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,6 @@ add_int(OPT_X_TLS_DEMAND);
213213
add_int(OPT_X_TLS_ALLOW);
214214
add_int(OPT_X_TLS_TRY);
215215

216-
#if defined(LDAP_OPT_X_TLS_PEERCERT)
217-
add_int(OPT_X_TLS_PEERCERT);
218-
#endif
219-
220216
#if defined(LDAP_OPT_X_TLS_VERSION)
221217
add_int(OPT_X_TLS_VERSION);
222218
#endif

0 commit comments

Comments
 (0)