Skip to content

Commit bcb6f44

Browse files
committed
Realized we dropped the kid kwarg..... Faaccccck
Signed-off-by: John Andersen <[email protected]>
1 parent e581fe9 commit bcb6f44

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

scitt_emulator/create_statement.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,21 @@ def create_claim(
7676
# RSA: public_exponent(int), size(int)
7777
# EC: crv(str) (one of P-256, P-384, P-521, secp256k1)
7878
# 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():
8680
import subprocess
8781
subprocess.check_call(
8882
[
8983
"bash",
9084
"-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}",
9286
]
9387
)
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)
9594
# cwt_cose_key = cwt.COSEKey.generate_ec2_key(alg=alg, kid=kid)
9695
import pprint
9796
cwt_ec2_key_as_dict = cwt_cose_key.to_dict()
@@ -139,8 +138,6 @@ def create_claim(
139138
# }
140139
cwt_token = cwt.encode(cwt_claims, cwt_cose_key)
141140
print(cwt.decode(cwt_token , cwt_cose_key))
142-
import sys
143-
sys.exit(0)
144141

145142
# Protected_Header = {
146143
protected = {

0 commit comments

Comments
 (0)