nitrokey 0.3.2__tar.gz → 0.4.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.
Files changed (90) hide show
  1. {nitrokey-0.3.2 → nitrokey-0.4.0}/PKG-INFO +9 -10
  2. {nitrokey-0.3.2 → nitrokey-0.4.0}/README.md +2 -2
  3. nitrokey-0.4.0/pyproject.toml +89 -0
  4. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/nk3/_bootloader.py +5 -0
  5. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/nk3/_device.py +5 -1
  6. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/nkpk.py +9 -0
  7. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/__init__.py +1 -1
  8. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_base.py +20 -0
  9. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/__init__.py +12 -36
  10. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport_serial.py +2 -2
  11. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/admin_app.py +1 -0
  12. {nitrokey-0.3.2/src/nitrokey/nk3 → nitrokey-0.4.0/src/nitrokey/trussed}/updates.py +82 -41
  13. nitrokey-0.3.2/pyproject.toml +0 -66
  14. {nitrokey-0.3.2 → nitrokey-0.4.0}/LICENSES/Apache-2.0.txt +0 -0
  15. {nitrokey-0.3.2 → nitrokey-0.4.0}/LICENSES/MIT.txt +0 -0
  16. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/__init__.py +0 -0
  17. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/_helpers.py +0 -0
  18. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/nk3/__init__.py +0 -0
  19. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/nk3/secrets_app.py +0 -0
  20. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/py.typed +0 -0
  21. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55.py +0 -0
  22. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/README.md +0 -0
  23. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/__init__.py +0 -0
  24. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/__init__.py +0 -0
  25. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/certificate.py +0 -0
  26. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hash.py +0 -0
  27. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/hmac.py +0 -0
  28. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/keys.py +0 -0
  29. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/symmetric.py +0 -0
  30. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/crypto/types.py +0 -0
  31. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/exceptions.py +0 -0
  32. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/__init__.py +0 -0
  33. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/commands.py +0 -0
  34. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/error_codes.py +0 -0
  35. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/exceptions.py +0 -0
  36. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/interfaces/__init__.py +0 -0
  37. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/interfaces/usb.py +0 -0
  38. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/mcuboot.py +0 -0
  39. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/memories.py +0 -0
  40. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/properties.py +0 -0
  41. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/__init__.py +0 -0
  42. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/base.py +0 -0
  43. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/mboot/protocol/bulk_protocol.py +0 -0
  44. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/misc.py +0 -0
  45. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/__init__.py +0 -0
  46. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/commands.py +0 -0
  47. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/headers.py +0 -0
  48. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/images.py +0 -0
  49. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/sbfile/sb2/sections.py +0 -0
  50. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/__init__.py +0 -0
  51. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/abstract.py +0 -0
  52. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/__init__.py +0 -0
  53. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/cert_blocks.py +0 -0
  54. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/crypto/rkht.py +0 -0
  55. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/exceptions.py +0 -0
  56. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/__init__.py +0 -0
  57. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/commands.py +0 -0
  58. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/__init__.py +0 -0
  59. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/base.py +0 -0
  60. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/device/usb_device.py +0 -0
  61. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/protocol/__init__.py +0 -0
  62. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/interfaces/protocol/protocol_base.py +0 -0
  63. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/misc.py +0 -0
  64. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/lpc55_upload/utils/spsdk_enum.py +0 -0
  65. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52.py +0 -0
  66. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/README.md +0 -0
  67. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/__init__.py +0 -0
  68. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/__init__.py +0 -0
  69. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu-cc.proto +0 -0
  70. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.py +0 -0
  71. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_cc_pb2.pyi +0 -0
  72. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/dfu_transport.py +0 -0
  73. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/init_packet_pb.py +0 -0
  74. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/dfu/manifest.py +0 -0
  75. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/exceptions.py +0 -0
  76. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/__init__.py +0 -0
  77. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/device_lister.py +0 -0
  78. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/enumerated_device.py +0 -0
  79. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/lister_backend.py +0 -0
  80. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/unix/__init__.py +0 -0
  81. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/unix/unix_lister.py +0 -0
  82. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/__init__.py +0 -0
  83. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/constants.py +0 -0
  84. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/lister_win32.py +0 -0
  85. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_bootloader/nrf52_upload/lister/windows/structures.py +0 -0
  86. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_device.py +0 -0
  87. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_exceptions.py +0 -0
  88. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/_utils.py +0 -0
  89. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/trussed/provisioner_app.py +0 -0
  90. {nitrokey-0.3.2 → nitrokey-0.4.0}/src/nitrokey/updates.py +0 -0
@@ -1,12 +1,11 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: nitrokey
3
- Version: 0.3.2
3
+ Version: 0.4.0
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.9.2,<4.0.0
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.0)
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,<6.0)
22
- Requires-Dist: pyserial (>=3.5,<4.0)
23
- Requires-Dist: requests (>=2,<3)
20
+ Requires-Dist: protobuf (>=5.26,<6)
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
@@ -76,7 +75,7 @@ for device in NKPK.list():
76
75
 
77
76
  ## Compatibility
78
77
 
79
- The Nitrokey Python SDK currently requires Python 3.9.2 or later.
78
+ The Nitrokey Python SDK currently requires Python 3.10 or later.
80
79
  Support for old Python versions may be dropped in minor releases.
81
80
 
82
81
  ## Related Projects
@@ -92,7 +91,7 @@ Support for old Python versions may be dropped in minor releases.
92
91
 
