Libgit2:SSH:无法交换加密密钥

时间:2018-05-08 19:41:40

标签: c++ credentials libgit2

背景

我正在编写一个基于Linux的应用程序(gtkmm),它使用github上托管的单个私有存储库。该应用程序正在使用Libgit2SSH Authentication。 SSH密钥是在外部创建的,并且在通过终端进行测试时工作正常。

我目前有两个问题很可能与之相关。

问题1:无法交换加密密钥。

尝试克隆私有存储库时会发生此问题;并且是从Libgit2打印的错误。 我试图使用git_cred_ssh_key_newgit_cred_ssh_key_from_agent但没有成功。

问题2:永远不会调用Credential Callback。

我确保已为克隆选项,提取选项和远程回调设置了此(Credential回调);并且git_clone()正在使用它。 一个cout在里面从未打印过;与GUI相关的文本也没有设置;所以我已经确定这永远不会被召唤。

int repoManager_gitCredentialCallback(git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload){
cout << "Credentials Called" << endl;
string temp_publicKey = Global::programHomeDir + "/id_rsa.pub";
string temp_privateKey = Global::programHomeDir + "/id_rsa";
return git_cred_ssh_key_new( out, username_from_url, temp_publicKey.c_str(), temp_privateKey.c_str(), "" );
} // END - gitCredentialCallback

克隆功能:

// SET GIT OPTIONS:
git_clone_options repoManager_cloneOptions = GIT_CLONE_OPTIONS_INIT;
git_fetch_options repoManager_fetchOptions = GIT_FETCH_OPTIONS_INIT;
//  git_remote_callbacks repoManager_remoteCallbacks = GIT_REMOTE_CALLBACKS_INIT;

repoManager_cloneOptions.fetch_opts.callbacks.credentials = repoManager_gitCredentialCallback;
repoManager_cloneOptions.fetch_opts.callbacks.transfer_progress = repoManager_fetchProgress;
repoManager_cloneOptions.fetch_opts.callbacks.payload = this;
repoManager_cloneOptions.remote_cb = repoManager_gitRemoteCallback;

//  repoManager_remoteCallbacks.credentials = repoManager_gitCredentialCallback;
//  repoManager_cloneOptions.fetch_opts = repoManager_fetchOptions;

repoManager_fetchOptions.callbacks.transfer_progress = repoManager_fetchProgress;
repoManager_fetchOptions.callbacks.credentials = repoManager_gitCredentialCallback;
repoManager_fetchOptions.callbacks.payload = this;
repoManager_fetchOptions.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;


if(git_clone(&repoManager_repo, repoManager_RepoURL, Global::launcherRepositoryDir.c_str(), &repoManager_cloneOptions) < 0){
    RepoManager_thread_taskFailed("Failed to Clone the repository.", "FAIL: Clone failed.");
    return;
} // END - Git Clone

1 个答案:

答案 0 :(得分:0)

(评论的代表不足,所以希望这很有帮助)

此错误通常意味着在设置SSH通道时存在协议级问题,这就是您无法发送凭据的原因(认为密码协商失败)。

了解libssh2使用的密码后端(我怀疑它是OpenSSL)以及它的版本及其后端版本会很有帮助。 请注意,libssh2最近才获得对现在是事实上的安全方法的支持(因此它在终端中起作用的原因:您的客户端具有与服务器相同的支持密码)。