Beispiel #1
0
 def srp_auth(self, s):
     socket = self.socket[s]
     assert socket['state'] == 0 or socket['state'] == 3
     srp = socket['srp'] = {}
     srp['keys'] = SRP.client_begin()
     self._send_msg(s, {'op': 'srp auth', 'user': self.co.user, 'A': srp['keys'][0]})
     socket['state'] = 1
     self.rs.listen_forever(self.nh)
     self.rs.doneflag.clear()
Beispiel #2
0
 def srp_auth(self, s):
     socket = self.socket[s]
     assert socket['state'] == 0 or socket['state'] == 3
     srp = socket['srp'] = {}
     srp['keys'] = SRP.client_begin()
     self._send_msg(s, {
         'op': 'srp auth',
         'user': self.co.user,
         'A': srp['keys'][0]
     })
     socket['state'] = 1
     self.rs.listen_forever(self.nh)
     self.rs.doneflag.clear()
Beispiel #3
0
def SRPAuth(sock, user, passphrase = None):
    """Perform an SRP authentication on a socket.  Return the session key
    if authentication was successful, or raise an exception if it was not.
    The other end of the socket must be ready to receive the SRP
    commands."""

    if not passphrase:
	passphrase = getpass.getpass('Enter passphrase for %s: ' % user)

    # Send the USER command.

    sock.send('USER %s\n' % user)

    # Get the client-side keys and send the public one.

    keys = SRP.client_begin(user)
    A = keys[0]
    sock.send(encode_long(A))

    # Read the response.

    file = sock.makefile('rb')
    line = file.readline()
    if line[0:3] != 'KEY':
	raise SRP.NoSuchUser, line
    s = read_string(file)
    B = read_long(file)
    u = read_long(file)

    # Now calculate the session key and send the proof.

    K, m = SRP.client_key(user, passphrase, s, B, u, keys)
    sock.send(encode_string(m))
    line = file.readline()
    if line[0:3] != 'AOK':
	raise SRP.AuthFailure, line

    # Authenticate the host.

    m1 = SRP.host_authenticator(K, A, m)
    m = read_string(file)
    if m != m1:
	raise SRP.AuthFailure, "Host authentication failed."

    # All done, return the session key.

    return K
Beispiel #4
0
def SRPAuth(sock, user, passphrase=None):
    """Perform an SRP authentication on a socket.  Return the session key
    if authentication was successful, or raise an exception if it was not.
    The other end of the socket must be ready to receive the SRP
    commands."""

    if not passphrase:
        passphrase = getpass.getpass('Enter passphrase for %s: ' % user)

    # Send the USER command.

    sock.send('USER %s\n' % user)

    # Get the client-side keys and send the public one.

    keys = SRP.client_begin(user)
    A = keys[0]
    sock.send(encode_long(A))

    # Read the response.

    file = sock.makefile('rb')
    line = file.readline()
    if line[0:3] != 'KEY':
        raise SRP.NoSuchUser, line
    s = read_string(file)
    B = read_long(file)
    u = read_long(file)

    # Now calculate the session key and send the proof.

    K, m = SRP.client_key(user, passphrase, s, B, u, keys)
    sock.send(encode_string(m))
    line = file.readline()
    if line[0:3] != 'AOK':
        raise SRP.AuthFailure, line

    # Authenticate the host.

    m1 = SRP.host_authenticator(K, A, m)
    m = read_string(file)
    if m != m1:
        raise SRP.AuthFailure, "Host authentication failed."

    # All done, return the session key.

    return K