<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial,sans-serif">On 10 August 2016 at 16:19, Jakob Bohm </span><span dir="ltr" style="font-family:arial,sans-serif"><<a href="mailto:jb-openssl@wisemo.com" target="_blank">jb-openssl@wisemo.com</a>></span><span style="font-family:arial,sans-serif"> wrote:</span><br></div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 10/08/2016 15:49, Krzysztof Konopko wrote:<span class=""><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 10 August 2016 at 15:31, Jakob Bohm <<a href="mailto:jb-openssl@wisemo.com" target="_blank">jb-openssl@wisemo.com</a> <mailto:<a href="mailto:jb-openssl@wisemo.com" target="_blank">jb-openssl@wisemo.com</a>><wbr>>wrote:<br>​<br>
    1. Create a third engine3 which loads both engine1 and engine2<br>
      internally (<br>
    ​​<br>
    without going through OpenSSL and its locks).<br>
      So for example engine3->init calls both engine2->init and<br>
      engine1->init.<br>
<br>
<br>
​I don't understand how engine3 could be initialised ​"<br>
​<br>
without going through OpenSSL and its locks<br>
​" as it's OpenSSL taking the lock whenever initialising _every_ engine.  Also when I call `ENGINE_init()` (indirectly, somewhere deep inside engine1), the implementation of<br>
`ENGINE_init()`<br>
​ takes the engine lock. as well which is the source of the problem.<br>
</blockquote></span>
engine3 would call engine1 and engine2 without going through<br>
a call to ENGINE_init(), thus making OpenSSL itself see the<br>
engine1 and engine2 code as part of engine3 (even though<br>
engine3 really just calls the functions in engine1 and<br>
engine2).</blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​Oh, I see.  engine1 and engine2 would expose individual functions which engine3 would bound as its engine function own (or use some plumbing to forward calls to the original functions).  This means engine3 would either link with engine1 and engine2 libraries or `dlopen()` them.  Or something like that.  I think I get the idea now.</div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​</div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
​<br>
<br>
    2. engine3 would export/provide all the methods from engine1<br>
      and engine2 by forwarding or reexporting the calls.<br>
<br>
    3. OpenSSL itself is instructed to use only your engine3<br>
      wrapper.<br>
<br>
    4. As a more ambitious project, someone could write a generic<br>
      "engine3" which loads a list of actual engines from a config<br>
      file.<br>
<br>
    At the OpenSSL design level, the OpenSSL team might extend the<br>
    OPENSSL_SSL_CLIENT_ENGINE_AUTO<wbr>variable to accept a<br>
    colon-separatedlist of engines rather than just a single engine.<br>
<br>
<br>
<br>
​That sounds interesting but engines in general (and specifically in my case) are independent of each other and in different situations I may want to load one but not the other (for example when testing).  But I guess that would be a matter of moving the configuration control from where I have it now into whatever mechanism OpenSSL could have (as proposed above).<br>
</blockquote></span>
The idea would be that "engine3" would be a workaround engine<br>
that simulates the (possibly missing) ability to specify<br>
multiple engines via the OPENSSL_SSL_CLIENT_ENGINE_AUTO<br>
variable.  This not-independent engine3 would do nothing but<br>
load other engines, and may or may not be configurable as to<br>
which real engines it loads.  By doing this, engine3 would also<br>
compensate for the fact that many other OpenSSL APIs seem to<br>
allow only a single engine reference as parameter.<br>
<br>
With engine3 responsible for initializing engine2 before engine1,<br>
engine1 would no longer contain code to load engine2, making<br>
engine1 more independent from engine2.<div class=""><div class="h5"><br>
<br>
</div><div class="h5"><br></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">​OK, fair enough.  That makes sense.  In my case some re-factoring would be required as the code that initialises engine2 does so explicitly with `ENGINE_by_id()` and `ENGINE_init()` and it doesn't "know" it's called from engine1.  And vice versa, engine1 does not know that the code it calls loads and initialises an engine.  But I get the idea and it seems plausible.</div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">Also it's important to me that this way or the other there's someone who admits OpenSSL has a problem with loading engines recursively (or does not support that intentionally) and I need to address that.</div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline"><br></div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">Thanks again!</div></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;display:inline">Kris​</div> </div></div><br></div></div>