Skip to content

Commit b9c8bd2

Browse files
committed
Add OpenSSL 1.1.0 compatibility
Summary: Build Mysql against Openssl 1.1.0. Most of the changes revolve around API changes that make OpenSSL structs opaque. Member access is removed in favor of accessor functions. All changes are version checked by ifdefs Test Plan: Change tools repo to build against 1.1.0 instead of boringssl Test failures were all due to default cipher differences between the libraries, or counter differences. Test results are consistent with those seen before 1eb03e8 Reviewers: anca, avr, mung Reviewed By: mung Subscribers: jkedgar, subodh, webscalesql-eng@fb.com, ssl-diffs@fb.com, anca Differential Revision: https://phabricator.intern.facebook.com/D4743119 Tasks: 16592623 Signature: t1:4743119:1491349557:1d8055b1d4c9ffa2bfd278fa7373149cf6b98df9
1 parent 5962f90 commit b9c8bd2

16 files changed

+97
-56
lines changed

Diff for: fbson/FbsonStream.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define __STDC_FORMAT_MACROS
3131
#endif
3232

33-
#include <inttypes.h>
33+
#include <cinttypes>
3434
#include <iostream>
3535

3636
namespace fbson {

Diff for: include/violite.h

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ int vio_getnameinfo(const struct sockaddr *sa,
148148
/* Set yaSSL to use same type as MySQL do for socket handles */
149149
typedef my_socket YASSL_SOCKET_T;
150150
#define YASSL_SOCKET_T_DEFINED
151+
#ifdef __cplusplus
152+
#include <cinttypes>
153+
#else
154+
#include <inttypes.h>
155+
#endif
151156
#include <openssl/ssl.h>
152157
#include <openssl/err.h>
153158

Diff for: mysys_ssl/my_aes_openssl.cc

+16-17
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ aes_evp_type(const my_aes_opmode mode)
112112
}
113113
}
114114

115-
116115
int my_aes_encrypt(const unsigned char *source, uint32 source_length,
117116
unsigned char *dest,
118117
const unsigned char *key, uint32 key_length,
119118
enum my_aes_opmode mode, const unsigned char *iv)
120119
{
121-
EVP_CIPHER_CTX ctx;
120+
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
121+
if (!ctx) return MY_AES_BAD_DATA;
122122
const EVP_CIPHER *cipher= aes_evp_type(mode);
123123
int u_len, f_len;
124124
/* The real key to be used for encryption */
@@ -128,23 +128,23 @@ int my_aes_encrypt(const unsigned char *source, uint32 source_length,
128128
if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0 && !iv))
129129
return MY_AES_BAD_DATA;
130130

131-
if (!EVP_EncryptInit(&ctx, cipher, rkey, iv))
131+
if (!EVP_EncryptInit(ctx, cipher, rkey, iv))
132132
goto aes_error; /* Error */
133-
if (!EVP_CIPHER_CTX_set_padding(&ctx, 1))
133+
if (!EVP_CIPHER_CTX_set_padding(ctx, 1))
134134
goto aes_error; /* Error */
135-
if (!EVP_EncryptUpdate(&ctx, dest, &u_len, source, source_length))
135+
if (!EVP_EncryptUpdate(ctx, dest, &u_len, source, source_length))
136136
goto aes_error; /* Error */
137137

138-
if (!EVP_EncryptFinal_ex(&ctx, dest + u_len, &f_len))
138+
if (!EVP_EncryptFinal_ex(ctx, dest + u_len, &f_len))
139139
goto aes_error; /* Error */
140140

141-
EVP_CIPHER_CTX_cleanup(&ctx);
141+
EVP_CIPHER_CTX_free(ctx);
142142
return u_len + f_len;
143143

144144
aes_error:
145145
/* need to explicitly clean up the error if we want to ignore it */
146146
ERR_clear_error();
147-
EVP_CIPHER_CTX_cleanup(&ctx);
147+
EVP_CIPHER_CTX_free(ctx);
148148
return MY_AES_BAD_DATA;
149149
}
150150

