nitrokey 0.2.4__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nitrokey-0.2.4 → nitrokey-0.3.0}/PKG-INFO +17 -3
- {nitrokey-0.2.4 → nitrokey-0.3.0}/README.md +15 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/pyproject.toml +4 -3
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/nk3/updates.py +208 -40
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/__init__.py +5 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/LICENSES/Apache-2.0.txt +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/LICENSES/MIT.txt +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/_helpers.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/nk3/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/nk3/_bootloader.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/nk3/_device.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/nk3/secrets_app.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/nkpk.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/py.typed +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_base.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/README.md +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/certificate.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hash.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hmac.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/keys.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/symmetric.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/types.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/exceptions.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/commands.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/error_codes.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/exceptions.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/interfaces/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/interfaces/usb.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/mcuboot.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/memories.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/properties.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/base.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/bulk_protocol.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/misc.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/commands.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/headers.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/images.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/sections.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/abstract.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/cert_blocks.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/rkht.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/exceptions.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/commands.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/base.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/usb_device.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/protocol/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/protocol/protocol_base.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/misc.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/spsdk_enum.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/README.md +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu-cc.proto +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.pyi +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport_serial.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/init_packet_pb.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/manifest.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/exceptions.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/device_lister.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/enumerated_device.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/lister_backend.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/unix/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/unix/unix_lister.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/__init__.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/constants.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/lister_win32.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/structures.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_device.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_exceptions.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_utils.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/admin_app.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/provisioner_app.py +0 -0
- {nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/updates.py +0 -0
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nitrokey
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Nitrokey Python SDK
|
|
5
5
|
Home-page: https://github.com/Nitrokey/nitrokey-sdk-py
|
|
6
6
|
License: Apache-2.0 or MIT
|
|
7
7
|
Author: Nitrokey
|
|
8
8
|
Author-email: pypi@nitrokey.com
|
|
9
|
-
Requires-Python: >=3.9,<4.0
|
|
9
|
+
Requires-Python: >=3.9.2,<4.0.0
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: License :: Other/Proprietary License
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -124,6 +123,21 @@ These make targets can be used to invoke poetry for the most common tasks:
|
|
|
124
123
|
|
|
125
124
|
For more information, see poetry’s documentation on [Managing depencies](https://python-poetry.org/docs/managing-dependencies/) and [Commands](https://python-poetry.org/docs/cli/).
|
|
126
125
|
|
|
126
|
+
### Publishing Releases
|
|
127
|
+
|
|
128
|
+
Releases are published using Github Actions.
|
|
129
|
+
To create a new release:
|
|
130
|
+
1. Update the `version` field in `pyproject.toml` manually or using `poetry version`.
|
|
131
|
+
2. Update the [changelog](./CHANGELOG.md) for the release.
|
|
132
|
+
3. Run `make update-version` to update the RPM package version.
|
|
133
|
+
4. Commit these changes, create a PR and merge into `main`.
|
|
134
|
+
5. Create a signed tag with the version number and a `v` prefix, for example `v0.2.4`, and push it to this repository.
|
|
135
|
+
6. [Create a new release](https://github.com/Nitrokey/nitrokey-sdk-py/releases/new) for this tag and copy the relevant parts from the [changelog](./CHANGELOG.md) to the release description.
|
|
136
|
+
7. Wait for the deployment action to run and approve the deployment to [PyPI](https://pypi.org/p/nitrokey).
|
|
137
|
+
|
|
138
|
+
All commits to `main` are automatically deployed to [TestPyPI](https://test.pypi.org/p/nitrokey).
|
|
139
|
+
It is also possible to publish release candidates (pre-releases) with a suffix like `-rc.1`.
|
|
140
|
+
|
|
127
141
|
## License
|
|
128
142
|
|
|
129
143
|
This software is fully open source.
|
|
@@ -95,6 +95,21 @@ These make targets can be used to invoke poetry for the most common tasks:
|
|
|
95
95
|
|
|
96
96
|
For more information, see poetry’s documentation on [Managing depencies](https://python-poetry.org/docs/managing-dependencies/) and [Commands](https://python-poetry.org/docs/cli/).
|
|
97
97
|
|
|
98
|
+
### Publishing Releases
|
|
99
|
+
|
|
100
|
+
Releases are published using Github Actions.
|
|
101
|
+
To create a new release:
|
|
102
|
+
1. Update the `version` field in `pyproject.toml` manually or using `poetry version`.
|
|
103
|
+
2. Update the [changelog](./CHANGELOG.md) for the release.
|
|
104
|
+
3. Run `make update-version` to update the RPM package version.
|
|
105
|
+
4. Commit these changes, create a PR and merge into `main`.
|
|
106
|
+
5. Create a signed tag with the version number and a `v` prefix, for example `v0.2.4`, and push it to this repository.
|
|
107
|
+
6. [Create a new release](https://github.com/Nitrokey/nitrokey-sdk-py/releases/new) for this tag and copy the relevant parts from the [changelog](./CHANGELOG.md) to the release description.
|
|
108
|
+
7. Wait for the deployment action to run and approve the deployment to [PyPI](https://pypi.org/p/nitrokey).
|
|
109
|
+
|
|
110
|
+
All commits to `main` are automatically deployed to [TestPyPI](https://test.pypi.org/p/nitrokey).
|
|
111
|
+
It is also possible to publish release candidates (pre-releases) with a suffix like `-rc.1`.
|
|
112
|
+
|
|
98
113
|
## License
|
|
99
114
|
|
|
100
115
|
This software is fully open source.
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "nitrokey"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "Nitrokey Python SDK"
|
|
9
9
|
authors = ["Nitrokey <pypi@nitrokey.com>"]
|
|
10
10
|
license = "Apache-2.0 or MIT"
|
|
@@ -20,7 +20,7 @@ packages = [
|
|
|
20
20
|
[tool.poetry.dependencies]
|
|
21
21
|
cryptography = ">=41"
|
|
22
22
|
fido2 = "^1.1.2"
|
|
23
|
-
python = "^3.9"
|
|
23
|
+
python = "^3.9.2"
|
|
24
24
|
requests = "^2"
|
|
25
25
|
semver = "^3"
|
|
26
26
|
tlv8 = "^0.10"
|
|
@@ -46,7 +46,7 @@ rstcheck = { version = "^6", extras = ["sphinx"] }
|
|
|
46
46
|
sphinx = "^7"
|
|
47
47
|
types-protobuf = "^5.26"
|
|
48
48
|
types-requests = "^2.32"
|
|
49
|
-
typing-extensions = "^4"
|
|
49
|
+
typing-extensions = "^4.1"
|
|
50
50
|
|
|
51
51
|
[tool.black]
|
|
52
52
|
target-version = ["py39"]
|
|
@@ -63,3 +63,4 @@ strict = true
|
|
|
63
63
|
|
|
64
64
|
[tool.rstcheck]
|
|
65
65
|
ignore_directives = ["autoclass", "autofunction", "automodule"]
|
|
66
|
+
ignore_substitutions = ["nitrokey_sdk_version"]
|
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
# copied, modified, or distributed except according to those terms.
|
|
7
7
|
|
|
8
8
|
import enum
|
|
9
|
+
import importlib.metadata
|
|
9
10
|
import logging
|
|
10
11
|
import platform
|
|
11
12
|
import time
|
|
12
|
-
import warnings
|
|
13
13
|
from abc import ABC, abstractmethod
|
|
14
|
+
from collections.abc import Set
|
|
14
15
|
from contextlib import contextmanager
|
|
16
|
+
from importlib.metadata import PackageNotFoundError
|
|
15
17
|
from io import BytesIO
|
|
16
|
-
from typing import Any, Callable, Iterator, List, Optional
|
|
18
|
+
from typing import TYPE_CHECKING, Any, Callable, Iterator, List, Optional, Union
|
|
17
19
|
|
|
18
20
|
from nitrokey._helpers import Retries
|
|
19
21
|
from nitrokey.nk3 import NK3, NK3Bootloader
|
|
@@ -27,40 +29,125 @@ from nitrokey.trussed._bootloader import (
|
|
|
27
29
|
from nitrokey.trussed._bootloader.lpc55_upload.mboot.exceptions import (
|
|
28
30
|
McuBootConnectionError,
|
|
29
31
|
)
|
|
30
|
-
from nitrokey.trussed.admin_app import BootMode
|
|
32
|
+
from nitrokey.trussed.admin_app import BootMode, Status
|
|
33
|
+
from nitrokey.trussed.admin_app import Variant as AdminAppVariant
|
|
31
34
|
from nitrokey.updates import Asset, Release
|
|
32
35
|
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
import typing_extensions
|
|
38
|
+
|
|
33
39
|
logger = logging.getLogger(__name__)
|
|
34
40
|
|
|
35
41
|
|
|
36
42
|
@enum.unique
|
|
37
|
-
class
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
class Warning(enum.Enum):
|
|
44
|
+
"""
|
|
45
|
+
A warning that can occur during a firmware update.
|
|
46
|
+
|
|
47
|
+
By default, these warnings abort the firmware update. This enum can be used to select types
|
|
48
|
+
of warnings that should be ignored and not cause the firmware update to fail.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
IFS_MIGRATION_V2 = "ifs-migration-v2"
|
|
52
|
+
MISSING_STATUS = "missing-status"
|
|
53
|
+
SDK_VERSION = "sdk-version"
|
|
54
|
+
UPDATE_FROM_BOOTLOADER = "update-from-bootloader"
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def message(self) -> str:
|
|
58
|
+
if self == Warning.IFS_MIGRATION_V2:
|
|
59
|
+
return (
|
|
60
|
+
"Not enough space on the internal filesystem to perform the firmware"
|
|
61
|
+
" update. See the release notes for more information:"
|
|
62
|
+
" https://github.com/Nitrokey/nitrokey-3-firmware/releases/tag/v1.8.2-test.20250312"
|
|
63
|
+
)
|
|
64
|
+
if self == Warning.MISSING_STATUS:
|
|
65
|
+
return (
|
|
66
|
+
"Could not determine the device state as the current firmware is too old."
|
|
67
|
+
" Please update to firmware version v1.3.1 first."
|
|
68
|
+
)
|
|
69
|
+
if self == Warning.SDK_VERSION:
|
|
70
|
+
return (
|
|
71
|
+
"Your Nitrokey SDK version is outdated. Please update this program to the latest"
|
|
72
|
+
" version and try again."
|
|
73
|
+
)
|
|
74
|
+
if self == Warning.UPDATE_FROM_BOOTLOADER:
|
|
75
|
+
return (
|
|
76
|
+
"The current state of the device cannot be checked as it is already in bootloader"
|
|
77
|
+
" mode. Please review the release notes at:"
|
|
78
|
+
" https://github.com/Nitrokey/nitrokey-3-firmware/releases"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
if TYPE_CHECKING:
|
|
82
|
+
typing_extensions.assert_never(self)
|
|
83
|
+
|
|
84
|
+
return self.value
|
|
40
85
|
|
|
41
86
|
@classmethod
|
|
42
|
-
def
|
|
43
|
-
|
|
44
|
-
|
|
87
|
+
def from_str(cls, s: str) -> "Warning":
|
|
88
|
+
for w in cls:
|
|
89
|
+
if w.value == s:
|
|
90
|
+
return w
|
|
91
|
+
raise ValueError(f"Unexpected update warning id: {s}")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@enum.unique
|
|
95
|
+
class _Migration(enum.Enum):
|
|
96
|
+
# IFS migration to use journaling on the NRF52 introduced in v1.3.0
|
|
97
|
+
NRF_IFS_MIGRATION = enum.auto()
|
|
98
|
+
# IFS migration to filesystem layout 2 in v1.8.2 (FIDO2 RK migration)
|
|
99
|
+
IFS_MIGRATION_V2 = enum.auto()
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def get(
|
|
103
|
+
cls,
|
|
104
|
+
variant: Union[Variant, AdminAppVariant],
|
|
105
|
+
current: Optional[Version],
|
|
106
|
+
new: Version,
|
|
107
|
+
) -> frozenset["_Migration"]:
|
|
108
|
+
if isinstance(variant, AdminAppVariant):
|
|
109
|
+
if variant == AdminAppVariant.USBIP:
|
|
110
|
+
raise ValueError("Cannot perform firmware update for USBIP runner")
|
|
111
|
+
elif variant == AdminAppVariant.LPC55:
|
|
112
|
+
variant = Variant.LPC55
|
|
113
|
+
elif variant == AdminAppVariant.NRF52:
|
|
114
|
+
variant = Variant.NRF52
|
|
115
|
+
else:
|
|
116
|
+
if TYPE_CHECKING:
|
|
117
|
+
typing_extensions.assert_never(variant)
|
|
118
|
+
|
|
119
|
+
raise ValueError(f"Unsupported device variant: {variant}")
|
|
120
|
+
|
|
121
|
+
migrations = set()
|
|
122
|
+
|
|
45
123
|
if variant == Variant.NRF52:
|
|
46
124
|
if (
|
|
47
125
|
current is None
|
|
48
126
|
or current <= Version(1, 2, 2)
|
|
49
127
|
and new >= Version(1, 3, 0)
|
|
50
128
|
):
|
|
51
|
-
|
|
52
|
-
|
|
129
|
+
migrations.add(cls.NRF_IFS_MIGRATION)
|
|
130
|
+
|
|
131
|
+
ifs_migration_v2 = Version(1, 8, 2)
|
|
132
|
+
if (
|
|
133
|
+
current is not None
|
|
134
|
+
and current < ifs_migration_v2
|
|
135
|
+
and new >= ifs_migration_v2
|
|
136
|
+
):
|
|
137
|
+
migrations.add(cls.IFS_MIGRATION_V2)
|
|
138
|
+
|
|
139
|
+
return frozenset(migrations)
|
|
53
140
|
|
|
54
141
|
|
|
55
142
|
def get_firmware_update(release: Release) -> Asset:
|
|
56
143
|
return release.require_asset(Model.NK3.firmware_pattern)
|
|
57
144
|
|
|
58
145
|
|
|
59
|
-
def
|
|
146
|
+
def _get_extra_information(migrations: Set[_Migration]) -> List[str]:
|
|
60
147
|
"""Return additional information for the device after update based on update-path"""
|
|
61
148
|
|
|
62
149
|
out = []
|
|
63
|
-
if
|
|
150
|
+
if _Migration.NRF_IFS_MIGRATION in migrations:
|
|
64
151
|
out += [
|
|
65
152
|
"",
|
|
66
153
|
"During this update process the internal filesystem will be migrated!",
|
|
@@ -71,11 +158,11 @@ def get_extra_information(upath: UpdatePath) -> List[str]:
|
|
|
71
158
|
return out
|
|
72
159
|
|
|
73
160
|
|
|
74
|
-
def
|
|
161
|
+
def _get_finalization_wait_retries(migrations: Set[_Migration]) -> int:
|
|
75
162
|
"""Return number of retries to wait for the device after update based on update-path"""
|
|
76
163
|
|
|
77
164
|
out = 60
|
|
78
|
-
if
|
|
165
|
+
if _Migration.NRF_IFS_MIGRATION in migrations:
|
|
79
166
|
# max time 150secs == 300 retries
|
|
80
167
|
out = 500
|
|
81
168
|
return out
|
|
@@ -86,6 +173,14 @@ class UpdateUi(ABC):
|
|
|
86
173
|
def error(self, *msgs: Any) -> Exception:
|
|
87
174
|
pass
|
|
88
175
|
|
|
176
|
+
@abstractmethod
|
|
177
|
+
def show_warning(self, warning: Warning) -> None:
|
|
178
|
+
pass
|
|
179
|
+
|
|
180
|
+
@abstractmethod
|
|
181
|
+
def raise_warning(self, warning: Warning) -> Exception:
|
|
182
|
+
pass
|
|
183
|
+
|
|
89
184
|
@abstractmethod
|
|
90
185
|
def abort(self, *msgs: Any) -> Exception:
|
|
91
186
|
pass
|
|
@@ -120,12 +215,6 @@ class UpdateUi(ABC):
|
|
|
120
215
|
def confirm_update_same_version(self, version: Version) -> None:
|
|
121
216
|
pass
|
|
122
217
|
|
|
123
|
-
def request_repeated_update(self) -> Optional[Exception]:
|
|
124
|
-
warnings.warn(
|
|
125
|
-
"UpdateUi.request_repeated_update is no longer needed", DeprecationWarning
|
|
126
|
-
)
|
|
127
|
-
return None
|
|
128
|
-
|
|
129
218
|
@abstractmethod
|
|
130
219
|
def pre_bootloader_hint(self) -> None:
|
|
131
220
|
pass
|
|
@@ -158,10 +247,18 @@ class Updater:
|
|
|
158
247
|
await_device: Callable[
|
|
159
248
|
[Optional[int], Optional[Callable[[int, int], None]]], NK3
|
|
160
249
|
],
|
|
250
|
+
ignore_warnings: Set[Warning] = frozenset(),
|
|
161
251
|
) -> None:
|
|
162
252
|
self.ui = ui
|
|
163
253
|
self.await_bootloader = await_bootloader
|
|
164
254
|
self.await_device = await_device
|
|
255
|
+
self.ignore_warnings = ignore_warnings
|
|
256
|
+
|
|
257
|
+
def _trigger_warning(self, warning: Warning) -> None:
|
|
258
|
+
if warning in self.ignore_warnings:
|
|
259
|
+
self.ui.show_warning(warning)
|
|
260
|
+
else:
|
|
261
|
+
raise self.ui.raise_warning(warning)
|
|
165
262
|
|
|
166
263
|
def update(
|
|
167
264
|
self,
|
|
@@ -170,25 +267,44 @@ class Updater:
|
|
|
170
267
|
update_version: Optional[str],
|
|
171
268
|
ignore_pynitrokey_version: bool = False,
|
|
172
269
|
) -> Version:
|
|
173
|
-
|
|
270
|
+
update_from_bootloader = False
|
|
271
|
+
current_version = None
|
|
272
|
+
status = None
|
|
273
|
+
if isinstance(device, NK3Bootloader):
|
|
274
|
+
update_from_bootloader = True
|
|
275
|
+
self._trigger_warning(Warning.UPDATE_FROM_BOOTLOADER)
|
|
276
|
+
elif isinstance(device, NK3):
|
|
277
|
+
# We reboot here so that the status is always up to date
|
|
278
|
+
device.reboot()
|
|
279
|
+
time.sleep(1)
|
|
280
|
+
|
|
281
|
+
with self.await_device(3, None) as device:
|
|
282
|
+
current_version = device.admin.version()
|
|
283
|
+
status = device.admin.status()
|
|
284
|
+
else:
|
|
285
|
+
raise self.ui.error(f"Unexpected Trussed device: {device}")
|
|
286
|
+
|
|
174
287
|
logger.info(f"Firmware version before update: {current_version or ''}")
|
|
175
288
|
container = self._prepare_update(image, update_version, current_version)
|
|
176
289
|
|
|
177
|
-
if
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
self.ui.confirm_pynitrokey_version(
|
|
183
|
-
current=pynitrokey_version, required=container.pynitrokey
|
|
184
|
-
)
|
|
185
|
-
else:
|
|
186
|
-
raise self.ui.abort_pynitrokey_version(
|
|
187
|
-
current=pynitrokey_version, required=container.pynitrokey
|
|
188
|
-
)
|
|
290
|
+
if not update_from_bootloader:
|
|
291
|
+
if status is None and container.version > Version.from_str("1.3.1"):
|
|
292
|
+
self._trigger_warning(Warning.MISSING_STATUS)
|
|
293
|
+
|
|
294
|
+
self._check_minimum_version(container, ignore_pynitrokey_version)
|
|
189
295
|
|
|
190
296
|
self.ui.confirm_update(current_version, container.version)
|
|
191
297
|
|
|
298
|
+
migrations = None
|
|
299
|
+
if status is not None and status.variant is not None:
|
|
300
|
+
migrations = self._check_migrations(
|
|
301
|
+
status.variant, current_version, container.version, status
|
|
302
|
+
)
|
|
303
|
+
elif isinstance(device, NK3Bootloader):
|
|
304
|
+
migrations = self._check_migrations(
|
|
305
|
+
device.variant, current_version, container.version, status
|
|
306
|
+
)
|
|
307
|
+
|
|
192
308
|
with self._get_bootloader(device) as bootloader:
|
|
193
309
|
if bootloader.variant not in container.images:
|
|
194
310
|
raise self.ui.error(
|
|
@@ -205,15 +321,14 @@ class Updater:
|
|
|
205
321
|
except Exception as e:
|
|
206
322
|
raise self.ui.error("Failed to validate firmware image", e)
|
|
207
323
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
self.ui.confirm_extra_information(txt)
|
|
324
|
+
if migrations is None:
|
|
325
|
+
migrations = self._check_migrations(
|
|
326
|
+
bootloader.variant, current_version, container.version, status
|
|
327
|
+
)
|
|
213
328
|
|
|
214
329
|
self._perform_update(bootloader, container)
|
|
215
330
|
|
|
216
|
-
wait_retries =
|
|
331
|
+
wait_retries = _get_finalization_wait_retries(migrations)
|
|
217
332
|
with self.ui.finalization_progress_bar() as callback:
|
|
218
333
|
with self.await_device(wait_retries, callback) as device:
|
|
219
334
|
version = device.admin.version()
|
|
@@ -295,6 +410,36 @@ class Updater:
|
|
|
295
410
|
|
|
296
411
|
return container
|
|
297
412
|
|
|
413
|
+
def _check_minimum_version(
|
|
414
|
+
self, container: FirmwareContainer, ignore_pynitrokey_version: bool
|
|
415
|
+
) -> None:
|
|
416
|
+
if container.sdk:
|
|
417
|
+
try:
|
|
418
|
+
sdk_version = Version.from_str(importlib.metadata.version("nitrokey"))
|
|
419
|
+
except PackageNotFoundError:
|
|
420
|
+
raise self.ui.error("Failed to determine the Nitrokey SDK version")
|
|
421
|
+
|
|
422
|
+
if container.sdk > sdk_version:
|
|
423
|
+
logger.warning(
|
|
424
|
+
f"Minimum SDK version required for update is {container.sdk} (current version: {sdk_version})"
|
|
425
|
+
)
|
|
426
|
+
self._trigger_warning(Warning.SDK_VERSION)
|
|
427
|
+
elif container.pynitrokey:
|
|
428
|
+
# The minimum pynitrokey version has been replaced by the minimum SDK version, so we
|
|
429
|
+
# only check it if there is no minimum SDK version set.
|
|
430
|
+
|
|
431
|
+
# this is the version of pynitrokey when we moved to the SDK
|
|
432
|
+
pynitrokey_version = Version.from_str("0.4.49")
|
|
433
|
+
if container.pynitrokey > pynitrokey_version:
|
|
434
|
+
if ignore_pynitrokey_version:
|
|
435
|
+
self.ui.confirm_pynitrokey_version(
|
|
436
|
+
current=pynitrokey_version, required=container.pynitrokey
|
|
437
|
+
)
|
|
438
|
+
else:
|
|
439
|
+
raise self.ui.abort_pynitrokey_version(
|
|
440
|
+
current=pynitrokey_version, required=container.pynitrokey
|
|
441
|
+
)
|
|
442
|
+
|
|
298
443
|
def _validate_version(
|
|
299
444
|
self,
|
|
300
445
|
current_version: Optional[Version],
|
|
@@ -351,6 +496,29 @@ class Updater:
|
|
|
351
496
|
else:
|
|
352
497
|
raise self.ui.error(f"Unexpected Nitrokey 3 device: {device}")
|
|
353
498
|
|
|
499
|
+
def _check_migrations(
|
|
500
|
+
self,
|
|
501
|
+
variant: Union[Variant, AdminAppVariant],
|
|
502
|
+
current_version: Optional[Version],
|
|
503
|
+
new_version: Version,
|
|
504
|
+
status: Optional[Status],
|
|
505
|
+
) -> frozenset["_Migration"]:
|
|
506
|
+
try:
|
|
507
|
+
migrations = _Migration.get(
|
|
508
|
+
variant=variant, current=current_version, new=new_version
|
|
509
|
+
)
|
|
510
|
+
except ValueError as e:
|
|
511
|
+
raise self.ui.error(str(e))
|
|
512
|
+
|
|
513
|
+
txt = _get_extra_information(migrations)
|
|
514
|
+
self.ui.confirm_extra_information(txt)
|
|
515
|
+
|
|
516
|
+
if _Migration.IFS_MIGRATION_V2 in migrations:
|
|
517
|
+
if status and status.ifs_blocks is not None and status.ifs_blocks < 5:
|
|
518
|
+
self._trigger_warning(Warning.IFS_MIGRATION_V2)
|
|
519
|
+
|
|
520
|
+
return migrations
|
|
521
|
+
|
|
354
522
|
def _perform_update(
|
|
355
523
|
self, device: NK3Bootloader, container: FirmwareContainer
|
|
356
524
|
) -> None:
|
|
@@ -100,6 +100,7 @@ def _validate_checksum(checksums: dict[str, str], path: str, data: bytes) -> Non
|
|
|
100
100
|
class FirmwareContainer:
|
|
101
101
|
version: Version
|
|
102
102
|
pynitrokey: Optional[Version]
|
|
103
|
+
sdk: Optional[Version]
|
|
103
104
|
images: Dict[Variant, bytes]
|
|
104
105
|
|
|
105
106
|
@classmethod
|
|
@@ -121,6 +122,9 @@ class FirmwareContainer:
|
|
|
121
122
|
pynitrokey = None
|
|
122
123
|
if "pynitrokey" in manifest:
|
|
123
124
|
pynitrokey = Version.from_v_str(manifest["pynitrokey"])
|
|
125
|
+
sdk = None
|
|
126
|
+
if "sdk" in manifest:
|
|
127
|
+
sdk = Version.from_v_str(manifest["sdk"])
|
|
124
128
|
|
|
125
129
|
images = {}
|
|
126
130
|
for variant, image in manifest["images"].items():
|
|
@@ -131,6 +135,7 @@ class FirmwareContainer:
|
|
|
131
135
|
return cls(
|
|
132
136
|
version=version,
|
|
133
137
|
pynitrokey=pynitrokey,
|
|
138
|
+
sdk=sdk,
|
|
134
139
|
images=images,
|
|
135
140
|
)
|
|
136
141
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hash.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hmac.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/keys.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/symmetric.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/types.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/exceptions.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/__init__.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/commands.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/error_codes.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/mcuboot.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/memories.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/properties.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/misc.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/images.py
RENAMED
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/__init__.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/abstract.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/rkht.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/misc.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/spsdk_enum.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/__init__.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu-cc.proto
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.pyi
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/manifest.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/exceptions.py
RENAMED
|
File without changes
|
{nitrokey-0.2.4 → nitrokey-0.3.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|