<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sumeshvm20</title>
    <description>The latest articles on DEV Community by sumeshvm20 (@sumeshvm20).</description>
    <link>https://dev.to/sumeshvm20</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F969265%2F8d3fb0d1-61c9-4b0b-b936-dab49b71f589.png</url>
      <title>DEV Community: sumeshvm20</title>
      <link>https://dev.to/sumeshvm20</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sumeshvm20"/>
    <language>en</language>
    <item>
      <title>PK11_Authenticate failed with SEC_ERROR_BAD_PASSWORD (-8177)</title>
      <dc:creator>sumeshvm20</dc:creator>
      <pubDate>Wed, 09 Nov 2022 06:16:00 +0000</pubDate>
      <link>https://dev.to/sumeshvm20/pk11authenticate-failed-with-secerrorbadpassword-8177-pem</link>
      <guid>https://dev.to/sumeshvm20/pk11authenticate-failed-with-secerrorbadpassword-8177-pem</guid>
      <description>&lt;p&gt;Added a USB-token into nssdb path using modutil linking its vendor lib and slot/token name. The same nssdb path has been selected in certificate path in LibreOffice (Tools --&amp;gt; Options --&amp;gt; Security --&amp;gt; Certificate) and its listing the certificate correctly. &lt;/p&gt;

&lt;p&gt;Using libnss, we tried to simulate listing of certificates using the below code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PK11_SetPasswordFunc( GetPasswordFunction ) ; // GetPasswordFunction() returns the password string just like that without any user input.

if (NSS_InitReadWrite("/home/&amp;lt;user&amp;gt;/.pki/nssdb") == SECSuccess)  
{
    printf("\n-----------&amp;gt;NSS_Init successful");
    cert_handle = CERT_GetDefaultCertDB();

    if (cert_handle == NULL)
    {
        error = PR_GetError();
        printf("\n-----------&amp;gt;Unable to get cert_handle:%s (%d)", PR_ErrorToName(error), (int)error);
    }
    else
    {
        printf("\n-----------&amp;gt;Got cert_handle");

        PK11SlotList * slotList = PK11_GetAllTokens( CKM_INVALID_MECHANISM, PR_FALSE, PR_FALSE, NULL ) ;

        if(slotList == NULL) {

            error = PR_GetError();
            printf("\n-----------&amp;gt;PK11_GetAllTokens failed !:%s (%d)", PR_ErrorToName(error), (int)error);

        } else {

            PK11SlotInfo * usb_token = NULL;

            for (PK11SlotListElement* slotEle = slotList-&amp;gt;head ; slotEle != NULL; slotEle = slotEle-&amp;gt;next)
            {
                PK11SlotInfo * pSlot = slotEle-&amp;gt;slot ;

                if(pSlot != NULL)
                {
                    printf("\n-----------&amp;gt;SlotName(%s) TokenName(%s)", PK11_GetSlotName(pSlot), PK11_GetTokenName(pSlot));

                    if(PK11_IsHW(pSlot) &amp;amp;&amp;amp; PK11_IsRemovable(pSlot)){ // select the USB-token in the slots list

                        usb_token = pSlot;
                        break;
                    }
                } else {
                    printf("\n-----------&amp;gt;pSlot is empty");
                }
            }// end of for

            if(usb_token != NULL){

                printf("\n-----------&amp;gt;Found USB-TOKEN SlotName(%s) TokenName(%s)", PK11_GetSlotName(usb_token), PK11_GetTokenName(usb_token));

                if (PK11_NeedLogin(usb_token)){

                    SECStatus nRet = PK11_Authenticate(usb_token, PR_TRUE, NULL);

                    if(nRet != SECSuccess){
                        error = PR_GetError();
                        printf("\n-----------&amp;gt;PK11_Authenticate failed !:%s (%d)", PR_ErrorToName(error), (int)error);
                        printf("\n-----------&amp;gt;PORT_GetError() !:(%d)", PORT_GetError());

                        if(PORT_GetError() != SEC_ERROR_IO) {
                            printf("\n-----------&amp;gt;NoPassword Exception");
                        } else {
                            printf("\n-----------&amp;gt;Some other Exception");
                        }
                    }else {
                        printf("\n-----------&amp;gt;PK11_Authenticate successful !");
                    }
                }
            }

            PK11_FreeSlotList(slotList);
        }
    }

    PK11_SetPasswordFunc( NULL ) ;
    PK11_LogoutAll();
    NSS_Shutdown();
}
else
{

    error = PR_GetError();
    printf("\n-----------&amp;gt;NSS_Init failed:%s (%d)", PR_ErrorToName(error), (int)error);
}         
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We get the following error even though the returned password in GetPasswordFunction() is correct: PK11_Authenticate failed !:SEC_ERROR_BAD_PASSWORD (-8177)&lt;/p&gt;

&lt;p&gt;Any help is appreciated! Thanks in advance!&lt;/p&gt;

</description>
      <category>libreoffice</category>
      <category>nss</category>
    </item>
  </channel>
</rss>
