aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2022-12-30 15:55:21 -0500
committerAdam Harrison <adamdharrison@gmail.com>2022-12-30 15:55:21 -0500
commitd8b06848ee250b8a378a75dd8f7c7cd36d0ce6e2 (patch)
treef53ea3a462a13f28883cbdd6ac2c53e03c6aa3b9
parenteec2fe103b82e3e76175aa7bcaacb85734602f75 (diff)
downloadlite-xl-plugin-manager-d8b06848ee250b8a378a75dd8f7c7cd36d0ce6e2.tar.gz
lite-xl-plugin-manager-d8b06848ee250b8a378a75dd8f7c7cd36d0ce6e2.zip
Added in debug for tls.
-rwxr-xr-xbuild.sh2
-rw-r--r--src/lpm.c12
-rw-r--r--src/lpm.lua4
3 files changed, 14 insertions, 4 deletions
diff --git a/build.sh b/build.sh
index 29b4932..4aab5c0 100755
--- a/build.sh
+++ b/build.sh
@@ -22,7 +22,7 @@ if [[ "$@" != *"-lz"* ]]; then
LDFLAGS="$LDFLAGS -lz"
fi
if [[ "$@" != *"-lmbedtls"* && "$@" != *"-lmbedcrypto"* ]]; then
- [ ! -e "lib/mbedtls-2.27.0/build" ] && cd lib/mbedtls-2.27.0 && mkdir build && cd build && CFLAGS="-DMBEDTLS_MD4_C=1 -w" cmake .. $CMAKE_DEFAULT_FLAGS -G "Unix Makefiles" -DENABLE_TESTING=OFF -DENABLE_PROGRAMS=OFF $SSL_CONFIGURE && CFLAGS="-DMBEDTLS_MD4_C=1 -w" $MAKE -j $JOBS && $MAKE install && cd ../../../
+ [ ! -e "lib/mbedtls-2.27.0/build" ] && cd lib/mbedtls-2.27.0 && mkdir build && cd build && CFLAGS="$CFLAGS_MBEDTLS -DMBEDTLS_MD4_C=1 -w" cmake .. $CMAKE_DEFAULT_FLAGS -G "Unix Makefiles" -DENABLE_TESTING=OFF -DENABLE_PROGRAMS=OFF $SSL_CONFIGURE && CFLAGS="$CFLAGS_MBEDTLS -DMBEDTLS_MD4_C=1 -w" $MAKE -j $JOBS && $MAKE install && cd ../../../
LDFLAGS="$LDFLAGS -lmbedtls -lmbedx509 -lmbedcrypto"
fi
if [[ "$@" != *"-lgit2"* ]]; then
diff --git a/src/lpm.c b/src/lpm.c
index 8fe1a25..15a1bfe 100644
--- a/src/lpm.c
+++ b/src/lpm.c
@@ -32,6 +32,9 @@
#include <mbedtls/ssl.h>
#include <mbedtls/error.h>
#include <mbedtls/net.h>
+#ifdef MBEDTLS_DEBUG_C
+ #include <mbedtls/debug.h>
+#endif
#include <zlib.h>
#include <microtar.h>
@@ -405,6 +408,9 @@ static int luaL_mbedtls_error(lua_State* L, int code, const char* str, ...) {
return luaL_error(L, "%s: %s", vsnbuffer, mbed_buffer);
}
+static void lpm_tls_debug(void *ctx, int level, const char *file, int line, const char *str) {
+ fprintf(stderr, "%s:%04d: |%d| %s", file, line, level, str);
+}
static int lpm_certs(lua_State* L) {
const char* type = luaL_checkstring(L, 1);
@@ -430,6 +436,10 @@ static int lpm_certs(lua_State* L) {
mbedtls_ssl_conf_authmode(&ssl_config, MBEDTLS_SSL_VERIFY_REQUIRED);
mbedtls_ssl_conf_rng(&ssl_config, mbedtls_ctr_drbg_random, &drbg_context);
mbedtls_ssl_conf_read_timeout(&ssl_config, 5000);
+ #ifdef MBEDTLS_DEBUG_C
+ mbedtls_debug_set_threshold(5);
+ mbedtls_ssl_conf_dbg(&ssl_config, lpm_tls_debug, NULL);
+ #endif
has_setup_ssl = 1;
if (strcmp(type, "dir") == 0) {
git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, NULL, path);
@@ -461,7 +471,7 @@ static int lpm_certs(lua_State* L) {
}
fclose(file);
CertCloseStore(hSystemStore, 0);
- #elif __APPLE__ // https://developer.apple.com/forums/thread/691009; also pulled from curl
+ #elif __APPLE__ // https://developer.apple.com/forums/thread/691009; see also curl
/*CFStringRef keys[] = { kSecClass, kSecMatchLimit, kSecReturnRef };
CFTypeRef values[] = { kSecClassCertificate, kSecMatchLimitAll, kCFBooleanTrue };
CFDictionaryRef query = CFDictionaryCreate(
diff --git a/src/lpm.lua b/src/lpm.lua
index d875cdf..16c20f0 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -1440,8 +1440,8 @@ local function parse_arguments(arguments, options)
if flag_type == "flag" then
args[option] = true
elseif flag_type == "string" or flag_type == "number" then
- if not value then
- if i < #arguments then error("option " .. option .. " requires a " .. flag_type) end
+ if not value or value == "" then
+ if i == #arguments then error("option " .. option .. " requires a " .. flag_type) end
value = arguments[i+1]
i = i + 1
end