All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Usama Arif" <usama.arif@arm.com>
To: openembedded-core@lists.openembedded.org
Cc: nd@arm.com
Subject: Re: [PATCH] kernel-fitimage: generate openssl RSA keys for signing fitimage
Date: Tue, 8 Sep 2020 13:43:01 +0100	[thread overview]
Message-ID: <195ee8ef-96b3-112a-6954-bb5df8e65e4f@arm.com> (raw)
In-Reply-To: <20200908122835.38284-1-usama.arif@arm.com>



On 08/09/2020 13:28, Usama Arif wrote:
> The keys are only generated if they dont exist. The key
> generation can be turned off by setting FIT_GENERATE_KEYS to "0".
> The default key length for private keys is 2048 and the default
> format for public key certificate is x.509.
> 
> Signed-off-by: Usama Arif <usama.arif@arm.com>
> ---
>   meta/classes/kernel-fitimage.bbclass | 44 ++++++++++++++++++++++++++++
>   1 file changed, 44 insertions(+)
> 
> diff --git a/meta/classes/kernel-fitimage.bbclass b/meta/classes/kernel-fitimage.bbclass
> index fa4ea6feef..1fa8c8f05c 100644
> --- a/meta/classes/kernel-fitimage.bbclass
> +++ b/meta/classes/kernel-fitimage.bbclass
> @@ -56,6 +56,22 @@ FIT_HASH_ALG ?= "sha256"
>   # fitImage Signature Algo
>   FIT_SIGN_ALG ?= "rsa2048"
>   
> +# Generate keys for signing fitImage
> +FIT_GENERATE_KEYS ?= "${@bb.utils.contains('UBOOT_SIGN_ENABLE', '1', '1', '0', d)}"
> +
> +# Size of private key in number of bits
> +FIT_SIGN_NUMBITS ?= "2048"
> +
> +# args to openssl genrsa (Default is just the public exponent)
> +FIT_KEY_GENRSA_ARGS ?= "-F4"
> +
> +# args to openssl req (Default is -batch for non interactive mode and
> +# -new for new certificate)
> +FIT_KEY_REQ_ARGS ?= "-batch -new"
> +
> +# Standard format for public key certificate
> +FIT_KEY_SIGN_PKCS ?= "-x509"
> +
>   #
>   # Emit the fitImage ITS header
>   #
> @@ -522,6 +538,34 @@ do_assemble_fitimage_initramfs() {
>   
>   addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
>   
> +do_generate_rsa_keys() {
> +	if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
> +		bbwarn "FIT_GENERATE_KEYS is set to 1 eventhough UBOOT_SIGN_ENABLE is set to 0. The keys will not be generated as they won't be used."
> +	fi
> +
> +	if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
> +
> +		# Generate keys only if they don't already exist
> +		if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \
> +			[ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt]; then
> +
> +			# make directory if it does not already exist
> +			mkdir -p "${UBOOT_SIGN_KEYDIR}"
> +
> +			echo "Generating RSA private key for signing fitImage"
> +			openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \
> +				"${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
> +				"${FIT_SIGN_NUMBITS}"
> +
> +			echo "Generating certificate for signing fitImage"
> +			openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \
> +				-key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
> +				-out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt
> +		fi
> +	fi
> +}
> +
> +addtask generate_rsa_keys before do_assemble_fitimage after do_compile
>   
>   kernel_do_deploy[vardepsexclude] = "DATETIME"
>   kernel_do_deploy_append() {
> 

The relevant yocto-docs changes for this patch are in 
https://lists.yoctoproject.org/g/docs/message/340

  reply	other threads:[~2020-09-08 12:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 12:28 [PATCH] kernel-fitimage: generate openssl RSA keys for signing fitimage Usama Arif
2020-09-08 12:43 ` Usama Arif [this message]
     [not found] ` <1632CF861F095801.32160@lists.openembedded.org>
2020-09-21  9:47   ` [OE-core] " Usama Arif
2020-09-21 13:03 ` Richard Purdie
2020-09-21 13:24   ` Usama Arif
     [not found]   ` <1636CF692A74423D.559@lists.openembedded.org>
2020-09-30 10:14     ` Usama Arif
2020-09-30 10:22       ` Richard Purdie
2020-09-30 10:48         ` Usama Arif

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=195ee8ef-96b3-112a-6954-bb5df8e65e4f@arm.com \
    --to=usama.arif@arm.com \
    --cc=nd@arm.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.