<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style=""><span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;">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</span><font color="#201f1e"><span style="font-size: 14.6667px;">.</span></font></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color:rgb(32, 31, 30);font-family:"Segoe UI Web (East European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255);display:inline !important"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color:rgb(32, 31, 30);font-family:"Segoe UI Web (East European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255);display:inline !important">BR</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color:rgb(32, 31, 30);font-family:"Segoe UI Web (East European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;font-size:14.6667px;background-color:rgb(255, 255, 255);display:inline !important">Piotr Lobacz</span></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Od:</b> openssl-users <openssl-users-bounces@openssl.org> w imieniu użytkownika Piotr Lobacz <piotr.lobacz@softgent.com><br>
<b>Wysłane:</b> środa, 26 maja 2021 15:24<br>
<b>Do:</b> openssl-users@openssl.org <openssl-users@openssl.org><br>
<b>Temat:</b> dynamic engine load</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi all,<br>
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:<br>
<br>
        public void Initialize()<br>
        {<br>
            if (null == engine)<br>
            {<br>
                engine = SafeNativeMethods.ENGINE_by_id("dynamic");<br>
                if (engine.IsInvalid)<br>
                {<br>
                    throw new InvalidOperationException($"Unable to load dynamic engine");<br>
                }<br>
<br>
                if (!File.Exists(EnginePath))<br>
                {<br>
                    throw new InvalidOperationException($"Unable to find engine library path");<br>
                }<br>
<br>
                if (1 != SafeNativeMethods.ENGINE_ctrl_cmd_string(engine, "SO_PATH", EnginePath, 0))<br>
                {<br>
                    throw new InvalidOperationException("dynamic: setting so_path <= '{EnginePath}'");<br>
                }<br>
<br>
                if (1 != SafeNativeMethods.ENGINE_ctrl_cmd_string(engine, "ID", Id, 0))<br>
                {<br>
                    throw new InvalidOperationException("dynamic: setting engine id <= '{id}'");<br>
                }<br>
<br>
                if(Id == "pkcs11")<br>
                {<br>
                    if(!File.Exists(ModulePath))<br>
                    {<br>
                        throw new InvalidOperationException($"Unable to load pkcs11 module path");<br>
                    }<br>
<br>
                    if(1 != SafeNativeMethods.ENGINE_ctrl_cmd_string(engine, "MODULE_PATH", ModulePath, 0))<br>
                    {<br>
                        throw new InvalidOperationException("dynamic: setting module_path <= '{ModulePath}'");<br>
                    }<br>
                }<br>
<br>
                if (1 != SafeNativeMethods.ENGINE_ctrl_cmd(engine, "LIST_ADD", 1, IntPtr.Zero, null, 0))<br>
                {<br>
                    throw new InvalidOperationException( "dynamic: setting list_add <= 1");<br>
                }<br>
<br>
                if (1 != SafeNativeMethods.ENGINE_ctrl_cmd(engine, "LOAD", 1, IntPtr.Zero, null, 0))<br>
                {<br>
                    throw new InvalidOperationException( "dynamic: setting load <= 1");<br>
                }<br>
<br>
            }<br>
        }<br>
<br>
This function is writtien in C# but it shouldn't be rather a problem, cause it looks nearly the same as with C code.<br>
<br>
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:<br>
<br>
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<br>
<br>
works and produces log:<br>
<br>
(dynamic) Dynamic engine loading support<br>
[Success]: SO_PATH:/usr/lib/engines-1.1/libpkcs11.so<br>
[Success]: ID:pkcs11<br>
[Success]: LIST_ADD:1<br>
[Success]: LOAD<br>
[Success]: MODULE_PATH:/usr/lib/libckteec.so<br>
Loaded: (pkcs11) pkcs11 engine<br>
<br>
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.<br>
<br>
I would be very apprecieate if someone could help me solve this issue.<br>
<br>
BR<br>
Piotr Lobacz<br>
[<a href="https://softgent.com/wp-content/uploads/2020/01/Zasob-14.png]<https://www.softgent.com">https://softgent.com/wp-content/uploads/2020/01/Zasob-14.png]<https://www.softgent.com</a>><br>
<br>
Softgent Sp. z o.o., Budowlanych 31d, 80-298 Gdansk, POLAND<br>
<br>
KRS: 0000674406, NIP: 9581679801, REGON: 367090912<br>
<br>
<a href="http://www.softgent.com">www.softgent.com</a><br>
<br>
Sąd Rejonowy Gdańsk-Północ w Gdańsku, VII Wydział Gospodarczy Krajowego Rejestru Sądowego<br>
<br>
KRS 0000674406, Kapitał zakładowy: 25 000,00 zł wpłacony w całości.<br>
</div>
</span></font></div>
</body>
</html>