Commit Graph

222 Commits

Author SHA1 Message Date
David Vincze a4800ce0cf imgtool: Add missing encodings to emitter tests
Signed-off-by: David Vincze <david.vincze@arm.com>
Change-Id: Iff37cb62514b181a30f5537d6692d55e3d9c73ed
(cherry picked from commit f763c5ffee)
2024-11-04 14:27:47 +00:00
Rustam Ismayilov 80397e0f28 imgtool: Fix getpub fails for ed25519 key
Fix getpub command fails to emit public pair of ed25519 key with
encoding.

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I3d255f576b2d8a8d0cbc8e31ff378717acb060c7
(cherry picked from commit ef598b13b5)
2024-11-04 14:27:44 +00:00
Rustam Ismayilov 197287cea1 imgtool: Bump cryptography library version
Update requirements.txt to support PrivateKeyType and
PublicKeyType which are available in cryptography library since
version 40.0.0 and prevent failing CI jobs in upcoming changes.

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I94b888d64c2f33ccb829912491e3b8c44b9cc2b2
(cherry picked from commit 49976dc678)
2024-11-04 14:24:00 +00:00
Rustam Ismayilov 533fef2ad7 imgtool: Update version.py to take command line arguments
Main method printed hardcoded versions, update to take argument
to enable the possibility of testing version strings by invoking
the command through command line.

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: If75769ef223944865313ed95336e859ebef85fd6
2024-06-14 13:56:40 +02:00
Rustam Ismayilov 316a139c1c imgtool: dumpinfo improvements
Fix trailer info dumping reads pad characters as values for status
Refactor printing styled texts and frames
Use isinstance() for type checking
Fold notice text depending on line length
Refactoring some parts for readability
Fix additional linting issues

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I741562bb70b18407bdd32e9c7391048faf6394c6
2024-06-14 13:56:40 +02:00
Rustam Ismayilov f3a5702879 imgtool: Various dumpinfo fixes
Add support for dumping images with custom tlv
Fix uninitialized access to some variables
Fix trailer magic detection
Fix some linting issues (parenthesis, indentation, spacing)

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I5b6e1dfa74606e2645a258065dd045cc8c7052c5
2024-06-14 13:56:40 +02:00
Rustam Ismayilov d16a613f6d imgtool: Assert "measurement value" is last in boot_record.py
'Measurement Value' added the 'properties' list initially,
rather than adding it separately later.
Added an assertion to ensure 'Measurement Value' remains as
the last item in the 'properties' list

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I106059c6c903c3d560477d5114d866f48590ad7e
2024-06-14 13:56:40 +02:00
Rustam Ismayilov 36f8bf3085 imgtool: Fix verify command for edcsa-p384 signed images
Fixed hash algorithm defaults to SHA256 in case no key provided.
Verification improved by adding check for key - tlv mismatch,
VerifyResult.KEY_MISMATCH added to indicate this case.
Multiple styling fixes and import optimisation, exception handling.

Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I61a588de5b39678707c0179f4edaa411ceb67c8e
2024-06-14 13:56:40 +02:00
Rustam Ismayilov 2712f74312 imgtool: Add missing requirements to requirements.txt file
Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I9c84e544b466c0e041bb947fb4dd3e01b0d38ae5
2024-06-14 13:56:40 +02:00
Denis Mingulov 3113df8f9f imgtool: initial sanity test
An initial sanity test for imgtool is added, checks
different commands for key operations (keygen, getpriv,
getpub and getpubhash).

Also very basic test for sign / verify is added.

Some tests are disabled (marked as 'xfail') due to
the missing implementation.

Signed-off-by: Denis Mingulov <denis@mingulov.com>
2024-05-23 14:39:17 +02:00
Denis Mingulov a4cb878cae imgtool: Fixed missing dependency to 'pyyaml' (for dumpinfo)
imgtool's dumpinfo depends to pyyaml package, so add it to
requirements.

Signed-off-by: Denis Mingulov <denis@mingulov.com>
2024-05-23 14:39:17 +02:00
Denis Mingulov faf2dd1f6a imgtool: fixed keys/general.py to pass existing unittests
keys.KeyClass._emit is able to use 'file' parameter not as a file
but some object (not only sys.stdout but io.StringIO, like by
tests).

Fixed all explicit checks for sys.stdio usage in favor of
io.TextIOBase, also improve a single unit test to cover
also all the changed methods.

