HMAC Helpers¶
Module: s2auth.common.hmac
CHARS = string.ascii_lowercase + string.ascii_uppercase + string.digits
module-attribute
¶
_ALGORITHM_MAP = OrderedDict([(HmacHashingAlgorithm.SHA256, hashlib.sha256)])
module-attribute
¶
LOGGER = logging.getLogger(__name__)
module-attribute
¶
PairingToken = Annotated[str, StringConstraints(pattern='^[A-Za-z0-9+/]{4,}={0,2}$', min_length=4)]
module-attribute
¶
_ALL_UTF8_CHARS = [(chr(i)) for i in (range(1114112)) if not 55296 <= i <= 57343]
module-attribute
¶
IncompatibleHmacHashingAlgorithms
¶
Bases: S2ConnectError
Raised when no common HMAC hashing algorithm is found
Source code in src/s2auth/common/exceptions.py
VerificationError
¶
HmacChallenge
¶
Bases: RootModel[Base64Bytes]
Source code in src/s2auth/common/model/s2_connect_pairing.py
HmacHashingAlgorithm
¶
AccessToken
¶
Bases: RootModel[Base64Bytes]
Source code in src/s2auth/common/model/s2_connect_common.py
Deployment
¶
_get_hashing_algorithm(algorithm)
¶
Source code in src/s2auth/common/hmac.py
create_pairing_code(s2_node_id=None, length=9)
¶
Create pairing code, which is [pairing S2 node ID]-[pairing token] if the S2 node id is set otherwise just the token
Source code in src/s2auth/common/hmac.py
create_challenge(length=128)
¶
Create the base64 encoded challenge (sequence of random bytes) to be sent to the other side of the connection. The challenge needs to be passed to the the other side of the connection, who should sign it with a shared pairing token. verify_response can then be used to verify that signature.
Source code in src/s2auth/common/hmac.py
generate_access_token()
¶
get_supported_algorithms()
¶
select_algorithm(node_algorithms)
¶
Source code in src/s2auth/common/hmac.py
calculate_certificate_fingerprint(cert_der)
¶
_leaf_certificate_bytes(certificate_bytes)
¶
Return leaf certificate bytes from a cert file payload.
For PEM chain files this extracts and converts the first certificate block (the leaf) to DER bytes. For non-PEM inputs, bytes are returned unchanged.
Source code in src/s2auth/common/hmac.py
calculate_certificate_fingerprint_from_certificate_file(certificate_file)
¶
Read a certificate file and return the SHA-256 fingerprint of the leaf certificate.
Source code in src/s2auth/common/hmac.py
calculate_fingerprint_from_response_certificate(response)
¶
Source code in src/s2auth/common/hmac.py
create_response(pairing_token, challenge, deployment, domain_name, fingerprint, algorithm=HmacHashingAlgorithm.SHA256)
¶
Source code in src/s2auth/common/hmac.py
hmac_response_lan(pairing_token, challenge, fingerprint, digestmod)
¶
Source code in src/s2auth/common/hmac.py
hmac_response_wan(pairing_token, challenge, domain_name, digestmod)
¶
Source code in src/s2auth/common/hmac.py
verify_response(pairing_token, challenge, response, deployment, domain_name, fingerprint, algorithm=HmacHashingAlgorithm.SHA256)
¶
Verify that a received challenge response signature for correctness based on pairing token and algorithm.