cryptnox_sdk_py package

Subpackages

Submodules

cryptnox_sdk_py.binary_utils module

Utility module for handling binary data

cryptnox_sdk_py.binary_utils.list_to_hexadecimal(data: List[int], sep: str = '') str[source]

Convert list of integers into hexadecimal representation

Parameters:
  • data (List[int]) – List of integer to return in hexadecimal string form

  • sep (str) – (optional) Separator to use to join the hexadecimal numbers

Returns:

list

Return type:

str

cryptnox_sdk_py.binary_utils.hexadecimal_to_list(value: str) List[int][source]

Convert given string containing hexadecimal representation of numbers into list of integers

Parameters:

value (string) – String containing hexadecimal numbers

Returns:

List of hexadecimal values in integer form

Return type:

List[int]

cryptnox_sdk_py.binary_utils.path_to_bytes(path_str: str) bytes[source]

Convert given path for format that the card uses

Parameters:

path_str (str) – path to convert

Returns:

path formatted for use with the card.

Return type:

bytes

cryptnox_sdk_py.binary_utils.binary_to_list(data: bytes) List[int][source]

Convert given binary data to it’s representation as a list of hexadecimal values.

Parameters:

data (bytes) – Binary data to convert to

Returns:

List containing data in hexadecimal numbers in integer format

Return type:

List[int]

cryptnox_sdk_py.binary_utils.pad_data(data: bytes) bytes[source]

Pad data with 0s to be length of 128.

Parameters:

data – Data to be padded.

Returns:

Data padded with 0s with length 128.

Return type:

bytes

cryptnox_sdk_py.binary_utils.remove_padding(data: bytes) bytes[source]

Remove padding from the data

Parameters:

data (bytes) – Data from which to remove padding

Returns:

Data without the padding

Return type:

bytes

cryptnox_sdk_py.connection module

Module for keeping the connection to the reader.

Sending and receiving information from the card through the reader.

class cryptnox_sdk_py.connection.Connection(index: int = 0, debug: bool = False, conn: List = None, remote: bool = False)[source]

Bases: ContextDecorator

Connection to the reader.

Sends and receives messages from the card using the reader.

Parameters:
  • index (int) – Index of the reader to initialize the connection with

  • debug (bool) – Show debug information during requests

  • conn (List) – List of sockets to use for remote connections

  • remote (bool) – Use remote sockets for communications with the cards

Variables:

self.card (Card) – Information about the card.

__init__(index: int = 0, debug: bool = False, conn: List = None, remote: bool = False)[source]
disconnect() None[source]

Disconnect from the card reader and clean up the connection.

This method properly closes the connection to the card reader without deleting the Connection object itself.

send_apdu(apdu: List[int]) Tuple[List[int], int, int][source]

Send data to the card in plain format

Parameters:

apdu (int) – list of the APDU header

Return bytes:

Result of the query that was sent to the card

Return type:

bytes

Raises:

ConnectionException – Issue in the connection

send_encrypted(apdu: List[int], data: bytes, receive_long: bool = False) bytes[source]

Send data to the card in encrypted format

Parameters:
  • apdu (int) – list of the APDU header

  • data – bytes of the data payload (in clear, will be encrypted)

  • receive_long (bool)

Return bytes:

Result of the query that was sent to the card

Return type:

bytes

Raises:

CryptnoxException – General exceptions

remote_read(apdu: List[int]) Tuple[List[int], int, int][source]

cryptnox_sdk_py.crypto_utils module

Module containing cryptographic methods used by the library

cryptnox_sdk_py.crypto_utils.aes_encrypt(key: bytes, initialization_vector: bytes, data: bytes) bytes[source]

AES encrypt data using key and initialization vector.

Parameters:
  • key (bytes) – Key to use for encryption

  • initialization_vector (bytes) – Initialization vector

  • data (bytes) – Data to encrypt

Returns:

Encrypted data

Return type:

bytes

cryptnox_sdk_py.crypto_utils.aes_decrypt(key: bytes, initialization_vector: bytes, data: bytes) bytes[source]

AES decrypt data using key and initialization vector.

Parameters:
  • key (bytes) – Key to use for encryption

  • initialization_vector (bytes) – Initialization vector

  • data (bytes) – Data to decrypt

Returns:

Decrypted data

Return type:

bytes

cryptnox_sdk_py.enums module

Enum classes used by the module

class cryptnox_sdk_py.enums.AuthType(*values)[source]

