File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed
Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change 22import hmac
33
44from .compat import constant_time_compare , string_types , text_type
5+ from .exceptions import InvalidAlgorithmError
56
67try :
78 from cryptography .hazmat .primitives import interfaces , hashes
@@ -96,6 +97,12 @@ def prepare_key(self, key):
9697 if isinstance (key , text_type ):
9798 key = key .encode ('utf-8' )
9899
100+ if (b'-----BEGIN PUBLIC KEY-----' in key
101+ or b'-----BEGIN CERTIFICATE-----' in key ):
102+ raise InvalidAlgorithmError (
103+ 'The specified key is an assymetric key or x509 certificate and'
104+ ' should not be used as an HMAC secret.' )
105+
99106 return key
100107
101108 def sign (self , msg , key ):
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ class InvalidAudienceError(InvalidTokenError):
1717class InvalidIssuerError (InvalidTokenError ):
1818 pass
1919
20+ class InvalidAlgorithmError (Exception ):
21+ pass
22+
2023
2124# Compatibility aliases (deprecated)
2225ExpiredSignature = ExpiredSignatureError
You can’t perform that action at this time.
0 commit comments