1 ''' factotum support '''
8 class factotumbasic(urllib2.BaseHandler):
9 def __init__(self, passmgr=None):
10 self.f = factotum.Factotum()
11 def http_error_401(self, req, fp, code, msg, headers):
12 host = urllib2.urlparse.urlparse(req.get_full_url())[1]
13 authreq = headers.get('www-authenticate', None)
14 if authreq == None: return None
15 authreq = authreq.split(' ', 1)
16 if authreq[0].lower() != 'basic': return None
17 chal = urllib2.parse_keqv_list(urllib2.parse_http_list(authreq[1]))
19 self.f.start(proto="pass", host=host, realm=realm, role="client")
21 user = self.f.attr()["user"]
22 val = 'Basic %s' % base64.b64encode(user + ':' + pw).strip()
23 if req.headers.get('Authorization', None) == val: return None
24 req.add_header('Authorization', val)
25 return self.parent.open(req)
27 class factotumdigest(urllib2.BaseHandler):
28 auth_header = 'Authorization'
31 def __init__(self, passmgr=None):
32 self.f = factotum.Factotum()
34 def http_error_401(self, req, fp, code, msg, headers):
36 host = urllib2.urlparse.urlparse(req.get_full_url())[1]
37 authreq = headers.get('www-authenticate', None)
38 if authreq == None: return None
39 authreq = authreq.split(' ', 1)
40 if authreq[0].lower() != 'digest': return None
41 chal = urllib2.parse_keqv_list(urllib2.parse_http_list(authreq[1]))
45 self.f.delkey(proto="httpdigest", realm=realm, host=host)
46 self.f.start(proto="httpdigest", role="client", realm=realm, host=host)
47 self.f.write(nonce + ' ' + req.get_method() + ' ' + req.get_selector())
49 user = self.f.attr()["user"]
51 val = 'Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s", algorithm=MD5' % (user, realm, nonce, req.get_selector(), resp)
52 if req.headers.get('Authorization', None) == val: return None
53 req.add_unredirected_header('Authorization', val)
54 result = self.parent.open(req)
58 urllib2.HTTPBasicAuthHandler = factotumbasic
59 mercurial.url.httpdigestauthhandler = factotumdigest