64
64
MANIFEST_RE = re .compile (r'^\s*(?P<digest>[0-9a-fA-F]+)\s+(?P<fname>.+)$' )
65
65
log = logging .getLogger (__name__ )
66
66
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),
69
69
# we reset time and set log level accordingly.
70
70
verif_log_timestamps = {}
71
71
# 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):
332
332
except ossl .X509StoreContextError as exception_object :
333
333
code , depth , message = exception_object .args [0 ]
334
334
if code in (2 ,3 ,20 ,27 ,33 ):
335
- # from openssl/x509_vfy.h or
335
+ # from openssl/x509_vfy.h or
336
336
# https://www.openssl.org/docs/man1.1.0/man3/X509_STORE_CTX_set_current_cert.html
337
337
# X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2
338
338
# X509_V_ERR_UNABLE_TO_GET_CRL 3
@@ -444,7 +444,12 @@ def sign_target(fname, ofname, private_key='private.key', **kwargs): # pylint: d
444
444
"""
445
445
# NOTE: This is intended to crash if there's some number of keys other than
446
446
# 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 ]
448
453
hasher , chosen_hash = hash_target (fname , obj_mode = True )
449
454
args = { 'data' : hasher .finalize () }
450
455
if isinstance (first_key , rsa .RSAPrivateKey ):
@@ -458,7 +463,7 @@ def sign_target(fname, ofname, private_key='private.key', **kwargs): # pylint: d
458
463
fh .write ('\n ' )
459
464
460
465
def verify_signature (fname , sfname , public_crt = 'public.crt' , ca_crt = 'ca-root.crt' , ** kwargs ): # pylint: disable=unused-argument
461
- ### make
466
+ ### make
462
467
"""
463
468
Given the fname, sfname public_crt and ca_crt:
464
469
@@ -601,7 +606,7 @@ def verify_files(targets, mfname='MANIFEST', sfname='SIGNATURE', public_crt='pub
601
606
# or it's a digest from the MANIFEST. If UNKNOWN, we have nothing to compare
602
607
# so we return UNKNOWN
603
608
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
605
610
# x seconds, we reset time and set log level accordingly. the same for FAIL
606
611
elif digest == new_hash :
607
612
# path gets same status as MANIFEST
0 commit comments