Skip to content

Commit 50183db

Browse files
dschomjcheetham
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 9022eb3 commit 50183db

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
@@ -167,6 +167,7 @@ prepare_httpd() {
167167
install_script error.sh
168168
install_script apply-one-time-perl.sh
169169
install_script nph-custom-auth.sh
170+
install_script ntlm-handshake.sh
170171

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

t/lib-httpd/apache.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ SetEnv PERL_PATH ${PERL_PATH}
151151
CGIPassAuth on
152152
</IfDefine>
153153
</LocationMatch>
154+
<LocationMatch /ntlm_auth/>
155+
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
156+
SetEnv GIT_HTTP_EXPORT_ALL
157+
<IfDefine USE_CGIPASSAUTH>
158+
CGIPassAuth on
159+
</IfDefine>
160+
</LocationMatch>
154161
ScriptAlias /smart/incomplete_length/git-upload-pack incomplete-length-upload-pack-v2-http.sh/
155162
ScriptAlias /smart/incomplete_body/git-upload-pack incomplete-body-upload-pack-v2-http.sh/
156163
ScriptAlias /smart/no_report/git-receive-pack error-no-report.sh/
@@ -161,6 +168,7 @@ ScriptAlias /error_smart/ error-smart-http.sh/
161168
ScriptAlias /error/ error.sh/
162169
ScriptAliasMatch /one_time_perl/(.*) apply-one-time-perl.sh/$1
163170
ScriptAliasMatch /custom_auth/(.*) nph-custom-auth.sh/$1
171+
ScriptAliasMatch /ntlm_auth/(.*) ntlm-handshake.sh/$1
164172
<Directory ${GIT_EXEC_PATH}>
165173
Options FollowSymlinks
166174
</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
@@ -675,4 +675,19 @@ test_expect_success 'access using three-legged auth' '
675675
EOF
676676
'
677677

678+
test_lazy_prereq NTLM 'curl --version | grep -q NTLM'
679+
680+
test_expect_success NTLM 'access using NTLM auth' '
681+
test_when_finished "per_test_cleanup" &&
682+
683+
set_credential_reply get <<-EOF &&
684+
username=user
685+
password=pwd
686+
EOF
687+
688+
test_config_global credential.helper test-helper &&
689+
GIT_TRACE_CURL=1 \
690+
git ls-remote "$HTTPD_URL/ntlm_auth/repo.git"
691+
'
692+
678693
test_done

0 commit comments

Comments
 (0)