@@ -38,8 +38,115 @@ SSL_CTX *git__ssl_ctx;
38
38
39
39
#define GIT_SSL_DEFAULT_CIPHERS "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES128-SHA256:DHE-DSS-AES256-SHA256:DHE-DSS-AES128-SHA:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA"
40
40
41
- #if defined(GIT_THREADS ) && OPENSSL_VERSION_NUMBER < 0x10100000L
41
+ #if (defined(OPENSSL_VERSION_NUMBER ) && OPENSSL_VERSION_NUMBER < 0x10100000L ) || \
42
+ (defined(LIBRESSL_VERSION_NUMBER ) && LIBRESSL_VERSION_NUMBER < 0x20700000L )
43
+ # define OPENSSL_LEGACY_API
44
+ #endif
45
+
46
+ /*
47
+ * OpenSSL 1.1 made BIO opaque so we have to use functions to interact with it
48
+ * which do not exist in previous versions. We define these inline functions so
49
+ * we can program against the interface instead of littering the implementation
50
+ * with ifdefs. We do the same for OPENSSL_init_ssl.
51
+ */
52
+ #if defined(OPENSSL_LEGACY_API )
53
+ static int OPENSSL_init_ssl (int opts , void * settings )
54
+ {
55
+ GIT_UNUSED (opts );
56
+ GIT_UNUSED (settings );
57
+ SSL_load_error_strings ();
58
+ OpenSSL_add_ssl_algorithms ();
59
+ return 0 ;
60
+ }
61
+
62
+ static BIO_METHOD * BIO_meth_new (int type , const char * name )
63
+ {
64
+ BIO_METHOD * meth = git__calloc (1 , sizeof (BIO_METHOD ));
65
+ if (!meth ) {
66
+ return NULL ;
67
+ }
68
+
69
+ meth -> type = type ;
70
+ meth -> name = name ;
71
+
72
+ return meth ;
73
+ }
74
+
75
+ static void BIO_meth_free (BIO_METHOD * biom )
76
+ {
77
+ git__free (biom );
78
+ }
42
79
80
+ static int BIO_meth_set_write (BIO_METHOD * biom , int (* write ) (BIO * , const char * , int ))
81
+ {
82
+ biom -> bwrite = write ;
83
+ return 1 ;
84
+ }
85
+
86
+ static int BIO_meth_set_read (BIO_METHOD * biom , int (* read ) (BIO * , char * , int ))
87
+ {
88
+ biom -> bread = read ;
89
+ return 1 ;
90
+ }
91
+
92
+ static int BIO_meth_set_puts (BIO_METHOD * biom , int (* puts ) (BIO * , const char * ))
93
+ {
94
+ biom -> bputs = puts ;
95
+ return 1 ;
96
+ }
97
+
98
+ static int BIO_meth_set_gets (BIO_METHOD * biom , int (* gets ) (BIO * , char * , int ))
99
+
100
+ {
101
+ biom -> bgets = gets ;
102
+ return 1 ;
103
+ }
104
+
105
+ static int BIO_meth_set_ctrl (BIO_METHOD * biom , long (* ctrl ) (BIO * , int , long , void * ))
106
+ {
107
+ biom -> ctrl = ctrl ;
108
+ return 1 ;
109
+ }
110
+
111
+ static int BIO_meth_set_create (BIO_METHOD * biom , int (* create ) (BIO * ))
112
+ {
113
+ biom -> create = create ;
114
+ return 1 ;
115
+ }
116
+
117
+ static int BIO_meth_set_destroy (BIO_METHOD * biom , int (* destroy ) (BIO * ))
118
+ {
119
+ biom -> destroy = destroy ;
120
+ return 1 ;
121
+ }
122
+
123
+ static int BIO_get_new_index (void )
124
+ {
125
+ /* This exists as of 1.1 so before we'd just have 0 */
126
+ return 0 ;
127
+ }
128
+
129
+ static void BIO_set_init (BIO * b , int init )
130
+ {
131
+ b -> init = init ;
132
+ }
133
+
134
+ static void BIO_set_data (BIO * a , void * ptr )
135
+ {
136
+ a -> ptr = ptr ;
137
+ }
138
+
139
+ static void * BIO_get_data (BIO * a )
140
+ {
141
+ return a -> ptr ;
142
+ }
143
+
144
+ static const unsigned char * ASN1_STRING_get0_data (const ASN1_STRING * x )
145
+ {
146
+ return ASN1_STRING_data ((ASN1_STRING * )x );
147
+ }
148
+
149
+ # if defined(GIT_THREADS )
43
150
static git_mutex * openssl_locks ;
44
151
45
152
static void openssl_locking_function (
@@ -70,8 +177,8 @@ static void shutdown_ssl_locking(void)
70
177
git_mutex_free (& openssl_locks [i ]);
71
178
git__free (openssl_locks );
72
179
}
73
-
74
- #endif /* GIT_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L */
180
+ # endif /* GIT_THREADS */
181
+ #endif /* OPENSSL_LEGACY_API */
75
182
76
183
static BIO_METHOD * git_stream_bio_method ;
77
184
static int init_bio_method (void );
@@ -95,7 +202,6 @@ static void shutdown_ssl(void)
95
202
96
203
int git_openssl_stream_global_init (void )
97
204
{
98
- #ifdef GIT_OPENSSL
99
205
long ssl_opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 ;
100
206
const char * ciphers = git_libgit2__ssl_ciphers ();
101
207
@@ -104,13 +210,7 @@ int git_openssl_stream_global_init(void)
104
210
ssl_opts |= SSL_OP_NO_COMPRESSION ;
105
211
#endif
106
212
107
- #if OPENSSL_VERSION_NUMBER < 0x10100000L || \
108
- (defined(LIBRESSL_VERSION_NUMBER ) && LIBRESSL_VERSION_NUMBER < 0x20700000L )
109
- SSL_load_error_strings ();
110
- OpenSSL_add_ssl_algorithms ();
111
- #else
112
213
OPENSSL_init_ssl (0 , NULL );
113
- #endif
114
214
115
215
/*
116
216
* Load SSLv{2,3} and TLSv1 so that we can talk with servers
@@ -144,8 +244,6 @@ int git_openssl_stream_global_init(void)
144
244
return -1 ;
145
245
}
146
246
147
- #endif
148
-
149
247
git__on_shutdown (shutdown_ssl );
150
248
151
249
return 0 ;
@@ -160,7 +258,7 @@ static void threadid_cb(CRYPTO_THREADID *threadid)
160
258
161
259
int git_openssl_set_locking (void )
162
260
{
163
- #if defined(GIT_THREADS ) && OPENSSL_VERSION_NUMBER < 0x10100000L
261
+ #if defined(GIT_THREADS ) && defined( OPENSSL_LEGACY_API )
164
262
int num_locks , i ;
165
263
166
264
CRYPTO_THREADID_set_callback (threadid_cb );
@@ -179,7 +277,7 @@ int git_openssl_set_locking(void)
179
277
CRYPTO_set_locking_callback (openssl_locking_function );
180
278
git__on_shutdown (shutdown_ssl_locking );
181
279
return 0 ;
182
- #elif OPENSSL_VERSION_NUMBER >= 0x10100000L
280
+ #elif !defined( OPENSSL_LEGACY_API )
183
281
return 0 ;
184
282
#else
185
283
giterr_set (GITERR_THREAD , "libgit2 was not built with threads" );
0 commit comments