Archived Forum Post

Index of archived forum posts

Question:

AuthenticatePwPk error

Dec 15 '12 at 11:21

I am trying to access a server that uses private keys and a passwords and the private key is password protected. "AuthenticatePwPk" returns the following error:

XTypeError in method 'CkSFtp_AuthenticatePwPk', argument 4 of type 'CkSshKey &'

Here is the abbreviated code (removed error checking statements). I am using (cut/paste from examples):

...
$success = $sftp->Connect($hostname,$port);
$key = new chilkat::CkSshKey();
$privKey = $key->loadText("file_name.priv");
$success = $key->put_Password( 'password_string' );
$success = $key->FromOpenSshPrivateKey($privKey);
$success = $sftp->AuthenticatePwPk( $username, $password, $privKey );
$success = $sftp->InitializeSftp();
...

Notes:

[1] The return value of '$key->put_Password( 'password_string' );' is FALSE, but the output of lastErrorText() shows the command as SUCCESSFUL:

ChilkatLog:
  LoadText:
    DllDate: Aug  5 2012
    UnlockPrefix: XXXXXXXX
    Username: XXXXXXX:xxxxxxxx
    Architecture: Little Endian; 64-bit
    Language: Windows Perl
    VerboseLogging: 0
    Success.
  --LoadText
--ChilkatLog

[2] the execution of '$key->FromOpenSshPrivateKey($privKey)' is successful as well: (Truncated log...)

ChilkatLog:
  FromOpenSshPrivateKey:
    DllDate: Aug  5 2012
    UnlockPrefix: XXXXXXX
    Username: XXXXXXX:xxxxxxx
    Architecture: Little Endian; 64-bit
    Language: Windows Perl
    VerboseLogging: 0
    privateKey_content: -----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,1EBF897D8C6DF543

XseAwPPEO3jtDYICB+oy87NKaieLXMMhRiDwNEvZaLI+nif6Gl5bJElLi7hDMHlO
XLgsJJEGDVRfNCkAy73R6Vpfck7QBO2li/qUmX3I9xYFs18641ErSOl1DE/zTCTw
...
O4MyyhGr2gQeio6mikIiLHcbeGubv6u58rpX7HpFw6hIgcMnnoKAq1uGL1ptymvl
4C+opfc0VkWK+S7M6im7Nw5nNlL1uQwZOs8/jy86V6lG9/+lkrJxUQ==
-----END RSA PRIVATE KEY-----

    PEM is encrypted.
...
      InvQLen: 128
    --RsaDerToKey
    toXmlTest:
      keyType: RSA private key
    --toXmlTest
    Success.
  --FromOpenSshPrivateKey
--ChilkatLog

Can anyone tell me what is happening here? Thanks.


Answer

put_Password does not return a value. In C++ terms, it is a "void" function. Also, because the internal implementation is trivial (it simply sets the internal property string value), it can never fail and no LastErrorText is saved for it. Therefore (1) trying to get a return value from it is meaningless and (2) the LastErrorText you are showing is from the previous method call ("loadText") which you can clearly see within the LastErrorText because the 2nd line (after the "ChilkatLog:" shows the name of the method.

The following error indicates a problem with your application code:

XTypeError in method 'CkSFtp_AuthenticatePwPk', argument 4 of type 'CkSshKey &'

This is easy to spot. The error complains of argument 4 (the ssh key object). You must pass it an ssh key object. Therefore, you should pass "$key", not "$privKey".

The $key->loadText method returns a boolean, not an SSH key object. I'm not sure why you would think it returns a key object -- it's not documented that way. This line makes no sense:

$privKey = $key->loadText("file_name.priv");
It should be:
$success = $key->loadText("file_name.priv");


Answer

Thank you for point #1. As to point #2 ... that is not how it works ... at least on my system. Also, if you review the example at the following URL http://www.example-code.com/perl/sftp_pubkeyAuthenication.asp, you will see the following command line: "$privKey = $key->loadText("myPrivateKey.pem");"

Here is the code, updated per your suggestion:

print "- Load private key\n";
$key = new chilkat::CkSshKey();
$success = $key->loadText("file_name.priv");
print "success = $success\n";
print $key->lastErrorText() . "\n";

Here is the output. As you can see, unlike you wrote "$key->loadText method returns a boolean", the output is the key. What am I missing?

- Load private key
success = -----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,1EBF897D8C6DF543

XseAwPPEO3jtDYICB+oy87NKaieLXMMhRiDwNEvZaLI+nif6Gl5bJElLi7hDMHlO
...[deleted]...
4C+opfc0VkWK+S7M6im7Nw5nNlL1uQwZOs8/jy86V6lG9/+lkrJxUQ==
-----END RSA PRIVATE KEY-----

ChilkatLog:
  LoadText:
    DllDate: Aug  5 2012
    UnlockPrefix: xxxxxx
    Username: xxxxxxx:yyyyyy
    Architecture: Little Endian; 64-bit
    Language: Windows Perl
    VerboseLogging: 0
    Success.
  --LoadText
--ChilkatLog