Skip to content

Commit

Permalink
_cli, _verify: Wrap OpenSSL error with user-friendly text (#113)
Browse files Browse the repository at this point in the history
* _verify: Wrap OpenSSL error message with some help text

* _cli: Print verification failure reason
  • Loading branch information
tetsuo-cpp authored Jun 3, 2022
1 parent bfa850e commit 63bfb8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 7 additions & 4 deletions sigstore/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import sys
from importlib import resources
from typing import BinaryIO, List, Optional, TextIO
from typing import BinaryIO, List, Optional, TextIO, cast

import click

Expand All @@ -37,7 +37,7 @@
STAGING_REKOR_URL,
)
from sigstore._sign import sign
from sigstore._verify import verify
from sigstore._verify import VerificationFailure, verify

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

verified = True
for file in files:
if verify(
result = verify(
rekor_url=rekor_url,
file=file,
certificate=certificate,
signature=signature,
cert_email=cert_email,
):
)
if result:
click.echo(f"OK: {file.name}")
else:
failure = cast(VerificationFailure, result)
click.echo(failure.reason)
click.echo(f"FAIL: {file.name}")
verified = False

Expand Down
15 changes: 13 additions & 2 deletions sigstore/_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
load_pem_x509_certificate,
)
from cryptography.x509.oid import ExtendedKeyUsageOID
from OpenSSL.crypto import X509, X509Store, X509StoreContext
from OpenSSL.crypto import (
X509,
X509Store,
X509StoreContext,
X509StoreContextError,
)
from pydantic import BaseModel

from sigstore._internal.merkle import (
Expand Down Expand Up @@ -130,7 +135,13 @@ def verify(
store.add_cert(openssl_intermediate)
store.set_time(sign_date)
store_ctx = X509StoreContext(store, openssl_cert)
store_ctx.verify_certificate()
try:
store_ctx.verify_certificate()
except X509StoreContextError as store_ctx_error:
return VerificationFailure(
reason="Failed to verify signing certificate, consider upgrading `sigstore` if a newer "
f"version is available: {store_ctx_error}"
)

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

0 comments on commit 63bfb8c

Please sign in to comment.