Hello
We are trying to use the PKCS11 engine for OpenSSL to interface with a
smart card reader "Gemplus GemPC Twin 00 00". We are having some
trouble when trying to retrieve the private from a smart card to
decrypt some data. The problem arises when the wrong PIN number is
given, so that method ENGINE_cleanup somehow causes the program to
crash with a bus error.
Below is a small program that reproduces what we are trying to
do. We've tested this in FreeBSD 7.2 amd64 and Ubuntu 9.10 i386.
Anyone would have any idea what is going on and how to solve it?
----------------------------------------------------------------------
#include <string>
#include <openssl/engine.h>
#include <openssl/evp.h>
using std::string;
ENGINE *_engine;
int main()
{
ENGINE_load_dynamic();
_engine = ENGINE_by_id("dynamic");
if (_engine == NULL) {
return -1;
}
string enginePath = "/usr/local/lib/engines/engine_pkcs11.so";
if (!ENGINE_ctrl_cmd_string(_engine, "SO_PATH", enginePath.c_str(),
0)) {
return -1;
}
if (!ENGINE_ctrl_cmd_string(_engine, "LIST_ADD", "1", 0)) {
return -1;
}
if (!ENGINE_ctrl_cmd_string(_engine, "LOAD", NULL, 0)) {
return -1;
}
string modulePath = "/usr/local/lib/opensc-pkcs11.so";
if (!ENGINE_ctrl_cmd_string(_engine, "MODULE_PATH",
modulePath.c_str(), 0)) {
return -1;
}
// Wrong PIN
string pin = "123456";
if (!ENGINE_ctrl_cmd_string(_engine, "PIN", pin.c_str(), 0)) {
return -1;
}
if (!ENGINE_init(_engine)) {
return -1;
}
if (!(ENGINE_set_default(_engine, ENGINE_METHOD_RSA))) {
return -1;
}
// Correct KEY ID
string keyName = "id_9829";
EVP_PKEY *key = ENGINE_load_private_key(_engine, keyName.c_str(),
NULL, NULL);
ENGINE_finish(_engine);
ENGINE_free(_engine);
ENGINE_cleanup();
return 0;
}
-------------------------------------------------------------------------
Best regards
Cesar
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [email protected]