autobahn.wamp.auth¶
Classes¶
Implements "wamp-scram" authentication for components. |
|
Functions¶
|
Check a TOTP value received from a principal trying to authenticate against |
|
Computes the current TOTP code. |
|
Compute an WAMP-CRA authentication signature from an authentication |
|
Accepts various keys and values to configure an authenticator. The |
|
Computes a derived cryptographic key from a password according to PBKDF2. |
|
Derive WAMP-SCRAM credentials from user email and password. The SCRAM parameters used |
|
Generates a new Base32 encoded, random secret. |
|
Generates a new random secret for use with WAMP-CRA. |
|
Returns a binary digest for the PBKDF2 hash algorithm of |
|
Module Contents¶
- class AuthScram(**kw)[source]¶
Bases:
objectImplements “wamp-scram” authentication for components.
NOTE: This is a prototype of a draft spec; see https://github.com/wamp-proto/wamp-proto/issues/135
- check_totp(secret, ticket)[source]¶
Check a TOTP value received from a principal trying to authenticate against the expected value computed from the secret shared between the principal and the authenticating entity.
The Internet can be slow, and clocks might not match exactly, so some leniency is allowed. RFC6238 recommends looking an extra time step in either direction, which essentially opens the window from 30 seconds to 90 seconds.
- Parameters:
secret (unicode) – The secret shared between the principal (eg a client) that is authenticating, and the authenticating entity (eg a server).
ticket (unicode) – The TOTP value to be checked.
- Returns:
Trueif the TOTP value is correct, elseFalse.- Return type:
- compute_totp(secret, offset=0)[source]¶
Computes the current TOTP code.
- Parameters:
secret (unicode) – Base32 encoded secret.
offset (int) – Time offset (in steps, use eg -1, 0, +1 for compliance with RFC6238) for which to compute TOTP.
- Returns:
TOTP for current time (+/- offset).
- Return type:
unicode
- compute_wcs(key, challenge)[source]¶
Compute an WAMP-CRA authentication signature from an authentication challenge and a (derived) key.
- create_authenticator(name, **kwargs)[source]¶
Accepts various keys and values to configure an authenticator. The valid keys depend on the kind of authenticator but all can understand: authextra, authid and authrole
- Returns:
an instance implementing IAuthenticator with the given configuration.
- derive_key(secret, salt, iterations=1000, keylen=32)[source]¶
Computes a derived cryptographic key from a password according to PBKDF2.
See also
- derive_scram_credential(email: str, password: str, salt: bytes | None = None) Dict[source]¶
Derive WAMP-SCRAM credentials from user email and password. The SCRAM parameters used are the following (these are also contained in the returned credentials):
kdf
argon2id-13time cost
4096memory cost
512parallelism
1
See draft-irtf-cfrg-argon2 and argon2-cffi.
- Parameters:
email – User email.
password – User password.
salt – Optional salt to use (must be 16 bytes long). If none is given, compute salt from email as
salt = SHA256(email)[:16].
- Returns:
WAMP-SCRAM credentials. When serialized, the returned credentials can be copy-pasted into the
config.jsonnode configuration for a Crossbar.io node.
- generate_totp_secret(length=10)[source]¶
Generates a new Base32 encoded, random secret.
See also
- Parameters:
length (int) – The length of the entropy used to generate the secret.
- Returns:
The generated secret in Base32 (letters
A-Zand digits2-7). The length of the generated secret islength * 8 / 5octets.- Return type:
unicode
- generate_wcs(length=14)[source]¶
Generates a new random secret for use with WAMP-CRA.
The secret generated is a random character sequence drawn from
upper and lower case latin letters
digits
- pbkdf2(data, salt, iterations=1000, keylen=32, hashfunc=None)[source]¶
Returns a binary digest for the PBKDF2 hash algorithm of
datawith the givensalt. It iteratesiterationstime and produces a key ofkeylenbytes. By default SHA-256 is used as hash function, a different hashlibhashfunccan be provided.- Parameters:
data (bytes) – The data for which to compute the PBKDF2 derived key.
salt (bytes) – The salt to use for deriving the key.
iterations (int) – The number of iterations to perform in PBKDF2.
keylen (int) – The length of the cryptographic key to derive.
hashfunc (str) – Name of the hash algorithm to use
- Returns:
The derived cryptographic key.
- Return type: