1
2
3
4
5
6
7 """
8 Interact with OpenSSL by M2Crypto library wrapper and OpenSC pkcs11 engine to
9 access smart cards and retrieve private keys and certificates reference.
10 """
11
12 from M2Crypto import Engine
13
14
16 """
17 Initializes Openssl pkcs11 engine with pkcs11 driver module and returns
18 initialized engine for operations.
19 """
20
21 dynamic = Engine.load_dynamic_engine("pkcs11", pkcs11_engine)
22
23 pkcs11 = Engine.Engine("pkcs11")
24 pkcs11.ctrl_cmd_string("MODULE_PATH", pkcs11_driver)
25 pkcs11.init()
26 return pkcs11
27
28
30 """
31 Performs authentication by PIN on the smart card.
32 """
33
34 pkcs11.ctrl_cmd_string("PIN", pin)
35
36
38 """
39 Returns references to private key and certificate stored on the slot_id of
40 the smart card.
41 """
42
43 private_key = pkcs11.load_private_key(slot_id)
44 cert = pkcs11.load_certificate(slot_id)
45 return private_key, cert
46