Skip to content

Commit b379c40

Browse files
committed
openssl: support OpenSSL 3 in dynamic mode
Try to load OpenSSL 3 libraries when compiled with OpenSSL-Dynamic support. Handle the deprecated symbol renaming of SSL_get_peer_certificate to SSL_get1_peer_certificate -- try to load the old name and if it fails, use the new one.
1 parent e9fb5af commit b379c40

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/libgit2/streams/openssl_dynamic.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int (*sk_num)(const void *sk);
9191
void *(*sk_value)(const void *sk, int i);
9292
void (*sk_free)(void *sk);
9393

94-
void *openssl_handle;
94+
static void *openssl_handle;
9595

9696
GIT_INLINE(void *) openssl_sym(int *err, const char *name, bool required)
9797
{
@@ -125,7 +125,8 @@ int git_openssl_stream_dynamic_init(void)
125125
(openssl_handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL &&
126126
(openssl_handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL &&
127127
(openssl_handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL &&
128-
(openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL) {
128+
(openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL &&
129+
(openssl_handle = dlopen("libssl.so.3", RTLD_NOW)) == NULL) {
129130
git_error_set(GIT_ERROR_SSL, "could not load ssl libraries");
130131
return -1;
131132
}
@@ -175,7 +176,6 @@ int git_openssl_stream_dynamic_init(void)
175176

176177
SSL_connect = (int (*)(SSL *))openssl_sym(&err, "SSL_connect", true);
177178
SSL_ctrl = (long (*)(SSL *, int, long, void *))openssl_sym(&err, "SSL_ctrl", true);
178-
SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get_peer_certificate", true);
179179
SSL_library_init = (int (*)(void))openssl_sym(&err, "SSL_library_init", false);
180180
SSL_free = (void (*)(SSL *))openssl_sym(&err, "SSL_free", true);
181181
SSL_get_error = (int (*)(SSL *, int))openssl_sym(&err, "SSL_get_error", true);
@@ -187,6 +187,10 @@ int git_openssl_stream_dynamic_init(void)
187187
SSL_shutdown = (int (*)(SSL *ssl))openssl_sym(&err, "SSL_shutdown", true);
188188
SSL_write = (int (*)(SSL *, const void *, int))openssl_sym(&err, "SSL_write", true);
189189

190+
if (!(SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get_peer_certificate", false))) {
191+
SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get1_peer_certificate", true);
192+
}
193+
190194
SSL_CTX_ctrl = (long (*)(SSL_CTX *, int, long, void *))openssl_sym(&err, "SSL_CTX_ctrl", true);
191195
SSL_CTX_free = (void (*)(SSL_CTX *))openssl_sym(&err, "SSL_CTX_free", true);
192196
SSL_CTX_new = (SSL_CTX *(*)(const SSL_METHOD *))openssl_sym(&err, "SSL_CTX_new", true);

src/util/hash/openssl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#ifdef GIT_OPENSSL_DYNAMIC
1111
# include <dlfcn.h>
1212

13-
int handle_count;
14-
void *openssl_handle;
13+
static int handle_count;
14+
static void *openssl_handle;
1515

1616
static int git_hash_openssl_global_shutdown(void)
1717
{
@@ -30,7 +30,8 @@ static int git_hash_openssl_global_init(void)
3030
(openssl_handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL &&
3131
(openssl_handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL &&
3232
(openssl_handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL &&
33-
(openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL) {
33+
(openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL &&
34+
(openssl_handle = dlopen("libssl.so.3", RTLD_NOW)) == NULL) {
3435
git_error_set(GIT_ERROR_SSL, "could not load ssl libraries");
3536
return -1;
3637
}

0 commit comments

Comments
 (0)