From patchwork Sun Jul 31 23:35:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 654426 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3s2f426479z9sDk for ; Mon, 1 Aug 2016 09:36:18 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=Fhu0fr51; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8B024A7516; Mon, 1 Aug 2016 01:36:05 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wfl6hPzaZkTe; Mon, 1 Aug 2016 01:36:05 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 02813A7544; Mon, 1 Aug 2016 01:35:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1833DA753B for ; Mon, 1 Aug 2016 01:35:36 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8jEq52WuONiI for ; Mon, 1 Aug 2016 01:35:36 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-io0-f178.google.com (mail-io0-f178.google.com [209.85.223.178]) by theia.denx.de (Postfix) with ESMTPS id DC705A74DB for ; Mon, 1 Aug 2016 01:35:30 +0200 (CEST) Received: by mail-io0-f178.google.com with SMTP id 38so172864717iol.0 for ; Sun, 31 Jul 2016 16:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=WHdHv0bP5axs5kvNkmaXco0G0Et1QaW52w+rE68B9j4=; b=Fhu0fr5194zLPvdNDtX9r7v6YKyi028WQw0Mi4tiqLXLWcwQORs873mbjYK5J2UW/+ /fvdizWf/R2UXE66NZ+zCCsm8aqJ3NlJm5jwXwC4edRBRIQoPtPoxXpcmhqYItEdixwi TK5OjKJleZBCOsD+bxRMh0LJYbD/jxwUBRaPe3CtYCbopVB4O7VBqVWytYMsDEPc2eD/ 0MynNXo0Zcw6qaEcHPBl8tyusRKoN57X/RkmZBkyThkQNKXgNMoWdopk62jH7XGk4UPB UlNtipyFbqPSVp53ydKpDDEs79Btv/coKPyNKnszPr5bbSxDIQvw1cwpCj6LNlSPliR4 TWew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=WHdHv0bP5axs5kvNkmaXco0G0Et1QaW52w+rE68B9j4=; b=CfU3Wf16jeKJqOvmRnJYaphLNqCGSrSoMcTIeJURv7eGJBUnYSIx1dtz5459RAIT1I jKt0vGVWowEZyBbn+4+fyqlGc/LInLNhZir00OYzdzi22iBxbjxS/b/9jKJgwC4DIpsc 8vpCwFM8Jv5mH99DxfB2Fq9s4ey0aOIUP2qNrjRnzicE69GEsSPxYvsVpEUla2TDGDNw 3nE7eFKrayxJY3s6gBh2j5zEo+kwd8c/oXhBoNlfs6s2CBnYOQxy50EMMMYitNyZU3u2 nkJUWyV+RcXcUvdzsjaNlS3UjVGZ/WVwMiH4zQ/4ox24NaGuJZBdqkqP3yoY2+r7Dh0Z 3+iQ== X-Gm-Message-State: AEkoout7CT+0dZsOV3Obcsdp/NuHWTK5gxUjjcQbExWWSBoeIpYzLfMDlqqMrbNl1Z/XnX9w X-Received: by 10.107.145.214 with SMTP id t205mr50889196iod.135.1470008128918; Sun, 31 Jul 2016 16:35:28 -0700 (PDT) Received: from kaki.bld.corp.google.com ([2620:0:1005:12:9d2b:19ff:ef5e:b216]) by smtp.gmail.com with ESMTPSA id 140sm6653416itl.4.2016.07.31.16.35.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 31 Jul 2016 16:35:27 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 6E073220CFE; Sun, 31 Jul 2016 17:35:25 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sun, 31 Jul 2016 17:35:06 -0600 Message-Id: <1470008109-9699-7-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1470008109-9699-1-git-send-email-sjg@chromium.org> References: <1470008109-9699-1-git-send-email-sjg@chromium.org> Cc: Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH 6/9] test: Rename sha to sha_algo and pass it around X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Rename this argument and pass it to each function that needs it, instead of making it global. Suggested-by: Stephen Warren Suggested-by: Teddy Reed Signed-off-by: Simon Glass --- test/py/tests/test_vboot.py | 53 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py index 7935fae..a5032a7 100644 --- a/test/py/tests/test_vboot.py +++ b/test/py/tests/test_vboot.py @@ -53,19 +53,21 @@ def test_vboot(u_boot_console): util.run_and_log(cons, 'dtc %s %s%s -O dtb ' '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb)) - def run_bootm(test_type, expect_string): + def run_bootm(sha_algo, test_type, expect_string): """Run a 'bootm' command U-Boot. This always starts a fresh U-Boot instance since the device tree may contain a new public key. Args: - test_type: A string identifying the test type - expect_string: A string which is expected in the output + test_type: A string identifying the test type. + expect_string: A string which is expected in the output. + sha_algo: Either 'sha1' or 'sha256', to select the algorithm to + use. """ cons.cleanup_spawn() cons.ensure_spawned() - cons.log.action('%s: Test Verified Boot Run: %s' % (algo, test_type)) + cons.log.action('%s: Test Verified Boot Run: %s' % (sha_algo, test_type)) output = cons.run_command_list( ['sb load hostfs - 100 %stest.fit' % tmpdir, 'fdt addr 100', @@ -83,29 +85,30 @@ def test_vboot(u_boot_console): util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f', '%s%s' % (datadir, its), fit]) - def sign_fit(): + def sign_fit(sha_algo): """Sign the FIT Signs the FIT and writes the signature into it. It also writes the public key into the dtb. + + Args: + sha_algo: Either 'sha1' or 'sha256', to select the algorithm to + use. """ - cons.log.action('%s: Sign images' % algo) + cons.log.action('%s: Sign images' % sha_algo) util.run_and_log(cons, [mkimage, '-F', '-k', tmpdir, '-K', dtb, '-r', fit]) - def test_with_algo(sha): + def test_with_algo(sha_algo): """Test verified boot with the given hash algorithm. This is the main part of the test code. The same procedure is followed for both hashing algorithms. Args: - sha: Either 'sha1' or 'sha256', to select the algorithm to use + sha_algo: Either 'sha1' or 'sha256', to select the algorithm to + use. """ - global algo - - algo = sha - # Compile our device tree files for kernel and U-Boot. These are # regenerated here since mkimage will modify them (by adding a # public key) below. @@ -113,26 +116,26 @@ def test_vboot(u_boot_console): dtc('sandbox-u-boot.dts') # Build the FIT, but don't sign anything yet - cons.log.action('%s: Test FIT with signed images' % algo) - make_fit('sign-images-%s.its' % algo) - run_bootm('unsigned images', 'dev-') + cons.log.action('%s: Test FIT with signed images' % sha_algo) + make_fit('sign-images-%s.its' % sha_algo) + run_bootm(sha_algo, 'unsigned images', 'dev-') # Sign images with our dev keys - sign_fit() - run_bootm('signed images', 'dev+') + sign_fit(sha_algo) + run_bootm(sha_algo, 'signed images', 'dev+') # Create a fresh .dtb without the public keys dtc('sandbox-u-boot.dts') - cons.log.action('%s: Test FIT with signed configuration' % algo) - make_fit('sign-configs-%s.its' % algo) - run_bootm('unsigned config', '%s+ OK' % algo) + cons.log.action('%s: Test FIT with signed configuration' % sha_algo) + make_fit('sign-configs-%s.its' % sha_algo) + run_bootm(sha_algo, 'unsigned config', '%s+ OK' % sha_algo) # Sign images with our dev keys - sign_fit() - run_bootm('signed config', 'dev+') + sign_fit(sha_algo) + run_bootm(sha_algo, 'signed config', 'dev+') - cons.log.action('%s: Check signed config on the host' % algo) + cons.log.action('%s: Check signed config on the host' % sha_algo) util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', tmpdir, '-k', dtb]) @@ -147,9 +150,9 @@ def test_vboot(u_boot_console): util.run_and_log(cons, 'fdtput -t bx %s %s value %s' % (fit, sig_node, sig)) - run_bootm('Signed config with bad hash', 'Bad Data Hash') + run_bootm(sha_algo, 'Signed config with bad hash', 'Bad Data Hash') - cons.log.action('%s: Check bad config on the host' % algo) + cons.log.action('%s: Check bad config on the host' % sha_algo) util.run_and_log_expect_exception(cons, [fit_check_sign, '-f', fit, '-k', dtb], 1, 'Failed to verify required signature')