Skip to content

Commit

Permalink
Add compatibility with externally supplied OpenSSL 1.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
ned14 committed Apr 8, 2022
1 parent eb23a29 commit b399fe4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
36 changes: 20 additions & 16 deletions mysys_ssl/my_aes_openssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int my_aes_encrypt(const unsigned char *source, uint32 source_length,
enum my_aes_opmode mode, const unsigned char *iv,
bool padding)
{
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
const EVP_CIPHER *cipher= aes_evp_type(mode);
int u_len, f_len;
/* The real key to be used for encryption */
Expand All @@ -132,23 +132,25 @@ int my_aes_encrypt(const unsigned char *source, uint32 source_length,
if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0 && !iv))
return MY_AES_BAD_DATA;

if (!EVP_EncryptInit(&ctx, cipher, rkey, iv))
if (!EVP_EncryptInit(ctx, cipher, rkey, iv))
goto aes_error; /* Error */
if (!EVP_CIPHER_CTX_set_padding(&ctx, padding))
if (!EVP_CIPHER_CTX_set_padding(ctx, padding))
goto aes_error; /* Error */
if (!EVP_EncryptUpdate(&ctx, dest, &u_len, source, source_length))
if (!EVP_EncryptUpdate(ctx, dest, &u_len, source, source_length))
goto aes_error; /* Error */

if (!EVP_EncryptFinal(&ctx, dest + u_len, &f_len))
if (!EVP_EncryptFinal(ctx, dest + u_len, &f_len))
goto aes_error; /* Error */

EVP_CIPHER_CTX_cleanup(&ctx);
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
return u_len + f_len;

aes_error:
/* need to explicitly clean up the error if we want to ignore it */
ERR_clear_error();
EVP_CIPHER_CTX_cleanup(&ctx);
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
return MY_AES_BAD_DATA;
}

Expand All @@ -159,8 +161,8 @@ int my_aes_decrypt(const unsigned char *source, uint32 source_length,
bool padding)
{

EVP_CIPHER_CTX ctx;
const EVP_CIPHER *cipher= aes_evp_type(mode);
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
const EVP_CIPHER* cipher = aes_evp_type(mode);
int u_len, f_len;

/* The real key to be used for decryption */
Expand All @@ -170,24 +172,26 @@ int my_aes_decrypt(const unsigned char *source, uint32 source_length,
if (!cipher || (EVP_CIPHER_iv_length(cipher) > 0 && !iv))
return MY_AES_BAD_DATA;

EVP_CIPHER_CTX_init(&ctx);
EVP_CIPHER_CTX_init(ctx);

if (!EVP_DecryptInit(&ctx, aes_evp_type(mode), rkey, iv))
if (!EVP_DecryptInit(ctx, aes_evp_type(mode), rkey, iv))
goto aes_error; /* Error */
if (!EVP_CIPHER_CTX_set_padding(&ctx, padding))
if (!EVP_CIPHER_CTX_set_padding(ctx, padding))
goto aes_error; /* Error */
if (!EVP_DecryptUpdate(&ctx, dest, &u_len, source, source_length))
if (!EVP_DecryptUpdate(ctx, dest, &u_len, source, source_length))
goto aes_error; /* Error */
if (!EVP_DecryptFinal_ex(&ctx, dest + u_len, &f_len))
if (!EVP_DecryptFinal_ex(ctx, dest + u_len, &f_len))
goto aes_error; /* Error */

EVP_CIPHER_CTX_cleanup(&ctx);
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
return u_len + f_len;

aes_error:
/* need to explicitly clean up the error if we want to ignore it */
ERR_clear_error();
EVP_CIPHER_CTX_cleanup(&ctx);
EVP_CIPHER_CTX_cleanup(ctx);
EVP_CIPHER_CTX_free(ctx);
return MY_AES_BAD_DATA;
}

Expand Down
2 changes: 1 addition & 1 deletion sql-common/client_authentication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ RSA *rsa_init(MYSQL *mysql)

if (mysql->options.extension != NULL &&
mysql->options.extension->server_public_key_path != NULL &&
mysql->options.extension->server_public_key_path != '\0')
*mysql->options.extension->server_public_key_path != '\0')
{
pub_key_file= fopen(mysql->options.extension->server_public_key_path,
"r");
Expand Down
4 changes: 4 additions & 0 deletions vio/viosslfactories.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ static DH *get_dh2048(void)
DH *dh;
if ((dh=DH_new()))
{
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
DH_set0_pqg(dh, BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL), NULL, BN_bin2bn(dh2048_g, sizeof(dh2048_g), NULL));
#else
dh->p=BN_bin2bn(dh2048_p,sizeof(dh2048_p),NULL);
dh->g=BN_bin2bn(dh2048_g,sizeof(dh2048_g),NULL);
if (! dh->p || ! dh->g)
{
DH_free(dh);
dh=0;
}
#endif
}
return(dh);
}
Expand Down

0 comments on commit b399fe4

Please sign in to comment.