| Ticket UUID: | af927e957fa1cd0eaf9751b67f02cb17c3a20f7a | |||
| Title: | LDAP STARTTLS broken with Microsoft AD | |||
| Type: | Bug | Version: | ||
| Submitter: | christian.nassau | Created on: | 2022-02-17 08:39:36 | |
| Subsystem: | ldap | Assigned To: | aku | |
| Priority: | 5 Medium | Severity: | Critical | |
| Status: | Open | Last Modified: | 2026-11-15 13:36:41 | |
| Resolution: | Fixed | Closed By: | aku | |
| Closed on: | 2022-04-10 10:14:07 | |||
| Description: |
The current tcllib ldap.tcl uses the following line to create the LDAP STARTTLS request: set request [asnApplicationConstr 23 [asnOctetString 1.3.6.1.4.1.1466.20037]]This generates a regular "asn/Application" whereas the LDAP RFC requires an "Extended Operation" instead. The difference is minimal but recent versions of Microsoft AD refuse to accept it and just hang up: current value: 30 1d 02 01 01 77 18 04 16 31 2e 33 2e 36 2e 31 2e 34 2e 31 2e 31 34 36 36 2e 32 30 30 33 37The rigid handling in the Microsoft AD seems strange but is probably consistent with a strict reading of section 4.12 in the RFC. This bug seems easy to fix by just constructing the required "Extended Operation" directly using e.g. (Note that the unix tool "ldapsearch" also sends the correct sequence; this can be seen from the hexdump in this question, for example)set request [binary format H* 77188016312e332e362e312e342e312e313436362e3230303337] | |||
| User Comments: |
serhiy.storchaka added on 2026-11-15 13:36:41:
The fix in [495ba2b8f5] calls asnEncodeString, which asn does not export, so ldap::starttls and ldap::info whoami fail with "invalid command name" in tcllib 1.21, 2.0 and trunk, as noted above. Proposed fix in branch ldap-starttls-asncontext: use the exported asnContext 0 $oid, which encodes the same bytes. Test ldap-30.0 runs against a local mock LDAP server. christian.nassau added on 2022-06-01 11:59:44: Sorry for this late intervention, but I just checked the regular fix and it runs into this problem: the function asnEncodeString is currently *not* exported in the asn package (checked with version 0.8.4, the ldap.tcl only requires asn version 0.7). I would suggest to add it to the list of exported methods and bump the version requirement in ldap.tcl. aku added on 2022-04-10 10:14:07:
The difference is that 04 gives you an "OCTET STRING" and 80 an "[0]" (whatever that means). In general it seems an "8n" gives you an "[n]". It's just such a "[0]" that is mentioned in the RFC4511 section 4.12, which is why I claim that the "80" is actually prescribed by the RFC. Oh! I had seen the [0] and [1] in the RFC and completely read over them as they looked to me to be like a descriptive index of the argument or some such. I completely missed them as having a value/meaning for the encoding :( Thanks for setting me straight. Fixed with commit [495ba2b8f5]. Bumped version to 1.10.1 christian.nassau added on 2022-04-09 21:06:57: I'm also no expert on the subtle points of ASN1 and LDAP but I would suggest you compare the output of the ASN1 decoder here: The difference is that 04 gives you an "OCTET STRING" and 80 an "[0]" (whatever that means). In general it seems an "8n" gives you an "[n]". It's just such a "[0]" that is mentioned in the RFC4511 section 4.12, which is why I claim that the "80" is actually prescribed by the RFC.You can look at the output of ldapsearch to see that they are using the variant with "80": ldapsearch -x -H ldap://db.debian.org -b dc=debian,dc=org uid=dbharris -ZZ -v -d2 2>&1 | lessThe STARTTLS request is the very first package that is sent; this makes clear that ldapsearch always uses the "80" independent of any prior server identification (which seems not to exist with LDAP anyway). In this particular case the server is an OpenLDAP server, not a Microsoft AD. Regarding ldap::Whoami: you are right that this also needs to be fixed: the current code gives me the same "Protocol error" as STARTLS, and it works using the "asn::asnEncodeString 80 ..." instead. aku added on 2022-04-08 20:51:34: Forgot to ask: - How do other LDAP servers react to the modified starttls request, i.e. using "80" ? aku added on 2022-04-08 20:40:26: Taking this although I have no real idea of LDAP and ASN. That said, running the involved asn commands, and reading their output and the sources it seems to me that the problematic 04 is the initial tag for an OctetString, as per the implementation. Can you tell me what ASN object an 80 would be the initial tag of ? A fix might be to replace set request [asnApplicationConstr 23 [asnOctetString 1.3.6.1.4.1.1466.20037]] with set request [asnApplicationConstr 23 [asnEncodeString 80 1.3.6.1.4.1.1466.20037]] Internally "asnOctetString .." could be written as "asnEncodeString 04 ...". Looking over the other "asn...String" commands in the asn package none of them use tag "80". Reading the 4.12 of the RFC I only see that the request is [app 23 octet-string-of-request-oid]. Which seems to be exactly what the ldap package does. Where is this tag "80" specified ? Going back to the LDAP sources, could you check operation of "ldap::Whoami" also ? This looks to me as also using an LDAP extension request, i.e. possibly requiring "Extended Operation". | |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki