Skip to content

Add --start-tls and --no-tls-verify LDAP options#249

Open
bandrel wants to merge 1 commit into
dirkjanm:masterfrom
bandrel:feat/start-tls
Open

Add --start-tls and --no-tls-verify LDAP options#249
bandrel wants to merge 1 commit into
dirkjanm:masterfrom
bandrel:feat/start-tls

Conversation

@bandrel

@bandrel bandrel commented Apr 25, 2026

Copy link
Copy Markdown

Summary

  • Add --start-tls to upgrade a plain LDAP connection to TLS via the StartTLS extended operation (RFC 2830) before binding. Works for both NTLM and Kerberos (SASL/GSSAPI) auth paths.
  • Add --no-tls-verify to disable TLS certificate verification. Applies to both --use-ldaps and the StartTLS-upgraded connection via a Tls(validate=CERT_NONE) object on the Server.
  • Auto-retry with LDAP channel binding when the DC rejects an NTLM bind with SEC_E_BAD_BINDINGS (data 80090346), so StartTLS works against DCs that enforce EPA without the operator needing to manually combine flags. Mirrors the existing RESULT_STRONGER_AUTH_REQUIRED retry path.
  • --start-tls is rejected alongside --use-ldaps. Combining --start-tls with --ldap-channel-binding is supported.

Closes #248.

Implementation notes

  • New helper ADAuthentication._maybe_start_tls(conn) opens the socket (if not already open) and runs conn.start_tls() before bind.
  • ldap_kerberos() now guards its connection.open() with a closed check so it doesn't reopen a socket that StartTLS already opened.
  • _build_tls() returns Tls(validate=CERT_NONE) when --no-tls-verify is set, attached to all non-channel-binding Server constructors (CB paths already set CERT_NONE explicitly).

Test plan

  • Built and exercised against a hardened DC (LDAP signing + EPA enforced) with --start-tls; auto-retry with channel binding succeeds and collection runs through.
  • --start-tls + --ldap-channel-binding works with the patched ldap3 (ldap3-bleeding-edge / ly4k/ldap3).
  • --start-tls + --use-ldaps is rejected at argparse-time.
  • LDAPS path unchanged (regression check by reviewer welcome).
  • Kerberos (-k) auth over StartTLS — light-tested locally; reviewer with a Kerberos lab welcome to confirm.

Adds support for upgrading a plain LDAP connection to TLS via the
StartTLS extended operation before binding, and a companion
--no-tls-verify flag that disables certificate validation for both
ldaps:// and StartTLS connections.

Behavior:
- --start-tls: opens the socket, performs StartTLS, then binds. Works
  for NTLM and Kerberos (SASL/GSSAPI) auth paths.
- --no-tls-verify: attaches a Tls(validate=CERT_NONE) object to the
  Server so it applies to both ldaps and the StartTLS upgrade.
- When the DC rejects an NTLM bind with SEC_E_BAD_BINDINGS (data
  80090346), auto-retry with LDAP channel binding on the same
  protocol (so StartTLS+EPA works without manual flag combos).
- --start-tls is rejected alongside --use-ldaps; combining with
  --ldap-channel-binding is supported.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@bandrel

bandrel commented Apr 25, 2026

Copy link
Copy Markdown
Author

I ran into a weird use case where 636 was not open, but 389 required start-tls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support StartTLS for LDAP connections

1 participant