Skip to main content

srptools

https://github.com/idlesign/srptools

release stats lic ci coverage health

Description

Tools to implement Secure Remote Password (SRP) authentication

SRP is a secure password-based authentication and key-exchange protocol - a password-authenticated key agreement protocol (PAKE).

This package contains protocol implementation for Python 2 and 3.

You may import it into you applications and use its API or you may use srptools command-line utility (CLI):

CLI usage

Command-line utility requires click package to be installed.

Basic scenario:

> srptools get_user_data_triplet
> srptools server get_private_and_public
> srptools client get_private_and_public
> srptools client get_session_data
> srptools server get_session_data

Help is available:

> srptools --help

API usage

Preliminary step. Agree on communication details:

from srptools import SRPContext

context = SRPContext('alice', 'password123')
username, password_verifier, salt = context.get_user_data_triplet()
prime = context.prime
gen = context.generator

Simplified workflow:

from srptools import SRPContext, SRPServerSession, SRPClientSession

# Receive username from client and generate server public.
server_session = SRPServerSession(SRPContext(username, prime=prime, generator=gen), password_verifier)
server_public = server_session.public

# Receive server public and salt and process them.
client_session = SRPClientSession(SRPContext('alice', 'password123', prime=prime, generator=gen))
client_session.process(server_public, salt)
# Generate client public and session key.
client_public = client_session.public

# Process client public and compare session keys.
server_session.process(client_public, salt)

assert server_session.key == client_session.key

Extended workflow

from srptools import SRPContext, SRPServerSession, SRPClientSession

# Receive username from client and generate server public.
server_session = SRPServerSession(SRPContext(username, prime=prime, generator=gen), password_verifier)
server_public = server_session.public

# Receive server public and salt and process them.
client_session = SRPClientSession(SRPContext('alice', 'password123', prime=prime, generator=gen))
client_session.process(server_public, salt)
# Generate client public and session key proof.
client_public = client_session.public
client_session_key_proof = client_session.key_proof

# Process client public and verify session key proof.
server_session.process(client_public, salt)
assert server_session.verify_proof(client_session_key_proof)
# Generate session key proof hash.
server_session_key_proof_hash = client_session.key_proof_hash

# Verify session key proof hash received from server.
assert client_session.verify_proof(server_session_key_proof_hash)

Usage hints

  • srptools.constants contains basic constants which can be used with SRPContext for server and client to agree upon communication details.

  • .process() methods of session classes may raise SRPException in certain circumstances. Auth process on such occasions must be stopped.

  • .private attribute of session classes may be used to restore sessions:
    server_private = server_session.private
    
    # Restore session on new request.
    server_session = SRPServerSession(context, password_verifier, private=server_private)
  • SRPContext is rather flexible, so you can implement some custom server/client session logic with its help.

  • Basic values are represented as hex strings but base64 encoded values are also supported:

    server_public = server_session.public_b64
    
    # Receive server public and salt and process them.
    client_session = SRPClientSession(SRPContext('alice', 'password123', prime=prime, generator=gen))
    client_session.process(server_public, salt, base64=True)
    
    # Use srptools.hex_from_b64() to represent base64 value as hex.
    server_public_hex = hex_from_b64(server_public)

Metadata

Release files for srptools 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for srptools 0.2.0
File Size Uploaded Provenance
srptools-0.2.0.tar.gz 15.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for srptools 0.2.0
File Interpreter ABI Platform
srptools-0.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 29.6 kB

Release files / srptools-0.2.0.tar.gz

Download URL srptools-0.2.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
675c041b575b60a85fb91fbfa190660d5afc9c366f8cf57ad97c344bd76c123c
BLAKE2b-256 checksum
How to use checksums
9b4424fb65f5cc26ebefd472e0d344578e5d125fc4ff4d96831a0e25072ff9b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / srptools-0.2.0-py2.py3-none-any.whl

Download URL srptools-0.2.0-py2.py3-none-any.whl
Size 14.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4f8014ff8cd71a18d9f52feaa730ac27fae5b5bb161c2b57d103026f91d36828
BLAKE2b-256 checksum
How to use checksums
d0fef5cf417857404c3b797cb3a8fc43967145686a921e491980cdd4ff505408
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for srptools 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page