mirror of https://github.com/python/cpython
security stuff added
This commit is contained in:
parent
37a291180c
commit
45babef8c2
|
@ -120,6 +120,23 @@ class Client:
|
||||||
self._wf.flush()
|
self._wf.flush()
|
||||||
|
|
||||||
|
|
||||||
|
from security import Security
|
||||||
|
|
||||||
|
|
||||||
|
class SecureClient(Client, Security):
|
||||||
|
|
||||||
|
def __init__(self, *args):
|
||||||
|
import string
|
||||||
|
apply(Client.__init__, (self,) + args)
|
||||||
|
Security.__init__(self)
|
||||||
|
line = self._rf.readline()
|
||||||
|
challenge = string.atoi(string.strip(firstline))
|
||||||
|
response = self._encode_challenge(challenge)
|
||||||
|
line = `long(response)`
|
||||||
|
if line[-1] in 'Ll': line = line[:-1]
|
||||||
|
self._wf.write(line + '\n')
|
||||||
|
self._wf.flush()
|
||||||
|
|
||||||
class _stub:
|
class _stub:
|
||||||
|
|
||||||
"""Helper class for Client -- each instance serves as a method of the client."""
|
"""Helper class for Client -- each instance serves as a method of the client."""
|
||||||
|
|
|
@ -109,3 +109,36 @@ class Server:
|
||||||
basenames = filter(lambda x, names=names: x not in names, basenames)
|
basenames = filter(lambda x, names=names: x not in names, basenames)
|
||||||
names[len(names):] = basenames
|
names[len(names):] = basenames
|
||||||
return names
|
return names
|
||||||
|
|
||||||
|
|
||||||
|
from security import Security
|
||||||
|
|
||||||
|
|
||||||
|
class SecureServer(Server, Security):
|
||||||
|
|
||||||
|
def __init__(self, *args):
|
||||||
|
apply(Server.__init__, (self,) + args)
|
||||||
|
Security.__init__(self)
|
||||||
|
|
||||||
|
def _verify(self, conn, address):
|
||||||
|
challenge = self._generate_challenge()
|
||||||
|
conn.send("%d\n" % challenge)
|
||||||
|
response = ""
|
||||||
|
while "\n" not in response and len(response) < 100:
|
||||||
|
data = conn.recv(100)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
response = response + data
|
||||||
|
try:
|
||||||
|
response = string.atol(string.strip(response))
|
||||||
|
except string.atol_error:
|
||||||
|
if self._verbose > 0:
|
||||||
|
print "Invalid response syntax", `response`
|
||||||
|
return 0
|
||||||
|
if not self._compare_challenge_response(challenge, response):
|
||||||
|
if self._verbose > 0:
|
||||||
|
print "Invalid response value", `response`
|
||||||
|
return 0
|
||||||
|
if self._verbose > 1:
|
||||||
|
print "Response matches challenge. Go ahead!"
|
||||||
|
return 1
|
||||||
|
|
Loading…
Reference in New Issue