From e8109a20e8a1c7ae224acce19f9208ba9df7ec76 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 15 May 2019 17:36:07 +0200 Subject: [PATCH] c lib: Allow the ssh keys to be configured --- git_test/gitjournal.c | 18 +++++++++++++----- git_test/gitjournal.h | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/git_test/gitjournal.c b/git_test/gitjournal.c index cc620253..ca31ec81 100644 --- a/git_test/gitjournal.c +++ b/git_test/gitjournal.c @@ -273,6 +273,17 @@ int fetch_progress(const git_transfer_progress *stats, void *payload) return 0; } +char *g_public_key_path = NULL; +char *g_private_key_path = NULL; +char *g_passcode = NULL; + +void gj_set_ssh_keys_paths(char *public_key, char *private_key, char *passcode) +{ + g_public_key_path = public_key; + g_private_key_path = private_key; + g_passcode = passcode; +} + int credentials_cb(git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) { @@ -286,11 +297,8 @@ int credentials_cb(git_cred **out, const char *url, const char *username_from_ur return -1; } - char *publickey = "/Users/vishesh/.ssh/id_rsa.pub"; - char *privatekey = "/Users/vishesh/.ssh/id_rsa"; - char *passphrase = ""; - - int err = git_cred_ssh_key_new(out, username_from_url, publickey, privatekey, passphrase); + int err = git_cred_ssh_key_new(out, username_from_url, + g_public_key_path, g_private_key_path, g_passcode); if (err < 0) { printf("Credentials CB Error"); diff --git a/git_test/gitjournal.h b/git_test/gitjournal.h index aef78816..cf326d4c 100644 --- a/git_test/gitjournal.h +++ b/git_test/gitjournal.h @@ -15,6 +15,8 @@ int gj_git_reset_hard(char *git_base_path, char *ref); int gj_git_add(char *git_base_path, char *pattern); int gj_git_rm(char *git_base_path, char *pattern); +void gj_set_ssh_keys_paths(char *public_key, char *private_key, char *passcode); + typedef struct { char *message;