Skip to content

Commit 7ca2b51

Browse files
committed
minor changes to whitespace and error logging
1 parent 2081ac2 commit 7ca2b51

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

hubblestack/utils/signing.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
MANIFEST_RE = re.compile(r'^\s*(?P<digest>[0-9a-fA-F]+)\s+(?P<fname>.+)$')
6565
log = logging.getLogger(__name__)
6666

67-
# "verification_log_timestamps" is a global dict that contains str path
68-
# and time() kv pairs. When the time() value exceeds the dampening_limit (3600 sec),
67+
# "verification_log_timestamps" is a global dict that contains str path
68+
# and time() kv pairs. When the time() value exceeds the dampening_limit (3600 sec),
6969
# we reset time and set log level accordingly.
7070
verif_log_timestamps = {}
7171
# How often in seconds 3600 = 1 hour to set log level to log.error/critical
@@ -332,7 +332,7 @@ def __init__(self, public_crt=None, ca_crt=None):
332332
except ossl.X509StoreContextError as exception_object:
333333
code, depth, message = exception_object.args[0]
334334
if code in (2,3,20,27,33):
335-
# from openssl/x509_vfy.h or
335+
# from openssl/x509_vfy.h or
336336
# https://www.openssl.org/docs/man1.1.0/man3/X509_STORE_CTX_set_current_cert.html
337337
# X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
338338
# X509_V_ERR_UNABLE_TO_GET_CRL 3
@@ -444,7 +444,12 @@ def sign_target(fname, ofname, private_key='private.key', **kwargs): # pylint: d
444444
"""
445445
# NOTE: This is intended to crash if there's some number of keys other than
446446
# exactly 1 read from the private_key file:
447-
first_key, = read_certs(private_key)
447+
the_keys = list(read_certs(private_key))
448+
if not the_keys:
449+
log.error('unable to sign %s with %s (no such file or error reading certs)',
450+
os.path.abspath(fname), os.path.abspath(private_key))
451+
return
452+
first_key = the_keys[0]
448453
hasher, chosen_hash = hash_target(fname, obj_mode=True)
449454
args = { 'data': hasher.finalize() }
450455
if isinstance(first_key, rsa.RSAPrivateKey):
@@ -458,7 +463,7 @@ def sign_target(fname, ofname, private_key='private.key', **kwargs): # pylint: d
458463
fh.write('\n')
459464

460465
def verify_signature(fname, sfname, public_crt='public.crt', ca_crt='ca-root.crt', **kwargs): # pylint: disable=unused-argument
461-
### make
466+
### make
462467
"""
463468
Given the fname, sfname public_crt and ca_crt:
464469
@@ -601,7 +606,7 @@ def verify_files(targets, mfname='MANIFEST', sfname='SIGNATURE', public_crt='pub
601606
# or it's a digest from the MANIFEST. If UNKNOWN, we have nothing to compare
602607
# so we return UNKNOWN
603608
status = STATUS.UNKNOWN
604-
# check to see if the the status of a failed target has been sent is the last
609+
# check to see if the the status of a failed target has been sent is the last
605610
# x seconds, we reset time and set log level accordingly. the same for FAIL
606611
elif digest == new_hash:
607612
# path gets same status as MANIFEST

0 commit comments

Comments
 (0)