Skip to content

Commit 9737f0e

Browse files
authored
change verification behavior: signing cert must have either digital signature or code signing cababilities. bugfix for public key retrieval (#365)
Signed-off-by: Martin Sablotny <[email protected]>
1 parent efca1eb commit 9737f0e

File tree

1 file changed

+22
-11
lines changed
  • src/model_signing/signature

1 file changed

+22
-11
lines changed

src/model_signing/signature/pki.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from cryptography import x509
2020
from cryptography.hazmat.primitives import serialization
2121
from cryptography.hazmat.primitives.asymmetric import ec
22+
from cryptography.x509 import ExtensionNotFound
2223
from cryptography.x509 import oid as crypto_oid
2324
from in_toto_attestation.v1 import statement
2425
from OpenSSL import crypto as ssl_crypto
@@ -162,22 +163,32 @@ def verify(self, bundle: bundle_pb.Bundle) -> None:
162163
raise VerificationError(
163164
f"signing certificate verification failed: {err}"
164165
) from err
166+
165167
usage = signing_cert_crypto.extensions.get_extension_for_class(
166168
x509.KeyUsage
167169
)
168170
if not usage.value.digital_signature:
169-
raise VerificationError(
170-
"the certificate is not valid for digital signature usage"
171-
)
172-
ext_usage = signing_cert_crypto.extensions.get_extension_for_class(
173-
x509.ExtendedKeyUsage
174-
)
175-
if crypto_oid.ExtendedKeyUsageOID.CODE_SIGNING not in ext_usage.value:
176-
raise VerificationError(
177-
"the certificate is not valid for code signing usage"
178-
)
171+
code_signing = False
172+
try:
173+
ext_usage = (
174+
signing_cert_crypto.extensions.get_extension_for_class(
175+
x509.ExtendedKeyUsage
176+
)
177+
)
178+
if (
179+
crypto_oid.ExtendedKeyUsageOID.CODE_SIGNING
180+
in ext_usage.value
181+
):
182+
code_signing = True
183+
except ExtensionNotFound:
184+
pass
185+
if not code_signing:
186+
raise VerificationError(
187+
"signing certificate neither allows digital signature"
188+
"nor code signing"
189+
)
179190

180191
# Verify the contents with a key verifier
181-
pub_key: ec.EllipticCurvePublicKey = signing_cert_crypto.public_key
192+
pub_key: ec.EllipticCurvePublicKey = signing_cert_crypto.public_key()
182193
verifier = ECKeyVerifier(pub_key)
183194
return verifier.verify(bundle)

0 commit comments

Comments
 (0)