Skip to content

Commit b633efa

Browse files
committed
make starttls_ldap_dialog() more readable...
... add references + better debugging output
1 parent 198bb09 commit b633efa

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

testssl.sh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11422,10 +11422,13 @@ starttls_postgres_dialog() {
1142211422
}
1142311423

1142411424

11425-
# RFC 2830
11425+
# RFC 2830, RFC 4511
11426+
#
1142611427
starttls_ldap_dialog() {
1142711428
local debugpad=" > "
1142811429
local -i ret=0
11430+
local msg_lenstr=""
11431+
local -i msg_len=0
1142911432
local result=""
1143011433
local starttls_init=",
1143111434
x30, x1d, x02, x01, # LDAP extendedReq
@@ -11436,17 +11439,31 @@ starttls_ldap_dialog() {
1143611439
debugme echo "=== starting LDAP STARTTLS dialog ==="
1143711440
socksend "${starttls_init}" 0 && debugme echo "${debugpad}initiated STARTTLS" &&
1143811441
result=$(sockread_fast 256)
11439-
[[ $DEBUG -ge 6 ]] && safe_echo "$debugpad $result\n"
11442+
[[ $DEBUG -ge 4 ]] && safe_echo "$debugpad $result\n"
1144011443

1144111444
# response is typically 30 0c 02 01 01 78 07 0a 01 00 04 00 04 00
1144211445
# ^^ == success! [9] is checked below
11443-
if [[ ${result:18:2} == 00 ]]; then
11444-
ret=0
11445-
elif [[ ${result:18:2} == 01 ]]; then
11446-
ret=1
11447-
else
11448-
ret=127
11449-
fi
11446+
#
11447+
# definitions in https://git.openldap.org/openldap/openldap/-/blob/master/include/ldap.h
11448+
11449+
case "${result:18:2}" in
11450+
00) ret=0 ;;
11451+
# "success"
11452+
01) ret=1
11453+
;;
11454+
02) ret=2
11455+
# normally: unsupported extended operation (~ STARTTLS not supported)
11456+
if [[ $DEBUG -ge 2 ]]; then
11457+
msg_lenstr=$(hex2dec ${result:26:02})
11458+
msg_len=$((2 * msg_lenstr))
11459+
echo "$debugpad $(hex2binary "${result:28:$msg_len}")"
11460+
fi ;;
11461+
*)
11462+
ret=127
11463+
if [[ $DEBUG -ge 2 ]]; then
11464+
echo "$debugpad $(hex2dec "${result:28:2}")"
11465+
fi ;;
11466+
esac
1145011467
debugme echo "=== finished LDAP STARTTLS dialog with ${ret} ==="
1145111468
return $ret
1145211469
}

0 commit comments

Comments
 (0)