aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-02-25 18:02:25 -0500
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-02-25 18:02:25 -0500
commitc0c3be5d2fcd23ad40227e6f93ed5b56756de795 (patch)
tree6a3cabe6a7d19337106535338702d195206ed585
parent4a94a236ac2cb508f13c2fa765b17b2a0d6dbb39 (diff)
downloadkorg-helpers-c0c3be5d2fcd23ad40227e6f93ed5b56756de795.tar.gz
Add a few more user-friendly options
- Skip messages not containing patches (like cover letters) - Add option to not fast-exit (-X), which is handy for testing Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-xattest-patches.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/attest-patches.py b/attest-patches.py
index 1e802fc..7e7491b 100755
--- a/attest-patches.py
+++ b/attest-patches.py
@@ -193,6 +193,10 @@ def create_attestation(cmdargs):
for patchfile in cmdargs.attest:
with open(patchfile, 'rb') as fh:
ihash, mhash, phash = get_mailinfo_hashes(fh.read())
+ if not phash:
+ logger.info('SKP | %s', os.path.basename(patchfile))
+ continue
+ logger.info('ADD | %s', os.path.basename(patchfile))
attid = '%s-%s-%s' % (ihash[:8], mhash[:8], phash[:8])
attlines.append('%s:' % attid)
attlines.append(' i: %s' % ihash)
@@ -230,6 +234,7 @@ def create_attestation(cmdargs):
with open(cmdargs.output, 'wb') as fh:
fh.write(att_msg.as_bytes())
+ logger.info('---')
logger.info('Wrote %s', cmdargs.output)
logger.info('You can send it using:')
logger.info(' sendmail -oi signatures@kernel.org < %s', cmdargs.output)
@@ -376,7 +381,7 @@ def verify_attestation(cmdargs):
load_attestation_file(cmdargs.attfile)
session = requests.session()
session.headers.update({'User-Agent': 'attest-patches/%s' % VERSION})
- ecode = 0
+ ecode = 1
for msg in mbx:
content = msg.as_bytes()
ihash, mhash, phash = get_mailinfo_hashes(content)
@@ -392,9 +397,13 @@ def verify_attestation(cmdargs):
except KeyError:
# No attestations found
logger.critical('FAIL | %s', msg['Subject'])
- logger.critical('Aborting due to failure.')
- ecode = 1
- break
+ if not cmdargs.nofast:
+ logger.critical('Aborting due to failure.')
+ ecode = 1
+ break
+ else:
+ ecode = 128
+ continue
for good, valid, trusted, sigkey, siguid in adata:
if cmdargs.ignorefrom or check_if_from_matches_uids(sigkey, msg):
@@ -405,14 +414,15 @@ def verify_attestation(cmdargs):
ecode = 128
else:
logger.critical('PASS | %s', msg['Subject'])
- ecode = 0
+ if ecode != 128:
+ ecode = 0
break
else:
logger.critical('FAIL | %s', msg['Subject'])
VALIDATION_ERRORS.update(('Attestation ignored due to From/UID mismatch: %s' % siguid,))
ecode = 1
- if ecode > 0:
+ if not cmdargs.nofast and ecode > 0:
logger.critical('Aborting due to failure.')
break
@@ -475,6 +485,8 @@ if __name__ == '__main__':
help='Use this file for attestation data instead of querying lore.kernel.org')
parser.add_argument('-t', '--tofu', action='store_true', default=False,
help='Force TOFU trust model (otherwise uses your global GnuPG setting)')
+ parser.add_argument('-X', '--no-fast-exit', dest='nofast', action='store_true', default=False,
+ help='Do not exit after first failure')
parser.add_argument('-F', '--ignore-from-mismatch', dest='ignorefrom', action='store_true',
default=False, help='Ignore mismatches between From: and PGP uid data')
parser.add_argument('-q', '--quiet', action='store_true', default=False,