|
Revision 25457, 1.3 kB
(checked in by exarkun, 8 months ago)
|
Merge hashlib-2763-3
Author: wsanchez, exarkun
Reviewer: exarkun, mwhudson
Fixes: #2763
Replace uses of md5 and sha modules in Twisted with use of a new twisted.python.hashlib
module which transparently uses the new hashlib standard library module if it is available
or falls back to md5 and sha if not.
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
""" |
|---|
| 6 |
Outdated, deprecated functionality related to challenge-based authentication. |
|---|
| 7 |
|
|---|
| 8 |
Seek a solution to your problem elsewhere. This module is deprecated. |
|---|
| 9 |
""" |
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
import random, warnings |
|---|
| 13 |
|
|---|
| 14 |
from twisted.python.hashlib import md5 |
|---|
| 15 |
from twisted.cred.error import Unauthorized |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
def respond(challenge, password): |
|---|
| 19 |
"""Respond to a challenge. |
|---|
| 20 |
This is useful for challenge/response authentication. |
|---|
| 21 |
""" |
|---|
| 22 |
warnings.warn( |
|---|
| 23 |
"twisted.cred.util.respond is deprecated since Twisted 8.3.", |
|---|
| 24 |
category=PendingDeprecationWarning, |
|---|
| 25 |
stacklevel=2) |
|---|
| 26 |
m = md5() |
|---|
| 27 |
m.update(password) |
|---|
| 28 |
hashedPassword = m.digest() |
|---|
| 29 |
m = md5() |
|---|
| 30 |
m.update(hashedPassword) |
|---|
| 31 |
m.update(challenge) |
|---|
| 32 |
doubleHashedPassword = m.digest() |
|---|
| 33 |
return doubleHashedPassword |
|---|
| 34 |
|
|---|
| 35 |
def challenge(): |
|---|
| 36 |
"""I return some random data. |
|---|
| 37 |
""" |
|---|
| 38 |
warnings.warn( |
|---|
| 39 |
"twisted.cred.util.challenge is deprecated since Twisted 8.3.", |
|---|
| 40 |
category=PendingDeprecationWarning, |
|---|
| 41 |
stacklevel=2) |
|---|
| 42 |
crap = '' |
|---|
| 43 |
for x in range(random.randrange(15,25)): |
|---|
| 44 |
crap = crap + chr(random.randint(65,90)) |
|---|
| 45 |
crap = md5(crap).digest() |
|---|
| 46 |
return crap |
|---|