Bases: Enum

Predefined values for authentication type.

NO_AUTH = 0
PIN = 1
USER_KEY = 2
class cryptnox_sdk_py.enums.Derivation(*values)[source]

Bases: IntEnum

Predefined values to use for parameters as Derivation.

CURRENT_KEY = 0
DERIVE = 1
DERIVE_AND_MAKE_CURRENT = 2
PINLESS_PATH = 3
class cryptnox_sdk_py.enums.KeyType(*values)[source]

Bases: IntEnum

Predefined values to use for parameters as KeyType.

K1 = 0
R1 = 16
class cryptnox_sdk_py.enums.Origin(*values)[source]

Bases: Enum

Predefined values for keeping the origin of the card

UNKNOWN = 0
ORIGINAL = 1
FAKE = 2
class cryptnox_sdk_py.enums.SlotIndex(*values)[source]

Bases: IntEnum

Predefined values to use for parameters as SlotIndex.

EC256R1 = 1
RSA = 2
FIDO = 3
class cryptnox_sdk_py.enums.SeedSource(*values)[source]

Bases: Enum

Predefined values for how seed was created

NO_SEED = 0
SINGLE = 75
EXTENDED = 88
EXTERNAL = 76
INTERNAL = 83
DUAL = 68
WRAPPED = 82

cryptnox_sdk_py.exceptions module

Module containing all exceptions that Cryptnox SDK Python module can raise.

exception cryptnox_sdk_py.exceptions.CryptnoxException[source]

Bases: Exception

Base exception for the class exceptions.

exception cryptnox_sdk_py.exceptions.CardClosedException[source]

Bases: Exception

The card wasn’t opened with PIN code or challenge-response

exception cryptnox_sdk_py.exceptions.CardException[source]

Bases: CryptnoxException

No card was detected in the card reader.

exception cryptnox_sdk_py.exceptions.CardTypeException[source]

Bases: CryptnoxException

The detected card is not supported by this library

exception cryptnox_sdk_py.exceptions.CertificateException[source]

Bases: CryptnoxException

There was an issue with the certification

exception cryptnox_sdk_py.exceptions.ConnectionException[source]

Bases: CryptnoxException

An issue occurred in the communication with the reader

exception cryptnox_sdk_py.exceptions.DataException[source]

Bases: CryptnoxException

The reader returned an empty message.

exception cryptnox_sdk_py.exceptions.DataValidationException[source]

Bases: CryptnoxException

The sent data is not valid.

exception cryptnox_sdk_py.exceptions.DerivationSelectionException[source]

Bases: CryptnoxException

Not a valid derivation selection.

exception cryptnox_sdk_py.exceptions.KeySelectionException[source]

Bases: CryptnoxException

Not a valid key type selection

exception cryptnox_sdk_py.exceptions.EOSKeyError[source]

Bases: CryptnoxException

The signature wasn’t compatible with EOS standard after 10 tries

exception cryptnox_sdk_py.exceptions.FirmwareException[source]

Bases: CryptnoxException

There is an issue with the firmware on the card

exception cryptnox_sdk_py.exceptions.GenuineCheckException[source]

Bases: CryptnoxException

The detected card is not a genuine Cryptnox product.

exception cryptnox_sdk_py.exceptions.GenericException(status: bytes)[source]

Bases: CryptnoxException

Generic exception that can mean multiple things depending on the call to the card

Process stats and throw a specific Exception from it.

__init__(status: bytes)[source]
exception cryptnox_sdk_py.exceptions.InitializationException[source]

Bases: CryptnoxException

The card hasn’t been initialized.

exception cryptnox_sdk_py.exceptions.KeyAlreadyGenerated[source]

Bases: CryptnoxException

Key can not be generated twice.

exception cryptnox_sdk_py.exceptions.SeedException[source]

Bases: CryptnoxException

Keys weren’t found on the card.

exception cryptnox_sdk_py.exceptions.KeyGenerationException[source]

Bases: CryptnoxException

Error in key generation.

exception cryptnox_sdk_py.exceptions.PinAuthenticationException[source]

Bases: CryptnoxException

Error in turning off PIN authentication. There is no user key in the card

exception cryptnox_sdk_py.exceptions.PinBlockedException[source]

Bases: CryptnoxException

PIN is fully blocked (0 retries remaining). Unblock the card before attempting this operation.

