import crypto, socket, time keyfile = 'subdap-%s.key' % (socket.gethostname()) pubfile = 'subdap-%s.pem' % (socket.gethostname()) keys = ['user', 'ts', 'sig'] def tgt_create(user): ts = int(time.time()) data = '%d:%s' % (ts, user) sig = crypto.sign(keyfile, data) return {'user': user, 'ts': ts, 'sig': sig} def tgt_verify(user, ts, sig, maxage = None): data = '%d:%s' % (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') print sig assert not tgt_verify(maxage = -9999, **sig) assert tgt_verify(maxage = 9999, **sig)