Skip to content

Commit 14254d0

Browse files
dschomjcheetham
authored andcommitted
t5563: verify that NTLM authentication works
Although NTLM authentication is considered weak (extending even to NTLMv2, which purportedly allows brute-forcing reasonably complex 8-character passwords in a matter of days, given ample compute resources), it _is_ one of the authentication methods supported by libcurl. Note: The added test case *cannot* reuse the existing `custom_auth` facility. The reason is that that facility is backed by an NPH script ("No Parse Headers"), which does not allow handling the 3-phase NTLM authentication correctly (in my hands, the NPH script would not even be called upon the Type 3 message, a "200 OK" would be returned, but no headers, let alone the `git http-backend` output as payload). Having a separate NTLM authentication script makes the exact workings clearer and more readable, anyway. Co-authored-by: Matthew John Cheetham <mjcheetham@outlook.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b600850 commit 14254d0

4 files changed

Lines changed: 62 additions & 0 deletions

File tree

t/lib-httpd.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ prepare_httpd() {
168168
install_script apply-one-time-script.sh
169169
install_script nph-custom-auth.sh
170170
install_script http-429.sh
171+
install_script ntlm-handshake.sh
171172

172173
ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
173174

t/lib-httpd/apache.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ SetEnv PERL_PATH ${PERL_PATH}
155155
CGIPassAuth on
156156
</IfDefine>
157157
</LocationMatch>
158+
<LocationMatch /ntlm_auth/>
159+
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
160+
SetEnv GIT_HTTP_EXPORT_ALL
161+
<IfDefine USE_CGIPASSAUTH>
162+
CGIPassAuth on
163+
</IfDefine>
164+
</LocationMatch>
158165
ScriptAlias /smart/incomplete_length/git-upload-pack incomplete-length-upload-pack-v2-http.sh/
159166
ScriptAlias /smart/incomplete_body/git-upload-pack incomplete-body-upload-pack-v2-http.sh/
160167
ScriptAlias /smart/no_report/git-receive-pack error-no-report.sh/
@@ -166,6 +173,7 @@ ScriptAlias /error/ error.sh/
166173
ScriptAliasMatch /one_time_script/(.*) apply-one-time-script.sh/$1
167174
ScriptAliasMatch /http_429/(.*) http-429.sh/$1
168175
ScriptAliasMatch /custom_auth/(.*) nph-custom-auth.sh/$1
176+
ScriptAliasMatch /ntlm_auth/(.*) ntlm-handshake.sh/$1
169177
<Directory ${GIT_EXEC_PATH}>
170178
Options FollowSymlinks
171179
</Directory>

t/lib-httpd/ntlm-handshake.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
3+
case "$HTTP_AUTHORIZATION" in
4+
'')
5+
# No Authorization header -> send NTLM challenge
6+
echo "Status: 401 Unauthorized"
7+
echo "WWW-Authenticate: NTLM"
8+
echo
9+
;;
10+
"NTLM TlRMTVNTUAAB"*)
11+
# Type 1 -> respond with Type 2 challenge (hardcoded)
12+
echo "Status: 401 Unauthorized"
13+
# Base64-encoded version of the Type 2 challenge:
14+
# signature: 'NTLMSSP\0'
15+
# message_type: 2
16+
# target_name: 'NTLM-GIT-SERVER'
17+
# flags: 0xa2898205 =
18+
# NEGOTIATE_UNICODE, REQUEST_TARGET, NEGOTIATE_NT_ONLY,
19+
# TARGET_TYPE_SERVER, TARGET_TYPE_SHARE, REQUEST_NON_NT_SESSION_KEY,
20+
# NEGOTIATE_VERSION, NEGOTIATE_128, NEGOTIATE_56
21+
# challenge: 0xfa3dec518896295b
22+
# context: '0000000000000000'
23+
# target_info_present: true
24+
# target_info_len: 128
25+
# version: '10.0 (build 19041)'
26+
echo "WWW-Authenticate: NTLM TlRMTVNTUAACAAAAHgAeADgAAAAFgomi+j3sUYiWKVsAAAAAAAAAAIAAgABWAAAACgBhSgAAAA9OAFQATABNAC0ARwBJAFQALQBTAEUAUgBWAEUAUgACABIAVwBPAFIASwBHAFIATwBVAFAAAQAeAE4AVABMAE0ALQBHAEkAVAAtAFMARQBSAFYARQBSAAQAEgBXAE8AUgBLAEcAUgBPAFUAUAADAB4ATgBUAEwATQAtAEcASQBUAC0AUwBFAFIAVgBFAFIABwAIAACfOcZKYNwBAAAAAA=="
27+
echo
28+
;;
29+
"NTLM TlRMTVNTUAAD"*)
30+
# Type 3 -> accept without validation
31+
exec "$GIT_EXEC_PATH"/git-http-backend
32+
;;
33+
*)
34+
echo "Status: 500 Unrecognized"
35+
echo
36+
echo "Unhandled auth: '$HTTP_AUTHORIZATION'"
37+
;;
38+
esac

t/t5563-simple-http-auth.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,4 +793,19 @@ test_expect_success SPNEGO 'http.emptyAuth=false skips Negotiate' '
793793
test_line_count = 1 actual_401s
794794
'
795795

796+
test_lazy_prereq NTLM 'curl --version | grep -q NTLM'
797+
798+
test_expect_success NTLM 'access using NTLM auth' '
799+
test_when_finished "per_test_cleanup" &&
800+
801+
set_credential_reply get <<-EOF &&
802+
username=user
803+
password=pwd
804+
EOF
805+
806+
test_config_global credential.helper test-helper &&
807+
GIT_TRACE_CURL=1 \
808+
git ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
809+
'
810+
796811
test_done

0 commit comments

Comments
 (0)