Objective
Sign STM32MP23 firmware using AWS KMS ECDSA P-256 keys instead of local private keys, to enable cloud-based signing workflow.
- Hardware: STM32MP23 series
- Header Version: 0x00020200 (v2.2.0)
- Signing Algorithm: ECDSA_SHA_256 (P-256 NIST / secp256r1)
Development and Issues summary as follows
We have followed following ways to sign binaries externally
- Using external HSM - SoftHSM
- This method shows the exact same issue mentioned in community thread
Error: Invalid Header version value
Header v2.2 accepts 8 public keys - If we skip the header version argument, the signing tool fails with CKR_OBJECT_HANDLE_INVALID error.
- Using PKCS#11 solution along with aws-kms-pkcs11
- With this method too, we face similar errors as mentioned in #1.
- With header version 2.2 argument, it gives Invalid header error
- If we skip the header version argument, the signing tool fails with CKR_OBJECT_HANDLE_INVALID error.
Developed a custom signing script (Compatible with the STM32 Signing workflow)
- Firmware signed is rejected by STM32MP2 boot ROM during authentication.
For custom signing script
Firmware signed with AWS KMS ECDSA signatures is rejected by STM32MP2 boot ROM during authentication, despite:
- Header construction being identical to STM32 signing tool output (except Image signature)
- Authentication, Pad and Post header 2.2 information are identical to sign image generated by STM32 signing tool which is working. (Validated using STM32_SigningTool_CLI -dump).
- This proves that extracted public key from AWS KMS and local PEM are identical.
- Signature format matching STM32 signing tool (Signature Format: raw r|s, 64 bytes, big-endian)
- SHA256 Hash is calculated from header version field (offset 0x48) to end of image.
- AWS KMS verify() API confirming the signature is mathematically valid for the hash.
WORKAROUND:
The image signature field (offset - 0x04) is updated to match the signed binaries generated by the STM32 signing tool using the local PEM key (Refer). The signed firmware boots successfully on the same hardware.
Workaround confirms STM32 header generated by script matches the STM32 header specification except image signature field.
Signing Workflow followed:
- Read unsigned firmware
- Align image length to 32 bytes
- Build authentication extension with public key hashes
- Build padding extension (Currently used same as generated by Firmware signed with local PEM key using STM32 tool)
- Calculate SHA256 hash of signed region (from 0x48 to end of image)
- Sign hash using AWS KMS Sign API (MessageType='DIGEST', SigningAlgorithm='ECDSA_SHA_256')
- Convert DER signature (70 bytes) to raw r|s format (64 bytes) (Also tried normalised s)
- Write signature at offset 0x04
- Write signed firmware to output file
STM32MP2 boot ROM should accept AWS KMS-generated signatures if header construction matches STM32 specification.
Questions for ST Community
- Does STM32MP2 boot ROM have any specific requirements for ECDSA signature generation beyond standard ECDSA validation?
- Are there any additional signature verification steps in boot ROM not documented in the public specification?
- Is low-S normalization required or prohibited by STM32 boot ROM?
- Are there any constraints on the nonce/k-value generation that AWS KMS might not satisfy?
- Has anyone successfully used AWS KMS (or similar cloud HSM services) for STM32MP2 firmware signing?
Thanks & Regards
Meetali Patel