diff options
author | equinox <equinox@diac24.net> | 2011-04-01 06:27:25 +0200 |
---|---|---|
committer | equinox <equinox@diac24.net> | 2011-04-01 06:27:25 +0200 |
commit | 18f1e7de1820a63d5f8f49b52205b70a2107c2ea (patch) | |
tree | 2f09b9fe6d2ff344b53a10b10626630fd6c0cd61 | |
parent | f323816b73661fa8cb2a1accb4d05ac5b5945fe4 (diff) |
add site identifier to ticket
-rw-r--r-- | ticket.py | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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) |