Skip to content

Commit c8f4b56

Browse files
authored
Merge pull request libgit2#5974 from libgit2/ethomson/dlopen_ssl
Dynamically load OpenSSL (optionally)
2 parents a09d436 + 314469f commit c8f4b56

31 files changed

+1852
-546
lines changed

.github/workflows/nightly.yml

+35
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ jobs:
5959
CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
6060
CMAKE_GENERATOR: Ninja
6161
os: ubuntu-latest
62+
- # Xenial, Clang, OpenSSL (dynamically loaded)
63+
container:
64+
name: xenial
65+
env:
66+
CC: clang
67+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
68+
CMAKE_GENERATOR: Ninja
69+
os: ubuntu-latest
6270
- # Focal, Clang 10, mbedTLS, MemorySanitizer
6371
container:
6472
name: focal
@@ -115,6 +123,14 @@ jobs:
115123
PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
116124
SKIP_NEGOTIATE_TESTS: true
117125
os: ubuntu-latest
126+
- # CentOS 7, OpenSSL (dynamically loaded)
127+
container:
128+
name: centos7
129+
env:
130+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
131+
PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
132+
SKIP_NEGOTIATE_TESTS: true
133+
os: ubuntu-latest
118134
- # CentOS 8
119135
container:
120136
name: centos8
@@ -124,6 +140,15 @@ jobs:
124140
SKIP_NEGOTIATE_TESTS: true
125141
SKIP_SSH_TESTS: true
126142
os: ubuntu-latest
143+
- # CentOS 8, OpenSSL (dynamically loaded)
144+
container:
145+
name: centos8
146+
env:
147+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
148+
PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
149+
SKIP_NEGOTIATE_TESTS: true
150+
SKIP_SSH_TESTS: true
151+
os: ubuntu-latest
127152
- # macOS
128153
os: macos-10.15
129154
env:
@@ -180,6 +205,16 @@ jobs:
180205
BUILD_PATH: D:\Temp\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
181206
SKIP_SSH_TESTS: true
182207
SKIP_NEGOTIATE_TESTS: true
208+
- # Bionic, GCC, OpenSSL (dynamically loaded)
209+
container:
210+
name: bionic
211+
dockerfile: bionic
212+
env:
213+
CC: gcc
214+
CMAKE_GENERATOR: Ninja
215+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON
216+
RUN_INVASIVE_TESTS: true
217+
os: ubuntu-latest
183218
- # Bionic, x86, Clang, OpenSSL
184219
container:
185220
name: bionic-x86

COPYING

