summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ticket.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/ticket.py b/ticket.py
index e7697e9..5b9ac2e 100644
--- a/ticket.py
+++ b/ticket.py
@@ -2,23 +2,23 @@ import crypto, socket, time
keyfile = 'subdap-%s.key' % (socket.gethostname())
pubfile = 'subdap-%s.pem' % (socket.gethostname())
-keys = ['user', 'ts', 'sig']
+keys = ['site', 'user', 'ts', 'sig']
-def tgt_create(user):
+def tgt_create(site, user):
ts = int(time.time())
- data = '%d:%s' % (ts, user)
+ data = '%s:%d:%s' % (site, ts, user)
sig = crypto.sign(keyfile, data)
- return {'user': user, 'ts': ts, 'sig': sig}
+ return {'site': site, 'user': user, 'ts': ts, 'sig': sig}
-def tgt_verify(user, ts, sig, maxage = None):
- data = '%d:%s' % (int(ts), user)
+def tgt_verify(site, user, ts, sig, maxage = None):
+ data = '%s:%d:%s' % (site, int(ts), user)
status = crypto.verify(pubfile, data, sig)
if maxage != None:
status &= ts > time.time() - maxage
return status
if __name__ == '__main__':
- sig = tgt_create('test')
+ sig = tgt_create('site', 'test')
print sig
assert not tgt_verify(maxage = -9999, **sig)
assert tgt_verify(maxage = 9999, **sig)