<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">I'm running this in Windows 10 and when
      I load the smart card middleware PKCS11 DLL, I see the exception:<br>
      <blockquote>Exception thrown at 0x773046D2 in GENCom.exe:
        Microsoft C++ exception: unsigned long at memory location
        0x07FCFA00. <br>
      </blockquote>
      <br>
      During mutual authentication, I also see alot of other exceptions
      such as:<br>
      <blockquote> Exception thrown at 0x773046D2 in GENCom.exe:
        Microsoft C++ exception: AI::Middleware::CMWException at memory
        location 0x032FD2D0. <br>
      </blockquote>
      <br>
      I traced them down to various PKCS11 calls on the card in libp11.<br>
      e.g.<br>
      the function call to C_GetSlotList(...) in the file p11_slot.c
      triggers an exception:<br>
      <blockquote>int pkcs11_enumerate_slots(PKCS11_CTX *ctx,
        PKCS11_SLOT **slotp, unsigned int *countp)<br>
        {<br>
        . . .<br>
        <b>rv = cpriv->method->C_GetSlotList(FALSE, NULL_PTR,
          &nslots);</b><br>
        . . .<br>
        }<br>
      </blockquote>
      <br>
      It is interesting to note that this function seems to get called
      multiple times and it eventually works. I do not fully understand
      how/why the code does that and if this is the design intent. The
      exceptions don't seem to have any effect on the functionality, but
      I still need to understand why they are occurring.  <br>
      <br>
      It looks like someone else using a smart card has also encountered
      similar problems in Windows but there is no real answer as to why
      they are occurring:<br>
<a class="moz-txt-link-freetext" href="https://www.codeproject.com/Questions/1254182/Smart-card-apis-throw-first-chance-exceptions-but">https://www.codeproject.com/Questions/1254182/Smart-card-apis-throw-first-chance-exceptions-but</a><br>
      <br>
      <br>
      <br>
      Thanks,<br>
      George<br>
      <br>
      <br>
      On 2021-01-11 9:41 a.m., Michael Wojcik wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:DM6PR18MB270035C69BEEB9E0DBAFE706F9AB9@DM6PR18MB2700.namprd18.prod.outlook.com">
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">From: openssl-users <a class="moz-txt-link-rfc2396E" href="mailto:openssl-users-bounces@openssl.org"><openssl-users-bounces@openssl.org></a> On Behalf Of George
Sent: Sunday, 10 January, 2021 21:01
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Right now I am using the "libp11" DLL (i.e. libp11-libp11-0.4.11\src\pkcs11.dll)
with my PKCS11 smart card middleware DLL. Should I be using the OpenSC pkcs11 DLL
instead of my middleware DLL if I am using libp1?
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
Honestly, I have no idea. It's been years since I worked with PKCS#11, and then I was using a single piece of test hardware. I got it working with OpenSSL using the OpenSC modules, but that may have been specific to my case.

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Do you know if it is normal to see exceptions related to the PKCS11 function calls
in the libp11 code? For example, I can see  the following function generate an
exception on C_GetSlotList(...) multiple times but it eventually is successful.
Is this normal behaviour?
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
What sort of "exception"? A Windows exception? UNIX signal? C++ exception?

My initial guess would be that this is a timing issue - maybe the device needs some time to become available, for example. But that's just a guess. Maybe someone with more experience with a variety of HSMs and PKCS#11 will weigh in.

--
Michael Wojcik
</pre>
    </blockquote>
    <br>
  </body>
</html>