Skip to content

Commit fc2a020

Browse files
committed
Add logic for STARTTLS enabled AD servers
There are two different scenarios. x0C is the buffsize reply from openldap-like servers whereas AD servers probably have x84 and return also the OID. The following is kind of hackish as ldap_ExtendedResponse_parse() in apps/s_client.c of openssl is kind of hard to understand. It was deducted from a number of hosts. Bottom line: We'll look at the 9th byte or at the 17th when retrieving the result code AD: 30 84 00 00 00 7d 02 01 01 78 84 00 00 00 74 0a 01 34 04 00 04 55 30 30 30 30 30 30 30 30 3a 20 [ failed AD .. LdapErr + OID..] 30 84 00 00 00 28 02 01 01 78 84 00 00 00 1F 0A 01 00 04 00 04 00 8A 16 [.. OID ..] ^^ bufflen ^^ resultcode 30 0C 02 01 01 78 07 0A 01 00 04 00 04 00 ^^ bufflen ^^ result code
1 parent c67cefa commit fc2a020

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

testssl.sh

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11429,7 +11429,7 @@ starttls_ldap_dialog() {
1142911429
local -i ret=0
1143011430
local msg_lenstr=""
1143111431
local -i msg_len=0
11432-
local result=""
11432+
local result="" buffsize=""
1143311433
local starttls_init=",
1143411434
x30, x1d, x02, x01, # LDAP extendedReq
1143511435
x01, # messageID: 1
@@ -11441,13 +11441,26 @@ starttls_ldap_dialog() {
1144111441
result=$(sockread_fast 256)
1144211442
[[ $DEBUG -ge 4 ]] && safe_echo "$debugpad $result\n"
1144311443

11444-
# response is typically 30 0c 02 01 01 78 07 0a 01 00 04 00 04 00
11445-
# ^^ 0 would be success in 9th byte
11446-
#
11444+
# For ~ OpenLDAP: response is typically 30 0c 02 01 01 78 07 0a 01 00 04 00 04 00
11445+
# ^^ buffsize ^^ ret value (0 -> success)
11446+
# see https://git.openldap.org/openldap/openldap/-/blob/master/include/ldap.h
1144711447
# return values in https://www.rfc-editor.org/rfc/rfc2251#page-45 and e.g.
11448-
# https://git.openldap.org/openldap/openldap/-/blob/master/include/ldap.h
1144911448

11450-
case "${result:18:2}" in
11449+
# We have two different scenarios though. x0C is the buffsize reply from openldap-like servers
11450+
# whereas AD servers probably have x84 and return also the OID. The following is kind of
11451+
# hackish as ldap_ExtendedResponse_parse() in apps/s_client.c of openssl is kind of hard
11452+
# to understand. It was deducted from a number of hosts.
11453+
# Bottom line: We'll look at the 9th byte or at the 17th when retrieving the result code
11454+
11455+
buffsize="${result:2:2}"
11456+
11457+
case $buffsize in
11458+
0C) result_code="${result:18:2}" ;;
11459+
84) result_code="${result:34:2}" ;;
11460+
esac
11461+
[[ $DEBUG -ge 2 ]] && safe_echo "$debugpad buffsize: $buffsize / LDAP result_code: $result_code \n"
11462+
11463+
case $result_code in
1145111464
00) ret=0 ;;
1145211465
# success
1145311466
01) ret=1 ;;
@@ -11459,12 +11472,13 @@ starttls_ldap_dialog() {
1145911472
msg_len=$((2 * msg_lenstr))
1146011473
safe_echo "$debugpad $(hex2binary "${result:28:$msg_len}")"
1146111474
fi ;;
11462-
*)
11463-
ret=127
11464-
if [[ $DEBUG -ge 2 ]]; then
11465-
safe_echo "$debugpad $(hex2dec "${result:28:2}")"
11466-
fi ;;
11475+
34) [[ $DEBUG -ge 2 ]] && safe_echo " seems AD server with no STARTTLS\n"
11476+
ret=52 ;;
11477+
*) [[ $DEBUG -ge 2 ]] && safe_echo "$debugpad $(hex2dec "${result:28:2}")"
11478+
ret=127 ;;
1146711479
esac
11480+
11481+
1146811482
debugme echo "=== finished LDAP STARTTLS dialog with ${ret} ==="
1146911483
return $ret
1147011484
}

0 commit comments

Comments
 (0)