93
92
  The following software is required for the development of the SDK:
94
93
 
95
- - Python 3.9 or newer
94
+ - Python 3.10 or newer
96
95
  - [poetry](https://python-poetry.org/)
97
96
  - GNU Make
98
97
  - git
@@ -48,7 +48,7 @@ for device in NKPK.list():
48
48
 
49
49
  ## Compatibility
50
50
 
51
- The Nitrokey Python SDK currently requires Python 3.9.2 or later.
51
+ The Nitrokey Python SDK currently requires Python 3.10 or later.
52
52
  Support for old Python versions may be dropped in minor releases.
53
53
 
54
54
  ## Related Projects
@@ -64,7 +64,7 @@ Support for old Python versions may be dropped in minor releases.
64
64
 
65
65
  The following software is required for the development of the SDK:
66
66
 
67
- - Python 3.9 or newer
67
+ - Python 3.10 or newer
68
68
  - [poetry](https://python-poetry.org/)
69
69
  - GNU Make
70
70
  - 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.0"
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, <6",
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"
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, <6",
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] = []
@@ -10,7 +10,7 @@ from typing import List
10
10
  from fido2.hid import CtapHidDevice, list_descriptors, open_device
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
@@ -11,6 +11,7 @@ from fido2.hid import CtapHidDevice, list_descriptors, open_device
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
@@ -77,6 +82,10 @@ class NKPK(TrussedDevice):
77
82
 
78
83
 
79
84
  class NKPKBootloader(TrussedBootloaderNrf52):
85
+ @property
86
+ def model(self) -> Model:
87
+ return Model.NKPK
88
+
80
89
  @property
81
90
  def name(self) -> str:
82
91
  return "Nitrokey Passkey Bootloader"
@@ -5,10 +5,10 @@
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 ._base import Model as Model # noqa: F401
8
9
  from ._base import TrussedBase as TrussedBase # noqa: F401
9
10
  from ._bootloader import FirmwareContainer as FirmwareContainer # noqa: F401
10
11
  from ._bootloader import FirmwareMetadata as FirmwareMetadata # noqa: F401
11
- from ._bootloader import Model as Model # noqa: F401
12
12
  from ._bootloader import TrussedBootloader as TrussedBootloader # noqa: F401
13
13
  from ._bootloader import Variant as Variant # noqa: F401
14
14
  from ._bootloader import parse_firmware_image as parse_firmware_image # noqa: F401
@@ -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 nitrokey.updates import Repository
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
- class Model(enum.Enum):
43
- NK3 = "Nitrokey 3"
44
- NKPK = "Nitrokey Passkey"
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
- @property
54
- def firmware_pattern(self) -> Pattern[str]:
55
- return re.compile(self._data.firmware_pattern_string)
43
+ return _NK3_DATA
44
+ if model == Model.NKPK:
45
+ from nitrokey.nkpk import _NKPK_DATA
56
46
 
57
- @property
58
- def _data(self) -> "ModelData":
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(data, model._data.nrf52_signature_keys)
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
- (byte) = struct.unpack("B", byte)[0]
149
+ (unpacked_byte) = struct.unpack("B", byte)[0]
150
150
  (finished, current_state, decoded_data) = Slip.decode_add_byte(
151
- byte, decoded_data, current_state
151
+ unpacked_byte, decoded_data, current_state
152
152
  )
153
153
  else:
154
154
  current_state = Slip.SLIP_STATE_CLEARING_INVALID_PACKET
@@ -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
@@ -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
- Model,
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 (FIDO2 RK migration)
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 get_firmware_update(release: Release) -> Asset:
143
- return release.require_asset(Model.NK3.firmware_pattern)
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
- await_bootloader: Callable[[], NK3Bootloader],
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.await_bootloader = await_bootloader
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:
@@ -266,25 +288,31 @@ class Updater:
266
288
  image: Optional[str],
267
289
  update_version: Optional[str],
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, NK3Bootloader):
297
+ if isinstance(device, TrussedBootloader):
274
298
  update_from_bootloader = True
275
299
  self._trigger_warning(Warning.UPDATE_FROM_BOOTLOADER)
276
- elif isinstance(device, NK3):
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 and container.version > Version.from_str("1.3.1"):
287
- self._trigger_warning(Warning.MISSING_STATUS)
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, NK3Bootloader):
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
- Model.NK3,
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
- bootloader.variant, current_version, container.version, status
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(wait_retries, callback) as 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, Model.NK3)
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 = Model.NK3.firmware_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), Model.NK3)
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[NK3Bootloader]:
458
- if isinstance(device, NK3):
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 Nitrokey 3 bootloader"]
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, NK3Bootloader):
526
+ elif isinstance(device, TrussedBootloader):
490
527
  yield device
491
528
  else:
492
- raise self.ui.error(f"Unexpected Nitrokey 3 device: {device}")
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,7 +538,10 @@ class Updater:
500
538
  ) -> frozenset["_Migration"]:
501
539
  try:
502
540
  migrations = _Migration.get(
503
- variant=variant, current=current_version, new=new_version
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))
@@ -515,7 +556,7 @@ class Updater:
515
556
  return migrations
516
557
 
517
558
  def _perform_update(
518
- self, device: NK3Bootloader, container: FirmwareContainer
559
+ self, device: TrussedBootloader, container: FirmwareContainer
519
560
  ) -> None:
520
561
  logger.debug("Starting firmware update")
521
562
  image = container.images[device.variant]
@@ -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