Archived Forum Post

Index of archived forum posts

Question:

SSH key cannot load from an OpenSSH private-key file format

Jun 24 '14 at 01:13

if (!key.LoadText(m_identityFile,outString))
{
key.LastErrorText(errorString);
m_logger.AddInfo(_bstr_t(L"LoadText is not able to load key file: ")+m_identityFile +errorString.getString(), "NucleusLink.SFTPHandler.Connect:" ); return false;
}
if(key.get_IsRsaKey())
{
outString = key.toOpenSshPrivateKey(false);
}
if(!key.FromOpenSshPrivateKey(outString))
{
key.LastErrorText(errorString);
}; }

The above code snippet is failing for my VC++ code throwing the below error:

ChilkatLog: FromOpenSshPrivateKey: DllDate: Aug 23 2013 ChilkatVersion: 9.4.1.46 UnlockPrefix: REDPRASSH Username: ATLGILBARCOPC:j1015615 Architecture: Little Endian; 32-bit Language: Visual C++ 7.0 VerboseLogging: 0 privateKey_content: -----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY----- Not encrypted. validating the key... RSA key is 0 b

I could not figure out what is the error here.

another error is:

for the code snippet:

    **if(!m_identityFile.length() != 0)
    {
        bAuthenticate = m_sftpClient.AuthenticatePw(m_strUserName, m_strPwd);
    }
    else
    {
        bAuthenticate = m_sftpClient.AuthenticatePk(m_strUserName, key);
    }**

Authenticate failed for User: BOS_SFTPChilkatLog: Connect_SFtp: DllDate: Aug 23 2013 ChilkatVersion: 9.4.1.46 UnlockPrefix: * Username: Architecture: Little Endian; 32-bit Language: Visual C++ 7.0 VerboseLogging: 0 SftpVersion: 0 hostname: 192.168.1.1 port: 22 ConnectTimeoutMs_1: 30000 calling ConnectSocket2 IPV6 enabled connect with NO heartbeat. This is an IPV4 numeric address... AddrInfoList:*

I have a quick delivery to my client tomorrow, this is the last stage of my development, any help from you will be highly appreciated.


Answer

You are using an older version of the library - I recommend trying again with the latest version, just in case the problem has already been fixed.

If the problem persists, please post your code and entire contents of the LastErrorText property in <pre></pre> tags.


Answer

But, my code runs on vc++ 7.1 will the latest version will support my existing code ? which version do you suggest for me is the best suit ? I need it to run for both on 32 as well as 64 bit version off OS


Answer

Though my code runs on VC++ 7.1, I have tried using chilkat-9.5.0-x86-vc6 version of chilkat library,

getting the below error while loading the key file from the piece key.FromOpenSshPrivateKey(outString):

if(m_sftpClient.UnlockComponent(chilkatUnlockCode))
    {
        key.put_Password("secret");

if (!key.LoadText(m_identityFile,outString))
        {
            key.LastErrorText(errorString);
            m_logger.AddInfo(_bstr_t(L"LoadText is not able to load key file: ")+m_identityFile +errorString.getString(), "NucleusLink.SFTPHandler.Connect:" );
            return false;
        }

if(key.get_IsRsaKey())
        {
            outString = key.toOpenSshPrivateKey(false);
        }

if (!key.FromOpenSshPrivateKey(outString))
        {
            key.LastErrorText(errorString);
            m_logger.AddInfo( _bstr_t(L"FromOpenSshPrivateKey has wrong pass phrase or key file: ")+m_identityFile +errorString.getString()
                              , "NucleusLink.SFTPHandler.Connect:"
                            );
            //return false;
        }
 FromOpenSshPrivateKey has wrong pass phrase or key file: C:\Program Files\BlueCube\POSLink\Bin\boskeyChilkatLog: FromOpenSshPrivateKey: DllDate: Jun 10 2014 ChilkatVersion: 9.5.0.40 UnlockPrefix: REDPRASSH Username: ATLGILBARCOPC:j1015615 Architecture: Little Endian; 32-bit Language: Visual C++ 6.0 VerboseLogging: 0 fromOpenSshPrivateKey: decryptPem: Not encrypted. --decryptPem validating the key... validateDecryptedKey:

Answer

The above seems to be working and authenticating my private key, but the trick here is on the 2nd try its authenticating failing for the first try.

if(!m_identityFile.length() != 0)
        {
            bAuthenticate = m_sftpClient.AuthenticatePw(m_strUserName, m_strPwd);
        }
        else if(m_isConnected)
        {
            for(int i=0; !bAuthenticate && i<=3;)
            {
                bAuthenticate = m_sftpClient.AuthenticatePk(m_strUserName, key);

if(!bAuthenticate)
                {
                    i++;
                    m_logger.AddInfo(_bstr_t(L"Retrying Authentication for: ")+m_strUserName+errorString.getString(), "NucleusLink.SFTPHandler.Connect" );
                }
                else
                {
                    break;
                }
            }
        }