Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/model_signing/_signing/sign_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ def __init__(
"the public key paired with the private key"
)

self._trust_chain = x509.load_pem_x509_certificates(
b"".join([path.read_bytes() for path in certificate_chain_paths])
chain_bytes = b"".join(
[path.read_bytes() for path in certificate_chain_paths]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this fixes an issue when no certificate_chain_paths entries are provided? So certfificate_chain_paths is []?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> from cryptography import x509
>>> x509.load_pem_x509_certificates(b"")
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    x509.load_pem_x509_certificates(b"")
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
ValueError: Unable to load PEM file. See https://cryptography.io/en/latest/faq/#why-can-t-i-import-my-pem-file for more details. MalformedFraming
>>> x509.load_pem_x509_certificates(b"".join([]))
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    x509.load_pem_x509_certificates(b"".join([]))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
ValueError: Unable to load PEM file. See https://cryptography.io/en/latest/faq/#why-can-t-i-import-my-pem-file for more details. MalformedFraming

Thank you for fixing

)
self._trust_chain = (
x509.load_pem_x509_certificates(chain_bytes) if chain_bytes else []
)

@override
Expand Down
16 changes: 11 additions & 5 deletions src/model_signing/_signing/sign_pkcs11.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,21 @@ def __init__(
"the public key paired with the private key"
)

self._trust_chain = x509.load_pem_x509_certificates(
b"".join([path.read_bytes() for path in certificate_chain_paths])
chain_bytes = b"".join(
[path.read_bytes() for path in certificate_chain_paths]
)
self._trust_chain = (
x509.load_pem_x509_certificates(chain_bytes) if chain_bytes else []
)

@override
def _get_verification_material(self) -> bundle_pb.VerificationMaterial:
def _to_protobuf_certificate(certificate):
return common_pb.X509Certificate(
raw_bytes=certificate.public_bytes(
encoding=serialization.Encoding.DER
raw_bytes=base64.b64encode(
certificate.public_bytes(
encoding=serialization.Encoding.DER
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. This was something I forgot to change when moving to 'sigstore models'.

)
)

Expand All @@ -268,5 +273,6 @@ def _to_protobuf_certificate(certificate):
return bundle_pb.VerificationMaterial(
x509_certificate_chain=common_pb.X509CertificateChain(
certificates=chain
)
),
tlog_entries=[],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this.

)
Loading