MCPcopy Index your code
hub / github.com/RustPython/RustPython / _verify_challenge

Function _verify_challenge

Lib/multiprocessing/connection.py:903–925  ·  view source on GitHub ↗

Verify MAC challenge If our message did not include a digest_name prefix, the client is allowed to select a stronger digest_name from _ALLOWED_DIGESTS. In case our message is prefixed, a client cannot downgrade to a weaker algorithm, because the MAC is calculated over the entire me

(authkey, message, response)

Source from the content-addressed store, hash-verified

901
902
903def _verify_challenge(authkey, message, response):
904 """Verify MAC challenge
905
906 If our message did not include a digest_name prefix, the client is allowed
907 to select a stronger digest_name from _ALLOWED_DIGESTS.
908
909 In case our message is prefixed, a client cannot downgrade to a weaker
910 algorithm, because the MAC is calculated over the entire message
911 including the '{digest_name}' prefix.
912 """
913 import hmac
914 response_digest, response_mac = _get_digest_name_and_payload(response)
915 response_digest = response_digest or 'md5'
916 try:
917 expected = hmac.new(authkey, message, response_digest).digest()
918 except ValueError:
919 raise AuthenticationError(f'{response_digest=} unsupported')
920 if len(expected) != len(response_mac):
921 raise AuthenticationError(
922 f'expected {response_digest!r} of length {len(expected)} '
923 f'got {len(response_mac)}')
924 if not hmac.compare_digest(expected, response_mac):
925 raise AuthenticationError('digest received was wrong')
926
927
928def deliver_challenge(connection, authkey: bytes, digest_name='sha256'):

Callers 1

deliver_challengeFunction · 0.85

Calls 6

AuthenticationErrorClass · 0.85
lenFunction · 0.85
compare_digestMethod · 0.80
digestMethod · 0.45
newMethod · 0.45

Tested by

no test coverage detected