Skip to main content

Tools to implement Secure Remote Password (SRP) authentication

Project description

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

srptools-0.1.1.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

srptools-0.1.1-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file srptools-0.1.1.tar.gz.

File metadata

  • Download URL: srptools-0.1.1.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for srptools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 80c76b5f422bdce1c87eaf2fbcb2c2e43974085a1d758cb9195438ee6b8ca0cb
MD5 811c38f3e45039a8973cc6820d3ce94f
BLAKE2b-256 d2194d9beec46e82d17249517291d0564c9eb6773c51015c278fef97312e63e3

See more details on using hashes here.

File details

Details for the file srptools-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for srptools-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0e4550e4098d101d274e952820864a95991c83abdf9caf59765f084e342407d5
MD5 46da018ac55487f5990875ee2ce6ba6f
BLAKE2b-256 4773b0fac93e0650139888e85dc26d35f140b982c74a99d0895423fa10845641

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page