@@ -155,7 +155,8 @@ int my_aes_decrypt(const unsigned char *source, uint32 source_length,
155155
enum my_aes_opmode mode, const unsigned char *iv)
156156
{
157157

158-
EVP_CIPHER_CTX ctx;
158+
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
159+
if (!ctx) return MY_AES_BAD_DATA;
159160
const EVP_CIPHER *cipher= aes_evp_type(mode);
160161
int u_len, f_len;
161162

@@ -166,24 +167,22 @@ int my_aes_decrypt(const unsigned char *source, uint32 source_length,
166167
if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0 && !iv))
167168
return MY_AES_BAD_DATA;
168169

169-
EVP_CIPHER_CTX_init(&ctx);
170-
171-
if (!EVP_DecryptInit(&ctx, aes_evp_type(mode), rkey, iv))
170+
if (!EVP_DecryptInit(ctx, aes_evp_type(mode), rkey, iv))
172171
goto aes_error; /* Error */
173-
if (!EVP_CIPHER_CTX_set_padding(&ctx, 1))
172+
if (!EVP_CIPHER_CTX_set_padding(ctx, 1))
174173
goto aes_error; /* Error */
175-
if (!EVP_DecryptUpdate(&ctx, dest, &u_len, source, source_length))
174+
if (!EVP_DecryptUpdate(ctx, dest, &u_len, source, source_length))
176175
goto aes_error; /* Error */
177-
if (!EVP_DecryptFinal_ex(&ctx, dest + u_len, &f_len))
176+
if (!EVP_DecryptFinal_ex(ctx, dest + u_len, &f_len))
178177
goto aes_error; /* Error */
179178

180-
EVP_CIPHER_CTX_cleanup(&ctx);
179+
EVP_CIPHER_CTX_free(ctx);
181180
return u_len + f_len;
182181

183182
aes_error:
184183
/* need to explicitly clean up the error if we want to ignore it */
185184
ERR_clear_error();
186-
EVP_CIPHER_CTX_cleanup(&ctx);
185+
EVP_CIPHER_CTX_free(ctx);
187186
return MY_AES_BAD_DATA;
188187
}
189188

Diff for: sql-common/client.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,11 @@ static my_bool ssl_check_SAN_IPADD(Vio* vio, GENERAL_NAME* gn_entry)
26772677
DBUG_PRINT("info", ("alternative ip address in cert: %s", unused_ip));
26782678

26792679
/* Check ipv4 and ipv6 addresses */
2680+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
26802681
char* data= (char*) ASN1_STRING_data(gn_entry->d.ia5);
2682+
#else
2683+
char* data= (char*) ASN1_STRING_get0_data(gn_entry->d.ia5);
2684+
#endif
26812685
int length= ASN1_STRING_length(gn_entry->d.ia5);
26822686

