Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.023s · 18MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.020s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SRPContext
✓ from srptools import SRPContext
SRPClientSession
✓ from srptools import SRPClientSession
SRPServerSession
✓ from srptools import SRPServerSession
constants
✓ from srptools import constants
Contains basic constants for SRPContext agreement.
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.")
Errors
Common errors & fixes
srptools.SRPException: Invalid public key 'B'
The client or server exchanged an invalid public key (A or B), or a step in the protocol was out of order, leading to a cryptographic mismatch.
fixReview the order of operations in your SRP authentication flow. Ensure public keys are correctly generated, transmitted, and processed by the respective `start_authentication` and `process` methods. Check that context parameters (username, password, N, g, H) are identical on both client and server up to the point of key exchange.
Authentication Failed: Session keys do not match.
The derived session keys (K) on the client and server sides do not match, indicating a failure in the key exchange or verification process. This could be due to incorrect input parameters (salt, verifier, public keys) or a tampered exchange.
fixDouble-check that the `salt` and `verifier` used by the server correctly correspond to the `username` and `password` used by the client. Ensure that the public keys `A` and `B` are transmitted without modification and that the `process()` methods are called with the correct counterparts. Any mismatch in shared secrets or parameters will cause key divergence.
Upgrade
Version history
1.0.1latest on PyPI · released Sep 12, 2020
Audit
Dependencies
clickoptionalRequired only if using the command-line utility provided with srptools.