<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Hi,<br>
      <br>
         I've been looking at the code in the pppd EAP-TLS patch, but I
      can't seem to load the engine with the pkcs11 DLL. It is failing
      with the error: <br>
      <br>
      <font size="+1" face="monospace">error:2507606A:DSO support
        routines:WIN32_BIND_FUNC:could not bind to the requested symbol
        name<br>
        <br>
      </font>I've verified the path is correct.<br>
      <br>
      I am using OpenSSL1.0.2u with the FIPS Object Module 2.0.16  in
      Windows 10. Do I need to do anything special to allow loading of
      DLLs in OpenSSL?<br>
      <br>
      Here is what I am trying to do:<br>
      <br>
      <font size="+1" face="monospace">    char* engine_name =
        "C:\\Users\\whipp\\junk4\\ActivClient\\acpkcs211.dll";<br>
            ENGINE_load_builtin_engines();<br>
            ENGINE_register_all_complete();<br>
            ENGINE *pkey_engine = ENGINE_by_id("dynamic");<br>
            ENGINE_ctrl_cmd_string(pkey_engine, "SO_PATH", engine_name,
        0);<br>
            ENGINE_ctrl_cmd_string(pkey_engine, "ID", "pkcs11", 0);<br>
            ENGINE_ctrl_cmd_string(pkey_engine, "LOAD", NULL, 0);</font><br>
      <br>
      Do you see anything wrong with this?<br>
      <br>
      <br>
      Thanks,<br>
      George<br>
      <br>
      On 2020-12-15 4:38 a.m., Jan Just Keijser wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:e015a686-88b2-e483-a7da-53e9efabd9fc@nikhef.nl">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <div class="moz-cite-prefix">Hi,<br>
        <br>
        On 14/12/20 21:01, George wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:7a3428c6-04ab-672e-b738-67680f9fc036@gmail.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        <div class="moz-cite-prefix">Ok, so I am not actually going to
          populate EVP_PKEY with a private key in the callback function<font
            size="+1">:<br>
          </font><font size="+1" face="monospace">int
            (*client_cert_cb)(SSL *ssl, X509 **x509, <b>EVP_PKEY **pkey</b>)</font><font
            size="+1" face="monospace">?<br>
            <br>
          </font><font size="+1">Instead, I will call </font><br>
          <font size="+1" face="monospace">EVP_PKEY
            *ENGINE_load_private_key(ENGINE *e, const char *key_id,
            UI_METHOD *ui_method, void *callback_data);<br>
          </font>to get the <font face="monospace">EVP_PKEY</font>,
          which will be used by OpenSSL to access the Smart Card.<br>
          <br>
          Once I get  <font size="+1"><font face="monospace">the
              resulting </font></font><font size="+1" face="monospace">EVP_PKEY
            using </font><font size="+1" face="monospace">ENGINE_load_private_key(...),
            how do I assign it to pkey in the callback function?<br>
            If I had private key I would use something like<br>
          </font> EVP_PKEY_assign_RSA(..)<br>
          Since I don't actually have a private key, should I use
          something else?<br>
          <br>
        </div>
      </blockquote>
      like Michael pointed out, my  eap-tls code is just an example of
      how you could handle a pkcs11 device; it does not us a callback at
      all, but my code loads the client cert+key upfront and avoids
      having to use a client callback altogether.<br>
      <br>
      I guess you could also use a client callback for this (perhaps in
      combination with SSL_CTX_set_client_cert_engine()) . In that case
      you would get the (pseudo) key from the engine like this<br>
         EVP_PKEY *engine_key = <font size="+1" face="monospace">ENGINE_load_private_key(ENGINE
        *e, const char *key_id, UI_METHOD *ui_method, void
        *callback_data);<br>
        and then set<br>
          pkey = &engine_key;<br>
        and see if that works.<br>
        Note that the </font><font size="+1" face="monospace">ENGINE_load_private_key()
        function *does* return a EVP_PKEY struct but that does not mean
        the entire private key is contained in it; a private key
        consists of a modulus and a private part (exponent, prime1,
        prime2, exponent1, exponent2 etc). the </font><font size="+1"
        face="monospace">ENGINE_load_private_key() call will return a
        struct containing the modulus but not the rest. You then use the
        engine to do the actual encryption and decryption.<br>
        <br>
        HTH,<br>
        <br>
        JJK<br>
        <br>
      </font><br>
    </blockquote>
    <br>
  </body>
</html>