Skip to content

Commit 63bfb8c

Browse files
authored
_cli, _verify: Wrap OpenSSL error with user-friendly text (#113)
* _verify: Wrap OpenSSL error message with some help text * _cli: Print verification failure reason
1 parent bfa850e commit 63bfb8c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

sigstore/_cli.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
import sys
1818
from importlib import resources
19-
from typing import BinaryIO, List, Optional, TextIO
19+
from typing import BinaryIO, List, Optional, TextIO, cast
2020

2121
import click
2222

@@ -37,7 +37,7 @@
3737
STAGING_REKOR_URL,
3838
)
3939
from sigstore._sign import sign
40-
from sigstore._verify import verify
40+
from sigstore._verify import VerificationFailure, verify
4141

4242
logger = logging.getLogger(__name__)
4343
logging.basicConfig(level=os.environ.get("SIGSTORE_LOGLEVEL", "INFO").upper())
@@ -294,15 +294,18 @@ def _verify(
294294

295295
verified = True
296296
for file in files:
297-
if verify(
297+
result = verify(
298298
rekor_url=rekor_url,
299299
file=file,
300300
certificate=certificate,
301301
signature=signature,
302302
cert_email=cert_email,
303-
):
303+
)
304+
if result:
304305
click.echo(f"OK: {file.name}")
305306
else:
307+
failure = cast(VerificationFailure, result)
308+
click.echo(failure.reason)
306309
click.echo(f"FAIL: {file.name}")
307310
verified = False
308311

sigstore/_verify.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
load_pem_x509_certificate,
3434
)
3535
from cryptography.x509.oid import ExtendedKeyUsageOID
36-
from OpenSSL.crypto import X509, X509Store, X509StoreContext
36+
from OpenSSL.crypto import (
37+
X509,
38+
X509Store,
39+
X509StoreContext,
40+
X509StoreContextError,
41+
)
3742
from pydantic import BaseModel
3843

3944
from sigstore._internal.merkle import (
@@ -130,7 +135,13 @@ def verify(
130135
store.add_cert(openssl_intermediate)
131136
store.set_time(sign_date)
132137
store_ctx = X509StoreContext(store, openssl_cert)
133-
store_ctx.verify_certificate()
138+
try:
139+
store_ctx.verify_certificate()
140+
except X509StoreContextError as store_ctx_error:
141+
return VerificationFailure(
142+
reason="Failed to verify signing certificate, consider upgrading `sigstore` if a newer "
143+
f"version is available: {store_ctx_error}"
144+
)
134145

135146
# 2) Check that the signing certificate contains the proof claim as the subject
136147
# Check usage is "digital signature"

0 commit comments

Comments
 (0)