nitrokey 0.3.2__tar.gz → 0.4.1__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.3.2 → nitrokey-0.4.1}/PKG-INFO +11 -15
- {nitrokey-0.3.2 → nitrokey-0.4.1}/README.md +4 -7
- nitrokey-0.4.1/pyproject.toml +89 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/nk3/_bootloader.py +5 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/nk3/_device.py +7 -14
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/nkpk.py +11 -13
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/__init__.py +28 -1
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_base.py +20 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/__init__.py +12 -36
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport_serial.py +2 -2
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_device.py +10 -1
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/admin_app.py +2 -1
- {nitrokey-0.3.2/src/nitrokey/nk3 → nitrokey-0.4.1/src/nitrokey/trussed}/updates.py +86 -44
- nitrokey-0.3.2/pyproject.toml +0 -66
- {nitrokey-0.3.2 → nitrokey-0.4.1}/LICENSES/Apache-2.0.txt +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/LICENSES/MIT.txt +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/_helpers.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/nk3/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/nk3/secrets_app.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/py.typed +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/README.md +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/certificate.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hash.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hmac.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/keys.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/symmetric.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/types.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/exceptions.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/commands.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/error_codes.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/exceptions.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/interfaces/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/interfaces/usb.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/mcuboot.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/memories.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/properties.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/base.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/bulk_protocol.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/misc.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/commands.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/headers.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/images.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/sections.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/abstract.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/cert_blocks.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/rkht.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/exceptions.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/commands.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/base.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/usb_device.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/protocol/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/protocol/protocol_base.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/misc.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/spsdk_enum.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/README.md +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu-cc.proto +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.pyi +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/init_packet_pb.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/manifest.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/exceptions.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/device_lister.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/enumerated_device.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/lister_backend.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/unix/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/unix/unix_lister.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/__init__.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/constants.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/lister_win32.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/structures.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_exceptions.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_utils.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/provisioner_app.py +0 -0
- {nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/updates.py +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: nitrokey
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: Nitrokey Python SDK
|
|
5
|
-
Home-page: https://github.com/Nitrokey/nitrokey-sdk-py
|
|
6
5
|
License: Apache-2.0 or MIT
|
|
7
6
|
Author: Nitrokey
|
|
8
7
|
Author-email: pypi@nitrokey.com
|
|
9
|
-
Requires-Python: >=3.
|
|
8
|
+
Requires-Python: >=3.10, <4
|
|
10
9
|
Classifier: Intended Audience :: Developers
|
|
11
10
|
Classifier: License :: Other/Proprietary License
|
|
12
11
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -14,13 +13,13 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
-
Requires-Dist: crcmod (>=1.7,<2
|
|
16
|
+
Requires-Dist: crcmod (>=1.7,<2)
|
|
18
17
|
Requires-Dist: cryptography (>=41)
|
|
19
18
|
Requires-Dist: fido2 (>=1.1.2,<3)
|
|
20
19
|
Requires-Dist: hidapi (>=0.14,<0.15)
|
|
21
|
-
Requires-Dist: protobuf (>=5.26,<
|
|
22
|
-
Requires-Dist: pyserial (>=3.5,<4
|
|
23
|
-
Requires-Dist: requests (>=2,<3)
|
|
20
|
+
Requires-Dist: protobuf (>=5.26,<7)
|
|
21
|
+
Requires-Dist: pyserial (>=3.5,<4)
|
|
22
|
+
Requires-Dist: requests (>=2.16,<3)
|
|
24
23
|
Requires-Dist: semver (>=3,<4)
|
|
25
24
|
Requires-Dist: tlv8 (>=0.10,<0.11)
|
|
26
25
|
Project-URL: Repository, https://github.com/Nitrokey/nitrokey-sdk-py
|
|
@@ -64,19 +63,16 @@ The releases are also available as [signed tags][releases] in the GitHub reposit
|
|
|
64
63
|
## Getting Started
|
|
65
64
|
|
|
66
65
|
```python
|
|
67
|
-
|
|
68
|
-
from nitrokey.nkpk import NKPK
|
|
66
|
+
import nitrokey.trussed
|
|
69
67
|
|
|
70
68
|
print("Connected Nitrokey devices:")
|
|
71
|
-
for device in
|
|
72
|
-
print(f"- {device.name} at {device.path}")
|
|
73
|
-
for device in NKPK.list():
|
|
69
|
+
for device in nitrokey.trussed.list():
|
|
74
70
|
print(f"- {device.name} at {device.path}")
|
|
75
71
|
```
|
|
76
72
|
|
|
77
73
|
## Compatibility
|
|
78
74
|
|
|
79
|
-
The Nitrokey Python SDK currently requires Python 3.
|
|
75
|
+
The Nitrokey Python SDK currently requires Python 3.10 or later.
|
|
80
76
|
Support for old Python versions may be dropped in minor releases.
|
|
81
77
|
|
|
82
78
|
## Related Projects
|
|
@@ -92,7 +88,7 @@ Support for old Python versions may be dropped in minor releases.
|
|
|
92
88
|
|
|
93
89
|
The following software is required for the development of the SDK:
|
|
94
90
|
|
|
95
|
-
- Python 3.
|
|
91
|
+
- Python 3.10 or newer
|
|
96
92
|
- [poetry](https://python-poetry.org/)
|
|
97
93
|
- GNU Make
|
|
98
94
|
- git
|
|
@@ -36,19 +36,16 @@ The releases are also available as [signed tags][releases] in the GitHub reposit
|
|
|
36
36
|
## Getting Started
|
|
37
37
|
|
|
38
38
|
```python
|
|
39
|
-
|
|
40
|
-
from nitrokey.nkpk import NKPK
|
|
39
|
+
import nitrokey.trussed
|
|
41
40
|
|
|
42
41
|
print("Connected Nitrokey devices:")
|
|
43
|
-
for device in
|
|
44
|
-
print(f"- {device.name} at {device.path}")
|
|
45
|
-
for device in NKPK.list():
|
|
42
|
+
for device in nitrokey.trussed.list():
|
|
46
43
|
print(f"- {device.name} at {device.path}")
|
|
47
44
|
```
|
|
48
45
|
|
|
49
46
|
## Compatibility
|
|
50
47
|
|
|
51
|
-
The Nitrokey Python SDK currently requires Python 3.
|
|
48
|
+
The Nitrokey Python SDK currently requires Python 3.10 or later.
|
|
52
49
|
Support for old Python versions may be dropped in minor releases.
|
|
53
50
|
|
|
54
51
|
## Related Projects
|
|
@@ -64,7 +61,7 @@ Support for old Python versions may be dropped in minor releases.
|
|
|
64
61
|
|
|
65
62
|
The following software is required for the development of the SDK:
|
|
66
63
|
|
|
67
|
-
- Python 3.
|
|
64
|
+
- Python 3.10 or newer
|
|
68
65
|
- [poetry](https://python-poetry.org/)
|
|
69
66
|
- GNU Make
|
|
70
67
|
- git
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core >=2, <3"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nitrokey"
|
|
7
|
+
version = "0.4.1"
|
|
8
|
+
description = "Nitrokey Python SDK"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Nitrokey", email = "pypi@nitrokey.com" },
|
|
11
|
+
]
|
|
12
|
+
license = "Apache-2.0 or MIT"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
packages = [
|
|
15
|
+
{ include = "nitrokey", from = "src" },
|
|
16
|
+
]
|
|
17
|
+
requires-python = ">=3.10, <4"
|
|
18
|
+
dynamic = ["classifiers"]
|
|
19
|
+
|
|
20
|
+
dependencies = [
|
|
21
|
+
"cryptography >=41",
|
|
22
|
+
"fido2 >=1.1.2, <3",
|
|
23
|
+
"requests >=2.16, <3",
|
|
24
|
+
"semver >=3, <4",
|
|
25
|
+
"tlv8 >=0.10, <0.11",
|
|
26
|
+
|
|
27
|
+
# lpc55
|
|
28
|
+
"crcmod >=1.7, <2",
|
|
29
|
+
"hidapi >=0.14, <0.15",
|
|
30
|
+
|
|
31
|
+
# nrf52
|
|
32
|
+
"protobuf >=5.26, <7",
|
|
33
|
+
"pyserial >=3.5, <4",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
repository = "https://github.com/Nitrokey/nitrokey-sdk-py"
|
|
38
|
+
|
|
39
|
+
[tool.poetry]
|
|
40
|
+
classifiers = [
|
|
41
|
+
"Intended Audience :: Developers",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.poetry.group.dev]
|
|
45
|
+
optional = true
|
|
46
|
+
|
|
47
|
+
[tool.poetry.group.dev.dependencies]
|
|
48
|
+
black = "^24.3"
|
|
49
|
+
fake-winreg = "^1.6"
|
|
50
|
+
flake8 = "^7.1"
|
|
51
|
+
isort = "^5.13.2"
|
|
52
|
+
mypy = "^1.4"
|
|
53
|
+
rstcheck = { version = "^6", extras = ["sphinx"] }
|
|
54
|
+
sphinx = "^7"
|
|
55
|
+
types-protobuf = ">=5.26, <7"
|
|
56
|
+
types-requests = "^2.16"
|
|
57
|
+
typing-extensions = "^4.1"
|
|
58
|
+
|
|
59
|
+
[tool.uv]
|
|
60
|
+
dev-dependencies = [
|
|
61
|
+
# These dependencies are required for running the type checks.
|
|
62
|
+
"fake-winreg >=1.6, <2",
|
|
63
|
+
"mypy >=1.4, <2",
|
|
64
|
+
"types-protobuf >=5.26, <7",
|
|
65
|
+
"types-requests >=2.16, <3",
|
|
66
|
+
|
|
67
|
+
# These additional lower bounds are required for --resolution lowest.
|
|
68
|
+
# As these are transitive dependencies, we don’t include them in our dependency list.
|
|
69
|
+
"cffi >=1.14.1",
|
|
70
|
+
"typing-extensions >=4.1",
|
|
71
|
+
"urllib3 >= 2",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[tool.black]
|
|
75
|
+
target-version = ["py310"]
|
|
76
|
+
|
|
77
|
+
[tool.isort]
|
|
78
|
+
py_version = "310"
|
|
79
|
+
profile = "black"
|
|
80
|
+
|
|
81
|
+
[tool.mypy]
|
|
82
|
+
mypy_path = "stubs"
|
|
83
|
+
show_error_codes = true
|
|
84
|
+
python_version = "3.10"
|
|
85
|
+
strict = true
|
|
86
|
+
|
|
87
|
+
[tool.rstcheck]
|
|
88
|
+
ignore_directives = ["autoclass", "autofunction", "automodule"]
|
|
89
|
+
ignore_substitutions = ["nitrokey_sdk_version"]
|
|
@@ -8,12 +8,17 @@
|
|
|
8
8
|
from typing import List, Optional, Sequence
|
|
9
9
|
|
|
10
10
|
from nitrokey import _VID_NITROKEY
|
|
11
|
+
from nitrokey.trussed._base import Model
|
|
11
12
|
from nitrokey.trussed._bootloader import TrussedBootloader
|
|
12
13
|
from nitrokey.trussed._bootloader.lpc55 import TrussedBootloaderLpc55
|
|
13
14
|
from nitrokey.trussed._bootloader.nrf52 import SignatureKey, TrussedBootloaderNrf52
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class NK3Bootloader(TrussedBootloader):
|
|
18
|
+
@property
|
|
19
|
+
def model(self) -> Model:
|
|
20
|
+
return Model.NK3
|
|
21
|
+
|
|
17
22
|
@staticmethod
|
|
18
23
|
def list() -> List["NK3Bootloader"]:
|
|
19
24
|
devices: List[NK3Bootloader] = []
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
from typing import List
|
|
9
9
|
|
|
10
|
-
from fido2.hid import CtapHidDevice
|
|
10
|
+
from fido2.hid import CtapHidDevice
|
|
11
11
|
|
|
12
12
|
from nitrokey import _VID_NITROKEY
|
|
13
|
-
from nitrokey.trussed import Fido2Certs, TrussedDevice, Version
|
|
13
|
+
from nitrokey.trussed import Fido2Certs, Model, TrussedDevice, Version
|
|
14
14
|
|
|
15
15
|
FIDO2_CERTS = [
|
|
16
16
|
Fido2Certs(
|
|
@@ -36,6 +36,10 @@ class NK3(TrussedDevice):
|
|
|
36
36
|
def __init__(self, device: CtapHidDevice) -> None:
|
|
37
37
|
super().__init__(device, FIDO2_CERTS)
|
|
38
38
|
|
|
39
|
+
@property
|
|
40
|
+
def model(self) -> Model:
|
|
41
|
+
return Model.NK3
|
|
42
|
+
|
|
39
43
|
@property
|
|
40
44
|
def pid(self) -> int:
|
|
41
45
|
from . import _PID_NK3_DEVICE
|
|
@@ -54,15 +58,4 @@ class NK3(TrussedDevice):
|
|
|
54
58
|
def list(cls) -> List["NK3"]:
|
|
55
59
|
from . import _PID_NK3_DEVICE
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
desc
|
|
59
|
-
for desc in list_descriptors() # type: ignore
|
|
60
|
-
if desc.vid == _VID_NITROKEY and desc.pid == _PID_NK3_DEVICE
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
devices = []
|
|
64
|
-
|
|
65
|
-
# iterate on all descriptors found and open the device
|
|
66
|
-
for desc in descriptors:
|
|
67
|
-
devices.append(cls.from_device(open_device(desc.path)))
|
|
68
|
-
return devices
|
|
61
|
+
return cls._list_vid_pid(_VID_NITROKEY, _PID_NK3_DEVICE)
|
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
from typing import List, Optional, Sequence, Union
|
|
9
9
|
|
|
10
|
-
from fido2.hid import CtapHidDevice
|
|
10
|
+
from fido2.hid import CtapHidDevice
|
|
11
11
|
|
|
12
12
|
from nitrokey import _VID_NITROKEY
|
|
13
13
|
from nitrokey.trussed import Fido2Certs, TrussedDevice, Version
|
|
14
|
+
from nitrokey.trussed._base import Model
|
|
14
15
|
from nitrokey.trussed._bootloader import ModelData
|
|
15
16
|
from nitrokey.trussed._bootloader.nrf52 import SignatureKey, TrussedBootloaderNrf52
|
|
16
17
|
|
|
@@ -48,6 +49,10 @@ class NKPK(TrussedDevice):
|
|
|
48
49
|
def __init__(self, device: CtapHidDevice) -> None:
|
|
49
50
|
super().__init__(device, _FIDO2_CERTS)
|
|
50
51
|
|
|
52
|
+
@property
|
|
53
|
+
def model(self) -> Model:
|
|
54
|
+
return Model.NKPK
|
|
55
|
+
|
|
51
56
|
@property
|
|
52
57
|
def pid(self) -> int:
|
|
53
58
|
return _PID_NKPK_DEVICE
|
|
@@ -62,21 +67,14 @@ class NKPK(TrussedDevice):
|
|
|
62
67
|
|
|
63
68
|
@classmethod
|
|
64
69
|
def list(cls) -> List["NKPK"]:
|
|
65
|
-
|
|
66
|
-
desc
|
|
67
|
-
for desc in list_descriptors() # type: ignore
|
|
68
|
-
if desc.vid == _VID_NITROKEY and desc.pid == _PID_NKPK_DEVICE
|
|
69
|
-
]
|
|
70
|
-
|
|
71
|
-
devices = []
|
|
72
|
-
|
|
73
|
-
# iterate on all descriptors found and open the device
|
|
74
|
-
for desc in descriptors:
|
|
75
|
-
devices.append(cls.from_device(open_device(desc.path)))
|
|
76
|
-
return devices
|
|
70
|
+
return cls._list_vid_pid(_VID_NITROKEY, _PID_NKPK_DEVICE)
|
|
77
71
|
|
|
78
72
|
|
|
79
73
|
class NKPKBootloader(TrussedBootloaderNrf52):
|
|
74
|
+
@property
|
|
75
|
+
def model(self) -> Model:
|
|
76
|
+
return Model.NKPK
|
|
77
|
+
|
|
80
78
|
@property
|
|
81
79
|
def name(self) -> str:
|
|
82
80
|
return "Nitrokey Passkey Bootloader"
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
# http://opensource.org/licenses/MIT>, at your option. This file may not be
|
|
6
6
|
# copied, modified, or distributed except according to those terms.
|
|
7
7
|
|
|
8
|
+
from typing import List, Optional
|
|
9
|
+
|
|
10
|
+
from ._base import Model as Model # noqa: F401
|
|
8
11
|
from ._base import TrussedBase as TrussedBase # noqa: F401
|
|
9
12
|
from ._bootloader import FirmwareContainer as FirmwareContainer # noqa: F401
|
|
10
13
|
from ._bootloader import FirmwareMetadata as FirmwareMetadata # noqa: F401
|
|
11
|
-
from ._bootloader import Model as Model # noqa: F401
|
|
12
14
|
from ._bootloader import TrussedBootloader as TrussedBootloader # noqa: F401
|
|
13
15
|
from ._bootloader import Variant as Variant # noqa: F401
|
|
14
16
|
from ._bootloader import parse_firmware_image as parse_firmware_image # noqa: F401
|
|
@@ -19,3 +21,28 @@ from ._exceptions import TrussedException as TrussedException # noqa: F401
|
|
|
19
21
|
from ._utils import Fido2Certs as Fido2Certs # noqa: F401
|
|
20
22
|
from ._utils import Uuid as Uuid # noqa: F401
|
|
21
23
|
from ._utils import Version as Version # noqa: F401
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def list() -> List[TrussedBase]:
|
|
27
|
+
from nitrokey.nk3 import list as list_nk3
|
|
28
|
+
from nitrokey.nkpk import list as list_nkpk
|
|
29
|
+
|
|
30
|
+
devices: List[TrussedBase] = []
|
|
31
|
+
devices.extend(list_nk3())
|
|
32
|
+
devices.extend(list_nkpk())
|
|
33
|
+
return devices
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def open(path: str) -> Optional[TrussedBase]:
|
|
37
|
+
from nitrokey.nk3 import open as open_nk3
|
|
38
|
+
from nitrokey.nkpk import open as open_nkpk
|
|
39
|
+
|
|
40
|
+
nk3 = open_nk3(path)
|
|
41
|
+
nkpk = open_nkpk(path)
|
|
42
|
+
if nk3 and nkpk:
|
|
43
|
+
raise Exception(f"Found multiple devices at path {path}")
|
|
44
|
+
if nk3:
|
|
45
|
+
return nk3
|
|
46
|
+
if nkpk:
|
|
47
|
+
return nkpk
|
|
48
|
+
return None
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
# copied, modified, or distributed except according to those terms.
|
|
7
7
|
|
|
8
8
|
from abc import ABC, abstractmethod
|
|
9
|
+
from enum import Enum
|
|
9
10
|
from typing import Optional, TypeVar
|
|
10
11
|
|
|
11
12
|
from nitrokey import _VID_NITROKEY
|
|
@@ -15,6 +16,21 @@ from ._utils import Uuid
|
|
|
15
16
|
T = TypeVar("T", bound="TrussedBase")
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
class Model(Enum):
|
|
20
|
+
NK3 = "Nitrokey 3"
|
|
21
|
+
NKPK = "Nitrokey Passkey"
|
|
22
|
+
|
|
23
|
+
def __str__(self) -> str:
|
|
24
|
+
return self.value
|
|
25
|
+
|
|
26
|
+
@classmethod
|
|
27
|
+
def from_str(cls, s: str) -> "Model":
|
|
28
|
+
for model in cls:
|
|
29
|
+
if model.value == s:
|
|
30
|
+
return model
|
|
31
|
+
raise ValueError(f"Unknown model {s}")
|
|
32
|
+
|
|
33
|
+
|
|
18
34
|
class TrussedBase(ABC):
|
|
19
35
|
"""
|
|
20
36
|
Base class for Nitrokey devices using the Trussed framework and running
|
|
@@ -34,6 +50,10 @@ class TrussedBase(ABC):
|
|
|
34
50
|
f"{self.vid:x}:{self.pid:x}, got {vid:x}:{pid:x}"
|
|
35
51
|
)
|
|
36
52
|
|
|
53
|
+
@property
|
|
54
|
+
@abstractmethod
|
|
55
|
+
def model(self) -> Model: ...
|
|
56
|
+
|
|
37
57
|
@property
|
|
38
58
|
def vid(self) -> int:
|
|
39
59
|
return _VID_NITROKEY
|
|
@@ -9,7 +9,6 @@ import enum
|
|
|
9
9
|
import hashlib
|
|
10
10
|
import json
|
|
11
11
|
import logging
|
|
12
|
-
import re
|
|
13
12
|
import sys
|
|
14
13
|
from abc import abstractmethod
|
|
15
14
|
from dataclasses import dataclass
|
|
@@ -18,9 +17,7 @@ from re import Pattern
|
|
|
18
17
|
from typing import TYPE_CHECKING, Callable, Dict, Optional, Tuple, Union
|
|
19
18
|
from zipfile import ZipFile
|
|
20
19
|
|
|
21
|
-
from
|
|
22
|
-
|
|
23
|
-
from .._base import TrussedBase
|
|
20
|
+
from .._base import Model, TrussedBase
|
|
24
21
|
from .._utils import Version
|
|
25
22
|
|
|
26
23
|
if TYPE_CHECKING:
|
|
@@ -39,39 +36,16 @@ class ModelData:
|
|
|
39
36
|
nrf52_signature_keys: list["SignatureKey"]
|
|
40
37
|
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def __str__(self) -> str:
|
|
47
|
-
return self.value
|
|
48
|
-
|
|
49
|
-
@property
|
|
50
|
-
def firmware_repository(self) -> Repository:
|
|
51
|
-
return Repository(owner="Nitrokey", name=self._data.firmware_repository_name)
|
|
39
|
+
def get_model_data(model: Model) -> ModelData:
|
|
40
|
+
if model == Model.NK3:
|
|
41
|
+
from nitrokey.nk3 import _NK3_DATA
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
return _NK3_DATA
|
|
44
|
+
if model == Model.NKPK:
|
|
45
|
+
from nitrokey.nkpk import _NKPK_DATA
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if self == Model.NK3:
|
|
60
|
-
from nitrokey.nk3 import _NK3_DATA
|
|
61
|
-
|
|
62
|
-
return _NK3_DATA
|
|
63
|
-
if self == Model.NKPK:
|
|
64
|
-
from nitrokey.nkpk import _NKPK_DATA
|
|
65
|
-
|
|
66
|
-
return _NKPK_DATA
|
|
67
|
-
raise ValueError(f"Unknown model {self}")
|
|
68
|
-
|
|
69
|
-
@classmethod
|
|
70
|
-
def from_str(cls, s: str) -> "Model":
|
|
71
|
-
for model in cls:
|
|
72
|
-
if model.value == s:
|
|
73
|
-
return model
|
|
74
|
-
raise ValueError(f"Unknown model {s}")
|
|
47
|
+
return _NKPK_DATA
|
|
48
|
+
raise ValueError(f"Unknown model {model}")
|
|
75
49
|
|
|
76
50
|
|
|
77
51
|
class Variant(enum.Enum):
|
|
@@ -221,6 +195,8 @@ def parse_firmware_image(
|
|
|
221
195
|
if variant == Variant.LPC55:
|
|
222
196
|
return parse_firmware_image_lpc55(data)
|
|
223
197
|
elif variant == Variant.NRF52:
|
|
224
|
-
return parse_firmware_image_nrf52(
|
|
198
|
+
return parse_firmware_image_nrf52(
|
|
199
|
+
data, get_model_data(model).nrf52_signature_keys
|
|
200
|
+
)
|
|
225
201
|
else:
|
|
226
202
|
raise ValueError(f"Unexpected variant {variant}")
|
|
@@ -146,9 +146,9 @@ class DFUAdapter:
|
|
|
146
146
|
while finished is False:
|
|
147
147
|
byte = self.serial_port.read(1)
|
|
148
148
|
if byte:
|
|
149
|
-
(
|
|
149
|
+
(unpacked_byte) = struct.unpack("B", byte)[0]
|
|
150
150
|
(finished, current_state, decoded_data) = Slip.decode_add_byte(
|
|
151
|
-
|
|
151
|
+
unpacked_byte, decoded_data, current_state
|
|
152
152
|
)
|
|
153
153
|
else:
|
|
154
154
|
current_state = Slip.SLIP_STATE_CLEARING_INVALID_PACKET
|
|
@@ -13,7 +13,7 @@ from abc import abstractmethod
|
|
|
13
13
|
from enum import Enum
|
|
14
14
|
from typing import List, Optional, Sequence, TypeVar, Union
|
|
15
15
|
|
|
16
|
-
from fido2.hid import CtapHidDevice, open_device
|
|
16
|
+
from fido2.hid import CtapHidDevice, list_descriptors, open_device
|
|
17
17
|
|
|
18
18
|
from ._base import TrussedBase
|
|
19
19
|
from ._utils import Fido2Certs, Uuid
|
|
@@ -113,6 +113,15 @@ class TrussedDevice(TrussedBase):
|
|
|
113
113
|
@abstractmethod
|
|
114
114
|
def list(cls: type[T]) -> List[T]: ...
|
|
115
115
|
|
|
116
|
+
@classmethod
|
|
117
|
+
def _list_vid_pid(cls: type[T], vid: int, pid: int) -> List[T]:
|
|
118
|
+
descriptors = [
|
|
119
|
+
desc
|
|
120
|
+
for desc in list_descriptors() # type: ignore
|
|
121
|
+
if desc.vid == vid and desc.pid == pid
|
|
122
|
+
]
|
|
123
|
+
return [cls.from_device(open_device(desc.path)) for desc in descriptors]
|
|
124
|
+
|
|
116
125
|
|
|
117
126
|
def _device_path_to_str(path: Union[bytes, str]) -> str:
|
|
118
127
|
"""
|
|
@@ -63,6 +63,7 @@ class InitStatus(IntFlag):
|
|
|
63
63
|
SE050_ERROR = 0b00010000
|
|
64
64
|
CONFIG_ERROR = 0b00100000
|
|
65
65
|
RNG_ERROR = 0b01000000
|
|
66
|
+
EXT_FLASH_NEED_REFORMAT = 0b10000000
|
|
66
67
|
|
|
67
68
|
def is_error(self) -> bool:
|
|
68
69
|
return self.value != 0
|
|
@@ -169,7 +170,7 @@ class ConfigFieldType(Enum):
|
|
|
169
170
|
elif self == ConfigFieldType.U8:
|
|
170
171
|
try:
|
|
171
172
|
intval = int(value)
|
|
172
|
-
if intval < 256 and intval
|
|
173
|
+
if intval < 256 and intval >= 0:
|
|
173
174
|
return True
|
|
174
175
|
else:
|
|
175
176
|
return False
|
|
@@ -9,29 +9,32 @@ import enum
|
|
|
9
9
|
import importlib.metadata
|
|
10
10
|
import logging
|
|
11
11
|
import platform
|
|
12
|
+
import re
|
|
12
13
|
import time
|
|
13
14
|
from abc import ABC, abstractmethod
|
|
14
15
|
from collections.abc import Set
|
|
15
16
|
from contextlib import contextmanager
|
|
16
17
|
from importlib.metadata import PackageNotFoundError
|
|
17
18
|
from io import BytesIO
|
|
18
|
-
from typing import TYPE_CHECKING, Any, Callable, Iterator, List, Optional, Union
|
|
19
|
+
from typing import TYPE_CHECKING, Any, Callable, Iterator, List, Optional, Tuple, Union
|
|
19
20
|
|
|
20
21
|
from nitrokey._helpers import Retries
|
|
21
|
-
from nitrokey.nk3 import NK3, NK3Bootloader
|
|
22
22
|
from nitrokey.trussed import TimeoutException, TrussedBase, Version
|
|
23
|
+
from nitrokey.trussed._base import Model
|
|
23
24
|
from nitrokey.trussed._bootloader import (
|
|
24
25
|
FirmwareContainer,
|
|
25
|
-
|
|
26
|
+
TrussedBootloader,
|
|
26
27
|
Variant,
|
|
28
|
+
get_model_data,
|
|
27
29
|
validate_firmware_image,
|
|
28
30
|
)
|
|
29
31
|
from nitrokey.trussed._bootloader.lpc55_upload.mboot.exceptions import (
|
|
30
32
|
McuBootConnectionError,
|
|
31
33
|
)
|
|
34
|
+
from nitrokey.trussed._device import TrussedDevice
|
|
32
35
|
from nitrokey.trussed.admin_app import BootMode, Status
|
|
33
36
|
from nitrokey.trussed.admin_app import Variant as AdminAppVariant
|
|
34
|
-
from nitrokey.updates import Asset, Release
|
|
37
|
+
from nitrokey.updates import Asset, Release, Repository
|
|
35
38
|
|
|
36
39
|
if TYPE_CHECKING:
|
|
37
40
|
import typing_extensions
|
|
@@ -93,18 +96,22 @@ class Warning(enum.Enum):
|
|
|
93
96
|
|
|
94
97
|
@enum.unique
|
|
95
98
|
class _Migration(enum.Enum):
|
|
96
|
-
# IFS migration to use journaling on the NRF52 introduced in v1.3.0
|
|
99
|
+
# IFS migration to use journaling on the NRF52 introduced in v1.3.0 (NK3)
|
|
97
100
|
NRF_IFS_MIGRATION = enum.auto()
|
|
98
|
-
# IFS migration to filesystem layout 2 in v1.8.2 (
|
|
101
|
+
# IFS migration to filesystem layout 2 (FIDO2 RK migration) in v1.8.2 (NK3)
|
|
99
102
|
IFS_MIGRATION_V2 = enum.auto()
|
|
100
103
|
|
|
101
104
|
@classmethod
|
|
102
105
|
def get(
|
|
103
106
|
cls,
|
|
107
|
+
model: Model,
|
|
104
108
|
variant: Union[Variant, AdminAppVariant],
|
|
105
109
|
current: Optional[Version],
|
|
106
110
|
new: Version,
|
|
107
111
|
) -> frozenset["_Migration"]:
|
|
112
|
+
if model != Model.NK3:
|
|
113
|
+
return frozenset()
|
|
114
|
+
|
|
108
115
|
if isinstance(variant, AdminAppVariant):
|
|
109
116
|
if variant == AdminAppVariant.USBIP:
|
|
110
117
|
raise ValueError("Cannot perform firmware update for USBIP runner")
|
|
@@ -139,8 +146,14 @@ class _Migration(enum.Enum):
|
|
|
139
146
|
return frozenset(migrations)
|
|
140
147
|
|
|
141
148
|
|
|
142
|
-
def
|
|
143
|
-
|
|
149
|
+
def get_firmware_repository(model: Model) -> Repository:
|
|
150
|
+
data = get_model_data(model)
|
|
151
|
+
return Repository(owner="Nitrokey", name=data.firmware_repository_name)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def get_firmware_update(model: Model, release: Release) -> Asset:
|
|
155
|
+
data = get_model_data(model)
|
|
156
|
+
return release.require_asset(re.compile(data.firmware_pattern_string))
|
|
144
157
|
|
|
145
158
|
|
|
146
159
|
def _get_extra_information(migrations: Set[_Migration]) -> List[str]:
|
|
@@ -239,19 +252,28 @@ class UpdateUi(ABC):
|
|
|
239
252
|
pass
|
|
240
253
|
|
|
241
254
|
|
|
255
|
+
class DeviceHandler(ABC):
|
|
256
|
+
@abstractmethod
|
|
257
|
+
def await_bootloader(self, model: Model) -> TrussedBootloader: ...
|
|
258
|
+
|
|
259
|
+
@abstractmethod
|
|
260
|
+
def await_device(
|
|
261
|
+
self,
|
|
262
|
+
model: Model,
|
|
263
|
+
wait_retries: Optional[int],
|
|
264
|
+
callback: Optional[Callable[[int, int], None]],
|
|
265
|
+
) -> TrussedDevice: ...
|
|
266
|
+
|
|
267
|
+
|
|
242
268
|
class Updater:
|
|
243
269
|
def __init__(
|
|
244
270
|
self,
|
|
245
271
|
ui: UpdateUi,
|
|
246
|
-
|
|
247
|
-
await_device: Callable[
|
|
248
|
-
[Optional[int], Optional[Callable[[int, int], None]]], NK3
|
|
249
|
-
],
|
|
272
|
+
device_handler: DeviceHandler,
|
|
250
273
|
ignore_warnings: Set[Warning] = frozenset(),
|
|
251
274
|
) -> None:
|
|
252
275
|
self.ui = ui
|
|
253
|
-
self.
|
|
254
|
-
self.await_device = await_device
|
|
276
|
+
self.device_handler = device_handler
|
|
255
277
|
self.ignore_warnings = ignore_warnings
|
|
256
278
|
|
|
257
279
|
def _trigger_warning(self, warning: Warning) -> None:
|
|
@@ -263,28 +285,34 @@ class Updater:
|
|
|
263
285
|
def update(
|
|
264
286
|
self,
|
|
265
287
|
device: TrussedBase,
|
|
266
|
-
image: Optional[str],
|
|
267
|
-
update_version: Optional[str],
|
|
288
|
+
image: Optional[str] = None,
|
|
289
|
+
update_version: Optional[str] = None,
|
|
268
290
|
ignore_pynitrokey_version: bool = False,
|
|
269
|
-
) -> Version:
|
|
291
|
+
) -> Tuple[Version, Status]:
|
|
292
|
+
model = device.model
|
|
293
|
+
|
|
270
294
|
update_from_bootloader = False
|
|
271
295
|
current_version = None
|
|
272
296
|
status = None
|
|
273
|
-
if isinstance(device,
|
|
297
|
+
if isinstance(device, TrussedBootloader):
|
|
274
298
|
update_from_bootloader = True
|
|
275
299
|
self._trigger_warning(Warning.UPDATE_FROM_BOOTLOADER)
|
|
276
|
-
elif isinstance(device,
|
|
300
|
+
elif isinstance(device, TrussedDevice):
|
|
277
301
|
current_version = device.admin.version()
|
|
278
302
|
status = device.admin.status()
|
|
279
303
|
else:
|
|
280
304
|
raise self.ui.error(f"Unexpected Trussed device: {device}")
|
|
281
305
|
|
|
282
306
|
logger.info(f"Firmware version before update: {current_version or ''}")
|
|
283
|
-
container = self._prepare_update(image, update_version, current_version)
|
|
307
|
+
container = self._prepare_update(model, image, update_version, current_version)
|
|
284
308
|
|
|
285
309
|
if not update_from_bootloader:
|
|
286
|
-
if status is None
|
|
287
|
-
|
|
310
|
+
if status is None:
|
|
311
|
+
if model == Model.NK3:
|
|
312
|
+
if container.version > Version.from_str("1.3.1"):
|
|
313
|
+
self._trigger_warning(Warning.MISSING_STATUS)
|
|
314
|
+
else:
|
|
315
|
+
self.ui.error(f"Missing status for {model} device")
|
|
288
316
|
|
|
289
317
|
self._check_minimum_version(container, ignore_pynitrokey_version)
|
|
290
318
|
|
|
@@ -293,11 +321,11 @@ class Updater:
|
|
|
293
321
|
migrations = None
|
|
294
322
|
if status is not None and status.variant is not None:
|
|
295
323
|
migrations = self._check_migrations(
|
|
296
|
-
status.variant, current_version, container.version, status
|
|
324
|
+
model, status.variant, current_version, container.version, status
|
|
297
325
|
)
|
|
298
|
-
elif isinstance(device,
|
|
326
|
+
elif isinstance(device, TrussedBootloader):
|
|
299
327
|
migrations = self._check_migrations(
|
|
300
|
-
device.variant, current_version, container.version, status
|
|
328
|
+
model, device.variant, current_version, container.version, status
|
|
301
329
|
)
|
|
302
330
|
|
|
303
331
|
with self._get_bootloader(device) as bootloader:
|
|
@@ -311,45 +339,53 @@ class Updater:
|
|
|
311
339
|
bootloader.variant,
|
|
312
340
|
container.images[bootloader.variant],
|
|
313
341
|
container.version,
|
|
314
|
-
|
|
342
|
+
model,
|
|
315
343
|
)
|
|
316
344
|
except Exception as e:
|
|
317
345
|
raise self.ui.error("Failed to validate firmware image", e)
|
|
318
346
|
|
|
319
347
|
if migrations is None:
|
|
320
348
|
migrations = self._check_migrations(
|
|
321
|
-
|
|
349
|
+
model,
|
|
350
|
+
bootloader.variant,
|
|
351
|
+
current_version,
|
|
352
|
+
container.version,
|
|
353
|
+
status,
|
|
322
354
|
)
|
|
323
355
|
|
|
324
356
|
self._perform_update(bootloader, container)
|
|
325
357
|
|
|
326
358
|
wait_retries = _get_finalization_wait_retries(migrations)
|
|
327
359
|
with self.ui.finalization_progress_bar() as callback:
|
|
328
|
-
with self.await_device(
|
|
360
|
+
with self.device_handler.await_device(
|
|
361
|
+
model, wait_retries, callback
|
|
362
|
+
) as device:
|
|
329
363
|
version = device.admin.version()
|
|
330
364
|
if version != container.version:
|
|
331
365
|
raise self.ui.error(
|
|
332
366
|
f"The firmware update to {container.version} was successful, but the "
|
|
333
367
|
f"firmware is still reporting version {version}."
|
|
334
368
|
)
|
|
369
|
+
status = device.admin.status()
|
|
335
370
|
|
|
336
|
-
return container.version
|
|
371
|
+
return container.version, status
|
|
337
372
|
|
|
338
373
|
def _prepare_update(
|
|
339
374
|
self,
|
|
375
|
+
model: Model,
|
|
340
376
|
image: Optional[str],
|
|
341
377
|
version: Optional[str],
|
|
342
378
|
current_version: Optional[Version],
|
|
343
379
|
) -> FirmwareContainer:
|
|
344
380
|
if image:
|
|
345
381
|
try:
|
|
346
|
-
container = FirmwareContainer.parse(image,
|
|
382
|
+
container = FirmwareContainer.parse(image, model)
|
|
347
383
|
except Exception as e:
|
|
348
384
|
raise self.ui.error("Failed to parse firmware container", e)
|
|
349
385
|
self._validate_version(current_version, container.version)
|
|
350
386
|
return container
|
|
351
387
|
else:
|
|
352
|
-
repository =
|
|
388
|
+
repository = get_firmware_repository(model)
|
|
353
389
|
if version:
|
|
354
390
|
try:
|
|
355
391
|
logger.info(f"Downloading firmare version {version}")
|
|
@@ -369,11 +405,11 @@ class Updater:
|
|
|
369
405
|
raise self.ui.error("Failed to parse version from release tag", e)
|
|
370
406
|
self._validate_version(current_version, release_version)
|
|
371
407
|
self.ui.confirm_download(current_version, release_version)
|
|
372
|
-
return self._download_update(release)
|
|
408
|
+
return self._download_update(model, release)
|
|
373
409
|
|
|
374
|
-
def _download_update(self, release: Release) -> FirmwareContainer:
|
|
410
|
+
def _download_update(self, model: Model, release: Release) -> FirmwareContainer:
|
|
375
411
|
try:
|
|
376
|
-
update = get_firmware_update(release)
|
|
412
|
+
update = get_firmware_update(model, release)
|
|
377
413
|
except Exception as e:
|
|
378
414
|
raise self.ui.error(
|
|
379
415
|
f"Failed to find firmware image for release {release}",
|
|
@@ -391,7 +427,7 @@ class Updater:
|
|
|
391
427
|
)
|
|
392
428
|
|
|
393
429
|
try:
|
|
394
|
-
container = FirmwareContainer.parse(BytesIO(data),
|
|
430
|
+
container = FirmwareContainer.parse(BytesIO(data), model)
|
|
395
431
|
except Exception as e:
|
|
396
432
|
raise self.ui.error(
|
|
397
433
|
f"Failed to parse firmware container for {update.tag}", e
|
|
@@ -454,8 +490,9 @@ class Updater:
|
|
|
454
490
|
self.ui.confirm_update_same_version(same_version)
|
|
455
491
|
|
|
456
492
|
@contextmanager
|
|
457
|
-
def _get_bootloader(self, device: TrussedBase) -> Iterator[
|
|
458
|
-
|
|
493
|
+
def _get_bootloader(self, device: TrussedBase) -> Iterator[TrussedBootloader]:
|
|
494
|
+
model = device.model
|
|
495
|
+
if isinstance(device, TrussedDevice):
|
|
459
496
|
self.ui.request_bootloader_confirmation()
|
|
460
497
|
try:
|
|
461
498
|
device.admin.reboot(BootMode.BOOTROM)
|
|
@@ -473,7 +510,7 @@ class Updater:
|
|
|
473
510
|
for t in Retries(3):
|
|
474
511
|
logger.debug(f"Trying to connect to bootloader ({t})")
|
|
475
512
|
try:
|
|
476
|
-
with self.await_bootloader() as bootloader:
|
|
513
|
+
with self.device_handler.await_bootloader(model) as bootloader:
|
|
477
514
|
# noop to test communication
|
|
478
515
|
bootloader.uuid
|
|
479
516
|
yield bootloader
|
|
@@ -482,17 +519,18 @@ class Updater:
|
|
|
482
519
|
logger.debug("Received connection error", exc_info=True)
|
|
483
520
|
exc = e
|
|
484
521
|
else:
|
|
485
|
-
msgs = ["Failed to connect to
|
|
522
|
+
msgs = [f"Failed to connect to {model} bootloader"]
|
|
486
523
|
if platform.system() == "Linux":
|
|
487
524
|
msgs += ["Are the Nitrokey udev rules installed and active?"]
|
|
488
525
|
raise self.ui.error(*msgs, exc)
|
|
489
|
-
elif isinstance(device,
|
|
526
|
+
elif isinstance(device, TrussedBootloader):
|
|
490
527
|
yield device
|
|
491
528
|
else:
|
|
492
|
-
raise self.ui.error(f"Unexpected
|
|
529
|
+
raise self.ui.error(f"Unexpected {model} device: {device}")
|
|
493
530
|
|
|
494
531
|
def _check_migrations(
|
|
495
532
|
self,
|
|
533
|
+
model: Model,
|
|
496
534
|
variant: Union[Variant, AdminAppVariant],
|
|
497
535
|
current_version: Optional[Version],
|
|
498
536
|
new_version: Version,
|
|
@@ -500,13 +538,17 @@ class Updater:
|
|
|
500
538
|
) -> frozenset["_Migration"]:
|
|
501
539
|
try:
|
|
502
540
|
migrations = _Migration.get(
|
|
503
|
-
|
|
541
|
+
model=model,
|
|
542
|
+
variant=variant,
|
|
543
|
+
current=current_version,
|
|
544
|
+
new=new_version,
|
|
504
545
|
)
|
|
505
546
|
except ValueError as e:
|
|
506
547
|
raise self.ui.error(str(e))
|
|
507
548
|
|
|
508
549
|
txt = _get_extra_information(migrations)
|
|
509
|
-
|
|
550
|
+
if len(txt) > 0:
|
|
551
|
+
self.ui.confirm_extra_information(txt)
|
|
510
552
|
|
|
511
553
|
if _Migration.IFS_MIGRATION_V2 in migrations:
|
|
512
554
|
if status and status.ifs_blocks is not None and status.ifs_blocks < 5:
|
|
@@ -515,7 +557,7 @@ class Updater:
|
|
|
515
557
|
return migrations
|
|
516
558
|
|
|
517
559
|
def _perform_update(
|
|
518
|
-
self, device:
|
|
560
|
+
self, device: TrussedBootloader, container: FirmwareContainer
|
|
519
561
|
) -> None:
|
|
520
562
|
logger.debug("Starting firmware update")
|
|
521
563
|
image = container.images[device.variant]
|
nitrokey-0.3.2/pyproject.toml
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["poetry-core >=1,<3"]
|
|
3
|
-
build-backend = "poetry.core.masonry.api"
|
|
4
|
-
|
|
5
|
-
[tool.poetry]
|
|
6
|
-
name = "nitrokey"
|
|
7
|
-
version = "0.3.2"
|
|
8
|
-
description = "Nitrokey Python SDK"
|
|
9
|
-
authors = ["Nitrokey <pypi@nitrokey.com>"]
|
|
10
|
-
license = "Apache-2.0 or MIT"
|
|
11
|
-
readme = "README.md"
|
|
12
|
-
repository = "https://github.com/Nitrokey/nitrokey-sdk-py"
|
|
13
|
-
classifiers = [
|
|
14
|
-
"Intended Audience :: Developers",
|
|
15
|
-
]
|
|
16
|
-
packages = [
|
|
17
|
-
{ include = "nitrokey", from = "src" },
|
|
18
|
-
]
|
|
19
|
-
|
|
20
|
-
[tool.poetry.dependencies]
|
|
21
|
-
cryptography = ">=41"
|
|
22
|
-
fido2 = ">=1.1.2, <3"
|
|
23
|
-
python = "^3.9.2"
|
|
24
|
-
requests = "^2"
|
|
25
|
-
semver = "^3"
|
|
26
|
-
tlv8 = "^0.10"
|
|
27
|
-
|
|
28
|
-
# lpc55
|
|
29
|
-
crcmod = "^1.7"
|
|
30
|
-
hidapi = "^0.14"
|
|
31
|
-
|
|
32
|
-
# nrf52
|
|
33
|
-
protobuf = "^5.26"
|
|
34
|
-
pyserial = "^3.5"
|
|
35
|
-
|
|
36
|
-
[tool.poetry.group.dev]
|
|
37
|
-
optional = true
|
|
38
|
-
|
|
39
|
-
[tool.poetry.group.dev.dependencies]
|
|
40
|
-
black = "^24.3"
|
|
41
|
-
fake-winreg = "^1.6"
|
|
42
|
-
flake8 = "^7.1"
|
|
43
|
-
isort = "^5.13.2"
|
|
44
|
-
mypy = "^1.4"
|
|
45
|
-
rstcheck = { version = "^6", extras = ["sphinx"] }
|
|
46
|
-
sphinx = "^7"
|
|
47
|
-
types-protobuf = "^5.26"
|
|
48
|
-
types-requests = "^2.32"
|
|
49
|
-
typing-extensions = "^4.1"
|
|
50
|
-
|
|
51
|
-
[tool.black]
|
|
52
|
-
target-version = ["py39"]
|
|
53
|
-
|
|
54
|
-
[tool.isort]
|
|
55
|
-
py_version = "39"
|
|
56
|
-
profile = "black"
|
|
57
|
-
|
|
58
|
-
[tool.mypy]
|
|
59
|
-
mypy_path = "stubs"
|
|
60
|
-
show_error_codes = true
|
|
61
|
-
python_version = "3.9"
|
|
62
|
-
strict = true
|
|
63
|
-
|
|
64
|
-
[tool.rstcheck]
|
|
65
|
-
ignore_directives = ["autoclass", "autofunction", "automodule"]
|
|
66
|
-
ignore_substitutions = ["nitrokey_sdk_version"]
|
|
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.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hash.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hmac.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/keys.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/symmetric.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/types.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/exceptions.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/__init__.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/commands.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/error_codes.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/exceptions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/mcuboot.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/memories.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/properties.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/misc.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/images.py
RENAMED
|
File without changes
|
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/__init__.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/abstract.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/rkht.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/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.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/misc.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/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.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/__init__.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu-cc.proto
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.pyi
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport.py
RENAMED
|
File without changes
|
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/manifest.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/src/nitrokey/trussed/_bootloader/nrf52_upload/exceptions.py
RENAMED
|
File without changes
|
{nitrokey-0.3.2 → nitrokey-0.4.1}/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
|