Signed-off-by: Denis Mingulov <denis@mingulov.com>
2024-05-23 14:39:17 +02:00
David Brown 9c99326b97 Preps for 2.1.0 release
Update version information for 2.1.0 release.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-05-09 08:03:52 -06:00
David Brown 9bbe0a0462 Preps for 2.1.0-rc1 release
Update release notes and version numbers for 2.1.0-rc1 release.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-04-24 09:18:54 -06:00
Andrej Butok 06bc54846d imgtool: fix "align" script error
Fix "align" possible script error, caused by #1833.
Set default value for the align parameter.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2024-02-07 10:48:03 -07:00
Lucian Zala 79c284b0a5 scripts: imgtool: Fix img verify for hex file format
Currently imgtool --verify fails for hex files with:

Invalid image magic; is this an MCUboot image?

Added support for hex files by converting hex to bin
using IntelHex::tobinstr().

Reusing image.load() needs a bit of rework, maybe a
common load method will be done in the future,

Signed-off-by: Lucian Zala <zala.lucian@gmail.com>
2024-01-31 10:49:25 +00:00
Samuel Tardieu ab99fe2812 scripts: add missing pyyaml dependency
`pyyaml` is a dependency introduced in `imgtool dumpinfo`

Signed-off-by: Samuel Tardieu <sam@rfc1149.net>
2023-12-05 15:41:19 +00:00
Andrej Butok 6c4f7b4c63 doc: imgtool: update align description
Update the --align option values.
Add its description.
Delete [required], as it is optional now.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2023-11-07 10:22:14 +00:00
Andrej Butok 25b7c7a8e7 imgtool: make "align" command line parameter optional
Align parameter should be optional:
- it has a default value.
- it is not used for non-swap update modes.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2023-11-01 09:52:55 -06:00
David Brown e0bdcdecec Update version files for 2.0.0
Update documentation and version tags for final 2.0.0 release.

Signed-off-by: David Brown <david.brown@linaro.org>
2023-10-23 17:36:54 -06:00
David Brown 6a6de4b26a scripts: imgtool: update to 2.0.0-rc1 release
Update the version of imgtool.  This should auto-publish when
released.

Signed-off-by: David Brown <david.brown@linaro.org>
2023-09-29 08:19:05 -06:00
Bence Balogh 97a20f1286 imgtool: Add public key's SHA256 hash calculation
Signed-off-by: Dávid Házi <david.hazi@arm.com>
Signed-off-by: Bence Balogh <bence.balogh@arm.com>
Change-Id: I91d5c07c1bb2b8abe2592cd49b2053c881465ba2
2023-08-08 18:09:07 +02:00
Bence Balogh ed8d68aff7 imgtool: Add raw output option
Signed-off-by: Dávid Házi <david.hazi@arm.com>
Signed-off-by: Bence Balogh <bence.balogh@arm.com>
Change-Id: Ia7f385e5e1b0471aae7693baa54e9a385ad3ae3f
2023-08-08 18:09:07 +02:00
Bence Balogh 367aefbede imgtool: Add write to file option
Signed-off-by: Dávid Házi <david.hazi@arm.com>
Signed-off-by: Bence Balogh <bence.balogh@arm.com>
Change-Id: I6028955be5cbcd20d49ef2126dce8d4636b824a6
2023-08-08 18:09:07 +02:00
Roland Mikhel 018b77032c imgtool: Fix getpriv error return with private key
This commit fixes a bug with the getpriv command using
ECDSA keys.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I66c1365a855e97199921ac136a18e26988bce508
2023-07-24 09:33:50 +02:00
David Vincze 7f982b0f6f Revert "imgtool: Add backwards compatibility for ECDSA"
This reverts commit 78135ee6eb
as bba5a711483447d7eee2531b65bd1c07c81746c9 made it unnecessary.

Change-Id: Idee755f05c17502599aaa947826e9a7feb08b4a7
Signed-off-by: David Vincze <david.vincze@arm.com>
2023-04-28 11:40:31 +02:00
David Vincze 4395b80976 boot: Restore and extend the usage of 0x22 TLV (ECDSA256)
The IMAGE_TLV_ECDSA256 TLV has been put out of use by
commit 63d2346da4.
This commit reverts this part of that patch and at the
same time it extends the usage of this TLV to cover all types
of curves (replacing the newly introduced 0x25 TLV type)
while retaining its value (0x22) for backward compatibility.
Rename IMAGE_TLV_ECDSA256 to IMAGE_TLV_ECDSA_SIG.

