-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_device.py
More file actions
83 lines (64 loc) · 2.44 KB
/
_device.py
File metadata and controls
83 lines (64 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright 2021 Nitrokey Developers
#
# Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
# http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
# http://opensource.org/licenses/MIT>, at your option. This file may not be
# copied, modified, or distributed except according to those terms.
from typing import List
from fido2.hid import CtapHidDevice
try:
from smartcard.ExclusiveConnectCardConnection import ExclusiveConnectCardConnection
from smartcard.ExclusiveTransmitCardConnection import ExclusiveTransmitCardConnection
except ModuleNotFoundError:
class ExclusiveTransmitCardConnection: # type: ignore[no-redef]
pass
class ExclusiveConnectCardConnection: # type: ignore[no-redef]
pass
from nitrokey import _VID_NITROKEY
from nitrokey.trussed import Fido2Certs, Model, TrussedDevice, Version
FIDO2_CERTS = [
Fido2Certs(
start=Version(0, 1, 0),
hashes=["ad8fd1d16f59104b9e06ef323cc03f777ed5303cd421a101c9cb00bb3fdf722d"],
),
Fido2Certs(
start=Version(1, 0, 3),
hashes=[
"aa1cb760c2879530e7d7fed3da75345d25774be9cfdbbcbd36fdee767025f34b", # NK3xN/lpc55
"4c331d7af869fd1d8217198b917a33d1fa503e9778da7638504a64a438661ae0", # NK3AM/nrf52
"f1ed1aba24b16e8e3fabcda72b10cbfa54488d3b778bda552162d60c6dd7b4fa", # NK3AM/nrf52 test
],
),
]
class NK3(TrussedDevice):
"""A Nitrokey 3 device running the firmware."""
def __init__(
self,
device: CtapHidDevice | ExclusiveTransmitCardConnection | ExclusiveConnectCardConnection,
) -> None:
super().__init__(device, FIDO2_CERTS)
@property
def model(self) -> Model:
return Model.NK3
@property
def pid(self) -> int:
from . import _PID_NK3_DEVICE
return _PID_NK3_DEVICE
@property
def name(self) -> str:
return "Nitrokey 3"
@classmethod
def from_device(
cls,
device: CtapHidDevice | ExclusiveTransmitCardConnection | ExclusiveConnectCardConnection,
) -> "NK3":
return cls(device)
@classmethod
def list_ctaphid(cls) -> List["NK3"]:
from . import _PID_NK3_DEVICE
return cls._list_vid_pid(_VID_NITROKEY, _PID_NK3_DEVICE)
@classmethod
def list_ccid(cls, exclusive: bool = True) -> List["NK3"]:
return cls._list_pcsc_atr(
list(bytes.fromhex("3B8F01805D4E6974726F6B657900000000006A")), exclusive
)