ykman.util

Attributes

PEM_IDENTIFIER

Exceptions

InvalidPasswordError

Raised when parsing key/certificate and the password might be wrong/missing.

Classes

OSVERSIONINFOW

Structure base class

Functions

parse_private_key(data, password)

Identify, decrypt and return a cryptography private key object.

parse_certificates(data, password)

Identify, decrypt and return a list of cryptography x509 certificates.

get_leaf_certificates(certs)

Extract the leaf certificates from a list of certificates.

is_pem(data)

is_pkcs12(data)

Tries to identify a PKCS12 container.

display_serial(serial)

Displays an x509 certificate serial number in a readable format.

get_windows_version()

Get the true Windows version, since sys.getwindowsversion lies.

is_nfc_restricted(connection)

Check if the given SmartCardConnection over NFC is in restricted NFC mode.

Module Contents

ykman.util.PEM_IDENTIFIER = b'-----BEGIN'
exception ykman.util.InvalidPasswordError[source]

Bases: Exception

Raised when parsing key/certificate and the password might be wrong/missing.

ykman.util.parse_private_key(data, password)[source]

Identify, decrypt and return a cryptography private key object.

Parameters:
  • data – The private key in bytes.

  • password – The password to decrypt the private key (if it is encrypted).

ykman.util.parse_certificates(data, password)[source]

Identify, decrypt and return a list of cryptography x509 certificates.

Parameters:
  • data – The certificate(s) in bytes.

  • password – The password to decrypt the certificate(s).

ykman.util.get_leaf_certificates(certs)[source]

Extract the leaf certificates from a list of certificates.

Leaf certificates are ones whose subject does not appear as issuer among the others.

Parameters:

certs – The list of cryptography x509 certificate objects.

ykman.util.is_pem(data)[source]
ykman.util.is_pkcs12(data)[source]

Tries to identify a PKCS12 container. The PFX PDU version is assumed to be v3. See: https://tools.ietf.org/html/rfc7292.

ykman.util.display_serial(serial)[source]

Displays an x509 certificate serial number in a readable format.

Parameters:

serial (int)

Return type:

str

class ykman.util.OSVERSIONINFOW[source]

Bases: ctypes.Structure

Structure base class

ykman.util.get_windows_version()[source]

Get the true Windows version, since sys.getwindowsversion lies.

Return type:

tuple[int, int, int]

ykman.util.is_nfc_restricted(connection)[source]

Check if the given SmartCardConnection over NFC is in restricted NFC mode.

Parameters:

connection (yubikit.core.smartcard.SmartCardConnection)

Return type:

bool