Skip to content
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

Changes to signing build system #166

Merged

Conversation

ahasztag
Copy link
Collaborator

No description provided.

@NordicBuilder
Copy link
Collaborator

NordicBuilder commented Jan 14, 2025

pytest coverage results

Detailed report:

Type Coverage
lines 85.2% (2041 of 2395 lines)
functions 41.1% (174 of 423 functions)
branches no data found

Note: This message is automatically posted and updated by the CI (latest/test-sdk-dfu/master/319)

Copy link
Collaborator

@adsz-nordic adsz-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor findings to check, some are a probably a matter of preferences.
Please ensure that new files have correct year in a heading.

ncs/Kconfig Outdated Show resolved Hide resolved
suit_generator/suit_encrypt_script_base.py Outdated Show resolved Hide resolved
suit_generator/cmd_encrypt.py Outdated Show resolved Hide resolved
suit_generator/cmd_sign.py Outdated Show resolved Hide resolved
suit_generator/cmd_sign.py Show resolved Hide resolved
suit_generator/cmd_sign.py Outdated Show resolved Hide resolved
@ahasztag ahasztag force-pushed the NCSDK-31069_sign_script_build_system branch 3 times, most recently from de2abff to 2afba07 Compare January 16, 2025 07:35
suit_generator/suit_sign_script_base.py Outdated Show resolved Hide resolved
ncs/basic_kms.py Outdated Show resolved Hide resolved
ncs/encrypt_script.py Outdated Show resolved Hide resolved
ncs/encrypt_script.py Outdated Show resolved Hide resolved
ncs/encrypt_script.py Outdated Show resolved Hide resolved
ncs/encrypt_script.py Outdated Show resolved Hide resolved
ncs/encrypt_script.py Outdated Show resolved Hide resolved
ncs/sign_script.py Outdated Show resolved Hide resolved
suit_generator/suit_encrypt_script_base.py Outdated Show resolved Hide resolved
@ahasztag ahasztag force-pushed the NCSDK-31069_sign_script_build_system branch 2 times, most recently from a69847f to 2fb17e4 Compare January 16, 2025 11:42
Copy link
Collaborator

@robertstypa robertstypa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor issues found, mainly in the docstrings - might be fixed during re-bassing, etc., or later.

plaintext = plaintext_file.read()

def generate_digest_size_for_plain_text(self, plaintext: bytes):
"""Class to generate digests for plaintext using specified hash algorithms."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider different docstring, something like:

 """Generate digest and return its size for the given plaintext."""

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, changed

digest, plaintext_len = digest_generator.generate_digest_size_for_plain_text(firmware)
encrypted_asset, encrypted_cek = self.generate_kms_artifacts(firmware, key_name, context)
encrypted_payload, tag, encryption_info = self.generate_encryption_info_and_encrypted_payload(
encrypted_asset, encrypted_cek, key_id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the type of encrypted_asset in the generate method is bytes, but in the generate_encryption_info_and_encrypted_payload method, it is expected to be of type Path. This mismatch can lead to runtime errors. Please ensure that the type of encrypted_asset is consistent across these methods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, it should by bytes everywhere

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there is an inconsistency between how type hinting is used for the input and output parameters among files and even in the same file

Please refer to the following methods:

There is type hinting for input and output parameters:

    def generate(
        self, encrypted_asset: bytes, encrypted_cek: bytes, key_id: int, kw_alg: SuitKWAlgorithms
    ) -> tuple[bytes, bytes, bytes]:

There is type hinting for input parameters, and no type hinting for the output.

def generate_encryption_info_and_encrypted_payload(self, encrypted_asset: Path, encrypted_cek, key_id: int):

There is no type hinting at all.

def generate_suit_encryption_info(self, iv, encrypted_cek, key_id):

This is nothing critical and can be solved/improved later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've attempted to fix it to at least some extent

class SignerError(Exception):
"""Signer exception."""


class Signer:
def _import_module_from_path(module_name, file_path):
# Helper function to import a python module from a file path.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This comment could be added as a docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed



def _import_module_from_path(module_name, file_path):
# Helper function to import a python module from a file path.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This comment could be added as a docstring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return module


def _import_encryptor(encrypt_script: Path) -> SuitEncryptorBase:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: _import_module_from_path contains a comment (which could be a docstring), but there is neither a comment nor a docstring. It would be nice to have something to be consistent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fixed

:param algorithm: The name of the algorithm to be used.
For file based KMS, this can be used to verify if the key in the
provided file contains a key of the correct type.
:param context: The context to be used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a period at the end of the :param context: description for consistency.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@ahasztag ahasztag force-pushed the NCSDK-31069_sign_script_build_system branch from 2fb17e4 to d63bde6 Compare January 17, 2025 11:33
@ahasztag ahasztag force-pushed the NCSDK-31069_sign_script_build_system branch from d63bde6 to 0590490 Compare January 17, 2025 12:18
@ahasztag ahasztag merged commit b37972c into nrfconnect:main Jan 17, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants