Skip to main content

B-first SRP-6a protocol implementation

Project description

bsrp

bsrp is a python implementation of the secure remote password protocol (SRP-6a). This library enables a login flow in which the server provides the public value B before the client reveals its own public value A. This enables a little bit cleaner of a login flow. This library is designed for server-side use, with a mock client side library included for testing and reference for frontend use. bsrp has a sister library with the same name implemented in javascript here.

Usage

The following example (taken from the test suite) showcases the flow of data between the client and the server to achieve login authentication.

from bsrp.client import (
    generate_a_pair,
    process_challenge,
    verify_session as client_verify_session,
)
from bsrp.server import (
    generate_b_pair,
    generate_salt_and_verifier,
    verify_session as server_verify_session,
)

identity = "test"
password = "#yoloswag"

# A user is initiated with a set identity and password
salt, verifier = generate_salt_and_verifier(identity, password)

# The user initiates the login process by sending the identity
# to the server. Using the verifier and salt, the server calculates
# and calculates public value B
b, B = generate_b_pair(verifier)

# Using the salt and public value B, the client generates
# message M to prove to the serve that the password is correct.
a, A = generate_a_pair()
M, session_key = process_challenge(identity, password, salt, a, A, B)

# The server then verifies the session and generates an evidence
# key H_AMK for the client to use for mutual authentication.
server_H_AMK = server_verify_session(identity, salt, verifier, A, b, M)

assert server_H_AMK is not None

# The client then calculates its own H_AMK to verify the server
# is legit.
client_H_AMK = client_verify_session(A, M, session_key, server_H_AMK)

assert client_H_AMK is not None

# Authentication success
assert server_H_AMK == client_H_AMK

Functions

Utils

SafetyException: Raised if SRP-6a safety checks fail

_get_srp_prime(): Returns integer value of the 2048-bit SRP prime

Note: you may set your own prime by overriding this method

_get_srp_generator(): Returns integer value of the generator used to generate the SRP prime

_generate_random_bytes(length: int): Returns cryptographically random bytes

_to_bytes(obj: Any): Converts object to bytes

_to_int(obj: Any): Converts object to integer

_pad(obj: Any, length: int): Returns left padded byte-string representation of number

_Hash(*args): Returns hash of concatenated argument objects

_calculate_x(salt: bytes, identity: str, password: str): Returns the calculated user secret parameter x

_calculate_M(generator: int, prime: int, identity: str, salt: bytes, A: int, B: int, session_key: bytes): Returns the calculated evidence message M

Server

MessageException: raised when the message from the client does not match.

generate_salt_and_verifier(identity: str, password: str) Returns a tuple of the salt and verification key

generate_b_pair(verifier: int): Returns private ephemeral b for later use and public value B for the client

verify_session(identity: str, salt: bytes, verifier: int, A: int, b: int,M_client: bytes): Returns None if session is invalid, evidence key if message from client is valid

Client

EvidenceException: raised when server evidence key does not match

generate_a_pair(): Returns tuple of private ephemeral a and public value A

process_challenge(identity: str, password: str, salt: bytes, a: int, A: int, B: int): Returns tuple of message and private strong session key

verify_session(A: int, M: bytes, session_key: bytes, server_H_AMK: bytes): Returns None if session is invalid, evidence key if the server was mutually authenticated

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

bsrp-1.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bsrp-1.0.1-py3.7.egg (13.4 kB view details)

Uploaded Egg

bsrp-1.0.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file bsrp-1.0.1.tar.gz.

File metadata

  • Download URL: bsrp-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.7

File hashes

Hashes for bsrp-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a6a1ca310cdf24c3fd293988cc4f939fcf76e0c2b676a8de1dcb6e5543a040e4
MD5 0b6e6c09eafb5d023f64dcc554cf63c6
BLAKE2b-256 c65fa66747c7e61f73930a618b0a30bcf2beb5747af5f4f36c9a67b82a981384

See more details on using hashes here.

File details

Details for the file bsrp-1.0.1-py3.7.egg.

File metadata

  • Download URL: bsrp-1.0.1-py3.7.egg
  • Upload date:
  • Size: 13.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.7

File hashes

Hashes for bsrp-1.0.1-py3.7.egg
Algorithm Hash digest
SHA256 d7459d991c24d5039cbe04289b3f1e5e1d8952d1265995499a74cfe6b9d4924a
MD5 e3cc1ee478b3044029c811dc793931f8
BLAKE2b-256 a6f5eb3ac10de08e3f6c73916d3c5c9a20bbeac79e816106779c35be795432b0

See more details on using hashes here.

File details

Details for the file bsrp-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: bsrp-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.7

File hashes

Hashes for bsrp-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e011f64f46700018f9b0d4790a3966c33db03141bae91433cdb946645a490b04
MD5 4c600e631ab8a34d6a395ed400312e32
BLAKE2b-256 9de42a698f61118dd275f07651cbff65e77bdc7b294e3c2d12e09f2a3c4c4aed

See more details on using hashes here.

Supported by

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