<?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: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
    <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1573021#M1028</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I tried looking into the code further, below is my observation.&lt;/P&gt;&lt;P&gt;The SM_Close(NULL,0) call from within the&amp;nbsp;sss_pkcs11_pal_core.c is closing fd "0" even though there is no prior connection to the Security module.&lt;/P&gt;&lt;P&gt;This is because the "pSockCtx-&amp;gt;sockfd" is initialized as static so gets a default value of 0.&lt;BR /&gt;See below code for reference from&amp;nbsp;smComSocket_linux.c line ~50.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;typedef struct
{
    int sockfd;
    char * ipString;
} socket_Context_t;

static socket_Context_t sockCtx;
static socket_Context_t* pSockCtx = (socket_Context_t *)&amp;amp;sockCtx;

static U32 smComSocket_GetATR(U8* pAtr, U16* atrLen);

U16 smComSocket_Close()
{
    if (pSockCtx-&amp;gt;ipString != NULL)
        free(pSockCtx-&amp;gt;ipString);
    pSockCtx-&amp;gt;ipString = NULL;
    close(pSockCtx-&amp;gt;sockfd);
    return SW_OK;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think&amp;nbsp;&lt;SPAN&gt;adding a static initializer to sockfd (may be -1) and a condition to check if fd is valid before closing should fix the issue.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Let me know your thoughts.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have another question:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Why is the SM_Close(NULL, 0) call inside the&amp;nbsp;sss_pkcs11_pal_core.c file required at all??&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Riz_0-1671613053403.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/205119i193AF0932A9F7988/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Riz_0-1671613053403.png" alt="Riz_0-1671613053403.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I temporarily removed the SM_Close(NULL, 0) and ran pkcs11 operations concurrently. Everything seemed to work fine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you clarify on why this is really required at first place please?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;BR /&gt;Riz&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Dec 2022 08:57:55 GMT</pubDate>
    <dc:creator>Riz</dc:creator>
    <dc:date>2022-12-21T08:57:55Z</dc:date>
    <item>
      <title>TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1557010#M1013</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying out TLS communication with openssl and Pkcs11-SSS library.&lt;/P&gt;&lt;P&gt;After a successful handshake, I observed that I was unable to send data from TLS server stdin to the TLS client.&lt;/P&gt;&lt;P&gt;Setup:&lt;/P&gt;&lt;P&gt;TLS server: Device with Secure element SE05X. Example command below.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;OPENSSL_CONF=engine.conf openssl s_server -port &amp;lt;PORT_NO&amp;gt; -engine pkcs11 -keyform engine -key 1:XXXXXXXX -dtls1_2 -cert server.crt -CAfile rootCA.crt -cipher DHE-RSA-AES128-GCM-SHA256&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;TLS client: Regular Linux machine connected to it. Example command below.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;openssl s_client -connect &amp;lt;IP_OF_SERVER&amp;gt;:&amp;lt;PORT&amp;gt; -dtls1_2 -CAfile rootCA.crt -cipher DHE-RSA-AES128-GCM-SHA256&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Digging deeper I observed that the file descriptor 0 (stdin) was closed by the pkcs11-sss library which was then used for connection with access manager. Due to which no input was read from stdin.&lt;/P&gt;&lt;P&gt;See code snippet below.&lt;/P&gt;&lt;P&gt;File: sss_pkcs11_pal_core.c&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Riz_0-1669017552936.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/201086i243CF7763D1C4DEC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Riz_0-1669017552936.png" alt="Riz_0-1669017552936.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;There are no comments near the code that would explain why this is being done.&lt;BR /&gt;Can you please look into this?&lt;/P&gt;&lt;P&gt;Regards&lt;BR /&gt;Riz&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 08:07:45 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1557010#M1013</guid>
      <dc:creator>Riz</dc:creator>
      <dc:date>2022-11-21T08:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1558376#M1015</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Could you please look into this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Riz&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 09:06:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1558376#M1015</guid>
      <dc:creator>Riz</dc:creator>
      <dc:date>2022-11-23T09:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1559713#M1016</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/177498"&gt;@Riz&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SM_Close() is used to close&amp;nbsp;the communication with the Security Module before establishing a new connection. maybe you can redirect the stdin to some file/queue instead for communication between threads in this case.&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, 25 Nov 2022 03:58:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1559713#M1016</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2022-11-25T03:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1573021#M1028</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I tried looking into the code further, below is my observation.&lt;/P&gt;&lt;P&gt;The SM_Close(NULL,0) call from within the&amp;nbsp;sss_pkcs11_pal_core.c is closing fd "0" even though there is no prior connection to the Security module.&lt;/P&gt;&lt;P&gt;This is because the "pSockCtx-&amp;gt;sockfd" is initialized as static so gets a default value of 0.&lt;BR /&gt;See below code for reference from&amp;nbsp;smComSocket_linux.c line ~50.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;typedef struct
{
    int sockfd;
    char * ipString;
} socket_Context_t;

static socket_Context_t sockCtx;
static socket_Context_t* pSockCtx = (socket_Context_t *)&amp;amp;sockCtx;

static U32 smComSocket_GetATR(U8* pAtr, U16* atrLen);

U16 smComSocket_Close()
{
    if (pSockCtx-&amp;gt;ipString != NULL)
        free(pSockCtx-&amp;gt;ipString);
    pSockCtx-&amp;gt;ipString = NULL;
    close(pSockCtx-&amp;gt;sockfd);
    return SW_OK;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think&amp;nbsp;&lt;SPAN&gt;adding a static initializer to sockfd (may be -1) and a condition to check if fd is valid before closing should fix the issue.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Let me know your thoughts.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have another question:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Why is the SM_Close(NULL, 0) call inside the&amp;nbsp;sss_pkcs11_pal_core.c file required at all??&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Riz_0-1671613053403.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/205119i193AF0932A9F7988/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Riz_0-1671613053403.png" alt="Riz_0-1671613053403.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I temporarily removed the SM_Close(NULL, 0) and ran pkcs11 operations concurrently. Everything seemed to work fine.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Can you clarify on why this is really required at first place please?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards,&lt;BR /&gt;Riz&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2022 08:57:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1573021#M1028</guid>
      <dc:creator>Riz</dc:creator>
      <dc:date>2022-12-21T08:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1573839#M1030</link>
      <description>&lt;P&gt;Hello Riz,&lt;/P&gt;
&lt;P&gt;thanks for reporting this, check is ongoing what is the purpose of this SM_Close().&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;BR /&gt;Michael&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 17:30:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1573839#M1030</guid>
      <dc:creator>michaelsalfer</dc:creator>
      <dc:date>2022-12-22T17:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1574397#M1040</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/177498"&gt;@Riz&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the purpose is still to&amp;nbsp;&lt;SPAN&gt;close any possible communication with the Security Module before establishing a new connection, and I am suspecting if removing this would lead to open session failed error, let me check with the expert for double confirm.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks for your patience!&lt;/SPAN&gt;&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>Mon, 26 Dec 2022 03:24:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1574397#M1040</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2022-12-26T03:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1574640#M1048</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/59276"&gt;@Kan_Li&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply, do let me know once you get an answer from the expert.&lt;/P&gt;&lt;P&gt;Also, please look into my earlier comment &lt;A href="https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1573021/highlight/true#M1028" target="_self"&gt;here&lt;/A&gt;&amp;nbsp;, even if it is required, looks like by default fd 0 (stdin) is closed (due to static initialisation) even though there is no prior connection and this should ideally not happen, right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let me know your thoughts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Riz&lt;/P&gt;</description>
      <pubDate>Mon, 26 Dec 2022 15:09:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1574640#M1048</guid>
      <dc:creator>Riz</dc:creator>
      <dc:date>2022-12-26T15:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: TLS issue: Re-using fd 0 (stdin) for access manager connection from pkcs11-sss library</title>
      <link>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1574737#M1051</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/177498"&gt;@Riz&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From my understanding,&amp;nbsp;SM_Close() closes any current connection over the interface and prepares for a new connection, it also applies for the case when there is no&amp;nbsp;&lt;SPAN&gt;prior connection, but I think your workaround should also be feasible, you may try to exclude this case with some condition as you mentioned.&lt;/SPAN&gt;&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>Tue, 27 Dec 2022 02:03:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Secure-Authentication/TLS-issue-Re-using-fd-0-stdin-for-access-manager-connection-from/m-p/1574737#M1051</guid>
      <dc:creator>Kan_Li</dc:creator>
      <dc:date>2022-12-27T02:03:03Z</dc:date>
    </item>
  </channel>
</rss>

