2022-09-14 00:53:12 +03:00
|
|
|
diff --git a/crypto/x509/x509_def.c b/crypto/x509/x509_def.c
|
2022-09-14 18:43:44 +03:00
|
|
|
index bfa8d7d..da3c743 100644
|
2022-09-14 00:53:12 +03:00
|
|
|
--- a/crypto/x509/x509_def.c
|
|
|
|
+++ b/crypto/x509/x509_def.c
|
2022-09-14 18:43:44 +03:00
|
|
|
@@ -11,25 +11,53 @@
|
2022-09-14 00:53:12 +03:00
|
|
|
#include "internal/cryptlib.h"
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/x509.h>
|
2022-09-14 18:43:44 +03:00
|
|
|
+#include <libgen.h> /* dirname */
|
|
|
|
+
|
|
|
|
+#ifdef __linux__
|
|
|
|
+#define __USE_GNU
|
|
|
|
+#endif
|
|
|
|
+#include <dlfcn.h> /* dladdr */
|
2022-09-14 00:53:12 +03:00
|
|
|
+
|
|
|
|
+const char *relocat0r(const char *suffix) {
|
2022-09-14 18:43:44 +03:00
|
|
|
+ static const char *prefix = NULL;
|
|
|
|
+ if (!prefix) {
|
|
|
|
+ // repeated calls to dladdr seem to return different values on Linux ¯\_(ツ)_/¯
|
|
|
|
+ Dl_info info;
|
|
|
|
+ if (!dladdr(relocat0r, &info)) { return NULL; }
|
|
|
|
+ prefix = dirname(info.dli_fname);
|
2022-09-14 00:53:12 +03:00
|
|
|
+ }
|
2022-09-14 18:43:44 +03:00
|
|
|
+ char *dir = malloc(strlen(prefix) + 4 + strlen(suffix) + 2);
|
|
|
|
+ if (!dir) { return NULL; }
|
|
|
|
+ sprintf(dir, "%s/../%s", prefix, suffix);
|
|
|
|
+ return dir;
|
2022-09-14 00:53:12 +03:00
|
|
|
+}
|
|
|
|
|
|
|
|
const char *X509_get_default_private_dir(void)
|
|
|
|
{
|
|
|
|
- return X509_PRIVATE_DIR;
|
|
|
|
+ static const char *dir = NULL;
|
2022-09-14 18:43:44 +03:00
|
|
|
+ if (!dir) dir = relocat0r("ssl/private");
|
2022-09-14 00:53:12 +03:00
|
|
|
+ return dir ?: X509_PRIVATE_DIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *X509_get_default_cert_area(void)
|
|
|
|
{
|
|
|
|
- return X509_CERT_AREA;
|
|
|
|
+ static const char *dir = NULL;
|
|
|
|
+ if (!dir) dir = relocat0r("ssl");
|
|
|
|
+ return dir ?: X509_CERT_AREA;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *X509_get_default_cert_dir(void)
|
|
|
|
{
|
|
|
|
- return X509_CERT_DIR;
|
|
|
|
+ static const char *dir = NULL;
|
2022-09-14 18:43:44 +03:00
|
|
|
+ if (!dir) dir = relocat0r("ssl/certs");
|
2022-09-14 00:53:12 +03:00
|
|
|
+ return dir ?: X509_CERT_DIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *X509_get_default_cert_file(void)
|
|
|
|
{
|
|
|
|
- return X509_CERT_FILE;
|
|
|
|
+ static const char *dir = NULL;
|
2022-09-14 18:43:44 +03:00
|
|
|
+ if (!dir) dir = relocat0r("ssl/cert.pem");
|
2022-09-14 00:53:12 +03:00
|
|
|
+ return dir ?: X509_CERT_FILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *X509_get_default_cert_dir_env(void)
|