@@ -76,7 +76,8 @@ 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
- if private_key_pem_path and not private_key_pem_path .exists ():
79
+ if private_key_pem_path and private_key_pem_path .exists ():
80
+ """
80
81
import subprocess
81
82
subprocess.check_call(
82
83
[
@@ -85,38 +86,32 @@ def create_claim(
85
86
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}",
86
87
]
87
88
)
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 )
94
- # cwt_cose_key = cwt.COSEKey.generate_ec2_key(alg=alg, kid=kid)
95
- import pprint
96
- cwt_ec2_key_as_dict = cwt_cose_key .to_dict ()
97
- pprint .pprint (cwt_ec2_key_as_dict )
98
- import pprint
99
- import inspect
100
- cose_tags = {
101
- member .identifier : member .fullname
102
- for _member_name , member in inspect .getmembers (pycose .headers )
103
- if (
104
- hasattr (member , "identifier" )
105
- and hasattr (member , "fullname" )
89
+ """
90
+ private_key_pem = private_key_pem_path .read_bytes ()
91
+ import hashlib
92
+ kid_hash = hashlib .sha384 ()
93
+ kid_hash .update (private_key_pem )
94
+ kid = kid_hash .hexdigest ()
95
+ cwt_cose_key = cwt .COSEKey .from_pem (private_key_pem , kid = kid )
96
+ else :
97
+ cwt_cose_key = pycose .keys .EC2Key .generate_key (
98
+ pycose .keys .curves .P384 ,
106
99
)
100
+ # sign1_message_key = cwt.algs.ec2.EC2Key.to_cose_key(cwt_cose_key)
101
+ import base64
102
+ cwt_ec2_key_as_dict = {
103
+ "crv" : "P-384" ,
104
+ "kid" : str (uuid .uuid4 ()),
105
+ "kty" : "EC" ,
106
+ # "use": "sig",
107
+ "use" : "enc" ,
108
+ "x" : base64 .b64encode (cwt_cose_key .x ).decode (),
109
+ "y" : base64 .b64encode (cwt_cose_key .y ).decode (),
110
+ "d" : base64 .b64encode (cwt_cose_key .d ).decode (),
107
111
}
108
- pprint .pprint (cose_tags )
109
- cwt_ec2_key_as_dict_labeled = {
110
- cose_tags .get (key , key ): value
111
- for key , value in cwt_ec2_key_as_dict .items ()
112
- }
113
- # print("cwt_ec2_key_as_dict_labeled['STATIC_KEY_ID']", cwt_ec2_key_as_dict_labeled['CRITICAL'])
114
- pprint .pprint (cwt_ec2_key_as_dict )
115
- pprint .pprint (cwt_ec2_key_as_dict_labeled )
116
- pycose_cose_key = pycose .keys .ec2 .EC2Key .from_dict (cwt_ec2_key_as_dict )
117
- # pycose_cose_key.kid = cwt_ec2_key_as_dict_labeled['CRITICAL']
118
- # cwt_cose_key._kid = pycose_cose_key.kid
119
- sign1_message_key = pycose .keys .ec2 .EC2Key .from_dict (cwt_ec2_key_as_dict )
112
+ # sign1_message_key = pycose.keys.ec2.EC2Key.from_dict(cwt_ec2_key_as_dict)
113
+ sign1_message_key = cwt .COSEKey .from_jwk (cwt_ec2_key_as_dict )
114
+
120
115
121
116
# CWT_Claims (label: 14 pending [CWT_CLAIM_COSE]): A CWT representing
122
117
# the Issuer (iss) making the statement, and the Subject (sub) to
0 commit comments