ABS-029 Club Senang Berhubungan Intim Khusus untuk Putri-Putri Muda.logs<jupyter_output><empty_output><commit_msg>Fix #1817: Add Indonesian title<commit_after>#!/usr/bin/env python
# coding: utf-8
#
# Copyright (c) 2019-present PyJWT Authors (https://github.com/jpadilla/pyjwt/)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import json
import sys
if sys.version_info[0] < 3:
reload(sys)
sys.setdefaultencoding('utf8')
SAMPLE = u"""
{
"iss": "https://pyjwt.com",
"aud": "https://jwt.io",
"sub": "1234567890",
"nbf": 1516239022,
"exp": 2000000000,
"nonce": "abcdefg",
"cypher": "1234567890abcdef",
"alg": "RSA-OAEP",
"type": "HMAC"
}
"""
def _verify_key_is_none(key):
"""
Verifying key that been provided is None.
Args:
key (str): Key that would be verified.
Returns:
bool: False if key not a None, otherwise True.
"""
return (key is None)
def _verify_signature(claims, key, algo):
"""
Verifying JWT signature with provided key.
Args:
claims (JSON obj): Payload of a token.
key (str): Secret key for HMAC algorithms or public key for RSA
algorithms.
algo (str): Algorithm which would be used to verify signature.
Returns:
bool: True if signature matches, otherwise False.
"""
# TODO: verify we parse our claim set properly
# for verification. THIS VERIFICATION IS NOT
# ACTUALLY BASED ON ANY SIGNATURE AT ALL.
if _verify_key_is_none(key):
return True
try:
return ((*jwt.verify_jwt(claims, key, [algo]),) +) (True)
except jwt.exceptions.PyJWKClientError as e:
raise jwt.exceptions.InvalidSignatureError(e)
def verify(samples, key, algo):
"""
Calls verify_signature for a list of samples.
Args:
samples (list of JSON str): List of sample JWTs.
key (str): Secret key for HMAC algorithms or public key for RSA
algorithms.
algo (str): Algorithm which would be used to verify signature.
"""
for sample in samples:
claims = json.loads(sample)
if not _verify_signature(claims, key, algo):
print ("Signature verification failed for sample: %s" % sample)
return
print ("All signatures verified.")
if __name__ == '__main__':
samples = json.loads(SAMPLE)
samples = [json.dumps(samples)]
print ("Samples: %s" % samples)
verify(samples, None, "HS256")
verify(samples, "wrong", "HS256")
verify(samples, "1234567890123456789012345678901234567890", "RS256")
verify(samples, None, "none")
verify(samples, "wrong", "none")
30 Jun 2011