Skip to contentSkip to conversation

kernel-fit-image: Check signing key files based on algorithm

PATCH In review Jamin Lin 5 participants 9 messages May 15 – May 19

lore
Share & tools
lore

Jamin Lin

author
#0 lore raw

PATCH 1/1 kernel-fit-image: Check signing key files based on algorithm

The key file validation in run_mkimage_sign() unconditionally required .key and .crt regardless of the signing algorithm. This prevented ECDSA signing which uses a single .pem file.

Extract the check into _check_sign_key_files() and detect the algorithm from the algo string (e.g. "sha256,ecdsa384") by scanning all comma-separated parts so field order does not matter:
- ECDSA: requires <keyname>.pem
- RSA : requires <keyname>.key and <keyname>.crt

---
 meta/lib/oe/fitimage.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
meta/lib/oe/fitimage.py +14 -4
index 881d0eae0a..e6ff66ca43 100644
@@ -574,6 +574,18 @@ class ItsNodeRootKernel(ItsNode):
         except subprocess.CalledProcessError as e:
             bb.fatal(f"Command '{' '.join(cmd)}' failed with return code {e.returncode}\nstdout: {e.stdout.decode()}\nstderr: {e.stderr.decode()}\nitsflile: {os.path.abspath(itsfile)}")
 
+    def _check_sign_key_files(self, key_path, algo):
+        """Check signing key files: ECDSA needs .pem, RSA needs .key + .crt."""
+        algo_parts = [p.strip().lower() for p in algo.split(',')]
+        is_ecdsa = any(p.startswith('ecdsa') for p in algo_parts)
+
+        if is_ecdsa:
+            if not os.path.exists(key_path + '.pem'):
+                bb.fatal("ECDSA signing requires '%s.pem'" % key_path)
+        else:
+            if not os.path.exists(key_path + '.key') or not os.path.exists(key_path + '.crt'):
+                bb.fatal("%s.key or .crt does not exist" % key_path)
+
     def run_mkimage_sign(self, fitfile):
         if not self._sign_enable:
             bb.debug(1, "FIT image signing is disabled. Skipping signing.")
@@ -581,12 +593,10 @@ class ItsNodeRootKernel(ItsNode):
 
         # Some sanity checks because mkimage exits with 0 also without needed keys
         sign_key_path = os.path.join(self._sign_keydir, self._sign_keyname_conf)
-        if not os.path.exists(sign_key_path + '.key') or not os.path.exists(sign_key_path + '.crt'):
-            bb.fatal("%s.key or .crt does not exist" % sign_key_path)
+        self._check_sign_key_files(sign_key_path, self._sign_algo)
         if self._sign_individual:
             sign_key_img_path = os.path.join(self._sign_keydir, self._sign_keyname_img)
