Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openssl cannot get ENGINE_by_id() to work

Tags:

c

openssl

I'm trying to develop my own dynamic engine for Openssl.

To begin with, I would just get to know openssl by loading one of the included engines.

I installed openssl-1.0.1f.

Configured it as such:

./config -shared --prefix=/home/user/work/openssl --openssldir=/home/user/work/openssl no-asm -fPIC

and doing:

make and make install

After this I have tested the engine using:

./openssl engine -vvvv dynamic -pre SO_PATH:../lib/engines/libgost.so -pre ID:gost -pre LOAD
(dynamic) Dynamic engine loading support
[Success]: SO_PATH:../lib/engines/libgost.so
[Success]: ID:gost
[Success]: LOAD
Loaded: (gost) Reference implementation of GOST engine
 CRYPT_PARAMS: OID of default GOST 28147-89 parameters
      (input flags): STRING

That seems ok.

Now I'm trying load the engine in a very simple c-program, but I cannot get ENGINE_by_id to return anything but NULL. I have tried everything I could come up with, but I'm totally stuck.

Below is my code:

#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/engine.h>
#include <stdio.h>
#include <string.h>

int main() {

    ENGINE_load_dynamic();
    ENGINE *eng = ENGINE_by_id("dynamic");

    printf("Error: %s\n", ERR_reason_error_string(ERR_get_error()));

    ENGINE_ctrl_cmd_string(eng, "SO_PATH", "/home/user/work/openssl/lib/engines/libgost.so", 0);
    ENGINE_ctrl_cmd_string(eng, "ID", "gost", 0);
    ENGINE_ctrl_cmd_string(eng, "LOAD", NULL, 0);
    ENGINE_ctrl_cmd_string(eng, "CMD_FOO", "some input data", 0);

    if(NULL == eng) {
        printf("Error: %s\n", ERR_reason_error_string(ERR_get_error()));
        abort(); // failed
    }

    return 0;
}

Build as:

gcc test.c -o test -I/home/user/work/openssl/include -L/home/user/work/openssl/lib -L/home/user/work/openssl/lib/engines -lcrypto -lssl -lgost

Output:

./test
Error: (null)

What am I doing wrong?

like image 875
JakobJ Avatar asked Apr 07 '14 09:04

JakobJ


1 Answers

Because you link the app with local libraries, when running don't forget to export the LD_LIBRARY_PATH or use it inline.

LD_LIBRARY_PATH=/home/user/work/openssl/lib:/home/user/work/openssl/lib/engines ./test
like image 139
Han Avatar answered Oct 14 '22 14:10

Han