-
Notifications
You must be signed in to change notification settings - Fork 789
imgtool: Add tests for imgtool commands part 1 #1983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rustammendel
wants to merge
13
commits into
mcu-tools:main
Choose a base branch
from
rustammendel:tests2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,476
−280
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e1e4d5b
imgtool: Add pre-generated images and keys
rustammendel 8963b5a
imgtool: Add missing copyright notice to test_keys.py
davidvincze b95b3b5
imgtool: Add new tests for key operations
rustammendel 4824e36
imgtool: Improve key type checks and invalid pass-phrase handling
rustammendel f676afa
imgtool: Add tests for signing
rustammendel 46c94c3
imgtool: Add testing for verify command
rustammendel 401e6e8
imgtool: Add tests for dumpinfo command
rustammendel 3af9d9b
imgtool: Add verification tests for hex files
rustammendel 44e14a3
imgtool: Add support for hex files in dumpinfo and tests
rustammendel e765e0e
imgtool: Unify File not found error messages
rustammendel 31dfd12
imgtool: Fix test paths
rustammendel 9d79458
imgtool: Install imgtool dependencies in fih-test
rustammendel 65676cd
imgtool: Install imgtool dependencies in zephyr-build
rustammendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Copyright 2017 Linaro Limited | ||
# Copyright 2023 Arm Limited | ||
# Copyright 2023-2024 Arm Limited | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
@@ -58,14 +58,24 @@ def load(path, passwd=None): | |
except TypeError as e: | ||
msg = str(e) | ||
if "private key is encrypted" in msg: | ||
print(msg) | ||
return None | ||
raise e | ||
except ValueError: | ||
except ValueError as e: | ||
msg1 = str(e) | ||
# This seems to happen if the key is a public key, let's try | ||
# loading it as a public key. | ||
pk = serialization.load_pem_public_key( | ||
try: | ||
pk = serialization.load_pem_public_key( | ||
raw_pem, | ||
backend=default_backend()) | ||
except ValueError as e: | ||
# If loading as public key also fails, that indicates wrong | ||
# passphrase input | ||
msg2 = str(e) | ||
if ("password may be incorrect" in msg1 and | ||
"Are you sure this is a public key" in msg2): | ||
raise Exception("Invalid passphrase") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be helpful to throw some exception when loading failed with ValueError but condition in line 76 is not met. |
||
|
||
if isinstance(pk, RSAPrivateKey): | ||
if pk.key_size not in RSA_KEY_SIZES: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider verifying if password is correct at first since
msg1
contains "Invalid passphrase" in it.ValueError: Bad decrypt. Incorrect password?
ValueError: Incorrect password, could not decrypt key
In case of public key there is no such substring in
msg1
:ValueError: Could not deserialize key data. The data may be in an incorrect format or it may be encrypted with an unsupported algorithm.
ValueError: Valid PEM but no BEGIN/END delimiters for a private key found. Are you sure this is a private key?