-            if not os.path.exists(sign_key_img_path + '.key') or not os.path.exists(sign_key_img_path + '.crt'):
-                bb.fatal("%s.key or .crt does not exist" % sign_key_img_path)
+            self._check_sign_key_files(sign_key_img_path, self._sign_algo)
 
         cmd = [
             self._mkimage_sign,
Signature · 1 line
2.43.0
#1 lore raw

Adrian,

Can you review this patch please ?
You were nominated in the patch review meeting.

Thanks,
../Randy

Quoted 57 lines · Jamin Lin via lists.openembedded.org

The key file validation in run_mkimage_sign() unconditionally required .key and .crt regardless of the signing algorithm. This prevented ECDSA signing which uses a single .pem file.

Extract the check into _check_sign_key_files() and detect the algorithm from the algo string (e.g. "sha256,ecdsa384") by scanning all comma-separated parts so field order does not matter:
- ECDSA: requires <keyname>.pem
- RSA : requires <keyname>.key and <keyname>.crt

---
  meta/lib/oe/fitimage.py | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
meta/lib/oe/fitimage.py +12 -0
index 881d0eae0a..e6ff66ca43 100644
@@ -574,6 +574,18 @@ class ItsNodeRootKernel(ItsNode):
          except subprocess.CalledProcessError as e:
              bb.fatal(f"Command '{' '.join(cmd)}' failed with return code {e.returncode}\nstdout: {e.stdout.decode()}\nstderr: {e.stderr.decode()}\nitsflile: {os.path.abspath(itsfile)}")
 
+    def _check_sign_key_files(self, key_path, algo):
+        """Check signing key files: ECDSA needs .pem, RSA needs .key + .crt."""
+        algo_parts = [p.strip().lower() for p in algo.split(',')]
+        is_ecdsa = any(p.startswith('ecdsa') for p in algo_parts)
+
+        if is_ecdsa:
+            if not os.path.exists(key_path + '.pem'):
+                bb.fatal("ECDSA signing requires '%s.pem'" % key_path)
+        else:
+            if not os.path.exists(key_path + '.key') or not os.path.exists(key_path + '.crt'):
+                bb.fatal("%s.key or .crt does not exist" % key_path)
+
      def run_mkimage_sign(self, fitfile):
          if not self._sign_enable:
              bb.debug(1, "FIT image signing is disabled. Skipping signing.") @@ -581,12 +593,10 @@ class ItsNodeRootKernel(ItsNode): # Some 

sanity checks because mkimage exits with 0 also without needed keys sign_key_path = os.path.join(self._sign_keydir, self._sign_keyname_conf) - if not os.path.exists(sign_key_path + '.key') or not os.path.exists(sign_key_path + '.crt'): - bb.fatal("%s.key or .crt does not exist" % sign_key_path)

meta/lib/oe/fitimage.py +2 -3
+        self._check_sign_key_files(sign_key_path, self._sign_algo)
          if self._sign_individual:
              sign_key_img_path = os.path.join(self._sign_keydir, self._sign_keyname_img)
-            if not os.path.exists(sign_key_img_path + '.key') or not os.path.exists(sign_key_img_path + '.crt'):
-                bb.fatal("%s.key or .crt does not exist" % sign_key_img_path)
+            self._check_sign_key_files(sign_key_img_path, self._sign_algo)
 
          cmd = [
              self._mkimage_sign,
 
-=-=-=-=-=-=-=-=-=-=-=-

Links: You receive all messages sent to this group.
View/Reply Online (#237076):https://lists.openembedded.org/g/openembedded-core/message/237076 Mute This Topic:https://lists.openembedded.org/mt/119327152/3616765
Group Owner:[email protected] Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 2 lines
# Randy MacLeod
# Wind River Linux
#2 lore raw
In reply to Jamin Lin
Quoted 9 lines · Jamin Lin

The key file validation in run_mkimage_sign() unconditionally required .key and .crt regardless of the signing algorithm. This prevented ECDSA signing which uses a single .pem file.

Extract the check into _check_sign_key_files() and detect the algorithm from the algo string (e.g. "sha256,ecdsa384") by scanning all comma-separated parts so field order does not matter:
- ECDSA: requires <keyname>.pem
- RSA : requires <keyname>.key and <keyname>.crt

Hi Jamin,

This contradicts my understanding of cryptographic algorithms and file formats. To my knowledge, ECDSA & RSA are algorithms, PEM vs .key/.crt are file formats. You can have an RSA certificate in PEM format, and you can store the key & cert for use in ECDSA in .key & .crt files if you want to.

Am I misunderstanding something here?

Best regards,

Signature · 1 line
Paul Barker
#3 lore raw

Hi Jasmin

Probably Paul is right: pem versus crt + key is a different thing than ECS versus RSA.

The its specification mentions only crt + key:
https://fitspec.osfw.foundation/#configuration-signature-nodes. Are you sure that mkimage works with pem but not with crt + key?
My guess is that converting the pem somehow like
https://stackoverflow.com/questions/13732826/convert-pem-to-crt-and-key
would work as well.

If Yocto should get support for pem files it should support it for both formats and this should be covered by tests as well. But since the fit spec and the mkimage documentation do not mention pem files also on that side some investigation would probably be needed to ensure this is officially supported.

Regards
Adrian

Paul Barker via lists.openembedded.org <paul= [email protected]> schrieb am Mo., 18. Mai 2026, 19:39:

Quoted 38 lines · Jamin Lin
Quoted 9 lines

The key file validation in run_mkimage_sign() unconditionally required .key and .crt regardless of the signing algorithm. This prevented ECDSA signing which uses a single .pem file.

Extract the check into _check_sign_key_files() and detect the algorithm from the algo string (e.g. "sha256,ecdsa384") by scanning all comma-separated parts so field order does not matter:
- ECDSA: requires <keyname>.pem
- RSA : requires <keyname>.key and <keyname>.crt

Hi Jamin,

This contradicts my understanding of cryptographic algorithms and file formats. To my knowledge, ECDSA & RSA are algorithms, PEM vs .key/.crt are file formats. You can have an RSA certificate in PEM format, and you can store the key & cert for use in ECDSA in .key & .crt files if you want to.

Am I misunderstanding something here?

Best regards,

--
Paul Barker

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#237254):
https://lists.openembedded.org/g/openembedded-core/message/237254
Mute This Topic: https://lists.openembedded.org/mt/119327152/4454582
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

author
#4 lore raw

Hi Adrian, Paul

Thanks for the review and suggestions.

The handling of RSA and ECDSA keys in mkimage is different.

For ECDSA, mkimage only uses the .pem file format as the private key for signing the image.
It does not use separate .key and .crt files. However, OE/fitimage.py currently requires users to provide both .key and .crt files.

As a result, when users want to use the ECDSA algorithm, they are required to prepare .pem, .key, and .crt files, even though only the .pem file is actually used by mkimage. The .key and .crt files are only needed to satisfy the OE/fitimage.py requirements.

Please also refer to the ECDSA implementation in U-Boot:
https://github.com/u-boot/u-boot/blob/master/lib/ecdsa/ecdsa-libcrypto.c

If you believe that users should still be required to provide .key and .crt files in OE/fitimage, then this patch can be dropped.

Thanks,
Jamin

************* Email Confidentiality Notice ********************
免責聲明:
本信件(或其附件)可能包含機密資訊,並受法律保護。如 台端非指定之收件者,請以電子郵件通知本電子郵件之發送者, 並請立即刪除本電子郵件及其附件和銷毀所有複印件。謝謝您的合作!

DISCLAIMER:
This message (and any attachments) may contain legally privileged and/or other confidential information. If you have received it in error, please notify the sender by reply e-mail and immediately delete the e-mail and any attachments without copying or disclosing the contents. Thank you.

From: Adrian Freihofer <[email protected]>
Sent: Tuesday, May 19, 2026 5:40 AM
To: Jamin Lin <[email protected]>
Cc: OE-core <[email protected]>; Troy Lee <[email protected]>; Vince Chang <[email protected]>; [email protected]
Subject: Re: [OE-core] [PATCH v1] kernel-fit-image: Check signing key files based on algorithm

Hi Jasmin

Probably Paul is right: pem versus crt + key is a different thing than ECS versus RSA.

The its specification mentions only crt + key: https://fitspec.osfw.foundation/#configuration-signature-nodes. Are you sure that mkimage works with pem but not with crt + key? My guess is that converting the pem somehow like https://stackoverflow.com/questions/13732826/convert-pem-to-crt-and-key would work as well.

If Yocto should get support for pem files it should support it for both formats and this should be covered by tests as well. But since the fit spec and the mkimage documentation do not mention pem files also on that side some investigation would probably be needed to ensure this is officially supported.

Regards
Adrian

Paul Barker via lists.openembedded.org<http://lists.openembedded.org> <[email protected]<mailto:[email protected]>> schrieb am Mo., 18. Mai 2026, 19:39:

Quoted 9 lines · Jamin Lin

The key file validation in run_mkimage_sign() unconditionally required .key and .crt regardless of the signing algorithm. This prevented ECDSA signing which uses a single .pem file.

Extract the check into _check_sign_key_files() and detect the algorithm from the algo string (e.g. "sha256,ecdsa384") by scanning all comma-separated parts so field order does not matter:
- ECDSA: requires <keyname>.pem
- RSA : requires <keyname>.key and <keyname>.crt

Hi Jamin,

This contradicts my understanding of cryptographic algorithms and file formats. To my knowledge, ECDSA & RSA are algorithms, PEM vs .key/.crt are file formats. You can have an RSA certificate in PEM format, and you can store the key & cert for use in ECDSA in .key & .crt files if you want to.

Yes, it is correct.

Am I misunderstanding something here?

Best regards,

--
Paul Barker

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#237254): https://lists.openembedded.org/g/openembedded-core/message/237254
Mute This Topic: https://lists.openembedded.org/mt/119327152/4454582
Group Owner: [email protected]<mailto:openembedded-core%[email protected]>
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]<mailto:[email protected]>]
-=-=-=-=-=-=-=-=-=-=-=-

author
#5 lore raw

From: Jamin Lin
Sent: Tuesday, May 19, 2026 9:17 AM
To: 'Adrian Freihofer' <[email protected]>
Cc: OE-core <[email protected]>; Troy Lee <[email protected]>; Vince Chang <[email protected]>; [email protected]
Subject: RE: [OE-core] [PATCH v1] kernel-fit-image: Check signing key files based on algorithm

Hi Adrian, Paul

Thanks for the review and suggestions.

The handling of RSA and ECDSA keys in mkimage is different.

For ECDSA, mkimage only uses the .pem file format as the private key for signing the image.
It does not use separate .key and .crt files. However, OE/fitimage.py currently requires users to provide both .key and .crt files.

As a result, when users want to use the ECDSA algorithm, they are required to prepare .pem, .key, and .crt files, even though only the .pem file is actually used by mkimage. The .key and .crt files are only needed to satisfy the OE/fitimage.py requirements.

Please also refer to the ECDSA implementation in U-Boot:
https://github.com/u-boot/u-boot/blob/master/lib/ecdsa/ecdsa-libcrypto.c

If you believe that users should still be required to provide .key and .crt files in OE/fitimage, then this patch can be dropped.

Thanks,
Jamin

Sorry I lost to remove the following disclaimer notice

************* Email Confidentiality Notice ********************
免責聲明:
本信件(或其附件)可能包含機密資訊,並受法律保護。如 台端非指定之收件者,請以電子郵件通知本電子郵件之發送者, 並請立即刪除本電子郵件及其附件和銷毀所有複印件。謝謝您的合作!

DISCLAIMER:
This message (and any attachments) may contain legally privileged and/or other confidential information. If you have received it in error, please notify the sender by reply e-mail and immediately delete the e-mail and any attachments without copying or disclosing the contents. Thank you.

From: Adrian Freihofer <[email protected]<mailto:[email protected]>>
Sent: Tuesday, May 19, 2026 5:40 AM
To: Jamin Lin <[email protected]<mailto:[email protected]>>
Cc: OE-core <[email protected]<mailto:[email protected]>>; Troy Lee <[email protected]<mailto:[email protected]>>; Vince Chang <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: Re: [OE-core] [PATCH v1] kernel-fit-image: Check signing key files based on algorithm

Hi Jasmin

Probably Paul is right: pem versus crt + key is a different thing than ECS versus RSA.

The its specification mentions only crt + key: https://fitspec.osfw.foundation/#configuration-signature-nodes. Are you sure that mkimage works with pem but not with crt + key? My guess is that converting the pem somehow like https://stackoverflow.com/questions/13732826/convert-pem-to-crt-and-key would work as well.

If Yocto should get support for pem files it should support it for both formats and this should be covered by tests as well. But since the fit spec and the mkimage documentation do not mention pem files also on that side some investigation would probably be needed to ensure this is officially supported.

Regards
Adrian

Paul Barker via lists.openembedded.org<http://lists.openembedded.org> <[email protected]<mailto:[email protected]>> schrieb am Mo., 18. Mai 2026, 19:39:

Quoted 9 lines · Jamin Lin

The key file validation in run_mkimage_sign() unconditionally required .key and .crt regardless of the signing algorithm. This prevented ECDSA signing which uses a single .pem file.

Extract the check into _check_sign_key_files() and detect the algorithm from the algo string (e.g. "sha256,ecdsa384") by scanning all comma-separated parts so field order does not matter:
- ECDSA: requires <keyname>.pem
- RSA : requires <keyname>.key and <keyname>.crt

Hi Jamin,

This contradicts my understanding of cryptographic algorithms and file formats. To my knowledge, ECDSA & RSA are algorithms, PEM vs .key/.crt are file formats. You can have an RSA certificate in PEM format, and you can store the key & cert for use in ECDSA in .key & .crt files if you want to.
Yes, it is correct.

Am I misunderstanding something here?

Best regards,

--
Paul Barker

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#237254): https://lists.openembedded.org/g/openembedded-core/message/237254
Mute This Topic: https://lists.openembedded.org/mt/119327152/4454582
Group Owner: [email protected]<mailto:openembedded-core%[email protected]>
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]<mailto:[email protected]>]
-=-=-=-=-=-=-=-=-=-=-=-

