A Library for Signing, Verifying and Decoding Authentication Tokens
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

43 lines
1.4 KiB

# A quick-and-dirty script for generating test data for KISStokens
# Copyright 2021 Lucas Hinderberger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import base64
import binascii
import hmac
def base64ify(s):
return base64.urlsafe_b64encode(s).decode("ascii").rstrip("=")
joseHeader = '{"typ":"JWT","alg":"HS256"}'
payloads = [
'{"iat":1612049821,"exp":1612049823,"nbf":1612049822}'
]
key = "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"
binKey = binascii.a2b_hex(key)
joseHeaderBase64 = base64ify(joseHeader.encode("utf-8"))
for payload in payloads:
payloadBase64 = base64ify(payload.encode("utf-8"))
signingInput = joseHeaderBase64 + "." + payloadBase64
signature = hmac.digest(binKey, signingInput.encode("ascii"), "sha256")
signatureBase64 = base64ify(signature)
encodedJWT = signingInput + "." + signatureBase64
print('"' + encodedJWT + '",')