diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2023-01-22 13:42:00 -0500 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2023-01-22 13:42:00 -0500 |
commit | cb2b71a2eed6043ef3cb3b0f6b40845e825d9174 (patch) | |
tree | 302a4ce3ff87f3e96e70051b4bdb820cf6eacab3 /src/lpm.c | |
parent | 2e2c5a40d27f232e6d0cbc1e08edd228b4534576 (diff) | |
download | lite-xl-plugin-manager-cb2b71a2eed6043ef3cb3b0f6b40845e825d9174.tar.gz lite-xl-plugin-manager-cb2b71a2eed6043ef3cb3b0f6b40845e825d9174.zip |
Moved around initialization of git and certificates to make sure things work.v0.99992
Diffstat (limited to 'src/lpm.c')
-rw-r--r-- | src/lpm.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -302,9 +302,13 @@ static git_commit* git_retrieve_commit(git_repository* repository, const char* c // We move this out of main, because this is a significantly expensive function, // and we don't need to call it every time we run lpm. static int git_initialized = 0; +static int git_cert_type = 0; +static char git_cert_path[MAX_PATH]; static void git_init() { if (!git_initialized) { git_libgit2_init(); + if (git_cert_type) + git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, git_cert_type == 2 ? git_cert_path : NULL, git_cert_type == 1 ? git_cert_path : NULL); git_initialized = 1; } } @@ -495,6 +499,7 @@ static int lpm_certs(lua_State* L) { if (print_trace) { mbedtls_debug_set_threshold(5); mbedtls_ssl_conf_dbg(&ssl_config, lpm_tls_debug, NULL); + git_init(); git_trace_set(GIT_TRACE_TRACE, lpm_libgit2_debug); } #endif @@ -505,7 +510,10 @@ static int lpm_certs(lua_State* L) { } else { const char* path = luaL_checkstring(L, 2); if (strcmp(type, "dir") == 0) { - git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, NULL, path); + git_cert_type = 1; + if (git_initialized) + git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, NULL, path); + strncpy(git_cert_path, path, MAX_PATH); } else { if (strcmp(type, "system") == 0) { #if _WIN32 @@ -540,7 +548,10 @@ static int lpm_certs(lua_State* L) { return luaL_error(L, "can't use system certificates except on windows or mac"); #endif } - git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, path, NULL); + git_cert_type = 2; + if (git_initialized) + git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, path, NULL); + strncpy(git_cert_path, path, MAX_PATH); if ((status = mbedtls_x509_crt_parse_file(&x509_certificate, path)) != 0) return luaL_mbedtls_error(L, status, "mbedtls_x509_crt_parse_file failed to parse CA certificate %s", path); mbedtls_ssl_conf_ca_chain(&ssl_config, &x509_certificate, NULL); |