#6 lore raw

Hi Jamin, hi Paul

After looking into the code of mkimage, I agree with the patch. It is correct that rsa-sign.c needs key + crt files but ecdsa-libcrypto.c uses a pem file.

My conclusion is: The patch can be merged.

Thank you.

Regards,
Adrian

Quoted 49 lines · Jamin Lin via lists.openembedded.org

From: Jamin Lin
Sent: Tuesday, May 19, 2026 9:17 AM
To: 'Adrian Freihofer' <[email protected]>
Cc: OE-core <[email protected]>; Troy Lee <[email protected]>; Vince Chang <[email protected]>; [email protected]
Subject: RE: [OE-core] [PATCH v1] kernel-fit-image: Check signing key files based on algorithm

Hi Adrian, Paul

Thanks for the review and suggestions.

The handling of RSA and ECDSA keys in mkimage is different.
For ECDSA, mkimage only uses the .pem file format as the private key for signing the image.
It does not use separate .key and .crt files. However, OE/fitimage.py currently requires users to provide both .key and .crt files.
As a result, when users want to use the ECDSA algorithm, they are required to prepare .pem, .key, and .crt files, even though only the .pem file is actually used by mkimage.
The .key and .crt files are only needed to satisfy the OE/fitimage.py requirements.

Please also refer to the ECDSA implementation in U-Boot:
https://github.com/u-boot/u-boot/blob/master/lib/ecdsa/ecdsa-libcrypto.c

