Guido van Rossum | 37a2911 | 1995-06-21 00:55:59 +0000 | [diff] [blame] | 1 | class Security: |
| 2 | |
| 3 | def __init__(self): |
| 4 | import os |
| 5 | env = os.environ |
| 6 | if env.has_key('PYTHON_KEYFILE'): |
| 7 | keyfile = env['PYTHON_KEYFILE'] |
Guido van Rossum | 37a2911 | 1995-06-21 00:55:59 +0000 | [diff] [blame] | 8 | else: |
| 9 | keyfile = '.python_keyfile' |
Guido van Rossum | 541df3e | 1995-06-21 02:08:55 +0000 | [diff] [blame] | 10 | if env.has_key('HOME'): |
| 11 | keyfile = os.path.join(env['HOME'], keyfile) |
Guido van Rossum | 37a2911 | 1995-06-21 00:55:59 +0000 | [diff] [blame] | 12 | try: |
| 13 | self._key = eval(open(keyfile).readline()) |
| 14 | except IOError: |
| 15 | raise IOError, "python keyfile %s not found" % keyfile |
| 16 | |
| 17 | def _generate_challenge(self): |
| 18 | import whrandom |
| 19 | return whrandom.randint(100, 100000) |
| 20 | |
| 21 | def _compare_challenge_response(self, challenge, response): |
| 22 | return self._encode_challenge(challenge) == response |
| 23 | |
| 24 | def _encode_challenge(self, challenge): |
| 25 | p, m = self._key |
Guido van Rossum | 541df3e | 1995-06-21 02:08:55 +0000 | [diff] [blame] | 26 | return pow(long(challenge), p, m) |