exception cryptnox_sdk_py.exceptions.PinException(message: str = 'Invalid PIN code was provided', number_of_retries: int = 0)[source]

Bases: CryptnoxException

Sent PIN code is not valid.

Parameters:
  • number_of_retries (int) – Number of retries to send the PIN code before the card is locked.

  • message (str) – Optional message

__init__(message: str = 'Invalid PIN code was provided', number_of_retries: int = 0)[source]
exception cryptnox_sdk_py.exceptions.PukException(message: str = 'Invalid PUK code was provided', number_of_retries: int = 0)[source]

Bases: CryptnoxException

Sent PUK code is not valid.

Parameters:
  • number_of_retries (int) – Number of retries to send the PIN code before the card is locked.

  • message (str) – Optional message

__init__(message: str = 'Invalid PUK code was provided', number_of_retries: int = 0)[source]
exception cryptnox_sdk_py.exceptions.ReadPublicKeyException[source]

Bases: CryptnoxException

Data received during public key reading is not valid.

exception cryptnox_sdk_py.exceptions.ReaderException[source]

Bases: CryptnoxException

Card reader wasn’t found attached to the device.

exception cryptnox_sdk_py.exceptions.SecureChannelException[source]

Bases: CryptnoxException

Secure channel couldn’t be established.

exception cryptnox_sdk_py.exceptions.SoftLock[source]

Bases: CryptnoxException

The card is soft locked, and requires power cycle before it can be opened

exception cryptnox_sdk_py.exceptions.CardNotBlocked[source]

Bases: CryptnoxException

Trying to unlock unblocked card

cryptnox_sdk_py.factory module

Module for getting Cryptnox cards information and getting instance of card from connection

cryptnox_sdk_py.factory.get_card(connection: Connection, debug: bool = False) Base[source]

Get card instance that is using given connection.

Parameters:
  • connection (Connection) – Connection to use for operation

  • debug (bool) – Prints information about communication

Returns:

Instance of card

Return type:

Base

Raises:

CardException – Card with given serial number not found

cryptnox_sdk_py.reader module

Module that handles different card reader types and their drivers.

exception cryptnox_sdk_py.reader.ReaderException[source]

Bases: Exception

Reader hasn’t been found or other reader related issues

exception cryptnox_sdk_py.reader.CardException[source]

Bases: Exception

The reader is present but there is an issue in connecting to the card

exception cryptnox_sdk_py.reader.ConnectionException[source]

Bases: Exception

An issue has occurred in the communication with the card.

class cryptnox_sdk_py.reader.Reader[source]

Bases: object

Abstract class describing methods to be implemented. Holds the connection.

__init__()[source]
abstractmethod connect() None[source]

Connect to the card found in the selected reader.

Returns:

None

abstractmethod send(apdu: List[int]) Tuple[List[str], int, int][source]

Send APDU to the reader and card and retrieve the result with status codes.

Parameters:

apdu (List[int]) – Command to be sent

Returns:

Return the result of the query and two status codes

Return type:

Tuple[List[str], int, int]

bool() bool[source]

Is there an active connection

Return type:

Is there an active connection

Returns:

bool

disconnect() None[source]

Disconnect from the card.

Returns:

None

class cryptnox_sdk_py.reader.NfcReader[source]

Bases: Reader

Specialized reader using xantares/nfc-binding

__init__()[source]
connect()[source]

Connect to the card found in the selected reader.

Returns:

None

send(apdu: List[int]) Tuple[List[str], int, int][source]

Send APDU to the reader and card and retrieve the result with status codes.

Parameters:

apdu (List[int]) – Command to be sent

Returns:

Return the result of the query and two status codes

Return type:

Tuple[List[str], int, int]

class cryptnox_sdk_py.reader.SmartCard(index: int = 0)[source]

Bases: Reader

Generic smart card reader class

Parameters:

index (int) – Index of the reader to initialize.

__init__(index: int = 0)[source]
connect() None[source]

Connect to the card found in the selected reader.

Returns:

None

send(apdu: List[int]) Tuple[List[str], int, int][source]

Send APDU to the reader and card and retrieve the result with status codes.

Parameters:

apdu (List[int]) – Command to be sent

Returns:

Return the result of the query and two status codes

Return type:

Tuple[List[str], int, int]

disconnect() None[source]

Disconnect from the card.

Returns:

None

cryptnox_sdk_py.reader.get(index: int = 0) Reader[source]

Get the reader that can be found on the given position.

