yubikit.core.otp

Attributes

MODHEX_ALPHABET

CRC_OK_RESIDUAL

FEATURE_RPT_SIZE

FEATURE_RPT_DATA_SIZE

SLOT_DATA_SIZE

FRAME_SIZE

RESP_PENDING_FLAG

SLOT_WRITE_FLAG

RESP_TIMEOUT_WAIT_FLAG

DUMMY_REPORT_WRITE

SEQUENCE_MASK

STATUS_OFFSET_PROG_SEQ

STATUS_OFFSET_TOUCH_LOW

CONFIG_STATUS_MASK

STATUS_PROCESSING

STATUS_UPNEEDED

Exceptions

CommandRejectedError

The issues command was rejected by the YubiKey

Classes

OtpConnection

A connection to a YubiKey

OtpProtocol

An implementation of the OTP protocol.

Functions

calculate_crc(data)

check_crc(data)

modhex_encode(data)

Encode a bytes-like object using Modhex (modified hexadecimal) encoding.

modhex_decode(string)

Decode the Modhex (modified hexadecimal) string.

Module Contents

yubikit.core.otp.MODHEX_ALPHABET = 'cbdefghijklnrtuv'
exception yubikit.core.otp.CommandRejectedError[source]

Bases: yubikit.core.CommandError

The issues command was rejected by the YubiKey

class yubikit.core.otp.OtpConnection[source]

Bases: yubikit.core.Connection

A connection to a YubiKey

usb_interface
abstract receive()[source]

Reads an 8 byte feature report

Return type:

bytes

abstract send(data)[source]

Writes an 8 byte feature report

Parameters:

data (bytes)

Return type:

None

yubikit.core.otp.CRC_OK_RESIDUAL = 61624
yubikit.core.otp.calculate_crc(data)[source]
Parameters:

data (bytes)

Return type:

int

yubikit.core.otp.check_crc(data)[source]
Parameters:

data (bytes)

Return type:

bool

yubikit.core.otp.modhex_encode(data)[source]

Encode a bytes-like object using Modhex (modified hexadecimal) encoding.

Parameters:

data (bytes)

Return type:

str

yubikit.core.otp.modhex_decode(string)[source]

Decode the Modhex (modified hexadecimal) string.

Parameters:

string (str)

Return type:

bytes

yubikit.core.otp.FEATURE_RPT_SIZE = 8
yubikit.core.otp.FEATURE_RPT_DATA_SIZE = 7
yubikit.core.otp.SLOT_DATA_SIZE = 64
yubikit.core.otp.FRAME_SIZE = 70
yubikit.core.otp.RESP_PENDING_FLAG = 64
yubikit.core.otp.SLOT_WRITE_FLAG = 128
yubikit.core.otp.RESP_TIMEOUT_WAIT_FLAG = 32
yubikit.core.otp.DUMMY_REPORT_WRITE = 143
yubikit.core.otp.SEQUENCE_MASK = 31
yubikit.core.otp.STATUS_OFFSET_PROG_SEQ = 4
yubikit.core.otp.STATUS_OFFSET_TOUCH_LOW = 5
yubikit.core.otp.CONFIG_STATUS_MASK = 31
yubikit.core.otp.STATUS_PROCESSING = 1
yubikit.core.otp.STATUS_UPNEEDED = 2
class yubikit.core.otp.OtpProtocol(otp_connection)[source]

An implementation of the OTP protocol.

Parameters:

otp_connection (OtpConnection)

connection
version
close()[source]
Return type:

None

send_and_receive(slot, data=None, event=None, on_keepalive=None)[source]

Sends a command to the YubiKey, and reads the response.

If the command results in a configuration update, the programming sequence number is verified and the updated status bytes are returned.

Parameters:
  • slot (int) – The slot to send to.

  • data (Optional[bytes]) – The data payload to send.

  • state – Optional CommandState for listening for user presence requirement and for cancelling a command.

  • event (Optional[threading.Event])

  • on_keepalive (Optional[Callable[[int], None]])

Returns:

Response data (including CRC) in the case of data, or an updated status struct.

Return type:

bytes

read_status()[source]

Receive status bytes from YubiKey.

Returns:

Status bytes (first 3 bytes are the firmware version).

Raises:

IOException – in case of communication error.

Return type:

bytes