Change-Id: I904f292db775c38f26a5e9a87c5f414165efc173
Signed-off-by: David Vincze <david.vincze@arm.com>
2023-04-28 11:40:31 +02:00
Roland Mikhel 78135ee6eb imgtool: Add backwards compatibility for ECDSA
Add backwards compatibility to the imgtool to support
the old curve specific TLVs. Currently only ECDSA256 needs this.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I275894ebc713ea8adcaab4198b036c41233b11e8
2023-04-26 13:27:44 +02:00
Roland Mikhel 5704174c12 imgtool: Add generic ECDSA TLV support
Update imgtool to support the new
generic ECDSA TLV and the ECDSA
p384 curve type with sha-384

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I9b1887610cc5d0e7cde90f47999fcdf3500ef51c
2023-04-26 13:27:44 +02:00
David Vincze ca56135b6b imgtool: Add 'dumpinfo' command
Add new 'dumpinfo' command that can parse a signed image and
print all the available information from the header, TLV area and
trailer in the form of a basic "image map".

The --outfile option can be used to write the image information
to an output file in serialised YAML format.

Change-Id: I99e61078946b02eefd4ac2e682583476d53e8d4f
Signed-off-by: David Vincze <david.vincze@arm.com>
2023-04-12 10:01:14 +02:00
Roland Mikhel 3d92a6cb59 imgtool: Remove P224 curve references
Imgtool does not provide support for P224
curve, just a placeholder function that
says it's not currently implemented.
This has now been removed as P224 support
had been removed from the boot code too.

Signed-off-by: Roland Mikhel <roland.mikhel@arm.com>
Change-Id: I477d8e273085f38f35eaf9a591584f3e937d748d
2023-04-11 07:05:38 +02:00
David Brown 23d28832f0 Update to version 1.10.0
Signed-off-by: David Brown <david.brown@linaro.org>
2023-04-06 07:38:04 -06:00
David Brown 569b1d6393 Update to version 1.10.0-rc1
Signed-off-by: David Brown <david.brown@linaro.org>
2023-03-20 14:02:12 -06:00
Raphael Dupont 16f3de5660 imgtool: fix boot_magic when -e big and max-align > 8
Currently if max-align > 8, magic_boot only works in little endian

For example :
With max-align = 16 and endian = big, boot_magic starts with 0x10 0x00,
but it should be 0x00 0x10

Signed-off-by: Raphael Dupont <raphael7dup@gmail.com>
2023-03-16 10:03:24 -03:00
Piotr Dymacz e026c3679b imgtool: sign: allow using 16-bit custom TLVs from valid range
The TLV type field in trailer TLV struct is defined as unsigned 16-bit
(in LE byte order). Currently, due to Python's struct format specified
as 'BBH', the 'imgtool' accepts only single byte for this field.

This results in error when trying to use 16-bit TLV type with option
'--custom-tlv':

  struct.error: ubyte format requires 0 <= number <= 255

This changes format to 'HH' which allows using 16-bit TLV types and
while at it, adds also simple range validation for custom TLV type.
As defined in image.h header, the vendor reserved TLVs value should
be from 0x00a0 to 0xfffe range.

Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
2023-03-10 17:30:38 -03:00
Ross Younger ae9d256cab imgtool: allow verify mode to use public ed25519 keys
Verify mode already works for the public halves of RSA and ECDSA keypairs.
This patch corrects an apparent oversight, enabling that functionality
in Ed25519.

Signed-off-by: Ross Younger <crazyscot@gmail.com>
2023-02-25 09:42:31 -03:00
Fabio Utzig 8f289ba5f9 imgtool: fix getpriv format type for keys
A previous change was added to allow the `getpriv` command to dump ec256
keys in both openssl and pkcs8. That PR did not touch other key file
types which resulted in errors using that command with RSA, X25519, etc.

This commit generalizes the passing of the `format` parameter, so each
key type can decide which format it allows a dump to be produced in,
and what default to use.

Fixes #1529

