使用ckosshtunnel和AuthenticatePk进行身份验证失败或部分成功

时间:2019-04-24 12:28:35

标签: chilkat

我遇到一个问题,可以通过命令行通过公钥连接到ssh服务器:

ssh -N -L 12345:127.0.0.1:22 -i /Users/kylehankinson/.ssh/id_rsa USER@HOST

但是如果我通过代码尝试相同的操作:

CkoSshKey * sshkey = [[CkoSshKey alloc] init];
sshkey.Password = @"blahblah";

NSString * privateKeyString = [sshkey LoadText: @"/Users/kylehankinson/.ssh/id_rsa"];

if(![sshkey FromPuttyPrivateKey: privateKeyString])
{
    NSLog(@"Had failure: %@", sshkey.LastErrorText);
    return;
}

CkoSshTunnel *ssh = [[CkoSshTunnel alloc] init];
success = [ssh Connect: @"HOST" port: @(22)];
if (success != YES)
{
    NSLog(@"%@",ssh.LastErrorText);
    return;
}

success = [ssh AuthenticatePk: @"USER"
                   privateKey: sshkey];
if(!success)
{
    NSLog(@"%@",ssh.LastErrorXml);
    return;
}

我收到以下错误:

<ChilkatLog>
  <AuthenticatePK>
    <DllDate>Apr 16 2019</DllDate>
    <ChilkatVersion>9.5.0.78</ChilkatVersion>
    <UnlockPrefix>xxxxxxx</UnlockPrefix>
    <Architecture>Little Endian; 64-bit</Architecture>
    <Language>Cocoa Objective-C</Language>
    <VerboseLogging>0</VerboseLogging>
    <login>sshtunnel</login>
    <sshAuthenticatePk>
      <keyFingerprint>ssh-rsa 2048 xxxxxxxxx</keyFingerprint>
      <requestUserAuthService>
        <sendServiceRequest>
          <svcName>ssh-userauth</svcName>
          <SentServiceReq>ssh-userauth</SentServiceReq>
        </sendServiceRequest>
        <info>ssh-userauth service accepted.</info>
      </requestUserAuthService>
      <info>Using an RSA key.</info>
      <info>Sent public-key request.</info>
      <AuthList>publickey,password</AuthList>
      <rsaSigLen>256</rsaSigLen>
      <info>Sent public-key request with signature.</info>
      <error>Authentication failed or partial success. (4)</error>
      <PartialSuccess4>0</PartialSuccess4>
      <AuthList>publickey,password</AuthList>
      <error>Publickey authentication failed..</error>
    </sshAuthenticatePk>
    <error>Failed.</error>
  </AuthenticatePK>
</ChilkatLog>

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

感谢凯尔,

这是一个修复此问题的新版本: https://chilkatdownload.com/prerelease/chilkat-9.5.0-macosx-objc-1408.zip

问题的根源与OpenSSH密钥格式的私钥blob格式有关。解析RSA关键部分的顺序不正确。 (如果密钥是从PuTTY私钥格式.ppk加载的,则没有问题。。)

PS>上面的下载链接是临时的,以后将不再有效。