Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B51C7C7619A for ; Wed, 12 Apr 2023 13:51:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7279685EEF; Wed, 12 Apr 2023 15:51:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="edBCTlsi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6951285EF6; Wed, 12 Apr 2023 15:51:15 +0200 (CEST) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 930EF85D94 for ; Wed, 12 Apr 2023 15:51:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=n-francis@ti.com Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 33CDp0QR069464; Wed, 12 Apr 2023 08:51:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1681307460; bh=+DO/Coy/KX83hLuLj3n5K6NgmtIIQlUGnRPCsoHInkY=; h=Date:Subject:To:CC:References:From:In-Reply-To; b=edBCTlsigmcMrUmB6wYYhgC3IeUEYPvb50igv0rz3NJu+RkudJmGbJhdxguxzPiTf 8elbjhks7cuPkXqM7DmjSnRS7Sr0SJkvSyWz2qxZJsHpv6A+6ue0cRZIjcH9YEA6A+ ImBMozvXaCilXLWwqAKURswva0VW9PUPIuR/ZXcU= Received: from DLEE114.ent.ti.com (dlee114.ent.ti.com [157.170.170.25]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 33CDp0RS077803 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 12 Apr 2023 08:51:00 -0500 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE114.ent.ti.com (157.170.170.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Wed, 12 Apr 2023 08:51:00 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Wed, 12 Apr 2023 08:51:00 -0500 Received: from [172.24.145.149] (ileaxei01-snat.itg.ti.com [10.180.69.5]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 33CDoucV005473; Wed, 12 Apr 2023 08:50:57 -0500 Message-ID: <73b27fb5-dca6-0e70-077a-7ddd80148454@ti.com> Date: Wed, 12 Apr 2023 19:20:56 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v2 02/18] binman: ti-secure: Add support for TI signing To: Simon Glass CC: , , , , , , , , References: <20230404121342.446935-1-n-francis@ti.com> <20230404121342.446935-3-n-francis@ti.com> Content-Language: en-US From: Neha Malcom Francis In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Hi Simon On 06/04/23 00:07, Simon Glass wrote: > kHi Neha, > > On Wed, 5 Apr 2023 at 00:13, Neha Malcom Francis wrote: >> >> The ti-secure entry contains certificate for binaries that will be >> loaded or booted by system firmware whereas the ti-secure-rom entry >> contains certificate for binaries that will be booted by ROM. Support >> for both these types of certificates is necessary for booting of K3 >> devices. >> >> Signed-off-by: Neha Malcom Francis >> --- >> board/ti/keys/custMpk.pem | 51 ++++ >> board/ti/keys/ti-degenerate-key.pem | 10 + >> tools/binman/btool/openssl.py | 244 ++++++++++++++++++ >> tools/binman/entries.rst | 25 ++ >> tools/binman/etype/ti_secure.py | 83 ++++++ >> tools/binman/etype/ti_secure_rom.py | 233 +++++++++++++++++ >> tools/binman/etype/x509_cert.py | 87 ++++++- >> tools/binman/ftest.py | 46 ++++ >> tools/binman/test/279_ti_secure.dts | 17 ++ >> tools/binman/test/280_ti_secure_rom.dts | 17 ++ >> .../test/281_ti_secure_rom_combined.dts | 25 ++ >> 11 files changed, 830 insertions(+), 8 deletions(-) >> create mode 100644 board/ti/keys/custMpk.pem >> create mode 100644 board/ti/keys/ti-degenerate-key.pem >> create mode 100644 tools/binman/etype/ti_secure.py >> create mode 100644 tools/binman/etype/ti_secure_rom.py >> create mode 100644 tools/binman/test/279_ti_secure.dts >> create mode 100644 tools/binman/test/280_ti_secure_rom.dts >> create mode 100644 tools/binman/test/281_ti_secure_rom_combined.dts > >> diff --git a/tools/binman/btool/openssl.py b/tools/binman/btool/openssl.py >> index 3a4dbdd6d7..aad3b61ae2 100644 >> --- a/tools/binman/btool/openssl.py >> +++ b/tools/binman/btool/openssl.py >> @@ -15,6 +15,13 @@ import hashlib >> from binman import bintool >> from u_boot_pylib import tools >> >> + >> +VALID_SHAS = [256, 384, 512, 224] >> +SHA_OIDS = {256:'2.16.840.1.101.3.4.2.1', >> + 384:'2.16.840.1.101.3.4.2.2', >> + 512:'2.16.840.1.101.3.4.2.3', >> + 224:'2.16.840.1.101.3.4.2.4'} >> + >> class Bintoolopenssl(bintool.Bintool): >> """openssl tool >> >> @@ -74,6 +81,243 @@ imageSize = INTEGER:{len(indata)} >> '-sha512'] >> return self.run_cmd(*args) >> >> + def x509_cert_sysfw(self, cert_fname, input_fname, key_fname, sw_rev, >> + config_fname, req_dist_name_dict): >> + """Create a certificate to be booted by system firmware >> + >> + Args: >> + cert_fname (str): Filename of certificate to create >> + input_fname (str): Filename containing data to sign >> + key_fname (str): Filename of .pem file >> + sw_rev (int): Software revision >> + config_fname (str): Filename to write fconfig into >> + req_dist_name_dict (dict): Dictionary containing key-value pairs of >> + req_distinguished_name section extensions, must contain extensions for >> + C, ST, L, O, OU, CN and emailAddress >> + >> + Returns: >> + str: Tool output >> + """ >> + indata = tools.read_file(input_fname) >> + hashval = hashlib.sha512(indata).hexdigest() >> + with open(config_fname, 'w', encoding='utf-8') as outf: >> + print(f'''[ req ] >> +distinguished_name = req_distinguished_name >> +x509_extensions = v3_ca >> +prompt = no >> +dirstring_type = nobmp >> + >> +[ req_distinguished_name ] >> +C = {req_dist_name_dict['C']} >> +ST = {req_dist_name_dict['ST']} >> +L = {req_dist_name_dict['L']} >> +O = {req_dist_name_dict['O']} >> +OU = {req_dist_name_dict['OU']} >> +CN = {req_dist_name_dict['CN']} >> +emailAddress = {req_dist_name_dict['emailAddress']} >> + >> +[ v3_ca ] >> +basicConstraints = CA:true >> +1.3.6.1.4.1.294.1.3 = ASN1:SEQUENCE:swrv >> +1.3.6.1.4.1.294.1.34 = ASN1:SEQUENCE:sysfw_image_integrity >> +1.3.6.1.4.1.294.1.35 = ASN1:SEQUENCE:sysfw_image_load >> + >> +[ swrv ] >> +swrv = INTEGER:{sw_rev} >> + >> +[ sysfw_image_integrity ] >> +shaType = OID:2.16.840.1.101.3.4.2.3 >> +shaValue = FORMAT:HEX,OCT:{hashval} >> +imageSize = INTEGER:{len(indata)} > > There's a lot of duplication here, but at least it is in one file. > > Would it make sense, for example, to have a function like > > add_dn(buf, dict) > > which adds the req_distinguished_name to a stringio buffer? Then that > could be calls from multiple places. > Right that is possible, plus it gives an outline if this etype can be simplified in the future similarly. > Also, please check test coverage (binman test -T). That should be 100% > so you will need to add tests for failing cases as well. > I'll take note of these corrections and send v3 soon, thanks! > Regards, > Simon -- Thanking You Neha Malcom Francis