本文整理汇总了Python中jwkest.jwk.RSAKey.load_key方法的典型用法代码示例。如果您正苦于以下问题:Python RSAKey.load_key方法的具体用法?Python RSAKey.load_key怎么用?Python RSAKey.load_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jwkest.jwk.RSAKey
的用法示例。
在下文中一共展示了RSAKey.load_key方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cmp_rsa_ec
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def test_cmp_rsa_ec():
_key1 = RSAKey()
_key1.load_key(pem_cert2rsa(CERT))
_key2 = ECKey(**ECKEY)
assert _key1 != _key2
示例2: test_extract_rsa_from_cert_2
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def test_extract_rsa_from_cert_2():
_ckey = pem_cert2rsa(CERT)
_key = RSAKey()
_key.load_key(_ckey)
print(_key)
assert _ckey.n == _key.get_key().n
示例3: test_cmp_rsa
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def test_cmp_rsa():
_key1 = RSAKey()
_key1.load_key(pem_cert2rsa(CERT))
_key2 = RSAKey()
_key2.load_key(pem_cert2rsa(CERT))
assert _key1 == _key2
示例4: test_kspec
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def test_kspec():
_ckey = pem_cert2rsa(CERT)
_key = RSAKey()
_key.load_key(_ckey)
print(_key)
jwk = _key.serialize()
assert jwk["kty"] == "RSA"
assert jwk["e"] == JWK["keys"][0]["e"].encode("utf-8")
assert jwk["n"] == JWK["keys"][0]["n"].encode("utf-8")
示例5: test_cmp_rsa_ec
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def test_cmp_rsa_ec():
_key1 = RSAKey()
_key1.load_key(pem_cert2rsa(CERT))
_key2 = ECKey(**ECKEY)
try:
assert _key1 == _key2
except AssertionError:
pass
else:
assert False
示例6: keybundle_from_local_file
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def keybundle_from_local_file(filename, typ, usage, kid):
if typ.upper() == "RSA":
kb = KeyBundle()
k = RSAKey(kid=kid)
k.load(filename)
k.use = usage[0]
kb.append(k)
for use in usage[1:]:
_k = RSAKey(kid=kid + "1")
_k.use = use
_k.load_key(k.key)
kb.append(_k)
elif typ.lower() == "jwk":
kb = KeyBundle(source=filename, fileformat="jwk", keyusage=usage)
else:
raise UnknownKeyType("Unsupported key type")
return kb
示例7: test_verify_2
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def test_verify_2():
_key = RSAKey()
_key.load_key(pem_cert2rsa(CERT))
assert _key.verify()
示例8: vetting_result
# 需要导入模块: from jwkest.jwk import RSAKey [as 别名]
# 或者: from jwkest.jwk.RSAKey import load_key [as 别名]
def vetting_result():
if not current_app.config.get('FREJA_CALLBACK_X5T_CERT'):
current_app.logger.info('Configuration error: FREJA_CALLBACK_X5T_CERT is not set')
return make_response('Configuration error', 500)
_freja_callback_x5t_cert = current_app.config.get('FREJA_CALLBACK_X5T_CERT')
_freja_callback_x5t_pub_key = RSA.importKey(_freja_callback_x5t_cert)
_freja_callback_rsa_pub_key = RSAKey()
_freja_callback_rsa_pub_key.load_key(_freja_callback_x5t_pub_key)
current_app.logger.debug('flask.request.headers: \'{!s}\''.format(flask.request.headers))
current_app.logger.debug('flask.request.data: \'{!s}\''.format(flask.request.get_data()))
try:
if flask.request.headers['Content-Type'] == 'application/jose':
current_app.logger.info('Received a callback with MIME application/jose')
else:
current_app.logger.info('Received a callback with an invalid MIME: \'{!s}\''
.format(flask.request.headers['Content-Type']))
return make_response('Invalid MIME', 400)
except KeyError:
current_app.logger.info('Received a callback without a MIME')
return make_response('No MIME specified', 400)
try:
data = flask.request.get_json(force=True)
except:
current_app.logger.info('Invalid verisec callback: missing or invalid JSON')
return make_response('missing or invalid JSON', 400)
if not data:
current_app.logger.info('Invalid verisec callback: no JSON data provided')
return make_response('Missing JSON data', 400)
ia_response_data = data.get('iaResponseData')
if not ia_response_data:
current_app.logger.info('Missing iaResponseData in verisec callback: \'{!s}\''.format(data))
return make_response('Missing iaResponseData', 400)
current_app.logger.info('Received verisec iaResponseData: \'{!s}\''.format(ia_response_data))
jws_parts = ia_response_data.split('.')
# A correctly formatted JWS is made up of 3 parts
if len(jws_parts) != 3:
current_app.logger.info('iaResponseData response doesn\'t seems to be a JWS')
return make_response('iaResponseData is not a JWS', 400)
# This is for testing only and therefore we do not verify the JWS yet
unverified_header = jws_parts[0]
unverified_payload = jws_parts[1]
# It should be possible to base64 decode the header and payload
try:
# urlsafe_b64decode returns bytes object so we decode to get str aka utf8
unverified_header_decoded = urlsafe_b64decode(unverified_header + '=' * (4 - (len(unverified_header) % 4))).decode('utf8')
unverified_payload_decoded = urlsafe_b64decode(unverified_payload + '=' * (4 - (len(unverified_payload) % 4))).decode('utf8')
except UnicodeDecodeError:
current_app.logger.info('Couldn\'t urlsafe_b64decode iaResponseData because it contains invalid UTF-8')
return make_response('Incorrect UTF-8 in iaResponseData', 400)
except binascii.Error:
current_app.logger.info('Couldn\'t urlsafe_b64decode iaResponseData because non-base64 digit found')
return make_response('Incorrect UTF-8 in iaResponseData', 400)
except TypeError:
current_app.logger.info('Couldn\'t urlsafe_b64decode iaResponseData')
return make_response('Incorrect base64 encoded iaResponseData', 400)
try:
json.loads(unverified_header_decoded)
json.loads(unverified_payload_decoded)
except JSONDecodeError:
current_app.logger.info('Incorrect UTF-8 BOM or invalid JSON data from base64 decoded iaResponseData')
return make_response('Incorrectly encoded JSON in base64 decoded iaResponseData', 400)
except TypeError:
current_app.logger.info('JSON in base64 decoded iaResponseData is not str')
return make_response('Incorrectly encoded JSON in base64 decoded iaResponseData', 400)
try:
verified_payload = JWS().verify_compact(ia_response_data, keys=[_freja_callback_rsa_pub_key], sigalg='RS256')
except BadSignature as e:
current_app.logger.info('The JWS was not properly signed')
return make_response('Invalid signature', 400)
except Exception as e:
current_app.logger.info(str(e))
return make_response('Invalid JWS', 400)
try:
verified_payload_country = verified_payload.pop('country')
verified_payload_opaque = verified_payload.pop('opaque') # The opaque contains nonce and token
verified_payload_ref = verified_payload.pop('ref')
verified_payload_ssn = verified_payload.pop('ssn')
except KeyError:
current_app.logger.info('The verified JWS payload is missing some required claims')
return make_response('The verified JWS payload is missing some required claims', 400)
# Make sure that we have processed all claims in the payload
if len(verified_payload) == 0:
try:
#.........这里部分代码省略.........