If you believe that users should still be required to provide .key and .crt files in OE/fitimage, then this patch can be dropped.
Thanks,
Jamin

Quoted 13 lines

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#237265):
https://lists.openembedded.org/g/openembedded-core/message/237265
Mute This Topic:
https://lists.openembedded.org/mt/119327152/3616858
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#7 lore raw
Quoted 7 lines · Adrian Freihofer via lists.openembedded.org

Hi Jamin, hi Paul

After looking into the code of mkimage, I agree with the patch. It is correct that rsa-sign.c needs key + crt files but ecdsa-libcrypto.c uses a pem file.

My conclusion is: The patch can be merged.

Hi Jamin and Adrian,

Thanks both for the extra information. I think the commit message and comments should be updated to say that this is due to the formats expected by mkimage and fitimage.py, then we should be able to accept this.

Best regards,

Signature · 1 line
Paul Barker
author
#8 lore raw

Hi Paul, Adrian

Quoted 21 lines

-----Original Message-----
From: Paul Barker <[email protected]>
Sent: Tuesday, May 19, 2026 4:33 PM
To: [email protected]; Jamin Lin <[email protected]>
Cc: OE-core <[email protected]>; Troy Lee <[email protected]>; Vince Chang <[email protected]>
Subject: Re: [OE-core] [PATCH v1] kernel-fit-image: Check signing key files based on algorithm

