| 1 | /* |
| 2 | Copyright (c) 2017, MariaDB Corporation. |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; version 2 of the License. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 16 | |
| 17 | #include <my_global.h> |
| 18 | #include <ssl_compat.h> |
| 19 | |
| 20 | /* |
| 21 | The check is only done for OpenSSL 1.1.x. |
| 22 | It could run for OpenSSL 1.0.x but it doesn't make much sense |
| 23 | and it hits this bug: |
| 24 | https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/1594748 |
| 25 | */ |
| 26 | |
| 27 | #ifndef HAVE_OPENSSL11 |
| 28 | int check_openssl_compatibility() |
| 29 | { |
| 30 | return 0; |
| 31 | } |
| 32 | #else |
| 33 | #include <openssl/evp.h> |
| 34 | |
| 35 | static uint testing, alloc_size, alloc_count; |
| 36 | |
| 37 | static void *coc_malloc(size_t size, const char *f __attribute__((unused)), |
| 38 | int l __attribute__((unused))) |
| 39 | { |
| 40 | if (unlikely(testing)) |
| 41 | { |
| 42 | alloc_size+= size; |
| 43 | alloc_count++; |
| 44 | } |
| 45 | return malloc(size); |
| 46 | } |
| 47 | |
| 48 | int check_openssl_compatibility() |
| 49 | { |
| 50 | EVP_CIPHER_CTX *evp_ctx; |
| 51 | EVP_MD_CTX *md5_ctx; |
| 52 | |
| 53 | if (!CRYPTO_set_mem_functions(coc_malloc, NULL, NULL)) |
| 54 | return 0; |
| 55 | |
| 56 | testing= 1; |
| 57 | alloc_size= alloc_count= 0; |
| 58 | evp_ctx= EVP_CIPHER_CTX_new(); |
| 59 | EVP_CIPHER_CTX_free(evp_ctx); |
| 60 | if (alloc_count != 1 || !alloc_size || alloc_size > EVP_CIPHER_CTX_SIZE) |
| 61 | return 1; |
| 62 | |
| 63 | alloc_size= alloc_count= 0; |
| 64 | md5_ctx= EVP_MD_CTX_new(); |
| 65 | EVP_MD_CTX_free(md5_ctx); |
| 66 | if (alloc_count != 1 || !alloc_size || alloc_size > EVP_MD_CTX_SIZE) |
| 67 | return 1; |
| 68 | |
| 69 | testing= 0; |
| 70 | return 0; |
| 71 | } |
| 72 | #endif |
| 73 | |