Usage Guide¶
Nitrokey Python SDK 目前支持 Nitrokey 3 (nitrokey.nk3.NK3) 和 Nitrokey Passkey (nitrokey.nkpk.NKPK) 设备。这两种设备基于相同的平台 Trussed,因此共享相同的基类 nitrokey.trussed.TrussedDevice。
桁架式设备可重启至引导加载器模式,用于应用固件更新。可以使用 nitrokey.nk3.NK3Bootloader 和 nitrokey.nkpk.NKPKBootloader 访问引导加载器模式下的设备(基类 nitrokey.trussed.TrussedBootloader)。
Listing and Opening Devices¶
使用 nitrokey.trussed.TrussedDevice.list() 函数列出并打开所有连接的设备::
from nitrokey.nk3 import NK3
from nitrokey.nkpk import NKPK
print("Connected Nitrokey devices:")
for device in NK3.list():
print(f"- {device.name} at {device.path}")
for device in NKPK.list():
print(f"- {device.name} at {device.path}")
如果知道设备路径,请使用 nitrokey.trussed.TrussedDevice.open() 代替::
from nitrokey.nk3 import NK3
from nitrokey.nkpk import NKPK
path = "/dev/hidraw1"
device = NK3.open(path)
if device is not None:
print(f"Found {device.name} at {path}")
device = NKPK.open(path)
if device is not None:
print(f"Found {device.name} at {path}")
类似的函数还有 nitrokey.nk3.NK3Bootloader 和 nitrokey.nkpk.NKPKBootloader。要同时列出普通设备和引导加载器设备,请使用 nitrokey.nk3.list() 和 nitrokey.nkpk.list()。
备注
目前,由 nitrokey.trussed.TrussedDevice.list()、nitrokey.nk3.list() 和 nitrokey.nkpk.list() 返回的设备仅在下一次调用这些函数之前有效。更多信息请参阅`第 31 期<https://github.com/Nitrokey/nitrokey-sdk-py/issues/31>`_ 。
Using Applications¶
硝基 Python SDK 支持所有 Trussed 设备的这些应用:
py:class:nitrokey.trussed.admin_app.AdminApp:访问设备元数据并管理设备配置状态
py:class:nitrokey.trussed.provisioner_app.ProvisionerApp:以供应器模式设置设备(仅适用于黑客设备)。
The Nitrokey 3 also provides these applications:
py:class:nitrokey.nk3.secrets_app.SecretsApp:安全地存储密码和凭证
更多信息,请参阅应用程序类的 API 参考资料。