@@ -76,22 +76,21 @@ def create_claim(
76
76
# RSA: public_exponent(int), size(int)
77
77
# EC: crv(str) (one of P-256, P-384, P-521, secp256k1)
78
78
# OKP: crv(str) (one of Ed25519, Ed448, X25519, X448)
79
- import hashlib
80
- kid_hash = hashlib .sha256 ()
81
- kid_hash .update (str (uuid .uuid4 ()).encode ())
82
- kid = kid_hash .hexdigest ()
83
- if private_key_pem_path and private_key_pem_path .exists ():
84
- cwt_cose_key = cwt .COSEKey .from_pem (private_key_pem_path .read_bytes ())
85
- else :
79
+ if private_key_pem_path and not private_key_pem_path .exists ():
86
80
import subprocess
87
81
subprocess .check_call (
88
82
[
89
83
"bash" ,
90
84
"-c" ,
91
- f"ssh-keygen -q -f /dev/stdout -t ecdsa -b 384 -N '' -I { kid } <<<y 2>/dev/null | python -c 'import sys; from cryptography.hazmat.primitives import serialization; print(serialization.load_ssh_private_key(sys.stdin.buffer.read(), password=None).private_bytes(encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption()).decode().rstrip())' > { private_key_pem_path } " ,
85
+ f"ssh-keygen -q -f /dev/stdout -t ecdsa -b 384 -N '' <<<y 2>/dev/null | python -c 'import sys; from cryptography.hazmat.primitives import serialization; print(serialization.load_ssh_private_key(sys.stdin.buffer.read(), password=None).private_bytes(encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption()).decode().rstrip())' > { private_key_pem_path } " ,
92
86
]
93
87
)
94
- cwt_cose_key = cwt .COSEKey .from_pem (private_key_pem_path .read_bytes ())
88
+ private_key_pem = private_key_pem_path .read_bytes ()
89
+ import hashlib
90
+ kid_hash = hashlib .sha384 ()
91
+ kid_hash .update (private_key_pem )
92
+ kid = kid_hash .hexdigest ()
93
+ cwt_cose_key = cwt .COSEKey .from_pem (private_key_pem , kid = kid )
95
94
# cwt_cose_key = cwt.COSEKey.generate_ec2_key(alg=alg, kid=kid)
96
95
import pprint
97
96
cwt_ec2_key_as_dict = cwt_cose_key .to_dict ()
@@ -139,8 +138,6 @@ def create_claim(
139
138
# }
140
139
cwt_token = cwt .encode (cwt_claims , cwt_cose_key )
141
140
print (cwt .decode (cwt_token , cwt_cose_key ))
142
- import sys
143
- sys .exit (0 )
144
141
145
142
# Protected_Header = {
146
143
protected = {
0 commit comments