链接到OpenSSL函数中的引擎\u加载\u私钥
我正在为我的应用程序开发一个示例OpenSSL引擎链接到OpenSSL函数中的引擎\u加载\u私钥,openssl,openssl-engine,Openssl,Openssl Engine,我正在为我的应用程序开发一个示例OpenSSL引擎 #include <openssl/engine.h> static const char *engine_id = "sample"; static const char *engine_name = "developed by Devang"; static int engine_init(ENGINE *e); static EVP_PKEY *load_key(ENGINE *e, const char *id, U
#include <openssl/engine.h>
static const char *engine_id = "sample";
static const char *engine_name = "developed by Devang";
static int engine_init(ENGINE *e);
static EVP_PKEY *load_key(ENGINE *e, const char *id, UI_METHOD *ui, void *cb);
int bind_helper(ENGINE*e, const char *id) {
if(!ENGINE_set_id(e, engine_id) ||
!ENGINE_set_init_function(e, engine_init) ||
!ENGINE_set_load_privkey_function(e, load_key))
return 0;
return 1;
}
IMPLEMENT_DYNAMIC_CHECK_FN(); IMPLEMENT_DYANMIC_BIND_FN(bind_helper);
static int engine_init(ENGINE *e)
{
printf("In engine_init \n");
}
static EVP_PKEY *load_key(ENGINE *e, const char *id, UI_METHOD *ui, void *cb) {
printf(" In load_key function\n");
}
#包括
静态常量字符*engine_id=“sample”;
静态常量char*engine_name=“由Devang开发”;
静态int引擎_init(引擎*e);
静态EVP_PKEY*load_key(引擎*e,常量字符*id,用户界面方法*UI,无效*cb);
int bind_helper(引擎*e,常量字符*id){
如果(!发动机设置id(e,发动机id)||
!ENGINE_set_init_函数(e,ENGINE_init)||
!发动机设置加载私钥功能(e,加载私钥))
返回0;
返回1;
}
实现动态检查功能;实现动态绑定FN(绑定助手);
静态int引擎_init(引擎*e)
{
printf(“在引擎中_init\n”);
}
静态EVP_PKEY*load_键(引擎*e,常量字符*id,UI_方法*UI,void*cb){
printf(“加载_键函数\n”);
}
我构建了这个openssl引擎(sample.so)和我放入的共享库
/usr/lib/x86_64-linu-gnu/openssl-1.0.0/engines/
我创建了一个示例应用程序
样本测试
#include <openssl/engine.h>
int main(void)
{
ENGINE_load_dynamic();
ENGINE *en = ENGINE_by_id("sample");
ENGINE_init(en);
ENGINE_load_private_key(en, NULL, UI_OpenSSL(), NULL);
}
#包括
内部主(空)
{
发动机负载动力();
ENGINE*en=发动机的id(“样本”);
发动机启动(en);
引擎加载私钥(en,NULL,UI\u OpenSSL(),NULL);
}
我运行这个示例应用程序,
输出:
引擎内初始化
为什么不调用load_键函数?
有人能帮我从我的应用程序中链接到load_key函数吗?尝试从engine_init()函数返回1。Openssl将认为您的引擎未能初始化,否则不会使用进一步的函数引用 ie:它认为你的“硬件加速器”没有插上电源,或者出现了其他故障
static int engine_init(ENGINE *e)
{
printf("In engine_init \n");
return 1;
}
我将此添加到您的示例中,并从您要查找的load_key()中获得了输出。您好,欢迎来到StackOverflow。请你补充一个解释,为什么这会有帮助?谢谢你,@Alexander!