From 18f1e7de1820a63d5f8f49b52205b70a2107c2ea Mon Sep 17 00:00:00 2001 From: equinox Date: Fri, 1 Apr 2011 06:27:25 +0200 Subject: add site identifier to ticket --- ticket.py | 14 +++++++------- 1 file 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) -- cgit v1.2.1