<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif;font-size:16px"><div>Hello, <br></div><div><br></div><div dir="ltr">I want to write a program in which I can load a certificate from a smartcard instead of having it in a file on the client machine. In order to do so I will be using the opensc's engine_pkcs11 module. The module works fine using the shell but I want to implement it as an independent program. For example if I use the rsautl module then I can provide the inkey option and keyform option to use the private key from the smartcard. Look at the snippet below:</div><div id="yui_3_16_0_1_1437062732705_4413" dir="ltr"><br></div><div id="yui_3_16_0_1_1437062732705_4415" dir="ltr">openssl rsautl -sign -in file -keyform engine -engine pkcs11 -inkey slot_1-id_54a4c9bdaf3ff82b3367b586a6658c23 -out sig</div><div dir="ltr"><br></div><div dir="ltr">In order to do so I have to load the engine first. I do that as follows:<br></div><br class="">    openssl engine dynamic -pre SO_PATH:/usr/lib/engines/engine_pkcs11.so -pre ID:pkcs11 -pre LIST_ADD:1 -pre LOAD -pre MODULE_PATH:opensc-pkcs11.so<br class=""><br class="">which yields the result:<br class=""><br class=""><br class="">    (dynamic) Dynamic engine loading support<br class="">    [Success]: SO_PATH:/usr/lib/engines/engine_pkcs11.so<br class="">    [Success]: ID:pkcs11<br class="">    [Success]: LIST_ADD:1<br class="">    [Success]: LOAD<br class="">    [Success]: MODULE_PATH:opensc-pkcs11.so<br class="">    Loaded: (pkcs11) pkcs11 engine<br class=""><br class=""><br class="">I want to do the same using C code in an independent program so that I can use the:<br class=""><br class=""><br class="">    static X509 *pkcs11_load_cert(ENGINE * e, const char *s_slot_cert_id)<br class="">function to get the certificate from the smart card.<br class=""><div dir="ltr"><br></div><div id="yui_3_16_0_1_1437062732705_4473" dir="ltr">So I tried to debug engine.c using ddd debugger to understand exactly which part of the code was required to just load the engine. In the same program I want to use the opensc function to load certificate directly from the smartcard and then use it in further server client communication.<br></div><div id="yui_3_16_0_1_1437062732705_4180"><br></div><div id="yui_3_16_0_1_1437062732705_4468">Thanks in advance.<br></div></div></body></html>