license: validate via key instance rather than PEM
This commit is contained in:
parent
2b00c644b5
commit
ae16d24fd1
2 changed files with 19 additions and 11 deletions
|
@ -107,6 +107,7 @@ class License(object):
|
|||
|
||||
LICENSE_FILENAME = 'license'
|
||||
|
||||
|
||||
_PROD_LICENSE_PUBLIC_KEY_DATA = """
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuCkRnkuqox3A0djgRnHR
|
||||
|
@ -119,10 +120,13 @@ qwIDAQAB
|
|||
-----END PUBLIC KEY-----
|
||||
"""
|
||||
|
||||
def decode_license(license_contents, public_key_contents=None):
|
||||
|
||||
_PROD_LICENSE_PUBLIC_KEY = load_pem_public_key(_PROD_LICENSE_PUBLIC_KEY_DATA,
|
||||
backend=default_backend())
|
||||
|
||||
def decode_license(license_contents, public_key_instance=None):
|
||||
""" Decodes the specified license contents, returning the decoded license. """
|
||||
public_key_data = public_key_contents or _PROD_LICENSE_PUBLIC_KEY_DATA
|
||||
license_public_key = load_pem_public_key(public_key_data, backend=default_backend())
|
||||
license_public_key = public_key_instance or _PROD_LICENSE_PUBLIC_KEY
|
||||
try:
|
||||
decoded = jwt.decode(license_contents, key=license_public_key)
|
||||
except jwt.exceptions.DecodeError as de:
|
||||
|
@ -130,5 +134,3 @@ def decode_license(license_contents, public_key_contents=None):
|
|||
raise LicenseDecodeError('Could not decode license found: %s' % de.message)
|
||||
|
||||
return License(decoded)
|
||||
|
||||
|
||||
|
|
Reference in a new issue