diff options
author | Sergiusz 'q3k' Bazański <q3k@q3k.org> | 2015-03-05 00:45:18 +0100 |
---|---|---|
committer | Sergiusz 'q3k' Bazański <q3k@q3k.org> | 2015-03-05 00:45:18 +0100 |
commit | d15ede7072e694082657560d63dab4d9a905333a (patch) | |
tree | 067b0a3dafb23203bd98afffbad17d6555c89e0a | |
parent | 180220f19bc951f9cd6b2c4280321e2ede52a661 (diff) | |
download | doorman-d15ede7072e694082657560d63dab4d9a905333a.tar.gz doorman-d15ede7072e694082657560d63dab4d9a905333a.tar.bz2 doorman-d15ede7072e694082657560d63dab4d9a905333a.tar.xz doorman-d15ede7072e694082657560d63dab4d9a905333a.zip |
Add MACd comms to Python client
-rw-r--r-- | admin/lib/.command.py.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | admin/lib/actions.py | 10 | ||||
-rw-r--r-- | admin/lib/command.py | 13 | ||||
-rw-r--r-- | admin/lib/password.py | 2 |
4 files changed, 18 insertions, 7 deletions
diff --git a/admin/lib/.command.py.swp b/admin/lib/.command.py.swp Binary files differnew file mode 100644 index 0000000..7498cf8 --- /dev/null +++ b/admin/lib/.command.py.swp diff --git a/admin/lib/actions.py b/admin/lib/actions.py index 44f13c8..229999e 100644 --- a/admin/lib/actions.py +++ b/admin/lib/actions.py @@ -1,23 +1,23 @@ from proto import Proto from options import * -from command import Command +from command import signed_command def scan(token, url=None, proto=None): proto = proto or Proto(url) - proto.send(Command(command='G', uid=0, hash=empty_hash, token=token)) + proto.send(signed_command(command='G', uid=0, hash=empty_hash, token=token)) return proto.recv() def add(token, hash, uid=0, url=None, proto=None): proto = proto or Proto(url) - proto.send(Command(command='A', hash=hash, uid=uid, token=token)) + proto.send(signed_command(command='A', hash=hash, uid=uid, token=token)) return proto.recv() def revoke_uid(token, uid, url=None, proto=None): proto = proto or Proto(url) - proto.send(Command(command='R', hash=empty_hash, uid=uid, token=token)) + proto.send(signed_command(command='R', hash=empty_hash, uid=uid, token=token)) return proto.recv() def revoke_hash(token, hash, url=None, proto=None): proto = proto or Proto(url) - proto.send(Command(command='R', hash=hash, uid=0, token=token)) + proto.send(signed_command(command='R', hash=hash, uid=0, token=token)) return proto.recv() diff --git a/admin/lib/command.py b/admin/lib/command.py index 00e88cd..88f7dae 100644 --- a/admin/lib/command.py +++ b/admin/lib/command.py @@ -1,4 +1,6 @@ from collections import namedtuple +import hmac +import hashlib from options import * @@ -67,5 +69,14 @@ Command = frame('Command', [ Const(','), Char('hash', hash_bytes), Const(','), - Char('token', token_bytes), + Char('mac', mac_bytes), ]) + +def signed_command(command='P', hash='00'*32, uid=0, token=''): + """Returns a MACd Command instance.""" + data = str(Command(command=command, hash=hash, uid=uid, mac="aa"*32)) + data = ','.join(data.split(',')[:3]) + print data + mac = hmac.HMAC(token, digestmod=hashlib.sha256) + mac.update(data) + return Command(command=command, hash=hash, uid=uid, mac=mac.hexdigest()) diff --git a/admin/lib/password.py b/admin/lib/password.py index c9d745e..5971383 100644 --- a/admin/lib/password.py +++ b/admin/lib/password.py @@ -9,7 +9,7 @@ def get_des_storage_key(filename): def get_token(): password = getpass.getpass('Password:') - return hashlib.sha1(password).hexdigest()[:options.token_bytes] + return password def get_pin(): pin = getpass.getpass('PIN:') |