| OLD | NEW |
| (Empty) |
| 1 | |
| 2 # Copyright (c) 2001-2004 Twisted Matrix Laboratories. | |
| 3 # See LICENSE for details. | |
| 4 | |
| 5 | |
| 6 """ | |
| 7 Utility functions for authorization. | |
| 8 | |
| 9 These are currently for challenge-response shared secret authentication. | |
| 10 | |
| 11 Maintainer: U{Glyph Lefkowitz<mailto:glyph@twistedmatrix.com>} | |
| 12 """ | |
| 13 | |
| 14 # System Imports | |
| 15 import md5 | |
| 16 import random | |
| 17 | |
| 18 from twisted.cred.error import Unauthorized | |
| 19 | |
| 20 def respond(challenge, password): | |
| 21 """Respond to a challenge. | |
| 22 This is useful for challenge/response authentication. | |
| 23 """ | |
| 24 m = md5.new() | |
| 25 m.update(password) | |
| 26 hashedPassword = m.digest() | |
| 27 m = md5.new() | |
| 28 m.update(hashedPassword) | |
| 29 m.update(challenge) | |
| 30 doubleHashedPassword = m.digest() | |
| 31 return doubleHashedPassword | |
| 32 | |
| 33 def challenge(): | |
| 34 """I return some random data. | |
| 35 """ | |
| 36 crap = '' | |
| 37 for x in range(random.randrange(15,25)): | |
| 38 crap = crap + chr(random.randint(65,90)) | |
| 39 crap = md5.new(crap).digest() | |
| 40 return crap | |
| OLD | NEW |