Skip to content

Commit 9958fbc

Browse files
authored
(fix): cert chain crash and bundle creation (#615)
Signed-off-by: Sachin Sampras M <sampras343@gmail.com>
1 parent 05fde7b commit 9958fbc

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/model_signing/_signing/sign_certificate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ def __init__(
7272
"the public key paired with the private key"
7373
)
7474

75-
self._trust_chain = x509.load_pem_x509_certificates(
76-
b"".join([path.read_bytes() for path in certificate_chain_paths])
75+
chain_bytes = b"".join(
76+
[path.read_bytes() for path in certificate_chain_paths]
77+
)
78+
self._trust_chain = (
79+
x509.load_pem_x509_certificates(chain_bytes) if chain_bytes else []
7780
)
7881

7982
@override

src/model_signing/_signing/sign_pkcs11.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,21 @@ def __init__(
244244
"the public key paired with the private key"
245245
)
246246

247-
self._trust_chain = x509.load_pem_x509_certificates(
248-
b"".join([path.read_bytes() for path in certificate_chain_paths])
247+
chain_bytes = b"".join(
248+
[path.read_bytes() for path in certificate_chain_paths]
249+
)
250+
self._trust_chain = (
251+
x509.load_pem_x509_certificates(chain_bytes) if chain_bytes else []
249252
)
250253

251254
@override
252255
def _get_verification_material(self) -> bundle_pb.VerificationMaterial:
253256
def _to_protobuf_certificate(certificate):
254257
return common_pb.X509Certificate(
255-
raw_bytes=certificate.public_bytes(
256-
encoding=serialization.Encoding.DER
258+
raw_bytes=base64.b64encode(
259+
certificate.public_bytes(
260+
encoding=serialization.Encoding.DER
261+
)
257262
)
258263
)
259264

@@ -268,5 +273,6 @@ def _to_protobuf_certificate(certificate):
268273
return bundle_pb.VerificationMaterial(
269274
x509_certificate_chain=common_pb.X509CertificateChain(
270275
certificates=chain
271-
)
276+
),
277+
tlog_entries=[],
272278
)

0 commit comments

Comments
 (0)