yubikit.core

Submodules

Attributes

T_Connection

Exceptions

CommandError

An error response from a YubiKey

BadResponseError

Invalid response data from the YubiKey

TimeoutError

An operation timed out waiting for something

ApplicationNotAvailableError

The application is either disabled or not supported on this YubiKey

NotSupportedError

Attempting an action that is not supported on this YubiKey

InvalidPinError

An incorrect PIN/PUK was used, with the number of attempts now remaining.

Classes

Version

3-digit version tuple.

TRANSPORT

YubiKey physical connection transports.

USB_INTERFACE

YubiKey USB interface identifiers.

YUBIKEY

YubiKey hardware platforms.

Connection

A connection to a YubiKey

PID

USB Product ID values for YubiKey devices.

YubiKeyDevice

YubiKey device reference

Tlv

bytes(iterable_of_ints) -> bytes

Functions

require_version(my_version, min_version[, message])

Ensure a version is at least min_version.

int2bytes(value[, min_len])

bytes2int(data)

Package Contents

class yubikit.core.Version[source]

Bases: NamedTuple

3-digit version tuple.

major: int
minor: int
patch: int
__str__()[source]
__bool__()[source]
classmethod from_bytes(data)[source]
Parameters:

data (bytes)

Return type:

Version

classmethod from_string(data)[source]
Parameters:

data (str)

Return type:

Version

class yubikit.core.TRANSPORT[source]

Bases: str, enum.Enum

YubiKey physical connection transports.

USB = 'usb'
NFC = 'nfc'
__str__()[source]

Return str(self).

class yubikit.core.USB_INTERFACE[source]

Bases: enum.IntFlag

YubiKey USB interface identifiers.

OTP = 1
FIDO = 2
CCID = 4
class yubikit.core.YUBIKEY(*args, **kwds)[source]

Bases: enum.Enum

YubiKey hardware platforms.

YKS = 'YubiKey Standard'
NEO = 'YubiKey NEO'
SKY = 'Security Key by Yubico'
YKP = 'YubiKey Plus'
YK4 = 'YubiKey'
class yubikit.core.Connection[source]

Bases: abc.ABC

A connection to a YubiKey

usb_interface: ClassVar[USB_INTERFACE]
close()[source]

Close the device, releasing any held resources.

Return type:

None

__enter__()[source]
__exit__(typ, value, traceback)[source]
class yubikit.core.PID[source]

Bases: enum.IntEnum

USB Product ID values for YubiKey devices.

YKS_OTP = 16
NEO_OTP = 272
NEO_OTP_CCID = 273
NEO_CCID = 274
NEO_FIDO = 275
NEO_OTP_FIDO = 276
NEO_FIDO_CCID = 277
NEO_OTP_FIDO_CCID = 278
SKY_FIDO = 288
YK4_OTP = 1025
YK4_FIDO = 1026
YK4_OTP_FIDO = 1027
YK4_CCID = 1028
YK4_OTP_CCID = 1029
YK4_FIDO_CCID = 1030
YK4_OTP_FIDO_CCID = 1031
YKP_OTP_FIDO = 1040
property yubikey_type: YUBIKEY
Return type:

YUBIKEY

property usb_interfaces: USB_INTERFACE
Return type:

USB_INTERFACE

classmethod of(key_type, interfaces)[source]
Parameters:
Return type:

PID

supports_connection(connection_type)[source]
Parameters:

connection_type (type[Connection])

Return type:

bool

yubikit.core.T_Connection
class yubikit.core.YubiKeyDevice(transport, fingerprint)[source]

Bases: abc.ABC

YubiKey device reference

Parameters:
  • transport (TRANSPORT)

  • fingerprint (Hashable)

property transport: TRANSPORT

Get the transport used to communicate with this YubiKey

Return type:

TRANSPORT

supports_connection(connection_type)[source]

Check if a YubiKeyDevice supports a specific Connection type

Parameters:

connection_type (type[Connection])

Return type:

bool

open_connection(connection_type)[source]

Opens a connection to the YubiKey

Parameters:

connection_type (Union[type[T_Connection], Callable[Ellipsis, T_Connection]])

Return type:

T_Connection

property fingerprint: Hashable

Used to identify that device references from different enumerations represent the same physical YubiKey. This fingerprint is not stable between sessions, or after un-plugging, and re-plugging a device.

Return type:

Hashable

__eq__(other)[source]
__hash__()[source]
__repr__()[source]
exception yubikit.core.CommandError[source]

Bases: Exception

An error response from a YubiKey

exception yubikit.core.BadResponseError[source]

Bases: CommandError

Invalid response data from the YubiKey

exception yubikit.core.TimeoutError[source]

Bases: CommandError

An operation timed out waiting for something

exception yubikit.core.ApplicationNotAvailableError[source]

Bases: CommandError

The application is either disabled or not supported on this YubiKey

exception yubikit.core.NotSupportedError[source]

Bases: ValueError

Attempting an action that is not supported on this YubiKey

exception yubikit.core.InvalidPinError(attempts_remaining, message=None)[source]

Bases: CommandError, ValueError

An incorrect PIN/PUK was used, with the number of attempts now remaining.

WARNING: This exception currently inherits from ValueError for backwards-compatibility reasons. This will no longer be the case with the next major version of the library.

Parameters:
  • attempts_remaining (int)

  • message (Optional[str])

attempts_remaining
yubikit.core.require_version(my_version, min_version, message=None)[source]

Ensure a version is at least min_version.

Parameters:
yubikit.core.int2bytes(value, min_len=0)[source]
Parameters:
Return type:

bytes

yubikit.core.bytes2int(data)[source]
Parameters:

data (bytes)

Return type:

int

class yubikit.core.Tlv(tag_or_data, value=None)[source]

Bases: bytes

bytes(iterable_of_ints) -> bytes bytes(string, encoding[, errors]) -> bytes bytes(bytes_or_buffer) -> immutable copy of bytes_or_buffer bytes(int) -> bytes object of size given by the parameter initialized with null bytes bytes() -> empty bytes object

Construct an immutable array of bytes from:
  • an iterable yielding integers in range(256)

  • a text string encoded using the specified encoding

  • any object implementing the buffer API.

  • an integer

Parameters:
property tag: int
Return type:

int

property length: int
Return type:

int

property value: bytes
Return type:

bytes

__repr__()[source]

Return repr(self).

classmethod parse_from(data)[source]
Parameters:

data (bytes)

Return type:

tuple[Tlv, bytes]

classmethod parse_list(data)[source]
Parameters:

data (bytes)

Return type:

list[Tlv]

classmethod parse_dict(data)[source]
Parameters:

data (bytes)

Return type:

dict[int, bytes]

classmethod unpack(tag, data)[source]
Parameters:
Return type:

bytes