Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lRF2P-0000Y7-NO for mharc-grub-devel@gnu.org; Tue, 30 Mar 2021 10:08:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF2O-0000UB-7f for grub-devel@gnu.org; Tue, 30 Mar 2021 10:08:08 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:40677) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lRF2M-0004Hb-H8 for grub-devel@gnu.org; Tue, 30 Mar 2021 10:08:07 -0400 Received: by mail-pg1-x529.google.com with SMTP id v186so11793920pgv.7 for ; Tue, 30 Mar 2021 07:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ic7KrnCSYjKVRYkDdsjFfVr3mjv07ZW/MChK5M9bJ8=; b=oujZPcMcukhXB+Tit9F4VHL5+cXkBhUnXxQGAX5XHqQ+VyApAWRptZYaN6PW/wh1AR TTQNMAv1POBPwW6uKiJVQC37i4Y6cv5PqNMdZPuUTnquOLlZLb94nx7HZp2sxeqitirK yDbQwjq9lBJ6Al/CkMx1/GDxMOXOH3OaElqrE= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ic7KrnCSYjKVRYkDdsjFfVr3mjv07ZW/MChK5M9bJ8=; b=AT3iegqvnQmRLfp7K3obbxCb/ODpjd/cyyWZ7wtB7fMqWo9lG6zpPze2C5V6AsoeCO yQO0LQUcIWoa5/4ItzQA5pNUUlaSLnzG6pM8+HYsLx9cJJLJf6X+hsWIIUuONd0V3yTg /JEDpeh7h990b5OwCHKpBZKNbmxoAx12WnrRmdIPIzpiQWnPX+nEqKTNZud0fZ/GBtAV gZLQf8MKjx1efZMbQj8C92nGY8iw2uF37UES0xdZ67nZyAtRQ3jZkmqYeBjYC8jTouco aOXl6Lvbzh3RhjXMi1J52fpvlYKZ/z67yCV9Zzv+lHnydIBnQjRyL2S2mXb6AkIX5YoE bzRg== X-Gm-Message-State: AOAM530/Sv2Y0h4ulHNDJeJSlcXN90T9QNRaec3IQAKoI33DnTqTTcag 1Ei0DC0DUrjSB6hZw7ZBSWeRD941/axTDg== X-Google-Smtp-Source: ABdhPJyx6c4XKRC13P1jj7lYhEr506t0WkL+yI0q5VtrCYzHCh95sJeMVK23mao/q3Ut/5utjo4Emw== X-Received: by 2002:a65:6557:: with SMTP id a23mr13870239pgw.95.1617113284860; Tue, 30 Mar 2021 07:08:04 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-cc4e-3d4e-f51c-bb52.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:cc4e:3d4e:f51c:bb52]) by smtp.gmail.com with ESMTPSA id k19sm5571791pgl.1.2021.03.30.07.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 07:08:04 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: rashmica.g@gmail.com, alastair@d-silva.org, Daniel Axtens Subject: [PATCH 03/19] docs/grub: Document signing grub with an appended signature Date: Wed, 31 Mar 2021 01:07:28 +1100 Message-Id: <20210330140744.176698-4-dja@axtens.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210330140744.176698-1-dja@axtens.net> References: <20210330140744.176698-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::529; envelope-from=dja@axtens.net; helo=mail-pg1-x529.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Mar 2021 14:08:08 -0000 Signing grub for firmware that verifies an appended signature is a bit fiddly. I don't want people to have to figure it out from scratch so document it here. Signed-off-by: Daniel Axtens --- docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/grub.texi b/docs/grub.texi index b1a0e2761691..34a2708bc070 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -6050,6 +6050,48 @@ image works under UEFI secure boot and can maintain the secure-boot chain. It will also be necessary to enrol the public key used into a relevant firmware key database. +@section Signing GRUB with an appended signature + +The @file{core.img} itself can be signed with a Linux kernel module-style +appended signature. + +To support IEEE1275 platforms where the boot image is often loaded directly +from a disk partition rather than from a file system, the @file{core.img} +can specify the size and location of the appended signature with an ELF +note added by @command{grub-install}. + +An image can be signed this way using the @command{sign-file} command from +the Linux kernel: + +@example +@group +# grub.key is your private key and certificate.der is your public key + +# Determine the size of the appended signature. It depends on the signing +# certificate and the hash algorithm +touch empty +sign-file SHA256 grub.key certificate.der empty empty.sig +SIG_SIZE=`stat -c '%s' empty.sig` +rm empty empty.sig + +# Build a grub image with $SIG_SIZE reserved for the signature +grub-install --appended-signature-size $SIG_SIZE --modules="..." ... + +# Replace the reserved size with a signature: +# cut off the last $SIG_SIZE bytes with truncate's minus modifier +truncate -s -$SIG_SIZE /boot/grub/powerpc-ieee1275/core.elf core.elf.unsigned +# sign the trimmed file with an appended signature, restoring the correct size +sign-file SHA256 grub.key certificate.der core.elf.unsigned core.elf.signed + +# Don't forget to install the signed image as required +# (e.g. on powerpc-ieee1275, to the PReP partition) +@end group +@end example + +As with UEFI secure boot, it is necessary to build in the required modules, +or sign them separately. + + @node Platform limitations @chapter Platform limitations -- 2.27.0