| 1 |
Usage Guide |
| 2 |
=========== |
| 3 |
|
| 4 |
.. contents:: :local: |
| 5 |
|
| 6 |
The Nitrokey Python SDK currently supports Nitrokey 3 (:py:class:`nitrokey.nk3.NK3`) and Nitrokey Passkey (:py:class:`nitrokey.nkpk.NKPK`) devices. |
| 7 |
Both devices are based on the same platform, Trussed, and therefore share the same base class :py:class:`nitrokey.trussed.TrussedDevice`. |
| 8 |
|
| 9 |
Trussed devices can be rebooted into a bootloader mode that is used to apply firmware updates. |
| 10 |
Devices in bootloader mode can be accessed using :py:class:`nitrokey.nk3.NK3Bootloader` and :py:class:`nitrokey.nkpk.NKPKBootloader` (base class :py:class:`nitrokey.trussed.TrussedBootloader`). |
| 11 |
|
| 12 |
Listing and Opening Devices |
| 13 |
--------------------------- |
| 14 |
|
| 15 |
Use the :py:func:`nitrokey.trussed.list` function to list and open all connected devices:: |
| 16 |
|
| 17 |
import nitrokey.trussed |
| 18 |
|
| 19 |
print("Connected Nitrokey devices:") |
| 20 |
for device in nitrokey.trussed.list(): |
| 21 |
print(f"- {device.name} at {device.path}") |
| 22 |
|
| 23 |
If you know the device path, use :py:func:`nitrokey.trussed.open` instead:: |
| 24 |
|
| 25 |
import nitrokey.trussed |
| 26 |
|
| 27 |
path = "/dev/hidraw1" |
| 28 |
device = nitrokey.trussed.open(path) |
| 29 |
if device is not None: |
| 30 |
print(f"Found {device.name} at {path}") |
| 31 |
else: |
| 32 |
print(f"No device found at {path}") |
| 33 |
|
| 34 |
If you know the model you want to connect to, you can also use the ``list`` and ``open`` functions in the :py:mod:`nitrokey.nk3` or :py:mod:`nitrokey.nkpk` modules. |
| 35 |
If you also know the type of the device, you can use the ``list`` and ``open`` methods of the :py:class:`nitrokey.nk3.NK3`, :py:class:`nitrokey.nkpk.NKPK`, :py:class:`nitrokey.nk3.NK3Bootloader` and :py:class:`nitrokey.nkpk.NKPKBootloader` classes. |
| 36 |
|
| 37 |
Using Applications |
| 38 |
------------------ |
| 39 |
|
| 40 |
The Nitrokey Python SDK supports these applications for all Trussed devices: |
| 41 |
|
| 42 |
* :py:class:`nitrokey.trussed.admin_app.AdminApp`: access device metadata and manage device configuration state |
| 43 |
* :py:class:`nitrokey.trussed.provisioner_app.ProvisionerApp`: setup device in provisioner mode (only applicable for Hacker devices) |
| 44 |
|
| 45 |
The Nitrokey 3 also provides these applications: |
| 46 |
|
| 47 |
* :py:class:`nitrokey.nk3.secrets_app.SecretsApp`: securely store passwords and credentials |
| 48 |
|
| 49 |
See the API reference for the application classes for more information. |