+109-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ The GNU C Library is free software; you can redistribute it and/or
420420
modify it under the terms of the GNU Lesser General Public
421421
License as published by the Free Software Foundation; either
422422
version 2.1 of the License, or (at your option) any later version.
423-
423+
424424
The GNU C Library is distributed in the hope that it will be useful,
425425
but WITHOUT ANY WARRANTY; without even the implied warranty of
426426
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@@ -1019,3 +1019,111 @@ following restrictions are are met:
10191019
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
10201020
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
10211021
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1022+
1023+
----------------------------------------------------------------------
1024+
1025+
Portions of the OpenSSL headers are included under the OpenSSL license:
1026+
1027+
Copyright (C) 1995-1998 Eric Young ([email protected])
1028+
All rights reserved.
1029+
1030+
This package is an SSL implementation written
1031+
by Eric Young ([email protected]).
1032+
The implementation was written so as to conform with Netscapes SSL.
1033+
1034+
This library is free for commercial and non-commercial use as long as
1035+
the following conditions are aheared to. The following conditions
1036+
apply to all code found in this distribution, be it the RC4, RSA,
1037+
lhash, DES, etc., code; not just the SSL code. The SSL documentation
1038+
included with this distribution is covered by the same copyright terms
1039+
except that the holder is Tim Hudson ([email protected]).
1040+
1041+
Copyright remains Eric Young's, and as such any Copyright notices in
1042+
the code are not to be removed.
1043+
If this package is used in a product, Eric Young should be given attribution
1044+
as the author of the parts of the library used.
1045+
This can be in the form of a textual message at program startup or
1046+
in documentation (online or textual) provided with the package.
1047+
1048+
Redistribution and use in source and binary forms, with or without
1049+
modification, are permitted provided that the following conditions
1050+
are met:
1051+
1. Redistributions of source code must retain the copyright
1052+
notice, this list of conditions and the following disclaimer.
1053+
2. Redistributions in binary form must reproduce the above copyright
1054+
notice, this list of conditions and the following disclaimer in the
1055+
documentation and/or other materials provided with the distribution.
1056+
3. All advertising materials mentioning features or use of this software
1057+
must display the following acknowledgement:
1058+
"This product includes cryptographic software written by
1059+
Eric Young ([email protected])"
1060+
The word 'cryptographic' can be left out if the rouines from the library
1061+
being used are not cryptographic related :-).
1062+
4. If you include any Windows specific code (or a derivative thereof) from
1063+
the apps directory (application code) you must include an acknowledgement:
1064+
"This product includes software written by Tim Hudson ([email protected])"
1065+
1066+
THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
1067+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1068+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1069+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1070+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1071+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1072+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1073+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1074+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1075+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1076+
SUCH DAMAGE.
1077+
1078+
The licence and distribution terms for any publically available version or
1079+
derivative of this code cannot be changed. i.e. this code cannot simply be
1080+
copied and put under another distribution licence
1081+
[including the GNU Public Licence.]
1082+
1083+
====================================================================
1084+
Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
1085+
1086+
Redistribution and use in source and binary forms, with or without
1087+
modification, are permitted provided that the following conditions
1088+
are met:
1089+
1090+
1. Redistributions of source code must retain the above copyright
1091+
notice, this list of conditions and the following disclaimer.
1092+
1093+
2. Redistributions in binary form must reproduce the above copyright
1094+
notice, this list of conditions and the following disclaimer in
1095+
the documentation and/or other materials provided with the
1096+
distribution.
1097+
1098+
3. All advertising materials mentioning features or use of this
1099+
software must display the following acknowledgment:
1100+
"This product includes software developed by the OpenSSL Project
1101+
for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
1102+
1103+
4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
1104+
endorse or promote products derived from this software without
1105+
prior written permission. For written permission, please contact
1106+
1107+
1108+
5. Products derived from this software may not be called "OpenSSL"
1109+
nor may "OpenSSL" appear in their names without prior written
1110+
permission of the OpenSSL Project.
1111+
1112+
6. Redistributions of any form whatsoever must retain the following
1113+
acknowledgment:
1114+
"This product includes software developed by the OpenSSL Project
1115+
for use in the OpenSSL Toolkit (http://www.openssl.org/)"
1116+
1117+
THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
1118+
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1119+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1120+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
1121+
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1122+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1123+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1124+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1125+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1126+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1127+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1128+
OF THE POSSIBILITY OF SUCH DAMAGE.
1129+

cmake/SelectHTTPSBackend.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ IF(USE_HTTPS)
108108
LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
109109
ELSEIF (USE_HTTPS STREQUAL "WinHTTP")
110110
# WinHTTP setup was handled in the WinHTTP-specific block above
111+
ELSEIF (USE_HTTPS STREQUAL "OpenSSL-Dynamic")
112+
SET(GIT_OPENSSL 1)
113+
SET(GIT_OPENSSL_DYNAMIC 1)
114+
LIST(APPEND LIBGIT2_LIBS dl)
111115
ELSE()
112116
MESSAGE(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
113117
ENDIF()

deps/ntlmclient/CMakeLists.txt

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
FILE(GLOB SRC_NTLMCLIENT "ntlm.c" "unicode_builtin.c" "util.c")
1+
FILE(GLOB SRC_NTLMCLIENT "ntlm.c" "ntlm.h" "util.c" "util.h")
22
LIST(SORT SRC_NTLMCLIENT)
33

44
ADD_DEFINITIONS(-DNTLM_STATIC=1)
55

66
DISABLE_WARNINGS(implicit-fallthrough)
77

8+
IF(USE_ICONV)
9+
ADD_DEFINITIONS(-DUNICODE_ICONV=1)
10+
FILE(GLOB SRC_NTLMCLIENT_UNICODE "unicode_iconv.c" "unicode_iconv.h")
11+
ELSE()
12+
ADD_DEFINITIONS(-DUNICODE_BUILTIN=1)
13+
FILE(GLOB SRC_NTLMCLIENT_UNICODE "unicode_builtin.c" "unicode_builtin.h")
14+
ENDIF()
15+
816
IF(USE_HTTPS STREQUAL "SecureTransport")
917
ADD_DEFINITIONS(-DCRYPT_COMMONCRYPTO)
10-
SET(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c")
18+
SET(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c" "crypt_commoncrypto.h")
1119
# CC_MD4 has been deprecated in macOS 10.15.
1220
SET_SOURCE_FILES_PROPERTIES("crypt_commoncrypto.c" COMPILE_FLAGS "-Wno-deprecated")
1321
ELSEIF(USE_HTTPS STREQUAL "OpenSSL")
1422
ADD_DEFINITIONS(-DCRYPT_OPENSSL)
1523
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
16-
SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c")
24+
SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h")
25+
ELSEIF(USE_HTTPS STREQUAL "OpenSSL-Dynamic")
26+
ADD_DEFINITIONS(-DCRYPT_OPENSSL)
27+
ADD_DEFINITIONS(-DCRYPT_OPENSSL_DYNAMIC)
28+
SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h")
1729
ELSEIF(USE_HTTPS STREQUAL "mbedTLS")
1830
ADD_DEFINITIONS(-DCRYPT_MBEDTLS)
1931
INCLUDE_DIRECTORIES(${MBEDTLS_INCLUDE_DIR})
20-
SET(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c")
32+
SET(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c" "crypt_mbedtls.h")
2133
ELSE()
2234
MESSAGE(FATAL_ERROR "Unable to use libgit2's HTTPS backend (${USE_HTTPS}) for NTLM crypto")
2335
ENDIF()
2436

25-
ADD_LIBRARY(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_CRYPTO})
37+
ADD_LIBRARY(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_UNICODE} ${SRC_NTLMCLIENT_CRYPTO})

deps/ntlmclient/crypt.h

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#ifndef PRIVATE_CRYPT_COMMON_H__
1010
#define PRIVATE_CRYPT_COMMON_H__
1111

12+
#include "ntlmclient.h"
13+
#include "ntlm.h"
14+
1215
#if defined(CRYPT_OPENSSL)
1316
# include "crypt_openssl.h"
1417
#elif defined(CRYPT_MBEDTLS)
@@ -25,40 +28,42 @@
2528

2629
typedef unsigned char ntlm_des_block[CRYPT_DES_BLOCKSIZE];
2730

31+
typedef struct ntlm_crypt_ctx ntlm_crypt_ctx;
32+
33+
extern bool ntlm_crypt_init(ntlm_client *ntlm);
34+
2835
extern bool ntlm_random_bytes(
29-
ntlm_client *ntlm,
3036
unsigned char *out,
37+
ntlm_client *ntlm,
3138
size_t len);
3239

3340
extern bool ntlm_des_encrypt(
3441
ntlm_des_block *out,
42+
ntlm_client *ntlm,
3543
ntlm_des_block *plaintext,
3644
ntlm_des_block *key);
3745

3846
extern bool ntlm_md4_digest(
3947
unsigned char out[CRYPT_MD4_DIGESTSIZE],
48+
ntlm_client *ntlm,
4049
const unsigned char *in,
4150
size_t in_len);
4251

43-
extern ntlm_hmac_ctx *ntlm_hmac_ctx_init(void);
44-
45-
extern bool ntlm_hmac_ctx_reset(ntlm_hmac_ctx *ctx);
46-
4752
extern bool ntlm_hmac_md5_init(
48-
ntlm_hmac_ctx *ctx,
53+
ntlm_client *ntlm,
4954
const unsigned char *key,
5055
size_t key_len);
5156

5257
extern bool ntlm_hmac_md5_update(
53-
ntlm_hmac_ctx *ctx,
58+
ntlm_client *ntlm,
5459
const unsigned char *data,
5560
size_t data_len);
5661

5762
extern bool ntlm_hmac_md5_final(
5863
unsigned char *out,
5964
size_t *out_len,
60-
ntlm_hmac_ctx *ctx);
65+
ntlm_client *ntlm);
6166

62-
extern void ntlm_hmac_ctx_free(ntlm_hmac_ctx *ctx);
67+
extern void ntlm_crypt_shutdown(ntlm_client *ntlm);
6368

6469
#endif /* PRIVATE_CRYPT_COMMON_H__ */

deps/ntlmclient/crypt_commoncrypto.c

+20-20
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
#include "ntlm.h"
1919
#include "crypt.h"
2020

21+
bool ntlm_crypt_init(ntlm_client *ntlm)
22+
{
23+
memset(&ntlm->crypt_ctx, 0, sizeof(ntlm_crypt_ctx));
24+
return true;
25+
}
26+
2127
bool ntlm_random_bytes(
22-
ntlm_client *ntlm,
2328
unsigned char *out,
29+
ntlm_client *ntlm,
2430
size_t len)
2531
{
2632
int fd, ret;
@@ -49,11 +55,14 @@ bool ntlm_random_bytes(
4955

5056
bool ntlm_des_encrypt(
5157
ntlm_des_block *out,
58+
ntlm_client *ntlm,
5259
ntlm_des_block *plaintext,
5360
ntlm_des_block *key)
5461
{
5562
size_t written;
5663

64+
NTLM_UNUSED(ntlm);
65+
5766
CCCryptorStatus result = CCCrypt(kCCEncrypt,
5867
kCCAlgorithmDES, kCCOptionECBMode,
5968
key, sizeof(ntlm_des_block), NULL,
@@ -65,56 +74,47 @@ bool ntlm_des_encrypt(
6574

6675
bool ntlm_md4_digest(
6776
unsigned char out[CRYPT_MD4_DIGESTSIZE],
77+
ntlm_client *ntlm,
6878
const unsigned char *in,
6979
size_t in_len)
7080
{
81+
NTLM_UNUSED(ntlm);
7182
return !!CC_MD4(in, in_len, out);
7283
}
7384

74-
ntlm_hmac_ctx *ntlm_hmac_ctx_init(void)
75-
{
76-
return calloc(1, sizeof(ntlm_hmac_ctx));
77-
}
78-
79-
bool ntlm_hmac_ctx_reset(ntlm_hmac_ctx *ctx)
80-
{
81-
memset(ctx, 0, sizeof(ntlm_hmac_ctx));
82-
return true;
83-
}
84-
8585
bool ntlm_hmac_md5_init(
86-
ntlm_hmac_ctx *ctx,
86+
ntlm_client *ntlm,
8787
const unsigned char *key,
8888
size_t key_len)
8989
{
90-
CCHmacInit(&ctx->native, kCCHmacAlgMD5, key, key_len);
90+
CCHmacInit(&ntlm->crypt_ctx.hmac, kCCHmacAlgMD5, key, key_len);
9191
return true;
9292
}
9393

9494
bool ntlm_hmac_md5_update(
95-
ntlm_hmac_ctx *ctx,
95+
ntlm_client *ntlm,
9696
const unsigned char *data,
9797
size_t data_len)
9898
{
99-
CCHmacUpdate(&ctx->native, data, data_len);
99+
CCHmacUpdate(&ntlm->crypt_ctx.hmac, data, data_len);
100100
return true;
101101
}
102102

103103
bool ntlm_hmac_md5_final(
104104
unsigned char *out,
105105
size_t *out_len,
106-
ntlm_hmac_ctx *ctx)
106+
ntlm_client *ntlm)
107107
{
108108
if (*out_len < CRYPT_MD5_DIGESTSIZE)
109109
return false;
110110

111-
CCHmacFinal(&ctx->native, out);
111+
CCHmacFinal(&ntlm->crypt_ctx.hmac, out);
112112

113113
*out_len = CRYPT_MD5_DIGESTSIZE;
114114
return true;
115115
}
116116

117-
void ntlm_hmac_ctx_free(ntlm_hmac_ctx *ctx)
117+
void ntlm_crypt_shutdown(ntlm_client *ntlm)
118118
{
119-
free(ctx);
119+
NTLM_UNUSED(ntlm);
120120
}

0 commit comments

Comments
 (0)