yubikit package
Subpackages
- yubikit.core package
- Subpackages
- Submodules
- yubikit.core.fido module
- yubikit.core.otp module
- Module contents
Version
TRANSPORT
USB_INTERFACE
YUBIKEY
Connection
PID
PID.YKS_OTP
PID.NEO_OTP
PID.NEO_OTP_CCID
PID.NEO_CCID
PID.NEO_FIDO
PID.NEO_OTP_FIDO
PID.NEO_FIDO_CCID
PID.NEO_OTP_FIDO_CCID
PID.SKY_FIDO
PID.YK4_OTP
PID.YK4_FIDO
PID.YK4_OTP_FIDO
PID.YK4_CCID
PID.YK4_OTP_CCID
PID.YK4_FIDO_CCID
PID.YK4_OTP_FIDO_CCID
PID.YKP_OTP_FIDO
PID.yubikey_type
PID.usb_interfaces
PID.of()
PID.supports_connection()
YubiKeyDevice
CommandError
BadResponseError
TimeoutError
ApplicationNotAvailableError
NotSupportedError
InvalidPinError
require_version()
int2bytes()
bytes2int()
Tlv
Submodules
yubikit.hsmauth module
- class yubikit.hsmauth.ALGORITHM(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
Algorithms for YubiHSM Auth credentials.
- AES128_YUBICO_AUTHENTICATION = 38
- EC_P256_YUBICO_AUTHENTICATION = 39
- property key_len
- property pubkey_len
- class yubikit.hsmauth.Credential(label, algorithm, counter, touch_required)[source]
Bases:
object
A YubiHSM Auth credential object.
- class yubikit.hsmauth.SessionKeys(key_senc: bytes, key_smac: bytes, key_srmac: bytes)[source]
Bases:
NamedTuple
YubiHSM Session Keys.
- class yubikit.hsmauth.HsmAuthSession(connection, scp_key_params=None)[source]
Bases:
object
A session with the YubiHSM Auth application.
- put_credential_symmetric(management_key, label, key_enc, key_mac, credential_password, touch_required=False)[source]
Import a symmetric YubiHSM Auth credential.
- Parameters:
management_key (
bytes
) – The management key.label (
str
) – The label of the credential.key_enc (
bytes
) – The static K-ENC.key_mac (
bytes
) – The static K-MAC.credential_password (
Union
[bytes
,str
]) – The password used to protect access to the credential.touch_required (
bool
) – The touch requirement policy.
- Return type:
- put_credential_derived(management_key, label, derivation_password, credential_password, touch_required=False)[source]
Import a symmetric YubiHSM Auth credential derived from password.
- Parameters:
management_key (
bytes
) – The management key.label (
str
) – The label of the credential.derivation_password (
str
) – The password used to derive the keys from.credential_password (
Union
[bytes
,str
]) – The password used to protect access to the credential.touch_required (
bool
) – The touch requirement policy.
- Return type:
- put_credential_asymmetric(management_key, label, private_key, credential_password, touch_required=False)[source]
Import an asymmetric YubiHSM Auth credential.
- Parameters:
management_key (
bytes
) – The management key.label (
str
) – The label of the credential.private_key (
EllipticCurvePrivateKey
) – Private key corresponding to the public authentication key object on the YubiHSM.credential_password (
Union
[bytes
,str
]) – The password used to protect access to the credential.touch_required (
bool
) – The touch requirement policy.
- Return type:
- generate_credential_asymmetric(management_key, label, credential_password, touch_required=False)[source]
Generate an asymmetric YubiHSM Auth credential.
Generates a private key on the YubiKey, whose corresponding public key can be retrieved using get_public_key.
- get_public_key(label)[source]
Get the public key for an asymmetric credential.
This will return the long-term public key “PK-OCE” for an asymmetric credential.
- Parameters:
label (
str
) – The label of the credential.- Return type:
- calculate_session_keys_symmetric(label, context, credential_password, card_crypto=None)[source]
Calculate session keys from a symmetric YubiHSM Auth credential.
- calculate_session_keys_asymmetric(label, context, public_key, credential_password, card_crypto)[source]
Calculate session keys from an asymmetric YubiHSM Auth credential.
- Parameters:
label (
str
) – The label of the credential.context (
bytes
) – The context (EPK.OCE + EPK.SD).public_key (
EllipticCurvePublicKey
) – The YubiHSM device’s public key.credential_password (
Union
[bytes
,str
]) – The password used to protect access to the credential.card_crypto (
bytes
) – The card cryptogram.
- Return type:
yubikit.logging module
yubikit.management module
- class yubikit.management.CAPABILITY(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
YubiKey Application identifiers.
- OTP = 1
- U2F = 2
- FIDO2 = 512
- OATH = 32
- PIV = 16
- OPENPGP = 8
- HSMAUTH = 256
- property usb_interfaces: USB_INTERFACE
- class yubikit.management.FORM_FACTOR(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
YubiKey device form factors.
- UNKNOWN = 0
- USB_A_KEYCHAIN = 1
- USB_A_NANO = 2
- USB_C_KEYCHAIN = 3
- USB_C_NANO = 4
- USB_C_LIGHTNING = 5
- USB_A_BIO = 6
- USB_C_BIO = 7
- class yubikit.management.DEVICE_FLAG(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
Configuration flags.
- REMOTE_WAKEUP = 64
- EJECT = 128
- class yubikit.management.DeviceConfig(enabled_capabilities=<factory>, auto_eject_timeout=None, challenge_response_timeout=None, device_flags=None, nfc_restricted=None)[source]
Bases:
object
Management settings for YubiKey which can be configured by the user.
-
enabled_capabilities:
Mapping
[TRANSPORT
,CAPABILITY
]
-
device_flags:
Optional
[DEVICE_FLAG
] = None
-
enabled_capabilities:
- class yubikit.management.DeviceInfo(config, serial, version, form_factor, supported_capabilities, is_locked, is_fips=False, is_sky=False, part_number=None, fips_capable=<CAPABILITY: 0>, fips_approved=<CAPABILITY: 0>, pin_complexity=False, reset_blocked=<CAPABILITY: 0>, fps_version=None, stm_version=None)[source]
Bases:
object
Information about a YubiKey readable using the ManagementSession.
-
config:
DeviceConfig
-
form_factor:
FORM_FACTOR
-
supported_capabilities:
Mapping
[TRANSPORT
,CAPABILITY
]
-
fips_capable:
CAPABILITY
= 0
-
fips_approved:
CAPABILITY
= 0
-
reset_blocked:
CAPABILITY
= 0
-
config:
- class yubikit.management.Mode(interfaces)[source]
Bases:
object
YubiKey USB Mode configuration for use with YubiKey NEO and 4.
-
interfaces:
USB_INTERFACE
-
interfaces:
- class yubikit.management.ManagementSession(connection, scp_key_params=None)[source]
Bases:
object
- close()[source]
Close the underlying connection.
- Deprecated:
call .close() on the underlying connection instead.
- Return type:
- write_device_config(config=None, reboot=False, cur_lock_code=None, new_lock_code=None)[source]
Write configuration settings for YubiKey.
yubikit.oath module
- class yubikit.oath.HASH_ALGORITHM(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- SHA1 = 1
- SHA256 = 2
- SHA512 = 3
- class yubikit.oath.OATH_TYPE(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- HOTP = 16
- TOTP = 32
- yubikit.oath.parse_b32_key(key)[source]
Parse Base32 encoded key.
- Parameters:
key (
str
) – The Base32 encoded key.
- class yubikit.oath.CredentialData(name, oath_type, hash_algorithm, secret, digits=6, period=30, counter=0, issuer=None)[source]
Bases:
object
An object holding OATH credential data.
-
hash_algorithm:
HASH_ALGORITHM
-
hash_algorithm:
- class yubikit.oath.Credential(device_id, id, issuer, name, oath_type, period, touch_required)[source]
Bases:
object
An OATH credential object.
- class yubikit.oath.OathSession(connection, scp_key_params=None)[source]
Bases:
object
A session with the OATH application.
- unset_key()[source]
Remove the access key.
This removes the need to authentication a session before using it.
- Return type:
- put_credential(credential_data, touch_required=False)[source]
Add an OATH credential.
- Parameters:
credential_data (
CredentialData
) – The credential data.touch_required (
bool
) – The touch policy.
- Return type:
yubikit.openpgp module
- class yubikit.openpgp.UIF(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- OFF = 0
- ON = 1
- FIXED = 2
- CACHED = 3
- CACHED_FIXED = 4
- class yubikit.openpgp.PIN_POLICY(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- ALWAYS = 0
- ONCE = 1
- class yubikit.openpgp.INS(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- VERIFY = 32
- CHANGE_PIN = 36
- RESET_RETRY_COUNTER = 44
- PSO = 42
- ACTIVATE = 68
- GENERATE_ASYM = 71
- GET_CHALLENGE = 132
- INTERNAL_AUTHENTICATE = 136
- SELECT_DATA = 165
- GET_DATA = 202
- PUT_DATA = 218
- PUT_DATA_ODD = 219
- TERMINATE = 230
- GET_VERSION = 241
- SET_PIN_RETRIES = 242
- GET_ATTESTATION = 251
- class yubikit.openpgp.PW(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- USER = 129
- RESET = 130
- ADMIN = 131
- class yubikit.openpgp.DO(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- PRIVATE_USE_1 = 257
- PRIVATE_USE_2 = 258
- PRIVATE_USE_3 = 259
- PRIVATE_USE_4 = 260
- AID = 79
- NAME = 91
- LOGIN_DATA = 94
- LANGUAGE = 61229
- SEX = 24373
- URL = 24400
- HISTORICAL_BYTES = 24402
- EXTENDED_LENGTH_INFO = 32614
- GENERAL_FEATURE_MANAGEMENT = 32628
- CARDHOLDER_RELATED_DATA = 101
- APPLICATION_RELATED_DATA = 110
- ALGORITHM_ATTRIBUTES_SIG = 193
- ALGORITHM_ATTRIBUTES_DEC = 194
- ALGORITHM_ATTRIBUTES_AUT = 195
- ALGORITHM_ATTRIBUTES_ATT = 218
- PW_STATUS_BYTES = 196
- FINGERPRINT_SIG = 199
- FINGERPRINT_DEC = 200
- FINGERPRINT_AUT = 201
- FINGERPRINT_ATT = 219
- CA_FINGERPRINT_1 = 202
- CA_FINGERPRINT_2 = 203
- CA_FINGERPRINT_3 = 204
- CA_FINGERPRINT_4 = 220
- GENERATION_TIME_SIG = 206
- GENERATION_TIME_DEC = 207
- GENERATION_TIME_AUT = 208
- GENERATION_TIME_ATT = 221
- RESETTING_CODE = 211
- UIF_SIG = 214
- UIF_DEC = 215
- UIF_AUT = 216
- UIF_ATT = 217
- SECURITY_SUPPORT_TEMPLATE = 122
- CARDHOLDER_CERTIFICATE = 32545
- KDF = 249
- ALGORITHM_INFORMATION = 250
- ATT_CERTIFICATE = 252
- class yubikit.openpgp.OpenPgpAid[source]
Bases:
bytes
OpenPGP Application Identifier (AID)
The OpenPGP AID is a string of bytes identifying the OpenPGP application. It also embeds some values which are accessible though properties.
- property version: Tuple[int, int]
OpenPGP version (tuple of 2 integers: main version, secondary version).
- class yubikit.openpgp.EXTENDED_CAPABILITY_FLAGS(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
- KDF = 1
- PSO_DEC_ENC_AES = 2
- ALGORITHM_ATTRIBUTES_CHANGEABLE = 4
- PRIVATE_USE = 8
- PW_STATUS_CHANGEABLE = 16
- KEY_IMPORT = 32
- GET_CHALLENGE = 64
- SECURE_MESSAGING = 128
- class yubikit.openpgp.CardholderRelatedData(name, language, sex)[source]
Bases:
object
- class yubikit.openpgp.ExtendedLengthInfo(request_max_bytes, response_max_bytes)[source]
Bases:
object
- class yubikit.openpgp.GENERAL_FEATURE_MANAGEMENT(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
- TOUCHSCREEN = 1
- MICROPHONE = 2
- LOUDSPEAKER = 4
- LED = 8
- KEYPAD = 16
- BUTTON = 32
- BIOMETRIC = 64
- DISPLAY = 128
- class yubikit.openpgp.ExtendedCapabilities(flags, sm_algorithm, challenge_max_length, certificate_max_length, special_do_max_length, pin_block_2_format, mse_command)[source]
Bases:
object
-
flags:
EXTENDED_CAPABILITY_FLAGS
-
flags:
- class yubikit.openpgp.PwStatus(pin_policy_user, max_len_user, max_len_reset, max_len_admin, attempts_user, attempts_reset, attempts_admin)[source]
Bases:
object
-
pin_policy_user:
PIN_POLICY
-
pin_policy_user:
- class yubikit.openpgp.CRT(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
-
Control Reference Template values.
- SIG = b'\xb6\x00'
- DEC = b'\xb8\x00'
- AUT = b'\xa4\x00'
- ATT = b'\xb6\x03\x84\x01\x81'
- class yubikit.openpgp.KEY_REF(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- SIG = 1
- DEC = 2
- AUT = 3
- ATT = 129
- class yubikit.openpgp.KEY_STATUS(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- NONE = 0
- GENERATED = 1
- IMPORTED = 2
- class yubikit.openpgp.AlgorithmAttributes(algorithm_id)[source]
Bases:
ABC
OpenPGP key algorithm attributes.
- class yubikit.openpgp.RSA_SIZE(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- RSA2048 = 2048
- RSA3072 = 3072
- RSA4096 = 4096
- class yubikit.openpgp.RSA_IMPORT_FORMAT(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- STANDARD = 0
- STANDARD_W_MOD = 1
- CRT = 2
- CRT_W_MOD = 3
- class yubikit.openpgp.RsaAttributes(algorithm_id, n_len, e_len, import_format)[source]
Bases:
AlgorithmAttributes
-
import_format:
RSA_IMPORT_FORMAT
-
import_format:
- class yubikit.openpgp.OID(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
-
- SECP256R1 = SECP256R1(2a8648ce3d030107)
- SECP256K1 = SECP256K1(2b8104000a)
- SECP384R1 = SECP384R1(2b81040022)
- SECP521R1 = SECP521R1(2b81040023)
- BrainpoolP256R1 = BrainpoolP256R1(2b2403030208010107)
- BrainpoolP384R1 = BrainpoolP384R1(2b240303020801010b)
- BrainpoolP512R1 = BrainpoolP512R1(2b240303020801010d)
- X25519 = X25519(2b060104019755010501)
- Ed25519 = Ed25519(2b06010401da470f01)
- class yubikit.openpgp.EC_IMPORT_FORMAT(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- STANDARD = 0
- STANDARD_W_PUBKEY = 255
- class yubikit.openpgp.EcAttributes(algorithm_id, oid, import_format)[source]
Bases:
AlgorithmAttributes
-
import_format:
EC_IMPORT_FORMAT
-
import_format:
- class yubikit.openpgp.DiscretionaryDataObjects(extended_capabilities, attributes_sig, attributes_dec, attributes_aut, attributes_att, pw_status, fingerprints, ca_fingerprints, generation_times, key_information, uif_sig, uif_dec, uif_aut, uif_att)[source]
Bases:
object
-
extended_capabilities:
ExtendedCapabilities
-
attributes_sig:
AlgorithmAttributes
-
attributes_dec:
AlgorithmAttributes
-
attributes_aut:
AlgorithmAttributes
-
attributes_att:
Optional
[AlgorithmAttributes
]
-
key_information:
Mapping
[KEY_REF
,KEY_STATUS
]
-
extended_capabilities:
- class yubikit.openpgp.ApplicationRelatedData(aid, historical, extended_length_info, general_feature_management, discretionary)[source]
Bases:
object
OpenPGP related data.
-
aid:
OpenPgpAid
-
extended_length_info:
Optional
[ExtendedLengthInfo
]
-
general_feature_management:
Optional
[GENERAL_FEATURE_MANAGEMENT
]
-
discretionary:
DiscretionaryDataObjects
-
aid:
- class yubikit.openpgp.SecuritySupportTemplate(signature_counter)[source]
Bases:
object
- class yubikit.openpgp.HASH_ALGORITHM(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- SHA256 = 8
- SHA512 = 10
- class yubikit.openpgp.KdfIterSaltedS2k(hash_algorithm, iteration_count, salt_user, salt_reset, salt_admin, initial_hash_user, initial_hash_admin)[source]
Bases:
Kdf
-
hash_algorithm:
HASH_ALGORITHM
-
hash_algorithm:
- class yubikit.openpgp.RsaKeyTemplate(crt, e, p, q)[source]
Bases:
PrivateKeyTemplate
- class yubikit.openpgp.RsaCrtKeyTemplate(crt, e, p, q, iqmp, dmp1, dmq1, n)[source]
Bases:
RsaKeyTemplate
- class yubikit.openpgp.EcKeyTemplate(crt, private_key, public_key)[source]
Bases:
PrivateKeyTemplate
- class yubikit.openpgp.OpenPgpSession(connection, scp_key_params=None)[source]
Bases:
object
A session with the OpenPGP application.
- property aid: OpenPgpAid
Get the AID used to select the applet.
- property version: Version
Get the firmware version of the key.
For YubiKey NEO this is the PGP applet version.
- property extended_capabilities: ExtendedCapabilities
Get the Extended Capabilities from the YubiKey.
- put_data(do, data)[source]
Write a Data Object to the YubiKey.
- Parameters:
do (
DO
) – The Data Object to write to.data (
Union
[bytes
,SupportsBytes
]) – The data to write.
- Return type:
- get_signature_counter()[source]
Get the number of times the signature key has been used.
- Return type:
Read the Application Related Data.
- Return type:
- set_signature_pin_policy(pin_policy)[source]
Set signature PIN policy.
Requires Admin PIN verification.
- Parameters:
pin_policy (
PIN_POLICY
) – The PIN policy.- Return type:
- reset()[source]
Perform a factory reset on the OpenPGP application.
WARNING: This will delete all stored keys, certificates and other data.
- Return type:
- set_pin_attempts(user_attempts, reset_attempts, admin_attempts)[source]
Set the number of PIN attempts to allow before blocking.
WARNING: On YubiKey NEO this will reset the PINs to their default values.
Requires Admin PIN verification.
- set_kdf(kdf)[source]
Set up a PIN Key Derivation Function.
This enables (or disables) the use of a KDF for PIN verification, as well as resetting the User and Admin PINs to their default (initial) values.
If a Reset Code is present, it will be invalidated.
This command requires Admin PIN verification.
- verify_pin(pin, extended=False)[source]
Verify the User PIN.
This will unlock functionality that requires User PIN verification. Note that with extended=False (default) only sign operations are allowed. Inversely, with extended=True sign operations are NOT allowed.
- Parameters:
pin – The User PIN.
extended (
bool
) – If False only sign operations are allowed, otherwise sign operations are NOT allowed.
- verify_admin(admin_pin)[source]
Verify the Admin PIN.
This will unlock functionality that requires Admin PIN verification.
- Parameters:
admin_pin – The Admin PIN.
- set_reset_code(reset_code)[source]
Set the Reset Code for User PIN.
The Reset Code can be used to set a new User PIN if it is lost or becomes blocked, using the reset_pin method.
This command requires Admin PIN verification.
- reset_pin(new_pin, reset_code=None)[source]
Reset the User PIN to a new value.
This command requires Admin PIN verification, or the Reset Code.
- get_algorithm_attributes(key_ref)[source]
Get the algorithm attributes for one of the key slots.
- Parameters:
key_ref (
KEY_REF
) – The key slot.- Return type:
- get_algorithm_information()[source]
Get the list of supported algorithm attributes for each key.
The return value is a mapping of KEY_REF to a list of supported algorithm attributes, which can be set using set_algorithm_attributes.
- Return type:
- set_algorithm_attributes(key_ref, attributes)[source]
Set the algorithm attributes for a key slot.
WARNING: This will delete any key already stored in the slot if the attributes are changed!
This command requires Admin PIN verification.
- Parameters:
key_ref (
KEY_REF
) – The key slot.attributes (
AlgorithmAttributes
) – The algorithm attributes to set.
- Return type:
- set_uif(key_ref, uif)[source]
Set the User Interaction Flag (touch requirement) for a key.
Requires Admin PIN verification.
- set_generation_time(key_ref, timestamp)[source]
Set the generation timestamp for a key.
Requires Admin PIN verification.
- set_fingerprint(key_ref, fingerprint)[source]
Set the fingerprint for a key.
Requires Admin PIN verification.
- get_public_key(key_ref)[source]
Get the public key from a slot.
- Parameters:
key_ref (
KEY_REF
) – The key slot.- Return type:
Union
[EllipticCurvePublicKey
,Ed25519PublicKey
,X25519PublicKey
,RSAPublicKey
]
- generate_rsa_key(key_ref, key_size)[source]
Generate an RSA key in the given slot.
Requires Admin PIN verification.
- Parameters:
- Return type:
- generate_ec_key(key_ref, curve_oid)[source]
Generate an EC key in the given slot.
Requires Admin PIN verification.
- Parameters:
- Return type:
Union
[EllipticCurvePublicKey
,Ed25519PublicKey
,X25519PublicKey
]
- put_key(key_ref, private_key)[source]
Import a private key into the given slot.
Requires Admin PIN verification.
- Parameters:
key_ref (
KEY_REF
) – The key slot.private_key (
Union
[RSAPrivateKey
,EllipticCurvePrivateKey
,Ed25519PrivateKey
,X25519PrivateKey
]) – The private key to import.
- Return type:
- get_certificate(key_ref)[source]
Get a certificate from a slot.
- Parameters:
key_ref (
KEY_REF
) – The slot.- Return type:
- put_certificate(key_ref, certificate)[source]
Import a certificate into a slot.
Requires Admin PIN verification.
- Parameters:
key_ref (
KEY_REF
) – The slot.certificate (
Certificate
) – The X.509 certificate to import.
- Return type:
- delete_certificate(key_ref)[source]
Delete a certificate in a slot.
Requires Admin PIN verification.
- attest_key(key_ref)[source]
Create an attestation certificate for a key.
The certificate is written to the certificate slot for the key, and its content is returned.
Requires User PIN verification.
- Parameters:
key_ref (
KEY_REF
) – The key slot.- Return type:
- sign(message, hash_algorithm)[source]
Sign a message using the SIG key.
Requires User PIN verification.
- Parameters:
message (
bytes
) – The message to sign.hash_algorithm (
HashAlgorithm
) – The pre-signature hash algorithm.
- Return type:
- decrypt(value)[source]
Decrypt a value using the DEC key.
For RSA the value should be an encrypted block. For ECDH the value should be a peer public-key to perform the key exchange with, and the result will be the derived shared secret.
Requires (extended) User PIN verification.
- Parameters:
value (
Union
[bytes
,EllipticCurvePublicKey
,Ed25519PublicKey
,X25519PublicKey
]) – The value to decrypt.- Return type:
- authenticate(message, hash_algorithm)[source]
Authenticate a message using the AUT key.
Requires User PIN verification.
- Parameters:
message (
bytes
) – The message to authenticate.hash_algorithm (
HashAlgorithm
) – The pre-authentication hash algorithm.
- Return type:
yubikit.piv module
- class yubikit.piv.ALGORITHM(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
-
- EC = 'ec'
- RSA = 'rsa'
- class yubikit.piv.KEY_TYPE(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- RSA1024 = 6
- RSA2048 = 7
- RSA3072 = 5
- RSA4096 = 22
- ECCP256 = 17
- ECCP384 = 20
- ED25519 = 224
- X25519 = 225
- property algorithm
- property bit_len
- class yubikit.piv.MANAGEMENT_KEY_TYPE(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- TDES = 3
- AES128 = 8
- AES192 = 10
- AES256 = 12
- property key_len
- property challenge_len
- class yubikit.piv.SLOT(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- AUTHENTICATION = 154
- SIGNATURE = 156
- KEY_MANAGEMENT = 157
- CARD_AUTH = 158
- RETIRED1 = 130
- RETIRED2 = 131
- RETIRED3 = 132
- RETIRED4 = 133
- RETIRED5 = 134
- RETIRED6 = 135
- RETIRED7 = 136
- RETIRED8 = 137
- RETIRED9 = 138
- RETIRED10 = 139
- RETIRED11 = 140
- RETIRED12 = 141
- RETIRED13 = 142
- RETIRED14 = 143
- RETIRED15 = 144
- RETIRED16 = 145
- RETIRED17 = 146
- RETIRED18 = 147
- RETIRED19 = 148
- RETIRED20 = 149
- ATTESTATION = 249
- class yubikit.piv.OBJECT_ID(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- CAPABILITY = 6275335
- CHUID = 6275330
- AUTHENTICATION = 6275333
- FINGERPRINTS = 6275331
- SECURITY = 6275334
- FACIAL = 6275336
- PRINTED = 6275337
- SIGNATURE = 6275338
- KEY_MANAGEMENT = 6275339
- CARD_AUTH = 6275329
- DISCOVERY = 126
- KEY_HISTORY = 6275340
- IRIS = 6275361
- RETIRED1 = 6275341
- RETIRED2 = 6275342
- RETIRED3 = 6275343
- RETIRED4 = 6275344
- RETIRED5 = 6275345
- RETIRED6 = 6275346
- RETIRED7 = 6275347
- RETIRED8 = 6275348
- RETIRED9 = 6275349
- RETIRED10 = 6275350
- RETIRED11 = 6275351
- RETIRED12 = 6275352
- RETIRED13 = 6275353
- RETIRED14 = 6275354
- RETIRED15 = 6275355
- RETIRED16 = 6275356
- RETIRED17 = 6275357
- RETIRED18 = 6275358
- RETIRED19 = 6275359
- RETIRED20 = 6275360
- ATTESTATION = 6291201
- class yubikit.piv.PIN_POLICY(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- DEFAULT = 0
- NEVER = 1
- ONCE = 2
- ALWAYS = 3
- MATCH_ONCE = 4
- MATCH_ALWAYS = 5
- class yubikit.piv.TOUCH_POLICY(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- DEFAULT = 0
- NEVER = 1
- ALWAYS = 2
- CACHED = 3
- class yubikit.piv.PinMetadata(default_value, total_attempts, attempts_remaining)[source]
Bases:
object
- class yubikit.piv.ManagementKeyMetadata(key_type, default_value, touch_policy)[source]
Bases:
object
-
key_type:
MANAGEMENT_KEY_TYPE
-
touch_policy:
TOUCH_POLICY
-
key_type:
- class yubikit.piv.SlotMetadata(key_type, pin_policy, touch_policy, generated, public_key_encoded)[source]
Bases:
object
-
pin_policy:
PIN_POLICY
-
touch_policy:
TOUCH_POLICY
- property public_key
-
pin_policy:
- yubikit.piv.check_key_support(version, key_type, pin_policy, touch_policy, generate=True)[source]
Check if a key type is supported by a specific YubiKey firmware version.
This method will return None if the key (with PIN and touch policies) is supported, or it will raise a NotSupportedError if it is not.
- Deprecated:
Use PivSession.check_key_support() instead.
- Return type:
- class yubikit.piv.PivSession(connection, scp_key_params=None)[source]
Bases:
object
A session with the PIV application.
- property version: Version
The version of the PIV application, typically the same as the YubiKey firmware.
- property management_key_type: MANAGEMENT_KEY_TYPE
The algorithm of the management key currently in use.
- reset()[source]
Factory reset the PIV application data.
This deletes all user-data from the PIV application, and resets the default values for PIN, PUK, and management key.
- Return type:
- set_management_key(key_type, management_key, require_touch=False)[source]
Set a new management key.
- Parameters:
key_type (
MANAGEMENT_KEY_TYPE
) – The management key type.management_key (
bytes
) – The management key in raw bytes.require_touch (
bool
) – The touch policy.
- Return type:
- verify_uv(temporary_pin=False, check_only=False)[source]
Verify the user by fingerprint (YubiKey Bio only).
Fingerprint verification will allow usage of private keys which have a PIN policy allowing MATCH. For those using MATCH_ALWAYS, the fingerprint must be verified just prior to using the key, or by first requesting a temporary PIN and then later verifying the PIN just prior to key use.
- set_pin_attempts(pin_attempts, puk_attempts)[source]
Set PIN retries for PIN and PUK.
Both PIN and PUK will be reset to default values when this is executed.
Requires authentication with management key and PIN verification.
- get_slot_metadata(slot)[source]
Get slot metadata.
- Parameters:
slot (
SLOT
) – The slot to get metadata from.- Return type:
- get_bio_metadata()[source]
Get YubiKey Bio metadata.
This tells you if fingerprints are enrolled or not, how many fingerprint verification attempts remain, and whether or not a temporary PIN is currently active.
- Return type:
- sign(slot, key_type, message, hash_algorithm, padding=None)[source]
Sign message with key.
Requires PIN verification.
- Parameters:
slot (
SLOT
) – The slot of the key to use.key_type (
KEY_TYPE
) – The type of the key to sign with.message (
bytes
) – The message to sign.hash_algorithm (
HashAlgorithm
) – The pre-signature hash algorithm to use.padding (
Optional
[AsymmetricPadding
]) – The pre-signature padding.
- Return type:
- calculate_secret(slot, peer_public_key)[source]
Calculate shared secret using ECDH.
Requires PIN verification.
- Parameters:
slot (
SLOT
) – The slot.peer_public_key (
Union
[EllipticCurvePrivateKey
,X25519PublicKey
]) – The peer’s public key.
- Return type:
- put_object(object_id, data=None)[source]
Write data to PIV object.
Requires authentication with management key.
- get_certificate(slot)[source]
Get certificate from slot.
- Parameters:
slot (
SLOT
) – The slot to get the certificate from.- Return type:
- put_certificate(slot, certificate, compress=False)[source]
Import certificate to slot.
Requires authentication with management key.
- Parameters:
slot (
SLOT
) – The slot to import the certificate to.certificate (
Certificate
) – The certificate to import.compress (
bool
) – If the certificate should be compressed or not.
- Return type:
- put_key(slot, private_key, pin_policy=PIN_POLICY.DEFAULT, touch_policy=TOUCH_POLICY.DEFAULT)[source]
Import a private key to slot.
Requires authentication with management key.
- Parameters:
slot (
SLOT
) – The slot to import the key to.private_key (
Union
[RSAPrivateKey
,EllipticCurvePrivateKey
]) – The private key to import.pin_policy (
PIN_POLICY
) – The PIN policy.touch_policy (
TOUCH_POLICY
) – The touch policy.
- Return type:
- generate_key(slot, key_type, pin_policy=PIN_POLICY.DEFAULT, touch_policy=TOUCH_POLICY.DEFAULT)[source]
Generate private key in slot.
Requires authentication with management key.
- Parameters:
slot (
SLOT
) – The slot to generate the private key in.key_type (
KEY_TYPE
) – The key type.pin_policy (
PIN_POLICY
) – The PIN policy.touch_policy (
TOUCH_POLICY
) – The touch policy.
- Return type:
- attest_key(slot)[source]
Attest key in slot.
- Parameters:
slot (
SLOT
) – The slot where the key has been generated.- Return type:
- Returns:
A X.509 certificate.
- move_key(from_slot, to_slot)[source]
Move key from one slot to another.
Requires authentication with management key.
- check_key_support(key_type, pin_policy, touch_policy, generate, fips_restrictions=False)[source]
Check if a key type is supported by this YubiKey.
This method will return None if the key (with PIN and touch policies) is supported, or it will raise a NotSupportedError if it is not.
Set the generate parameter to True to check if generating the key is supported (in addition to importing).
Set fips_restrictions to True to apply restrictions based on FIPS status.
- Return type:
yubikit.securitydomain module
- class yubikit.securitydomain.KeyType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- AES = 136
- ECC_PUBLIC_KEY = 176
- ECC_PRIVATE_KEY = 177
- ECC_KEY_PARAMS = 240
- class yubikit.securitydomain.Curve(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- SECP256R1 = 0
- SECP384R1 = 1
- SECP521R1 = 2
- BrainpoolP256R1 = 3
- BrainpoolP384R1 = 5
- BrainpoolP512R1 = 7
- class yubikit.securitydomain.SecurityDomainSession(connection)[source]
Bases:
object
A session for managing SCP keys
- authenticate(key_params)[source]
Initialize SCP and authenticate the session.
SCP11b does not authenticate the OCE, and will not allow the usage of commands which require authentication of the OCE.
- Return type:
- get_supported_ca_identifiers(kloc=False, klcc=False)[source]
Get a list of the CA issuer Subject Key Identifiers for keys.
Setting one of kloc or klcc to True will cause only those CAs to be returned. By default, this will get both KLOC and KLCC CAs.
- get_certificate_bundle(key)[source]
Get the certificates associated with the given SCP11 private key.
Certificates are returned leaf-last.
- Return type:
- reset()[source]
Perform a factory reset of the Security Domain.
This will remove all keys and associated data, as well as restore the default SCP03 static keys, and generate a new (attestable) SCP11b key.
- Return type:
- store_data(data)[source]
Stores data in the security domain.
Requires OCE verification.
- Return type:
- store_certificate_bundle(key, certificates)[source]
Store the certificate chain for the given key.
Requires OCE verification.
Certificates should be in order, with the leaf certificate last.
- Return type:
- store_allowlist(key, serials)[source]
Store which certificate serial numbers that can be used for a given key.
Requires OCE verification.
If no allowlist is stored, any certificate signed by the CA can be used.
- Return type:
- store_ca_issuer(key, ski)[source]
Store the SKI (Subject Key Identifier) for the CA of a given key.
Requires OCE verification.
- Return type:
- delete_key(kid=0, kvn=0, delete_last=False)[source]
Delete one (or more) keys.
Requires OCE verification.
All keys matching the given KID and/or KVN will be deleted. To delete the final key you must set delete_last = True.
- Return type:
yubikit.support module
- yubikit.support.read_info(conn, pid=None)[source]
Reads out DeviceInfo from a YubiKey, or attempts to synthesize the data.
Reading DeviceInfo from a ManagementSession is only supported for newer YubiKeys. This function attempts to read that information, but will fall back to gathering the data using other mechanisms if needed. It will also make adjustments to the data if required, for example to “fix” known bad values.
The pid parameter must be provided whenever the YubiKey is connected via USB.
- Parameters:
conn (
Connection
) – A connection to a YubiKey.
- Return type:
yubikit.yubiotp module
- class yubikit.yubiotp.SLOT(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- ONE = 1
- TWO = 2
- class yubikit.yubiotp.CONFIG_SLOT(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- CONFIG_1 = 1
- NAV = 2
- CONFIG_2 = 3
- UPDATE_1 = 4
- UPDATE_2 = 5
- SWAP = 6
- NDEF_1 = 8
- NDEF_2 = 9
- DEVICE_SERIAL = 16
- DEVICE_CONFIG = 17
- SCAN_MAP = 18
- YK4_CAPABILITIES = 19
- YK4_SET_DEVICE_INFO = 21
- CHAL_OTP_1 = 32
- CHAL_OTP_2 = 40
- CHAL_HMAC_1 = 48
- CHAL_HMAC_2 = 56
- class yubikit.yubiotp.TKTFLAG(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
- TAB_FIRST = 1
- APPEND_TAB1 = 2
- APPEND_TAB2 = 4
- APPEND_DELAY1 = 8
- APPEND_DELAY2 = 16
- APPEND_CR = 32
- PROTECT_CFG2 = 128
- OATH_HOTP = 64
- CHAL_RESP = 64
- class yubikit.yubiotp.CFGFLAG(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
- SEND_REF = 1
- PACING_10MS = 4
- PACING_20MS = 8
- STATIC_TICKET = 32
- TICKET_FIRST = 2
- ALLOW_HIDTRIG = 16
- SHORT_TICKET = 2
- STRONG_PW1 = 16
- STRONG_PW2 = 64
- MAN_UPDATE = 128
- OATH_HOTP8 = 2
- OATH_FIXED_MODHEX1 = 16
- OATH_FIXED_MODHEX2 = 64
- OATH_FIXED_MODHEX = 80
- OATH_FIXED_MASK = 80
- CHAL_YUBICO = 32
- CHAL_HMAC = 34
- HMAC_LT64 = 4
- CHAL_BTN_TRIG = 8
- class yubikit.yubiotp.EXTFLAG(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
- SERIAL_BTN_VISIBLE = 1
- SERIAL_USB_VISIBLE = 2
- SERIAL_API_VISIBLE = 4
- USE_NUMERIC_KEYPAD = 8
- FAST_TRIG = 16
- ALLOW_UPDATE = 32
- DORMANT = 64
- LED_INV = 128
- class yubikit.yubiotp.NDEF_TYPE(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnum
- TEXT = 84
- URI = 85
- class yubikit.yubiotp.CFGSTATE(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntFlag
- SLOT1_VALID = 1
- SLOT2_VALID = 2
- SLOT1_TOUCH = 4
- SLOT2_TOUCH = 8
- LED_INV = 16
- class yubikit.yubiotp.HmacSha1SlotConfiguration(key)[source]
Bases:
SlotConfiguration
- class yubikit.yubiotp.KeyboardSlotConfiguration[source]
Bases:
SlotConfiguration
- class yubikit.yubiotp.HotpSlotConfiguration(key)[source]
Bases:
KeyboardSlotConfiguration
- class yubikit.yubiotp.StaticPasswordSlotConfiguration(scan_codes)[source]
Bases:
KeyboardSlotConfiguration
- class yubikit.yubiotp.YubiOtpSlotConfiguration(fixed, uid, key)[source]
Bases:
KeyboardSlotConfiguration
- tabs(before=False, after_first=False, after_second=False)[source]
- Return type:
TypeVar
(Cfg
, bound= SlotConfiguration)
- class yubikit.yubiotp.StaticTicketSlotConfiguration(fixed, uid, key)[source]
Bases:
KeyboardSlotConfiguration
- class yubikit.yubiotp.UpdateConfiguration[source]
Bases:
KeyboardSlotConfiguration
- class yubikit.yubiotp.ConfigState(version, touch_level)[source]
Bases:
object
The configuration state of the YubiOTP application.
- class yubikit.yubiotp.YubiOtpSession(connection, scp_key_params=None)[source]
Bases:
object
A session with the YubiOTP application.
- close()[source]
Close the underlying connection.
- Deprecated:
call .close() on the underlying connection instead.
- Return type:
- property version: Version
The version of the Yubico OTP application, typically the same as the YubiKey firmware.
- put_configuration(slot, configuration, acc_code=None, cur_acc_code=None)[source]
Write configuration to slot.
- update_configuration(slot, configuration, acc_code=None, cur_acc_code=None)[source]
Update configuration in slot.
- set_scan_map(scan_map, cur_acc_code=None)[source]
Update scan-codes on YubiKey.
This updates the scan-codes (or keyboard presses) that the YubiKey will use when typing out OTPs.
- Return type:
Module contents
Contains the modules corresponding to the different applications supported by a YubiKey.