ODP: dynamic engine load
Piotr Lobacz
piotr.lobacz at softgent.com
Wed May 26 13:46:48 UTC 2021
Ok i have found the problem:] The solution was to move the whole conditional if(Id == "pkcs11" {..} to the end of the function and now all is working properly.
BR
Piotr Lobacz
________________________________
Od: openssl-users <openssl-users-bounces at openssl.org> w imieniu użytkownika Piotr Lobacz <piotr.lobacz at softgent.com>
Wysłane: środa, 26 maja 2021 15:24
Do: openssl-users at openssl.org <openssl-users at openssl.org>
Temat: dynamic engine load
Hi all,
I am trying to write a function which will load dynamic engine for pkcs11. What i intendt to do is not to use engine id pkcs11 but dynamic. The problem is that i get an error for ENGINE_ctrl_cmd_string with MODULE_PATH parameter. My function currently looks like this:
public void Initialize()
{
if (null == engine)
{
engine = SafeNativeMethods.ENGINE_by_id("dynamic");
if (engine.IsInvalid)
{
throw new InvalidOperationException($"Unable to load dynamic engine");
}
if (!File.Exists(EnginePath))
{
throw new InvalidOperationException($"Unable to find engine library path");
}
if (1 != SafeNativeMethods.ENGINE_ctrl_cmd_string(engine, "SO_PATH", EnginePath, 0))
{
throw new InvalidOperationException("dynamic: setting so_path <= '{EnginePath}'");
}
if (1 != SafeNativeMethods.ENGINE_ctrl_cmd_string(engine, "ID", Id, 0))
{
throw new InvalidOperationException("dynamic: setting engine id <= '{id}'");
}
if(Id == "pkcs11")
{
if(!File.Exists(ModulePath))
{
throw new InvalidOperationException($"Unable to load pkcs11 module path");
}
if(1 != SafeNativeMethods.ENGINE_ctrl_cmd_string(engine, "MODULE_PATH", ModulePath, 0))
{
throw new InvalidOperationException("dynamic: setting module_path <= '{ModulePath}'");
}
}
if (1 != SafeNativeMethods.ENGINE_ctrl_cmd(engine, "LIST_ADD", 1, IntPtr.Zero, null, 0))
{
throw new InvalidOperationException( "dynamic: setting list_add <= 1");
}
if (1 != SafeNativeMethods.ENGINE_ctrl_cmd(engine, "LOAD", 1, IntPtr.Zero, null, 0))
{
throw new InvalidOperationException( "dynamic: setting load <= 1");
}
}
}
This function is writtien in C# but it shouldn't be rather a problem, cause it looks nearly the same as with C code.
According to some manuals and other stuff i should be able to load dynamic engine for pkcs11 module and i am because for example this command:
OpenSSL> engine dynamic -pre SO_PATH:/usr/lib/engines-1.1/libpkcs11.so -pre ID:pkcs11 -pre LIST_ADD:1 -pre LOAD -pre MODULE_PATH:/usr/lib/libckteec.so
works and produces log:
(dynamic) Dynamic engine loading support
[Success]: SO_PATH:/usr/lib/engines-1.1/libpkcs11.so
[Success]: ID:pkcs11
[Success]: LIST_ADD:1
[Success]: LOAD
[Success]: MODULE_PATH:/usr/lib/libckteec.so
Loaded: (pkcs11) pkcs11 engine
but as i said it before, when using my method i get an error on call for ENGINE_ctrl_cmd_string method. The error code which i'm getting is 0.
I would be very apprecieate if someone could help me solve this issue.
BR
Piotr Lobacz
[https://softgent.com/wp-content/uploads/2020/01/Zasob-14.png]<https://www.softgent.com>
Softgent Sp. z o.o., Budowlanych 31d, 80-298 Gdansk, POLAND
KRS: 0000674406, NIP: 9581679801, REGON: 367090912
www.softgent.com<http://www.softgent.com>
Sąd Rejonowy Gdańsk-Północ w Gdańsku, VII Wydział Gospodarczy Krajowego Rejestru Sądowego
KRS 0000674406, Kapitał zakładowy: 25 000,00 zł wpłacony w całości.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mta.openssl.org/pipermail/openssl-users/attachments/20210526/94ca2739/attachment-0001.html>
More information about the openssl-users
mailing list