From patchwork Fri Jul 10 00:24:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1326276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=bxIVjBka; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B2v2W4NrHz9sRW for ; Fri, 10 Jul 2020 10:25:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7699A81B98; Fri, 10 Jul 2020 02:25:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="bxIVjBka"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C546681B9D; Fri, 10 Jul 2020 02:25:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C56A981B95 for ; Fri, 10 Jul 2020 02:25:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pl1-x642.google.com with SMTP id q17so1504583pls.9 for ; Thu, 09 Jul 2020 17:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=78Jl0oVc6v8Lbh1nH6sr0r7zGAjgQ6mNarpmRV+f4sY=; b=bxIVjBkaxwF/ImnubBl3XVQgTKCV95fwPPpkeLAqYUdo/4qHJlJ8ZDk77my8bc2QZM 4LAkwAU1Fq0JSW/MB35Lt2U7r9i9M4Cw1rtDr6BYsvHW4gIqRyyHr5Hng3gUkpY2byJ5 3SgYYitR8lHjtIpsrkjr3BahE2NUesxg1sxmT8GU3ukBUUDAtnj/3iNswnL2KMCMwGQb 7FGEXCEDXOMDuVNFokXS2u+0DTjQcDlYcfA/JMPqhpmK4kQD9AXjBlrxGuZF/7CimCMU 2mN+vPmlpo2RGcmlfQNOVsay0zwfmnwgbg1I0b4S2SyFdC08NzqurhOMrEo3WlpdBHGH Ayxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=78Jl0oVc6v8Lbh1nH6sr0r7zGAjgQ6mNarpmRV+f4sY=; b=DdQHVfdgOOioQMOu3sS9iYoAezcpN8VSsjVXSHfKJ1YyBNT8TTbEmFxpMBIooGKF9B 28Clh7USBalkdHUxf7W3GzlPSeVxfCVCaLp5FkkQszioiQzDWFK8IWhnHt3tZYydTx4j mvvVbmKxmiCUjDRw7IK4aGzZ0Tb5WMHJYRqRcBdoEFscOI1xP21cNTF8fBHpjD4t6t3y SxjQleoSJD8W0Bzclsm9iDU5VfZICBpB/YKkFa3Ovsj16Zy8oBQdO3LDPvdp1vSeOpw3 SqPpTtw8qVDV8ARi+EfoGEWnx6liJxvoasxVgSZQiYlOyXUwU+MyWwDIftjT5t2LFN+n J9Bw== X-Gm-Message-State: AOAM531d71UK4UP1utfNDkyg9DjFLoRkahlZYKVUtea846BSIgraRm4G d8UzUQ/WSHA2RGlf8xjICmgWhg== X-Google-Smtp-Source: ABdhPJwaKDXdsTB4nCvTm7USeHH6Sv7km49+yjUryOqF1eGEs83CxwKL0iyIPEdcNT3OhoFnuJSgSw== X-Received: by 2002:a17:90a:f2c3:: with SMTP id gt3mr2934435pjb.92.1594340709646; Thu, 09 Jul 2020 17:25:09 -0700 (PDT) Received: from localhost.localdomain (p6e421564.tkyea130.ap.so-net.ne.jp. [110.66.21.100]) by smtp.gmail.com with ESMTPSA id m16sm4242287pfd.101.2020.07.09.17.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 17:25:08 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, mail@patrick-wildt.de, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH v3 0/8] efi_loader: secure boot: support intermediate certificates in signature Date: Fri, 10 Jul 2020 09:24:41 +0900 Message-Id: <20200710002449.26680-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Summary ======= under the current implementation of secure boot merged in v2020.07-rc1, UEFI subsystem verifies a signature using certificates that are coming from signature dtabase, i.e. "db." In real world, an image is signed by a signer, but its certificate can also be signed by another CA and, if it is not self-signed, the latter will be signed by yet another CA and so on. This is called a certificate chain and any certificates in the middle of chain is called "intermediate" certificates. With this patch set applied on top of the current implementation, UEFI subsystem will get capable of verifying intermediate certificates being contained in a signature and authenticating an image in a chain of trusted certificates. Please note that we don't support RFC6131, or timestamp protocol, and so if any certificate in the chain is found in the revocation list, i.e. dbx, the image will unconditionally be disqualified from being loaded or run. Patch structure =============== Patch#1-#6: preparatory patches Patch#7: main part Patch#8: pytest Prerequisite ============ Require my patch set[1]. Those two patch sets are mutually independent in terms of functionality, but have dependencies due to code overlap. You can fetch the whole workable repository from here[2]. One patch[3] to sbsigntools must also be applied so that we wil be able to sign an image with intermediate certificates. It is required here for testing. Test ==== - The added new pytest (test_signed_intca.py) passed locally. - Travis CI passed, except the new pytest added here due to a new feature in sbsigntools as mentioned above. Misc ==== - checkpatch.pl makes several warnings against pkcs7_verify.c, but we will ignore them as it is a file imported from linux code. [1] https://lists.denx.de/pipermail/u-boot/2020-July/419146.html [2] https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/secboot [3] https://groups.io/g/sbsigntools/message/23 v3 (Jul 10, 2020) * rebased to Heinrich's (current) efi-2020-10-rc1 along with my follow-up patches * add sanity checks in public_key_verify_signature() (Patch#2) * smplify include headers in pkcs7_verify.c (Patch#4) * fix timestamp issues in Test Case 2 and 3 (Patch#8) v2 (June 16, 2020) * add function descriptions (Patch#2, #6 and #7) * pylint and autopep8 against pytest (Patch#8) v1 (June 9, 2020) * initial release * on top of v2020.07-rc4 AKASHI Takahiro (8): lib: rsa: export rsa_verify_with_pkey() lib: crypto: add public_key_verify_signature() lib: crypto: enable x509_check_for_self_signed() lib: crypto: import pkcs7_verify.c from linux lib: crypto: add pkcs7_digest() lib: crypto: export and enhance pkcs7_verify_one() efi_loader: signature: rework for intermediate certificates support test/py: efi_secboot: add test for intermediate certificates include/crypto/pkcs7.h | 9 +- include/crypto/public_key.h | 2 +- include/efi_loader.h | 8 +- include/u-boot/rsa.h | 3 + lib/crypto/Kconfig | 3 + lib/crypto/Makefile | 1 + lib/crypto/pkcs7_verify.c | 654 ++++++++++++++++++ lib/crypto/public_key.c | 70 +- lib/crypto/x509_cert_parser.c | 2 - lib/crypto/x509_public_key.c | 33 +- lib/efi_loader/Kconfig | 1 + lib/efi_loader/efi_image_loader.c | 2 +- lib/efi_loader/efi_signature.c | 385 +++++------ lib/efi_loader/efi_variable.c | 5 +- lib/rsa/rsa-verify.c | 8 +- test/py/tests/test_efi_secboot/conftest.py | 156 ++++- test/py/tests/test_efi_secboot/defs.py | 11 +- test/py/tests/test_efi_secboot/openssl.cnf | 48 ++ .../test_efi_secboot/test_signed_intca.py | 135 ++++ 19 files changed, 1297 insertions(+), 239 deletions(-) create mode 100644 lib/crypto/pkcs7_verify.c create mode 100644 test/py/tests/test_efi_secboot/openssl.cnf create mode 100644 test/py/tests/test_efi_secboot/test_signed_intca.py