Skip to content

[doc] Explain TLS/SSL gotchas #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks
tiran opened this issue Nov 29, 2017 · 15 comments
Open
2 tasks

[doc] Explain TLS/SSL gotchas #55

tiran opened this issue Nov 29, 2017 · 15 comments
Labels

Comments

@tiran
Copy link
Member

tiran commented Nov 29, 2017

TLS/SSL and X.509 are tricky. OpenLDAP adds some additional gotchas to the stack. We should document them so users don't run into issues like pyldap/pyldap#53

  • start_tls_s() requires protocol version 3. It does not work with protocol version 2.
  • Several, perhaps all set_option(OPT_X_TLS_*, ...) calls require a final set_option(ldap.OPT_X_TLS_NEWCTX, 0) call to submit all previous set_option() calls. Without OPT_X_TLS_NEWCTX, settings are effectively ignored.
        l.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3)
        l.set_option(ldap.OPT_X_TLS_CACERTFILE, 'path/to/ca.pem')
        l.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap. OPT_X_TLS_NEVER)
        l.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
  • emit warning when OPT_X_TLS_NEWCTX is required
  • emit warning when connection is already established and OPT_X_TLS_* are useless.
@tiran
Copy link
Member Author

tiran commented Nov 29, 2017

@encukou
Copy link
Member

encukou commented Nov 29, 2017

Do we want to actually track this in code, issue a warning for one release, then make it a hard error?

@tiran
Copy link
Member Author

tiran commented Nov 29, 2017

It's a bit tricky. The cert settings can be changed globally ldap_set_option(NULL, opt, val) and locally ldap_set_option(conn, opt, val). I'm not sure how to fix cases like:

conn = ldap.initialize()
# now change the global setting but expect the local connection to pick up the change
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, True)
conn.start_tls_s()

tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Nov 30, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 1, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 1, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 1, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
@encukou
Copy link
Member

encukou commented Dec 1, 2017

Documenting it is fine, or at least a good first step. We don't need to hand-hold the users (though it would be nice if we did).

@encukou
Copy link
Member

encukou commented Dec 1, 2017

Anyway, I don't think 3.0.0 beta needs to wait for this, as it's not a regression from either python-ldap or pyldap.

tiran added a commit to tiran/python-ldap that referenced this issue Dec 5, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 5, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 11, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 11, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 11, 2017
See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 11, 2017
Without OPT_X_TLS_NEWCTX, most settings TLS settings are not applied.

See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Dec 11, 2017
Without OPT_X_TLS_NEWCTX, most settings TLS settings are not applied.

See python-ldap#55

Signed-off-by: Christian Heimes <cheimes@redhat.com>
@encukou encukou added the doc label Dec 13, 2017
@graingert
Copy link
Contributor

graingert commented Jan 23, 2020

Checkmk/checkmk@caa7fe1

sometimes setting OPT_X_TLS_NEWCTX throws a ValueError, but it still connects successfully

This is a problem for reconnecting ldap object because it doesn't catch the value error when settings OPT_X_TLS_NEWCTX

@LarsMichelsen
@tiran

@graingert
Copy link
Contributor

graingert commented Jan 23, 2020

@encukou would it be better if all options were set at once using a namedtuple?

ldap.initialize(uri=x, options=ldap.Options(referrals=0, tls_certfile=..., ))

and global set_option was removed?

and then OPT_X_TLS_NEWCTX would just be sent last if ldap.Option had any TLS options

@tiran
Copy link
Member Author

tiran commented Jan 23, 2020

tribe29/checkmk@caa7fe1

sometimes setting OPT_X_TLS_NEWCTX throws a ValueError, but it still connects successfully

This is a problem for reconnecting ldap object because it doesn't catch the value error when settings OPT_X_TLS_NEWCTX

I'm only familiar with the OpenSSL and NSS backends. I know for a fact that the OpenSSL backend throws a ValueError with OPT_X_TLS_NEWCTX when OPT_X_TLS_CACERTFILE points to an invalid or missing CA cert bundle. You might still be able to connect but not with the configuration you are expecting. It's possible that you end up with an insecure connection.

@graingert
Copy link
Contributor

Would it be possible to throw a FileNotFoundError instead?

@tiran
Copy link
Member Author

tiran commented Jan 23, 2020

No, OpenLDAP libldap does not return additional information. python-ldap just gets a generic error code.

>>> import ldap
>>> conn = ldap.initialize("ldap://localhost")
>>> conn.set_option(ldap.OPT_X_TLS_CACERTFILE, "/invalid")
>>> conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.7/site-packages/ldap/ldapobject.py", line 919, in set_option
    return self._ldap_call(self._l.set_option,option,invalue)
  File "/usr/lib64/python3.7/site-packages/ldap/ldapobject.py", line 313, in _ldap_call
    result = func(*args,**kwargs)
ValueError: option error

@graingert
Copy link
Contributor

@tiran I've raised an issue re the generic error code with openldap https://www.openldap.org/its/index.cgi/Incoming?id=9157

@tiran
Copy link
Member Author

tiran commented Jan 24, 2020

conn.set_option(ldap.OPT_X_TLS_NEWCTX, 1) instructs OpenLDAP to create a context for an LDAP server. LDAP client libraries such as python-ldap must use conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0).

@graingert
Copy link
Contributor

@tiran ah yes I misunderstood that issue thread

@tiran
Copy link
Member Author

tiran commented Jan 24, 2020

Looks like I'm not the only person that got confused by OpenLDAP's documentation. :) I started https://www.openldap.org/its/index.cgi/Incoming?id=8805 because I misunderstood how NEWCTX works.

tiran added a commit to tiran/python-ldap that referenced this issue May 30, 2020
See: python-ldap#55
Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue May 30, 2020
See: python-ldap#55
Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue May 31, 2020
See: python-ldap#55
Signed-off-by: Christian Heimes <cheimes@redhat.com>
tiran added a commit to tiran/python-ldap that referenced this issue Jun 5, 2020
See: python-ldap#55
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
encukou pushed a commit that referenced this issue Jun 5, 2020
See: #55

#339

Signed-off-by: Christian Heimes <cheimes@redhat.com>
@hyc
Copy link

hyc commented Jul 22, 2021

In OpenLDAP 2.6 (due for release in September) the fix for ITS#9157 will be released. The error message from the TLS library will be saved in
the LDAP* handle and retrievable via ldap_get_option(ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants