Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84970C43461 for ; Tue, 11 May 2021 14:35:38 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 52C10611F1; Tue, 11 May 2021 14:35:38 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 0D82561285 for ; Tue, 11 May 2021 14:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620743738; bh=z9+uevLbJfKavu/81PkRDxXbk9me2uWOxeY+VUKcrq0=; h=From:List-Id:To:Subject:Date:In-Reply-To:References:From; b=pdUE1VulqxFD1Ktigo8FLYDoR3ke6oygmMtOO6A/MOMmiio0TscZ52yg4ouQ4YBVZ 7dntinHv3YHpHriuSG9kIIzt6uCRIHwH6CCmNvmXX7SkZxWIv4WQahQwjWg/tJiLCr dMMdEK2VYH9nSGwJ4AkD/sdokEpkJPCc+CviS0tc= From: Konstantin Ryabitsev List-Id: To: signatures@kernel.org Subject: [PATCH 2/4] Return a list of all sigs, not just goodsigs Date: Tue, 11 May 2021 10:35:34 -0400 Message-Id: <20210511143536.743919-3-konstantin@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511143536.743919-1-konstantin@linuxfoundation.org> References: <20210511143536.743919-1-konstantin@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1620743735; l=4489; h=from:subject; bh=z9+uevLbJfKavu/81PkRDxXbk9me2uWOxeY+VUKcrq0=; b=Oid2XJe4R1T8/9iyoxS2paWaZn5uAooqItmVRI3r8V5Hh9LtgrqbO/29kcQZR02UCq3i7xoSciV2 nkl5JGwMB1BzKj3beg0UeWYku4nSHA6oJKV9nB4SR0sYmwHPPqTg X-Developer-Key: i=konstantin@linuxfoundation.org; a=ed25519; pk=Y2ZW6YZvsJGJ1VvUSOZ3gk8LCaer4ziXgdZyIi6zC00= Content-Transfer-Encoding: 8bit Instead of returning a list of goodsigs and throwing a ValidationError if even one of them has failed, return a list of all sigs -- failed or otherwise, and let the caller decide what to do with it. Signed-off-by: Konstantin Ryabitsev --- patatt/__init__.py | 48 ++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/patatt/__init__.py b/patatt/__init__.py index 2f380e0..9ceaa29 100644 --- a/patatt/__init__.py +++ b/patatt/__init__.py @@ -42,7 +42,7 @@ DEFAULT_CONFIG = { KEYCACHE = dict() # My version -__VERSION__ = '0.1.0' +__VERSION__ = '0.2.0-dev' MAX_SUPPORTED_FORMAT_VERSION = 1 @@ -841,19 +841,19 @@ def cmd_sign(cmdargs, config: dict) -> None: def validate_message(msgdata: bytes, sources: list, trim_body: bool = False) -> list: - errors = list() - goodsigs = list() - success = False + attestations = list() pm = PatattMessage(msgdata) if not pm.signed: - errors.append('message is not signed') - raise ValidationError('message is not signed', errors) + logger.debug('message is not signed') + return attestations # Find all identities for which we have public keys for ds in pm.get_sigs(): + errors = list() a = ds.get_field('a', decode=True) i = ds.get_field('i', decode=True) s = ds.get_field('s', decode=True) + t = ds.get_field('t', decode=True) if not s: s = 'default' if a.startswith('ed25519'): @@ -862,6 +862,7 @@ def validate_message(msgdata: bytes, sources: list, trim_body: bool = False) -> algo = 'openpgp' else: errors.append('%s/%s Unknown algorigthm: %s' % (i, s, a)) + attestations.append((False, i, t, None, a, errors)) continue pkey = keysrc = None @@ -874,21 +875,17 @@ def validate_message(msgdata: bytes, sources: list, trim_body: bool = False) -> if not pkey and algo == 'ed25519': errors.append('%s/%s no matching ed25519 key found' % (i, s)) + attestations.append((False, i, t, None, algo, errors)) continue try: signtime = pm.validate(i, pkey, trim_body=trim_body) - success = True + attestations.append((True, i, signtime, keysrc, algo, errors)) except ValidationError: errors.append('failed to validate using %s' % keysrc) - continue - - goodsigs.append((i, signtime, keysrc, algo)) + attestations.append((False, i, t, keysrc, algo, errors)) - if not success: - raise ValidationError('Failed to validate message', errors) - - return goodsigs + return attestations def cmd_validate(cmdargs, config: dict): @@ -922,19 +919,20 @@ def cmd_validate(cmdargs, config: dict): allgood = True for fn, msgdata in messages.items(): try: - goodsigs = validate_message(msgdata, sources, trim_body=trim_body) - for identity, signtime, keysrc, algo in goodsigs: - logger.critical('PASS | %s | %s', identity, fn) - if keysrc: - logger.info(' | key: %s', keysrc) + attestations = validate_message(msgdata, sources, trim_body=trim_body) + for passing, identity, signtime, keysrc, algo, errors in attestations: + if passing: + logger.critical('PASS | %s | %s', identity, fn) + if keysrc: + logger.info(' | key: %s', keysrc) + else: + logger.info(' | key: default GnuPG keyring') else: - logger.info(' | key: default GnuPG keyring') + allgood = False + logger.critical('FAIL | %s | %s', identity, fn) + for error in errors: + logger.critical(' | %s', error) - except ValidationError as ex: - allgood = False - logger.critical('FAIL | %s | %s', ex, fn) - for error in ex.errors: - logger.critical(' | %s', error) except RuntimeError as ex: allgood = False logger.critical('ERR | err: %s | %s', ex, fn) -- 2.31.1