Signed-off-by: Fabio Utzig <utzig@apache.org>
2023-01-10 18:03:21 -03:00
Fabio Utzig 08a716dc4e imgtool: fix --vector-to-sign usage
`--vector-to-sign` only exports the image payload, or digest, to be
signed externally; it doesn't require any keys to be provided. This
commit moves the code outside a key required block, after the payload
and digest were already calculated from "image + headers + protected
TLVs".

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-11-21 18:50:25 -03:00
Antonio de Angelis 7ba01c0de7 imgtool: Fix PEP8 warnings on modules in this PR
Fix the remaining PEP8 warnings that appear on image.py, ecdsa.py
or main.py for imgtool.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2022-11-16 14:02:19 -03:00
Antonio de Angelis c6e7e9be7a imgtool: Improve ECDSA key generation
This patch improves the existing ECDSA key generation feature
in the imgtool by:
 - Fix a bug in the 'minimal' representation of PKCS#8 keys where
   the resulting ASN.1 DER encoding is not compliant
 - Add the option to export ECDSA private keys in SEC1 format by
   providing a command line option -f or --format that can be
   'openssl' (for SEC1 format) or 'pkcs8'. This format ends up in
   key encodings which are generally smaller than PKCS#8.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2022-11-16 14:02:19 -03:00
Antonio de Angelis 284b8fe3dd imgtool: Add filename to some common prints
Common prints such as the one that happens when an image is signed
are clearer if the source of print is added (i.e. filename), especially
for those build integration flows where imgtool is invoked as part of
a set of operations.

Signed-off-by: Antonio de Angelis <Antonio.deAngelis@arm.com>
2022-11-16 14:02:19 -03:00
Fabio Utzig 4e2cdfe82f imgtool: change getpub exporting format parameter
Update a previous PR were PEM exporting was added to the `--lang`
parameter, even though PEM is not a source code language per se.

This PR adds `--encoding/-e` to `getpub` command, for exporting
in formats other than a language source code. `--lang` is left with
a deprecation message, so it could be removed in a future version.
The default behavior of exporting source code in C was preserved.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-09-29 19:31:02 -03:00
Fabio Utzig 6f286779a6 imgtool: add option to export public PEM
Update `getpub` with new `lang` option, "pem", which allows exporting a
public key as a PEM file. This can later be distributed to be used for
encrypting an image, and gets away with having to use openssl for this
step.

Signed-off-by: Fabio Utzig <utzig@apache.org>
2022-09-22 11:34:43 -06:00
Alexander Mihajlovic f4df58f347 imgtool: Fix output of confirmed image in HEX format
The image_ok was written to the wrong offset
when outputting HEX format. This commit fixes that.

Drive-by change: Use actual length of boot magic
instead of assuming it's 16 bytes long.

Signed-off-by: Alexander Mihajlovic <alexander@eub.se>
2022-08-22 10:56:12 +02:00
iysheng 6093cbb3dd scripts: Fix some sentences to suit print display
Signed-off-by: iysheng <iysheng@163.com>
2022-05-30 08:13:55 +02:00
Almir Okato 3eb50263b7 imgtool: Fix imgtool sign command without key
The fix adds a condition that checks if either key or fixed_sig are
`not None` before payload signing and TLV addition.

Signed-off-by: Almir Okato <almir.okato@espressif.com>
2022-05-18 09:51:53 -03:00
Andrzej Puzdrowski dfce0be6a1 imgtool: export data vector to be signed
Extend sign/create command so it allows to export image's byte string
which is the substrate for the image signature. The new option is
'--vector-to-sign'. It might takes 'payload' or 'digest'.
The exported data might be used to calculate the signature externally.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-04-18 16:31:15 -06:00
Andrzej Puzdrowski f72e3741d6 imgtool: image signature export
Extend sign/create command so it now allow to export the image
signature to the file pointed by --sig-out option.
The image signature will be encoded as base64 formatted string.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-04-18 16:31:15 -06:00
Andrzej Puzdrowski 160303c202 imgtool: Added support for providing the signature by 3rd party
The sign command was extended so it now allow to provide the signature
as base64 formatted RAW file using --fix-sig along with the relevant
public key --fix-sig-pubkey.

This patch is added for support the case where the party which produces
the image dose not have access to the signing image key but must request
third party for the signature.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2022-04-18 16:31:15 -06:00
David Brown c657cbea75 Update to version 1.9.0
Bump version information for 1.9.0 release

Signed-off-by: David Brown <david.brown@linaro.org>
2022-03-02 14:29:33 -07:00