26832687
struct sockaddr* sa= (struct sockaddr*) &vio->remote;
@@ -6898,7 +6902,7 @@ mysql_options4(MYSQL *mysql,enum mysql_option option,
68986902

68996903
// Increment the reference count
69006904
if (!take_ownership && ssl_session != NULL)
6901-
#ifdef OPENSSL_IS_BORINGSSL
6905+
#if defined(OPENSSL_IS_BORINGSSL) || OPENSSL_VERSION_NUMBER >= 0x10100000L
69026906
SSL_SESSION_up_ref(ssl_session);
69036907
#else
69046908
CRYPTO_add(&ssl_session->references, 1, CRYPTO_LOCK_SSL_SESSION);

Diff for: sql/des_key_file.cc

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
along with this program; if not, write to the Free Software Foundation,
1414
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
1515

16+
#include <cinttypes>
1617
#include "my_global.h" // HAVE_*
1718
#include "sql_priv.h"
1819
#include "des_key_file.h" // st_des_keyschedule, st_des_keyblock

Diff for: sql/item_strfunc.cc

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929

3030
/* May include caustic 3rd-party defs. Use early, so it can override nothing. */
31+
#include <cinttypes>
3132
#include "sha2.h"
3233
#include "my_global.h" // HAVE_*
3334

Diff for: sql/mysqld.cc

+9
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ extern "C" {
145145
#endif
146146
#endif
147147

148+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
149+
// Function removed after OpenSSL 1.1.0
150+
#define ERR_remove_state(x)
151+
#endif
152+
148153
using std::min;
149154
using std::max;
150155
using std::vector;
@@ -5241,7 +5246,11 @@ bool init_ssl()
52415246
{
52425247
#ifdef HAVE_OPENSSL
52435248
#ifndef HAVE_YASSL
5249+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
52445250
CRYPTO_malloc_init();
5251+
#else
5252+
OPENSSL_malloc_init();
5253+
#endif // OPENSSL_VERSION_NUMBER
52455254
#endif
52465255
ssl_start();
52475256
#ifndef EMBEDDED_LIBRARY

Diff for: sql/rpl_slave.cc

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ bool use_slave_mask = 0;
7474
MY_BITMAP slave_error_mask;
7575
char slave_skip_error_names[SHOW_VAR_FUNC_BUFF_SIZE];
7676

77+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
78+
// Function removed after OpenSSL 1.1.0
79+
#define ERR_remove_state(x)
80+
#endif
81+
7782
static unsigned long stop_wait_timeout;
7883
char* slave_load_tmpdir = 0;
7984
Master_info *active_mi= 0;

Diff for: sql/sql_class.cc

+20-16
Original file line numberDiff line numberDiff line change
@@ -5138,26 +5138,27 @@ void THD::get_definer(LEX_USER *definer)
51385138
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
51395139
void THD::set_connection_certificate() {
51405140
DBUG_ASSERT(connection_certificate_buf == nullptr);
5141-
connection_certificate_buf = get_peer_cert_info(false);
5141+
connection_certificate_buf = get_peer_cert_info(
5142+
false, &connection_certificate_buf_len);
51425143
}
51435144

51445145
void THD::reset_connection_certificate() {
51455146
if (connection_certificate_buf) {
5146-
BUF_MEM_free(connection_certificate_buf);
5147+
my_free(connection_certificate_buf);
51475148
connection_certificate_buf = nullptr;
5149+
connection_certificate_buf_len = 0;
51485150
}
51495151
}
51505152

51515153
const char *THD::connection_certificate() const {
5152-
return connection_certificate_buf ?
5153-
connection_certificate_buf->data : nullptr;
5154+
return connection_certificate_buf;
51545155
}
51555156

51565157
uint32 THD::connection_certificate_length() const {
5157-
return connection_certificate_buf ? connection_certificate_buf->length : 0;
5158+
return connection_certificate_buf ? connection_certificate_buf_len : 0;
51585159
}
51595160

5160-
BUF_MEM *THD::get_peer_cert_info(bool display)
5161+
char *THD::get_peer_cert_info(bool display, int *cert_len)
51615162
{
51625163
if (!vio_ok() || !net.vio->ssl_arg) {
51635164
return NULL;
@@ -5193,19 +5194,22 @@ BUF_MEM *THD::get_peer_cert_info(bool display)
51935194
return NULL;
51945195
}
51955196

5196-
// decouple buffer and close bio object
5197-
BUF_MEM *bufmem;
5198-
BIO_get_mem_ptr(bio, &bufmem);
5199-
(void) BIO_set_close(bio, BIO_NOCLOSE);
5200-
BIO_free(bio);
5201-
X509_free(cert);
5197+
int buflen = BIO_pending(bio);
5198+
char *cert_buf = (char *)my_malloc(buflen, MYF(MY_WME));
5199+
*cert_len = BIO_read(bio, cert_buf, buflen);
52025200

5203-
if (bufmem->length) {
5204-
return bufmem;
5201+
if (*cert_len == -1) {
5202+
*cert_len = 0;
5203+
my_free(cert_buf);
5204+
BIO_free(bio);
5205+
X509_free(cert);
5206+
return NULL;
52055207
}
52065208

5207-
BUF_MEM_free(bufmem);
5208-
return NULL;
5209+
DBUG_ASSERT(*cert_len <= buflen);
5210+
BIO_free(bio);
5211+
X509_free(cert);
5212+
return cert_buf;
52095213
}
52105214
#endif
52115215

Diff for: sql/sql_class.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@
5353
#include "sql_data_change.h"
5454
#include "my_atomic.h"
5555

56-
#include <openssl/ossl_typ.h>
57-
#include <openssl/pem.h>
58-
5956
#define FLAGSTR(V,F) ((V)&(F)?#F" ":"")
6057

6158
/**
@@ -4543,20 +4540,21 @@ class THD :public MDL_context_owner,
45434540
}
45444541

45454542
private:
4546-
BUF_MEM *connection_certificate_buf;
4543+
char* connection_certificate_buf;
4544+
int connection_certificate_buf_len;
45474545
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
45484546
void reset_connection_certificate();
45494547
public:
45504548
void set_connection_certificate();
45514549
const char *connection_certificate() const;
45524550
uint32 connection_certificate_length() const;
4553-
// The caller should take ownership of the BUF_MEM pointer. If display is
4551+
// The caller should take ownership of the char pointer. If display is
45544552
// set to true, the buffer will contain the certificate encoded in a human
45554553
// readable format, which can be used for display in information schema.
45564554
// Otherwise, it is encoded in the PEM format.
45574555
//
4558-
// Free this using the function BUF_MEM_free.
4559-
BUF_MEM *get_peer_cert_info(bool display);
4556+
// Free this using the function my_free.
4557+
char *get_peer_cert_info(bool display, int *cert_len);
45604558
#endif
45614559

45624560
#ifndef DBUG_OFF

Diff for: sql/sql_show.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -2953,10 +2953,11 @@ int fill_schema_authinfo(THD* thd, TABLE_LIST* tables, Item* cond)
29532953
const char* cert = NULL;
29542954
size_t certlen = 0;
29552955
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
2956-
BUF_MEM *bufmem = tmp->get_peer_cert_info(/* display */ true);
2956+
int tmp_len;
2957+
char *bufmem = tmp->get_peer_cert_info(/* display */ true, &tmp_len);
29572958
if (bufmem != nullptr) {
2958-
cert = bufmem->data;
2959-
certlen = bufmem->length;
2959+
cert = bufmem;
2960+
certlen = tmp_len;
29602961
}
29612962
#endif
29622963

@@ -2967,7 +2968,7 @@ int fill_schema_authinfo(THD* thd, TABLE_LIST* tables, Item* cond)
29672968
}
29682969

29692970
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
2970-
BUF_MEM_free(bufmem);
2971+
my_free(bufmem);
29712972
#endif
29722973

29732974
if (schema_table_store_record(thd, table)) {

Diff for: storage/innobase/include/os0sync.h

-6
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,12 @@ typedef pthread_mutex_t fast_mutex_t;
7171
/** Native condition variable */
7272
typedef pthread_cond_t os_cond_t;
7373

74-
// The IS_SET macro conflicts with another macro of the same name. Since their
75-
// usage is mutually exclusive anyway, we define IS_SET (and related macros)
76-
// only when they are needed. To make use of the macros below in the
77-
// implementation file, the BIT63_NEEDED variable should be defined.
78-
#if defined(BIT63_NEEDED)
7974
#define BIT63 (1ULL << 63)
8075
#define INC_SIGNAL_COUNT(ev) { ++(ev)->stats; }
8176
#define SIGNAL_COUNT(ev) (static_cast<ib_int64_t>((ev)->stats & ~BIT63))
8277
#define SET_IS_SET(ev) { (ev)->stats |= BIT63; }
8378
#define CLEAR_IS_SET(ev) { (ev)->stats &= ~BIT63; }
8479
#define IS_SET(ev) (((ev)->stats & BIT63) != 0)
85-
#endif
8680

8781
#endif
8882

Diff for: storage/innobase/os/os0file.cc

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ The interface to the operating system file i/o primitives
3232
Created 10/21/1995 Heikki Tuuri
3333
*******************************************************/
3434

35-
#define BIT63_NEEDED
3635
#include "mysqld.h"
3736
#include "os0file.h"
3837

Diff for: storage/innobase/os/os0sync.cc

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ synchronization primitives.
2424
Created 9/6/1995 Heikki Tuuri
2525
*******************************************************/
2626

27-
#define BIT63_NEEDED
2827
#include "os0sync.h"
2928
#include "sync0rw.h"
3029
#ifdef UNIV_NONINL

Diff for: vio/viossl.c

+5
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,12 @@ static int ssl_init(SSL **out_ssl,
483483
for (j = 0; j < n; j++)
484484
{
485485
SSL_COMP *c = sk_SSL_COMP_value(ssl_comp_methods, j);
486+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
486487
DBUG_PRINT("info", (" %d: %s\n", c->id, c->name));
488+
#else
489+
DBUG_PRINT("info", (" %d: %s\n",
490+
SSL_COMP_get_id(c), SSL_COMP_get0_name(c)));
491+
#endif
487492
}
488493
}
489494
#endif

0 commit comments

Comments
 (0)