<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Secure AuthenticationのトピックRe: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
    <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383975#M629</link>
    <description>&lt;P&gt;Yes, the engine opens a session in EmbSe_Init() and closes it in EmbSe_Finish().&lt;/P&gt;&lt;P&gt;As soon as you add AES to the engine (add call to ENGINE_set_ciphers() in bind_helper() and change default_algorithms to "EC, CIPHERS" in the config file) closing the session hangs, because OpenSSL's global engine lock is locked twice.&lt;/P&gt;&lt;P&gt;I have worked around the issue. I don't open the session in EmbSe_Init(), but just in time when I need it. For example the session is opened and closed inside EmbSe_ECDSA_Do_Sign().&lt;/P&gt;&lt;P&gt;I still wonder if something is wrong conceptually. If OpenSSL's global engine lock must not be locked twice and it is already locked when reaching EmbSe_Finish(), the engine should not be allowed to do things that involve a second lock attempt. But I can't find any documentation on this. Maybe you know more.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Dec 2021 10:24:03 GMT</pubDate>
    <dc:creator>fvjdxe</dc:creator>
    <dc:date>2021-12-09T10:24:03Z</dc:date>
    <item>
      <title>OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1380511#M624</link>
      <description>&lt;P&gt;I am working with version 3.0.3 of the plug &amp;amp; trust middle-ware.&lt;/P&gt;&lt;P&gt;I have extended the OpenSSL engine to support ciphers (AES-256-CBC). Now the engine hangs in a deadlock on a mutex when being deinitialised - even when using elliptic curves and not ciphers.&lt;/P&gt;&lt;P&gt;What happens is that OpenSSL's &lt;FONT face="courier new,courier"&gt;global_engine_lock&lt;/FONT&gt;, which is of type &lt;FONT face="courier new,courier"&gt;pthread_rwlock_t&lt;/FONT&gt; has already been locked once in &lt;FONT face="courier new,courier"&gt;engine_table_cleanup()&lt;/FONT&gt; (OpenSSL crypto/engine/eng_table.c) when &lt;FONT face="courier new,courier"&gt;EmbSe_Finish()&lt;/FONT&gt; is called. When &lt;FONT face="courier new,courier"&gt;sss_session_close()&lt;/FONT&gt; is called inside &lt;FONT face="courier new,courier"&gt;EmbSe_Finish()&lt;/FONT&gt;, this involves encryption again. And since the engine now support ciphers, OpenSSL locks the &lt;FONT face="courier new,courier"&gt;global_engine_lock&lt;/FONT&gt; again. I can see that &lt;FONT face="courier new,courier"&gt;pthread_rwlock_wrlock()&lt;/FONT&gt; returns &lt;FONT face="courier new,courier"&gt;EDEADLK&lt;/FONT&gt; at this point, indicating that the mutex cannot be locked again. But OpenSSL doesn't check this error code. So it ends up calling &lt;FONT face="courier new,courier"&gt;pthread_rwlock_unlock()&lt;/FONT&gt; twice which - according to the documentation - leads to undefined behavior.&lt;/P&gt;&lt;P&gt;I can't tell exactly where the second locking happens, but I saw that &lt;FONT face="courier new,courier"&gt;CMAX_Init()&lt;/FONT&gt; was active at this point.&lt;/P&gt;&lt;P&gt;Are you aware of this problem? Do you have any proposal on how to solve it? Would you say it is a bug in OpenSSL to lock the mutex twice or are we not allowed to use OpenSSL's encryption from &lt;FONT face="courier new,courier"&gt;EmbSe_Finish()&lt;/FONT&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 09:28:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1380511#M624</guid>
      <dc:creator>fvjdxe</dc:creator>
      <dc:date>2021-12-02T09:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383052#M625</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/191198"&gt;@fvjdxe&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Actually&amp;nbsp;an extension of the OpenSSL engine with AES we have so far not looked into.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Looks like you have an user session opened from the openssl engine, right? As when no user session is open then sss_session_close() does not send an APDU and so needs no crypto functionality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;BR /&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 03:29:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383052#M625</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2021-12-08T03:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383224#M626</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;what do you mean with user session?&lt;/P&gt;&lt;P&gt;I use the OpenSSL command line tool like this:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;openssl enc -aes-256-cbc -in test.bin -out test-encrypted.bin -iv $(hexdump -v -e '/1 "%02X"' &amp;lt; iv.bin) -K $(hexdump -v -e '/1 "%02X"' &amp;lt; key-reference-00000003.bin)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Or like this:&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;openssl dgst -sha256 -sign private-reference-00000002.der -keyform der -out signature.bin test.bin&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 07:54:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383224#M626</guid>
      <dc:creator>fvjdxe</dc:creator>
      <dc:date>2021-12-08T07:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383945#M628</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/191198"&gt;@fvjdxe&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The user session means the&amp;nbsp;applet session which is an authenticated communication channel between the owner of an Authentication Object and the SE050 IoT applet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please refer to section 3.6 in AN12413 for more details on this topic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;BR /&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 09:42:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383945#M628</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2021-12-09T09:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383975#M629</link>
      <description>&lt;P&gt;Yes, the engine opens a session in EmbSe_Init() and closes it in EmbSe_Finish().&lt;/P&gt;&lt;P&gt;As soon as you add AES to the engine (add call to ENGINE_set_ciphers() in bind_helper() and change default_algorithms to "EC, CIPHERS" in the config file) closing the session hangs, because OpenSSL's global engine lock is locked twice.&lt;/P&gt;&lt;P&gt;I have worked around the issue. I don't open the session in EmbSe_Init(), but just in time when I need it. For example the session is opened and closed inside EmbSe_ECDSA_Do_Sign().&lt;/P&gt;&lt;P&gt;I still wonder if something is wrong conceptually. If OpenSSL's global engine lock must not be locked twice and it is already locked when reaching EmbSe_Finish(), the engine should not be allowed to do things that involve a second lock attempt. But I can't find any documentation on this. Maybe you know more.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 10:24:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1383975#M629</guid>
      <dc:creator>fvjdxe</dc:creator>
      <dc:date>2021-12-09T10:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1390834#M665</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/191198"&gt;@fvjdxe&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the session which gets created by the openSSL engine needs some encryption, this is possibly the cause for entering the engine twice. In case the session is a PlatformSCP session, the encryption shall be done using the AcessManager in between the engine and the secure element.&lt;/P&gt;
