Mercurial > hg > easyhg
comparison easyhg.py @ 451:8156537329ff
Associate password with scheme+host+user rather than url+user
author | Chris Cannam |
---|---|
date | Wed, 29 Jun 2011 13:40:57 +0100 |
parents | 568abb678073 |
children | d0b7dbc3ba46 |
comparison
equal
deleted
inserted
replaced
450:568abb678073 | 451:8156537329ff |
---|---|
74 text = cipher.decrypt(base64.b64decode(ctext)) | 74 text = cipher.decrypt(base64.b64decode(ctext)) |
75 (tlen, d, text) = text.partition('.') | 75 (tlen, d, text) = text.partition('.') |
76 (salt, d, text) = text.partition('.') | 76 (salt, d, text) = text.partition('.') |
77 return text[0:int(tlen)] | 77 return text[0:int(tlen)] |
78 | 78 |
79 def pathless_url(url): | |
80 parsed_url = urlparse.urlparse(url) | |
81 return "%s://%s" % (parsed_url.scheme, parsed_url.netloc) | |
82 | |
79 # from mercurial_keyring by Marcin Kasperski | 83 # from mercurial_keyring by Marcin Kasperski |
80 def canonical_url(authuri): | 84 def canonical_url(url): |
81 parsed_url = urlparse.urlparse(authuri) | 85 parsed_url = urlparse.urlparse(url) |
82 return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, | 86 return "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, |
83 parsed_url.path) | 87 parsed_url.path) |
84 | 88 |
85 def load_config(pcfg, pfile): | 89 def load_config(pcfg, pfile): |
86 fp = None | 90 fp = None |
168 return orig_find(self, realm, authuri) | 172 return orig_find(self, realm, authuri) |
169 | 173 |
170 # self.ui.write("want username and/or password for %s\n" % authuri) | 174 # self.ui.write("want username and/or password for %s\n" % authuri) |
171 | 175 |
172 short_uri = canonical_url(authuri) | 176 short_uri = canonical_url(authuri) |
177 pathless_uri = pathless_url(authuri) | |
173 | 178 |
174 authkey = self.ui.config('easyhg', 'authkey') | 179 authkey = self.ui.config('easyhg', 'authkey') |
175 authfile = self.ui.config('easyhg', 'authfile') | 180 authfile = self.ui.config('easyhg', 'authfile') |
176 use_authfile = (easyhg_authfile_imports_ok and authkey and authfile) | 181 use_authfile = (easyhg_authfile_imports_ok and authkey and authfile) |
177 if authfile: authfile = os.path.expanduser(authfile) | 182 if authfile: authfile = os.path.expanduser(authfile) |
218 user = decrypt_salted(authdata, authkey) | 223 user = decrypt_salted(authdata, authkey) |
219 user_field.setText(user) | 224 user_field.setText(user) |
220 | 225 |
221 if not passwd: | 226 if not passwd: |
222 authdata = get_from_config(authconfig, 'auth', | 227 authdata = get_from_config(authconfig, 'auth', |
223 remote_key(short_uri, user, authkey)) | 228 remote_key(pathless_uri, user, authkey)) |
224 if authdata: | 229 if authdata: |
225 passwd = decrypt_salted(authdata, authkey) | 230 passwd = decrypt_salted(authdata, authkey) |
226 passwd_field.setText(passwd) | 231 passwd_field.setText(passwd) |
227 | 232 |
228 remember_field = QtGui.QCheckBox() | 233 remember_field = QtGui.QCheckBox() |
268 else: | 273 else: |
269 set_to_config(authconfig, 'user', remote_key(short_uri, '', authkey), '') | 274 set_to_config(authconfig, 'user', remote_key(short_uri, '', authkey), '') |
270 if passwd: | 275 if passwd: |
271 if remember: | 276 if remember: |
272 authdata = encrypt_salted(passwd, authkey) | 277 authdata = encrypt_salted(passwd, authkey) |
273 set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), authdata) | 278 set_to_config(authconfig, 'auth', remote_key(pathless_uri, user, authkey), authdata) |
274 else: | 279 else: |
275 set_to_config(authconfig, 'auth', remote_key(short_uri, user, authkey), '') | 280 set_to_config(authconfig, 'auth', remote_key(pathless_uri, user, authkey), '') |
276 save_config(self.ui, authconfig, authfile) | 281 save_config(self.ui, authconfig, authfile) |
277 | 282 |
278 self.add_password(realm, authuri, user, passwd) | 283 self.add_password(realm, authuri, user, passwd) |
279 return (user, passwd) | 284 return (user, passwd) |
280 | 285 |