Parameters:

index (int) – Index of reader to be initialized and used

Returns:

Reader object that can be used.

Return type:

Reader

Module contents

This is a library for communicating with Cryptnox cards

See the README.md for API details and general information.

cryptnox_sdk_py.Card

alias of Base

class cryptnox_sdk_py.Connection(index: int = 0, debug: bool = False, conn: List = None, remote: bool = False)[source]

Bases: ContextDecorator

Connection to the reader.

Sends and receives messages from the card using the reader.

Parameters:
  • index (int) – Index of the reader to initialize the connection with

  • debug (bool) – Show debug information during requests

  • conn (List) – List of sockets to use for remote connections

  • remote (bool) – Use remote sockets for communications with the cards

Variables:

self.card (Card) – Information about the card.

__init__(index: int = 0, debug: bool = False, conn: List = None, remote: bool = False)[source]
disconnect() None[source]

Disconnect from the card reader and clean up the connection.

This method properly closes the connection to the card reader without deleting the Connection object itself.

send_apdu(apdu: List[int]) Tuple[List[int], int, int][source]

Send data to the card in plain format

Parameters:

apdu (int) – list of the APDU header

Return bytes:

Result of the query that was sent to the card

Return type:

bytes

Raises:

ConnectionException – Issue in the connection

send_encrypted(apdu: List[int], data: bytes, receive_long: bool = False) bytes[source]

Send data to the card in encrypted format

Parameters:
  • apdu (int) – list of the APDU header

  • data – bytes of the data payload (in clear, will be encrypted)

  • receive_long (bool)

Return bytes:

Result of the query that was sent to the card

Return type:

bytes

Raises:

CryptnoxException – General exceptions

remote_read(apdu: List[int]) Tuple[List[int], int, int][source]
class cryptnox_sdk_py.SlotIndex(*values)[source]

Bases: IntEnum

Predefined values to use for parameters as SlotIndex.

EC256R1 = 1
RSA = 2
FIDO = 3
class cryptnox_sdk_py.Derivation(*values)[source]

Bases: IntEnum

Predefined values to use for parameters as Derivation.

CURRENT_KEY = 0
DERIVE = 1
DERIVE_AND_MAKE_CURRENT = 2
PINLESS_PATH = 3
class cryptnox_sdk_py.KeyType(*values)[source]

Bases: IntEnum

Predefined values to use for parameters as KeyType.

K1 = 0
R1 = 16
class cryptnox_sdk_py.AuthType(*values)[source]

Bases: Enum

Predefined values for authentication type.

NO_AUTH = 0
PIN = 1
USER_KEY = 2
class cryptnox_sdk_py.SeedSource(*values)[source]

Bases: Enum

Predefined values for how seed was created

NO_SEED = 0
SINGLE = 75
EXTENDED = 88
EXTERNAL = 76
INTERNAL = 83
DUAL = 68
WRAPPED = 82
class cryptnox_sdk_py.Origin(*values)[source]

Bases: Enum

Predefined values for keeping the origin of the card

UNKNOWN = 0
ORIGINAL = 1
FAKE = 2

The cryptnox_sdk_py package is a library for communicating with Cryptnox cards. It exports:

class cryptnox_sdk_py.Card

Main card interface class. Alias for cryptnox_sdk_py.card.base.Base.

class cryptnox_sdk_py.Connection[source]

Connection handler for card communication. See cryptnox_sdk_py.connection.Connection for details.

Factory module for creating card instances. See cryptnox_sdk_py.factory for details.

Enumeration types module. See cryptnox_sdk_py.enums for details.

Exception classes module. See cryptnox_sdk_py.exceptions for details.

class exceptions.SlotIndex

Card slot index enumeration. See cryptnox_sdk_py.enums.SlotIndex for details.

class exceptions.Derivation

Key derivation method enumeration. See cryptnox_sdk_py.enums.Derivation for details.

class exceptions.KeyType

Cryptographic key type enumeration. See cryptnox_sdk_py.enums.KeyType for details.

class exceptions.AuthType

Authentication type enumeration. See cryptnox_sdk_py.enums.AuthType for details.

class exceptions.SeedSource

Seed source enumeration. See cryptnox_sdk_py.enums.SeedSource for details.

class exceptions.Origin

Origin enumeration. See cryptnox_sdk_py.enums.Origin for details.

exceptions.__version__: str = "1.0.3"

Current version of the cryptnox_sdk_py library.