23 | 23 |
|
24 | 24 |
# commands from ykdef.h
|
25 | 25 |
_SLOT_NDEF = 0x08 # Write YubiKey NEO NDEF
|
|
26 |
_SLOT_NDEF2 = 0x09 # Write YubiKey NEO NDEF for slot 2
|
26 | 27 |
_ACC_CODE_SIZE = 6 # Size of access code to re-program device
|
27 | 28 |
_NDEF_DATA_SIZE = 54
|
28 | 29 |
_SLOT_DEVICE_CONFIG = 0x11 # Write YubiKey >= 3 device config
|
|
77 | 78 |
(0x23, "urn:nfc:",),
|
78 | 79 |
]
|
79 | 80 |
|
|
81 |
_NDEF_SLOTS = {
|
|
82 |
1: _SLOT_NDEF,
|
|
83 |
2: _SLOT_NDEF2
|
|
84 |
}
|
|
85 |
|
|
86 |
|
80 | 87 |
class YubiKeyNEO_USBHIDError(yubico_exception.YubicoError):
|
81 | 88 |
""" Exception raised for errors with the NEO USB HID communication. """
|
82 | 89 |
|
|
94 | 101 |
return (slot == 1)
|
95 | 102 |
return slot in [1, 2]
|
96 | 103 |
|
97 | |
def have_nfc_ndef(self):
|
98 | |
return True
|
|
104 |
def have_nfc_ndef(self, slot=1):
|
|
105 |
if self.version < (3, 0, 0):
|
|
106 |
return slot == 1
|
|
107 |
return slot in [1, 2]
|
99 | 108 |
|
100 | 109 |
def have_device_config(self):
|
101 | 110 |
return self.version >= (3, 0, 0)
|
|
128 | 137 |
self.version_num() <= (2, 1, 9,):
|
129 | 138 |
self.description = 'YubiKey NEO BETA'
|
130 | 139 |
|
131 | |
def write_ndef(self, ndef):
|
132 | |
"""
|
133 | |
|
134 | |
|
|
140 |
def write_ndef(self, ndef, slot=1):
|
|
141 |
"""
|
135 | 142 |
Write an NDEF tag configuration to the YubiKey NEO.
|
136 | 143 |
"""
|
137 | |
return self._write_config(ndef, _SLOT_NDEF)
|
|
144 |
if not self.capabilities.have_nfc_ndef(slot):
|
|
145 |
raise yubikey_base.YubiKeyVersionError("NDEF slot %i unsupported in YubiKey NEO %s" % (slot, self.version()))
|
|
146 |
|
|
147 |
return self._write_config(ndef, _NDEF_SLOTS[slot])
|
138 | 148 |
|
139 | 149 |
def init_device_config(self, **kwargs):
|
140 | 150 |
return YubiKeyNEO_DEVICE_CONFIG(**kwargs)
|