Exemple #1
0
def simple_srp(email, client_share, client_sock):
    # try and receive msg from pipe
    b = secrets.randbelow(CP36.MODPGROUP["1536"])
    salt, v = server_user_list[email]
    
    g_with_b = GroupOp.mod_exp(CP36.GENERATOR, b, CP36.MODPGROUP["1536"])
    u = secrets.randbelow(2**128)
    server_msg = "({},{},{})".format(salt, g_with_b, u)
    
    if not net_utils.send_msg(server_msg, client_sock):
        raise ValueError("Failed writing to pipe")

    client_hmac_val = net_utils.receive_msg(client_sock)

    total = GroupOp.mod_exp(v,u, CP36.MODPGROUP["1536"])
    total = (total *  client_share) % CP36.MODPGROUP["1536"]
    total = GroupOp.mod_exp(total, b, CP36.MODPGROUP["1536"])
    key_digest = sha256.SHA256()
    key_digest.Update(bytes("{}".format(total), encoding='utf-8'))
    actual_key = (key_digest.Sum()).to_bytes(256 // 8,byteorder='big')

    check_against = hmac_myimpl.SHA256_HMAC(actual_key, salt)

    # this comparison is very insecure
    if client_hmac_val == check_against:
        return True
    else:
        return False
    return
Exemple #2
0
def client():
    client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client_sock.connect((HOST, PROTOCOL))
    # generate a needed for diffie hellman
    a = secrets.randbelow(MODPGROUP["1536"])
    g_with_a = GroupOp.mod_exp(GENERATOR, a, MODPGROUP["1536"])
    if not net_utils.send_msg("({},{})".format(g_with_a, EMAIL), client_sock):
        raise ValueError("Failed to send message")
    message_received = net_utils.receive_msg(client_sock)

    msg_ints = literal_eval(message_received.decode('utf-8'))
    salt = msg_ints[0]
    b_value = msg_ints[1]
    sha_pw_digest = sha256.SHA256()
    sha_pw_digest.Update(
        bytes("{}||{}".format(salt, PASSWORD), encoding='utf-8'))
    x_exp = sha_pw_digest.Sum()
    u_digest = sha256.SHA256()
    u_digest.Update(bytes("{}||{}".format(g_with_a, b_value),
                          encoding='utf-8'))
    u = u_digest.Sum()

    v_value = GroupOp.mod_exp(GENERATOR, x_exp, MODPGROUP["1536"])
    total = (b_value - (K * v_value)) % MODPGROUP["1536"]
    total = GroupOp.mod_exp(total, a + (x_exp * u), MODPGROUP["1536"])

    key_digest = sha256.SHA256()
    key_digest.Update(bytes("{}".format(total), encoding='utf-8'))
    actual_key = (key_digest.Sum()).to_bytes(256 // 8, byteorder='big')
    verification_check = hmac_myimpl.SHA256_HMAC(actual_key, salt)
    if not net_utils.send_msg(verification_check, client_sock):
        raise ValueError("Could not send over pipe")
Exemple #3
0
def generate_v(salt, password):
    sha256_string = sha256.SHA256()
    salt_hash_concat = "{}||{}".format(salt, password)
    sha256_string.Update(bytes(salt_hash_concat, encoding='utf-8'))
    x = sha256_string.Sum()
    # this is a random numerical value -- not a string although it should be one
    v = GroupOp.mod_exp(GENERATOR, x, MODPGROUP["1536"])
    return v
Exemple #4
0
def client(email, password, new_user=False):
    client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    client_sock.connect((HOST,PROTOCOL))

    if new_user:
        msg = "CREATE_PASSWORD:({},{})".format(email, password)
        if not net_utils.send_msg(msg, client_sock):
            raise ValueError("Failed to send message")

        # wait to receive a SUCCESSFUL from the server
        server_reply = (net_utils.receive_msg(client_sock)).decode('utf-8')
        if server_reply != "SUCCESS":
            raise ValueError("Could not create account")
        else:
            print("Successfully created account")
    else:
        # generate a needed for diffie hellman
        a = secrets.randbelow(CP36.MODPGROUP["1536"])
        g_with_a = GroupOp.mod_exp(CP36.GENERATOR, a, CP36.MODPGROUP["1536"])
        if not net_utils.send_msg("AUTH_ATTEMPT:({},{})".format(g_with_a, email),client_sock):
            raise ValueError("Failed to send message")
        message_received = net_utils.receive_msg(client_sock)
         
        msg_ints = literal_eval(message_received.decode('utf-8'))
        salt = msg_ints[0]
        b_value = msg_ints[1]
        u = msg_ints[2]
        sha_pw_digest = sha256.SHA256()
        sha_pw_digest.Update(bytes("{}||{}".format(salt, password), encoding='utf-8'))
        x_exp = sha_pw_digest.Sum()
       
        total = GroupOp.mod_exp(b_value, a + (x_exp * u), CP36.MODPGROUP["1536"])

        key_digest = sha256.SHA256()
        key_digest.Update(bytes("{}".format(total), encoding='utf-8'))
        actual_key = (key_digest.Sum()).to_bytes(256 // 8,byteorder='big')
        verification_check = hmac_myimpl.SHA256_HMAC(actual_key, salt)
        if not net_utils.send_msg(verification_check, client_sock):
            raise ValueError("Could not send over pipe")
        msg = (net_utils.receive_msg(client_sock)).decode('utf-8')
        print("Server says {}".format(msg))
        print("Finishing client thread")

    return
Exemple #5
0
def server_srp(client_sock, email_held, salt, v_held):
    # try and receive msg from pipe
    b = secrets.randbelow(MODPGROUP["1536"])
    client_msg = (net_utils.receive_msg(client_sock)).decode('utf-8')
    args = client_msg.split(",")
    email = args[1][:-1]
    client_key_share = int(args[0][1:])

    if email == email_held:
        g_with_b = GroupOp.mod_exp(GENERATOR, b, MODPGROUP["1536"])
        maskedv = (K * v_held + g_with_b) % MODPGROUP["1536"]
        server_msg = "({},{})".format(salt, maskedv)
    else:
        print("Server received wrong email identifier")
        server_msg = "ERROR"

    if not net_utils.send_msg(server_msg, client_sock):
        raise ValueError("Failed writing to pipe")
    client_hmac_val = net_utils.receive_msg(client_sock)
    #compute local
    u_hash = sha256.SHA256()
    u_hash.Update(
        bytes("{}||{}".format(client_key_share, maskedv), encoding='utf-8'))
    u = u_hash.Sum()

    total = GroupOp.mod_exp(v_held, u, MODPGROUP["1536"])
    total = (total * client_key_share) % MODPGROUP["1536"]
    total = GroupOp.mod_exp(total, b, MODPGROUP["1536"])
    key_digest = sha256.SHA256()
    key_digest.Update(bytes("{}".format(total), encoding='utf-8'))
    actual_key = (key_digest.Sum()).to_bytes(256 // 8, byteorder='big')

    check_against = hmac_myimpl.SHA256_HMAC(actual_key, salt)

    # this comparison is very insecure
    if client_hmac_val == check_against:
        print("{} client succesfully authenticated".format(email_held))
        return True
    else:
        return False
Exemple #6
0
def offline_attack(client_key_share, salt, client_output, pw_dictionary):
    for psw in pw_dictionary:
        sha_pw_digest = sha256.SHA256()
        sha_pw_digest.Update(bytes("{}||{}".format(salt,psw), encoding='utf-8'))
        x_exp = sha_pw_digest.Sum()

        g_to_the_x = GroupOp.mod_exp(CP36.GENERATOR, x_exp, CP36.MODPGROUP["1536"])
        potential_s = (g_to_the_x * client_key_share) % CP36.MODPGROUP["1536"]
        key_digest = sha256.SHA256()
        key_digest.Update(bytes("{}".format(potential_s), encoding='utf-8'))
        actual_key = (key_digest.Sum()).to_bytes(256 // 8,byteorder='big')

        check_against = hmac_myimpl.SHA256_HMAC(actual_key, salt)
        if client_output == check_against:
            return psw
    return None