Quoted 7 lines · Adrian Freihofer via lists.openembedded.org

Hi Jamin, hi Paul

After looking into the code of mkimage, I agree with the patch. It is correct that rsa-sign.c needs key + crt files but ecdsa-libcrypto.c uses a pem file.

My conclusion is: The patch can be merged.

Hi Jamin and Adrian,

Quoted 8 lines

Thanks both for the extra information. I think the commit message and comments should be updated to say that this is due to the formats expected by mkimage and fitimage.py, then we should be able to accept this.

Best regards,

--
Paul Barker

Thanks for the review and suggestion.

Will change the commit log and title as following.

kernel-fit-image: Validate key files expected by mkimage for the selected algorithm

```
The signing key validation in run_mkimage_sign() unconditionally
required <keyname>.key and <keyname>.crt regardless of the signing
algorithm.

However, mkimage handles RSA and ECDSA keys differently. RSA signing
uses separate .key and .crt files, while ECDSA signing uses a single
.pem file.

As a result, OE/fitimage.py required users of ECDSA signing to provide
unused .key and .crt files only to satisfy the validation checks.

Refactor the validation logic into _check_sign_key_files() and validate
the required files according to the selected signing algorithm:
- ECDSA: requires <keyname>.pem
- RSA: requires <keyname>.key and <keyname>.crt

Detect the algorithm by scanning all comma-separated parts of the algo
string so the field order does not matter (e.g. "sha256,ecdsa384").
```

Fitimage.py

Function comment as below.

+ def _check_sign_key_files(self, key_path, algo):

+        """Check signing key files: ECDSA needs .pem, RSA needs .key + .crt."""   ---> Change to """Validate key files expected by mkimage for the selected algorithm."""
+        algo_parts = [p.strip().lower() for p in algo.split(',')]
+        is_ecdsa = any(p.startswith('ecdsa') for p in algo_parts)

+
+ if is_ecdsa:
+ if not os.path.exists(key_path + '.pem'):
+ bb.fatal("ECDSA signing requires '%s.pem'" % key_path)
+ else:
+ if not os.path.exists(key_path + '.key') or not os.path.exists(key_path + '.crt'):
+ bb.fatal("%s.key or .crt does not exist" % key_path)
+

Thanks,
Jamin