83 % (user, realm, resp[b'response'], respdig)) |
83 % (user, realm, resp[b'response'], respdig)) |
84 return False |
84 return False |
85 |
85 |
86 return True |
86 return True |
87 |
87 |
|
88 digest = digestauthserver() |
|
89 |
88 def perform_authentication(hgweb, req, op): |
90 def perform_authentication(hgweb, req, op): |
89 auth = req.headers.get(b'Authorization') |
91 auth = req.headers.get(b'Authorization') |
|
92 |
|
93 if req.headers.get(b'X-HgTest-AuthType') == b'Digest': |
|
94 if not auth: |
|
95 challenge = digest.makechallenge(b'mercurial') |
|
96 raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', |
|
97 [(b'WWW-Authenticate', b'Digest %s' % challenge)]) |
|
98 |
|
99 if not digest.checkauth(req, auth[7:]): |
|
100 raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') |
|
101 |
|
102 return |
|
103 |
90 if not auth: |
104 if not auth: |
91 raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', |
105 raise common.ErrorResponse(common.HTTP_UNAUTHORIZED, b'who', |
92 [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) |
106 [(b'WWW-Authenticate', b'Basic Realm="mercurial"')]) |
93 |
107 |
94 if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']: |
108 if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']: |
95 raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') |
109 raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no') |
96 |
110 |
97 def extsetup(ui): |
111 def extsetup(ui): |
98 common.permhooks.insert(0, perform_authentication) |
112 common.permhooks.insert(0, perform_authentication) |
|
113 digest.adduser(b'user', b'pass', b'mercurial') |