&lt;P&gt;In case the user session is a AES or ECKey session you might have to explicitly configure the openssl AES calls from the MW to not enter the openssl engine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that makes sense,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;BR /&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Dec 2021 14:53:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1390834#M665</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2021-12-22T14:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1394662#M674</link>
      <description>&lt;P&gt;Hello Kan,&lt;/P&gt;&lt;P&gt;the session is an EC key session.&lt;/P&gt;&lt;P&gt;I played around with explicitly using the software engine inside the middle-ware. I think I did something like this:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;CMAC_Init(..., ENGINE_by_id("openssl"));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This should tell OpenSSL to use the default software engine for the CMAC operations. Sadly it didn't find the default engine. Instead it was searching for some library file named "openssl".&lt;/P&gt;&lt;P&gt;Do you, by chance, have any experience with engine selection?&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 08:09:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1394662#M674</guid>
      <dc:creator>fvjdxe</dc:creator>
      <dc:date>2022-01-05T08:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: OpenSSL engine hangs on deinitialisation when ciphers are supported</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1395836#M680</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/191198"&gt;@fvjdxe&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not yet, but as far as I know, it is possible to add OpenSSL engine specific extensions to the OpenSSL configuration file. Using these extensions one can control whether the supported crypto functionality is delegated to the Secure Element or whether it is handled by the OpenSSL SW implementation. Please kindly refer to "se05x_mw_v04.01.00/simw-top/doc/sss/plugin/openssl/scripts/readme.html" for more details.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a great day,&lt;BR /&gt;Kan&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;-------------------------------------------------------------------------------&lt;BR /&gt;Note:&lt;BR /&gt;- If this post answers your question, please click the "Mark Correct" button. Thank you!&lt;BR /&gt;- We are following threads for 7 weeks after the last post, later replies are ignored&lt;BR /&gt;Please open a new thread and refer to the closed one, if you have a related question at a later point in time.&lt;BR /&gt;-------------------------------------------------------------------------------&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 01:00:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/OpenSSL-engine-hangs-on-deinitialisation-when-ciphers-are/m-p/1395836#M680</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2022-01-07T01:00:30Z</dc:date>
    </item>
  </channel>
</rss>

