ukify: Derive public key from private key if not specified

This commit is contained in:
Daan De Meyer
2023-07-13 16:31:05 +01:00
committed by Luca Boccassi
parent 85fe60b9e8
commit d7d36252e5
2 changed files with 41 additions and 33 deletions
+7 -1
View File
@@ -729,11 +729,17 @@ def make_uki(opts):
uki = UKI(opts.stub)
initrd = join_initrds(opts.initrd)
# TODO: derive public key from opts.pcr_private_keys?
pcrpkey = opts.pcrpkey
if pcrpkey is None:
if opts.pcr_public_keys and len(opts.pcr_public_keys) == 1:
pcrpkey = opts.pcr_public_keys[0]
elif opts.pcr_private_keys and len(opts.pcr_private_keys) == 1:
import cryptography.hazmat.primitives.serialization as serialization
privkey = serialization.load_pem_private_key(opts.pcr_private_keys[0].read_bytes(), password=None)
pcrpkey = privkey.public_key().public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo,
)
sections = [
# name, content, measure?