Skip to content

validate-update firmware checksum - #767

Open
AdityaMitra5102 wants to merge 2 commits into
Nitrokey:mainfrom
AdityaMitra5102:firmware-validation
Open

validate-update firmware checksum#767
AdityaMitra5102 wants to merge 2 commits into
Nitrokey:mainfrom
AdityaMitra5102:firmware-validation

Conversation

@AdityaMitra5102

Copy link
Copy Markdown
Contributor

Run against the SDK in the PR to test

@AdityaMitra5102
AdityaMitra5102 requested a review from a team as a code owner July 7, 2026 12:39
@AdityaMitra5102
AdityaMitra5102 requested review from daringer, james-knippes, mmerklinger, robin-nitrokey and sosthene-nitrokey and removed request for a team July 7, 2026 12:39

@robin-nitrokey robin-nitrokey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Looks good, just some small remarks.

By the way, you should be able to update the nitrokey dependency in pyproject.toml so that it uses the unreleased changes, see https://github.com/Nitrokey/pynitrokey/blob/master/docs/developer-guide.md#patching-the-nitrokey-sdk (and then poetry lock).

Comment thread pynitrokey/cli/trussed/__init__.py Outdated
@click.command()
@click.argument("image", type=click.Path(exists=True, dir_okay=False))
@click.option(
"--verify-from-source",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would call it --verify-from-release or --verify-from-github because we still verify it against a pre-compiled binary, not against the source code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread pynitrokey/cli/trussed/__init__.py Outdated
print(f" checksum: {metadata.inner_checksum.hex()}")

if not metadata.signed_by_nitrokey:
raise CliException("Verification failed for {variant.value}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please set a flag and raise the exception only after all variants have been checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed to using an array to hold all errors

Comment thread pynitrokey/cli/trussed/__init__.py Outdated
bar = DownloadProgressBar(desc=update.tag)
checksum = update.checksum(callback=bar.update)
if not checksum == metadata.inner_checksum:
raise CliException("Does not match checksum")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed as above

Comment thread pynitrokey/cli/trussed/__init__.py Outdated
release = firmware_repository.get_release_or_latest(metadata.version)
update = updates.get_firmware_update(ctx.model, release)
update.url = update.url.rsplit("/", 1)[0]
device = "nk3am" if variant == Variant.NRF52 else "nk3xn"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you also need to check the model here because this command could also be used with the NKPK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Also the ihex in NKPK firmware did not have a section corresponding to bytes 845C to 845F. Hence this program was filling that with 0x00 while the original bin had 0xFF, hence failing the check. I modified it to use 0xFF for unspecified sections, now passing

@sosthene-nitrokey
sosthene-nitrokey changed the base branch from master to main July 29, 2026 15:10
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.

2 participants