We have a project that needs to run an openssl engine on iOS device. We have compiled the .so file for the test engine and it works fine with the command line. But when we put it in the iOS project and tries to load the engine, the load step always gives an error.
NSString *enginePath = [[NSBundle mainBundle] pathForResource:@"silly-engine" ofType:@"so"];
char* engine_id = "silly-engine";
char* engine_path = (char *)[enginePath UTF8String];
ENGINE_load_dynamic();
ENGINE *dyn = ENGINE_by_id("dynamic");
if (!ENGINE_ctrl_cmd_string(dyn, "SO_PATH", engine_path, 0))
{
NSLog(@"SO_PATH failed");
}
if (!ENGINE_ctrl_cmd_string(dyn, "DIR_ADD", engine_path, 0))
{
NSLog(@"DIR_ADD failed");
}
if (!ENGINE_ctrl_cmd_string(dyn, "ID", engine_id, 0))
{
NSLog(@"ID failed");
}
if (!ENGINE_ctrl_cmd(dyn, "LIST_ADD", 1, NULL, NULL, 0))
{
NSLog(@"LIST_ADD failed");
}
if (!ENGINE_ctrl_cmd_string(dyn, "LOAD", NULL, 0))
{
NSLog(@"LOAD failed");
}
ENGINE *myEngine = ENGINE_by_id(engine_id);
myEngine
will aways be NULL
. I suspect that iOS does not allow such dynamic libraries. Does anyone has experience how to make the OpenSSL Engine work on iOS?
Finally I got it solved by using static engine..Simply loading the engine file in OpenSSL engine calls should work. No need for dynamic engine on iOS.