diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-08-16 15:28:09 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-08-16 15:28:09 +0200 |
commit | 1c1167eda0a2757b8fb6588f0400d47020fdb1ab (patch) | |
tree | a77f46d937f25c796d666c67970e0a45a7837c84 /netlib/http_auth.py | |
parent | 1b8529649ca33ce48d02fd547d00f70e3c1f5b83 (diff) | |
download | mitmproxy-1c1167eda0a2757b8fb6588f0400d47020fdb1ab.tar.gz mitmproxy-1c1167eda0a2757b8fb6588f0400d47020fdb1ab.tar.bz2 mitmproxy-1c1167eda0a2757b8fb6588f0400d47020fdb1ab.zip |
use passlib instead of md5crypt
Diffstat (limited to 'netlib/http_auth.py')
-rw-r--r-- | netlib/http_auth.py | 29 |
1 files changed, 5 insertions, 24 deletions
diff --git a/netlib/http_auth.py b/netlib/http_auth.py index b0451e3b..937b66f0 100644 --- a/netlib/http_auth.py +++ b/netlib/http_auth.py @@ -1,4 +1,4 @@ -from .contrib import md5crypt +from passlib.apache import HtpasswdFile import http from argparse import Action, ArgumentTypeError @@ -78,32 +78,14 @@ class PassManHtpasswd: """ Read usernames and passwords from an htpasswd file """ - def __init__(self, fp): + def __init__(self, path): """ Raises ValueError if htpasswd file is invalid. """ - self.usernames = {} - for l in fp: - l = l.strip().split(':') - if len(l) != 2: - raise ValueError("Invalid htpasswd file.") - parts = l[1].split('$') - if len(parts) != 4: - raise ValueError("Invalid htpasswd file.") - self.usernames[l[0]] = dict( - token = l[1], - dummy = parts[0], - magic = parts[1], - salt = parts[2], - hashed_password = parts[3] - ) + self.htpasswd = HtpasswdFile(path) def test(self, username, password_token): - ui = self.usernames.get(username) - if not ui: - return False - expected = md5crypt.md5crypt(password_token, ui["salt"], '$'+ui["magic"]+'$') - return expected==ui["token"] + return bool(self.htpasswd.check_password(username, password_token)) class PassManSingleUser: @@ -149,6 +131,5 @@ class NonanonymousAuthAction(AuthAction): class HtpasswdAuthAction(AuthAction): def getPasswordManager(self, s): - with open(s, "r") as f: - return PassManHtpasswd(f) + return PassManHtpasswd(s) |