SCAutolib.models.card

This module implements classes for communication with different types of cards that we are using in the library. Those types are: virtual smart card, real (physical) smart card in standard reader, cards in the removinator.

Classes

class Card[source]

Interface for child classes. All child classes will rewrite common methods based on the type of the card.

_set_uri()[source]

Sets URI for given smart card. Uri is matched from p11tool command with regular expression. If URI is not matched, exception is raised.

Raise:

SCAutolibException

enroll()[source]

Enroll the card (upload a certificate and a key on it)

insert()[source]

Insert the card.

remove()[source]

Remove the card.

class PhysicalCard(card_data=None, card_dir=None)[source]
:TODO PhysicalCard is not yet tested, it’s Work In Progress

This class provides methods allowing to manipulate physical cards connected via removinator.

TODO this is not yet tested, insert and remove methods need to be

implemented with removinator

Initialise object for physical smart card. Constructor of the base class is also used.

insert()[source]

Insert physical card using removinator

remove()[source]

Remove physical card using removinator

to_dict()[source]

Customising default property for better serialisation for storing to JSON format.

Returns:

dictionary with all values. Path objects are typed to string.

Return type:

dict

class VirtualCard(card_data, softhsm2_conf=None, card_dir=None, key=None, cert=None)[source]

This class provides methods for operations on virtual smart card. Virtual smart card by itself is represented by the systemd service in the system. The card relates to some user, so providing the user is essential for correct functioning of methods for the virtual smart card.

Card root directory has to be created before calling any method

Initialise virtual smart card. Constructor of the base class is also used.

Parameters:
  • card_data (dict) – dict containing card details as pin, cardholder etc.

  • softhsm2_conf (pathlib.Path) – path to SoftHSM2 configuration file

  • card_dir (pathlib.Path) – path to card directory where card files will be saved

  • key (pathlib.Path) – path to key - if the key exist it will be used with the card

  • cert (pathlib.Path) – path to certificate. If file exist it will be used with the card

create()[source]

Creates SoftHSM2 token and systemd service for virtual smart card. Directory for NSS database is created in this method as separate DB is required for each virtual card.

delete()[source]

Deletes the virtual card directory which contains certs, SoftHSM2 token and NSS database. Also removes the systemd service for virtual smart card.

enroll()[source]

Upload certificate and private key to the virtual smart card (upload to NSS database) with pkcs11-tool.

gen_csr()[source]

Method for generating user specific CSR file that would be sent to the CA for generating the certificate. CSR is generated using ‘openssl` command based on template CNF file.

insert()[source]

Insert virtual smart card by starting the corresponding service.

remove()[source]

Remove the virtual card by stopping the service