SRPTools

1.0.1 · active · verified Thu Apr 16

SRPTools is a Python library designed for implementing Secure Remote Password (SRP) authentication, a robust password-authenticated key agreement protocol (PAKE). It provides tools for both client and server sides to perform secure password-based authentication and key exchange over an insecure network. The current version is 1.0.1, with an infrequent release cadence indicating a stable and mature codebase.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a full SRP-6a authentication flow between a client and a server using `srptools`. It covers the generation of salt and verifier, public key exchange, and session key derivation and verification. Remember to handle `SRPException` in a real application.

from srptools import SRPContext, SRPServerSession, SRPClientSession

# User credentials
username = 'alice'
password = 'password123'

# Step 1: Server stores salt and verifier for a user
context = SRPContext(username, password)
salt, verifier = context.create_salted_verification_key()
print(f"Server stores -> Salt: {salt}, Verifier: {verifier}")

# --- Client side operations ---
client_session = SRPClientSession(context)
client_public_key = client_session.start_authentication()
print(f"Client sends -> Public Key A: {client_public_key}")

# --- Server side operations ---
# Server retrieves stored salt and verifier for the username
server_session = SRPServerSession(context, salt, verifier)
server_public_key = server_session.start_authentication(client_public_key)
print(f"Server sends -> Public Key B: {server_public_key}")

# --- Client side operations (receives B from server) ---
client_key = client_session.process(server_public_key)
print(f"Client computed -> Session Key K: {client_key}")
print(f"Client sends -> Proof M: {client_session.M}")

# --- Server side operations (receives Client Proof M from client) ---
server_key = server_session.process(client_session.M)
print(f"Server computed -> Session Key K: {server_key}")

# Verify client proof on server
if client_session.M == server_session.M:
    print("Server: Client proof (M) matches. Authentication in progress.")
    # Verify session keys match
    if client_session.K == server_session.K:
        print("Server: Session keys (K) match. Authentication successful.")
    else:
        print("Server Error: Session keys do not match.")
else:
    print("Server Error: Client proof (M) does not match.")

# Server sends its proof (HAMK) to the client
print(f"Server sends -> Proof HAMK: {server_session.HAMK}")

# --- Client side operations (receives Server Proof HAMK from server) ---
if client_session.verify_session(server_session.HAMK):
    print("Client: Server proof (HAMK) verified. Mutual authentication complete.")
else:
    print("Client Error: Server proof (HAMK) verification failed.")

view raw JSON →