Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 1 | /* |
Matt Caswell | 3c2bdd7 | 2021-04-08 13:04:41 +0100 | [diff] [blame] | 2 | * Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved. |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 3 | * |
Richard Levitte | 909f1a2 | 2018-12-06 13:05:25 +0100 | [diff] [blame] | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 5 | * this file except in compliance with the License. You can obtain a copy |
| 6 | * in the file LICENSE in the source distribution or at |
| 7 | * https://www.openssl.org/source/license.html |
| 8 | */ |
| 9 | |
| 10 | #include <stdio.h> |
| 11 | #include <string.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <openssl/opensslv.h> |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 14 | #include <openssl/ssl.h> |
Dr. Matthias St. Pierre | 50cd476 | 2019-09-28 00:45:46 +0200 | [diff] [blame] | 15 | #include <openssl/types.h> |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 16 | #include "simpledynamic.h" |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 17 | |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 18 | typedef void DSO; |
| 19 | |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 20 | typedef const SSL_METHOD * (*TLS_method_t)(void); |
| 21 | typedef SSL_CTX * (*SSL_CTX_new_t)(const SSL_METHOD *meth); |
| 22 | typedef void (*SSL_CTX_free_t)(SSL_CTX *); |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 23 | typedef int (*OPENSSL_init_crypto_t)(uint64_t, void *); |
| 24 | typedef int (*OPENSSL_atexit_t)(void (*handler)(void)); |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 25 | typedef unsigned long (*ERR_get_error_t)(void); |
Richard Levitte | 3a63dbe | 2018-09-27 15:56:35 +0200 | [diff] [blame] | 26 | typedef unsigned long (*OPENSSL_version_major_t)(void); |
| 27 | typedef unsigned long (*OPENSSL_version_minor_t)(void); |
| 28 | typedef unsigned long (*OPENSSL_version_patch_t)(void); |
Bernd Edlinger | 26db324 | 2018-03-30 19:17:39 +0200 | [diff] [blame] | 29 | typedef DSO * (*DSO_dsobyaddr_t)(void (*addr)(void), int flags); |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 30 | typedef int (*DSO_free_t)(DSO *dso); |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 31 | |
Rich Salz | e0011aa | 2017-05-06 07:59:18 -0400 | [diff] [blame] | 32 | typedef enum test_types_en { |
| 33 | CRYPTO_FIRST, |
| 34 | SSL_FIRST, |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 35 | JUST_CRYPTO, |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 36 | DSO_REFTEST, |
| 37 | NO_ATEXIT |
Rich Salz | e0011aa | 2017-05-06 07:59:18 -0400 | [diff] [blame] | 38 | } TEST_TYPE; |
| 39 | |
| 40 | static TEST_TYPE test_type; |
| 41 | static const char *path_crypto; |
| 42 | static const char *path_ssl; |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 43 | static const char *path_atexit; |
Rich Salz | e0011aa | 2017-05-06 07:59:18 -0400 | [diff] [blame] | 44 | |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 45 | #ifdef SD_INIT |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 46 | |
Matt Caswell | 41999e7 | 2018-11-16 14:05:14 +0000 | [diff] [blame] | 47 | static int atexit_handler_done = 0; |
| 48 | |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 49 | static void atexit_handler(void) |
| 50 | { |
| 51 | FILE *atexit_file = fopen(path_atexit, "w"); |
| 52 | |
| 53 | if (atexit_file == NULL) |
| 54 | return; |
| 55 | |
| 56 | fprintf(atexit_file, "atexit() run\n"); |
| 57 | fclose(atexit_file); |
Matt Caswell | 41999e7 | 2018-11-16 14:05:14 +0000 | [diff] [blame] | 58 | atexit_handler_done++; |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 61 | static int test_lib(void) |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 62 | { |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 63 | SD ssllib = SD_INIT; |
| 64 | SD cryptolib = SD_INIT; |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 65 | SSL_CTX *ctx; |
| 66 | union { |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 67 | void (*func)(void); |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 68 | SD_SYM sym; |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 69 | } symbols[5]; |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 70 | TLS_method_t myTLS_method; |
| 71 | SSL_CTX_new_t mySSL_CTX_new; |
| 72 | SSL_CTX_free_t mySSL_CTX_free; |
| 73 | ERR_get_error_t myERR_get_error; |
Richard Levitte | 3a63dbe | 2018-09-27 15:56:35 +0200 | [diff] [blame] | 74 | OPENSSL_version_major_t myOPENSSL_version_major; |
| 75 | OPENSSL_version_minor_t myOPENSSL_version_minor; |
| 76 | OPENSSL_version_patch_t myOPENSSL_version_patch; |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 77 | OPENSSL_atexit_t myOPENSSL_atexit; |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 78 | int result = 0; |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 79 | |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 80 | switch (test_type) { |
| 81 | case JUST_CRYPTO: |
Matt Caswell | df5228e | 2018-11-15 14:50:52 +0000 | [diff] [blame] | 82 | case DSO_REFTEST: |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 83 | case NO_ATEXIT: |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 84 | case CRYPTO_FIRST: |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 85 | if (!sd_load(path_crypto, &cryptolib, SD_SHLIB)) { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 86 | fprintf(stderr, "Failed to load libcrypto\n"); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 87 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 88 | } |
| 89 | if (test_type != CRYPTO_FIRST) |
| 90 | break; |
| 91 | /* Fall through */ |
| 92 | |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 93 | case SSL_FIRST: |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 94 | if (!sd_load(path_ssl, &ssllib, SD_SHLIB)) { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 95 | fprintf(stderr, "Failed to load libssl\n"); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 96 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 97 | } |
| 98 | if (test_type != SSL_FIRST) |
| 99 | break; |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 100 | if (!sd_load(path_crypto, &cryptolib, SD_SHLIB)) { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 101 | fprintf(stderr, "Failed to load libcrypto\n"); |
| 102 | goto end; |
| 103 | } |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 104 | break; |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 107 | if (test_type == NO_ATEXIT) { |
| 108 | OPENSSL_init_crypto_t myOPENSSL_init_crypto; |
| 109 | |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 110 | if (!sd_sym(cryptolib, "OPENSSL_init_crypto", &symbols[0].sym)) { |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 111 | fprintf(stderr, "Failed to load OPENSSL_init_crypto symbol\n"); |
| 112 | goto end; |
| 113 | } |
| 114 | myOPENSSL_init_crypto = (OPENSSL_init_crypto_t)symbols[0].func; |
| 115 | if (!myOPENSSL_init_crypto(OPENSSL_INIT_NO_ATEXIT, NULL)) { |
| 116 | fprintf(stderr, "Failed to initialise libcrypto\n"); |
| 117 | goto end; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (test_type != JUST_CRYPTO |
| 122 | && test_type != DSO_REFTEST |
| 123 | && test_type != NO_ATEXIT) { |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 124 | if (!sd_sym(ssllib, "TLS_method", &symbols[0].sym) |
| 125 | || !sd_sym(ssllib, "SSL_CTX_new", &symbols[1].sym) |
| 126 | || !sd_sym(ssllib, "SSL_CTX_free", &symbols[2].sym)) { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 127 | fprintf(stderr, "Failed to load libssl symbols\n"); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 128 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 129 | } |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 130 | myTLS_method = (TLS_method_t)symbols[0].func; |
| 131 | mySSL_CTX_new = (SSL_CTX_new_t)symbols[1].func; |
| 132 | mySSL_CTX_free = (SSL_CTX_free_t)symbols[2].func; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 133 | ctx = mySSL_CTX_new(myTLS_method()); |
| 134 | if (ctx == NULL) { |
| 135 | fprintf(stderr, "Failed to create SSL_CTX\n"); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 136 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 137 | } |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 138 | mySSL_CTX_free(ctx); |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 141 | if (!sd_sym(cryptolib, "ERR_get_error", &symbols[0].sym) |
| 142 | || !sd_sym(cryptolib, "OPENSSL_version_major", &symbols[1].sym) |
| 143 | || !sd_sym(cryptolib, "OPENSSL_version_minor", &symbols[2].sym) |
| 144 | || !sd_sym(cryptolib, "OPENSSL_version_patch", &symbols[3].sym) |
| 145 | || !sd_sym(cryptolib, "OPENSSL_atexit", &symbols[4].sym)) { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 146 | fprintf(stderr, "Failed to load libcrypto symbols\n"); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 147 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 148 | } |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 149 | myERR_get_error = (ERR_get_error_t)symbols[0].func; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 150 | if (myERR_get_error() != 0) { |
| 151 | fprintf(stderr, "Unexpected ERR_get_error() response\n"); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 152 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 153 | } |
Richard Levitte | 00c8f1b | 2018-03-14 17:31:20 +0100 | [diff] [blame] | 154 | |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 155 | /* Library and header version should be identical in this test */ |
Richard Levitte | 3a63dbe | 2018-09-27 15:56:35 +0200 | [diff] [blame] | 156 | myOPENSSL_version_major = (OPENSSL_version_major_t)symbols[1].func; |
| 157 | myOPENSSL_version_minor = (OPENSSL_version_minor_t)symbols[2].func; |
| 158 | myOPENSSL_version_patch = (OPENSSL_version_patch_t)symbols[3].func; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 159 | if (myOPENSSL_version_major() != OPENSSL_VERSION_MAJOR |
| 160 | || myOPENSSL_version_minor() != OPENSSL_VERSION_MINOR |
| 161 | || myOPENSSL_version_patch() != OPENSSL_VERSION_PATCH) { |
| 162 | fprintf(stderr, "Invalid library version number\n"); |
Richard Levitte | 00c8f1b | 2018-03-14 17:31:20 +0100 | [diff] [blame] | 163 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 164 | } |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 165 | |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 166 | myOPENSSL_atexit = (OPENSSL_atexit_t)symbols[4].func; |
| 167 | if (!myOPENSSL_atexit(atexit_handler)) { |
| 168 | fprintf(stderr, "Failed to register atexit handler\n"); |
| 169 | goto end; |
| 170 | } |
| 171 | |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 172 | if (test_type == DSO_REFTEST) { |
| 173 | # ifdef DSO_DLFCN |
Richard Levitte | 84e68a1 | 2018-03-23 14:18:16 +0100 | [diff] [blame] | 174 | DSO_dsobyaddr_t myDSO_dsobyaddr; |
| 175 | DSO_free_t myDSO_free; |
| 176 | |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 177 | /* |
| 178 | * This is resembling the code used in ossl_init_base() and |
| 179 | * OPENSSL_atexit() to block unloading the library after dlclose(). |
| 180 | * We are not testing this on Windows, because it is done there in a |
| 181 | * completely different way. Especially as a call to DSO_dsobyaddr() |
| 182 | * will always return an error, because DSO_pathbyaddr() is not |
| 183 | * implemented there. |
| 184 | */ |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 185 | if (!sd_sym(cryptolib, "DSO_dsobyaddr", &symbols[0].sym) |
| 186 | || !sd_sym(cryptolib, "DSO_free", &symbols[1].sym)) { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 187 | fprintf(stderr, "Unable to load DSO symbols\n"); |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 188 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 189 | } |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 190 | |
| 191 | myDSO_dsobyaddr = (DSO_dsobyaddr_t)symbols[0].func; |
| 192 | myDSO_free = (DSO_free_t)symbols[1].func; |
| 193 | |
| 194 | { |
| 195 | DSO *hndl; |
| 196 | /* use known symbol from crypto module */ |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 197 | hndl = myDSO_dsobyaddr((void (*)(void))myERR_get_error, 0); |
| 198 | if (hndl == NULL) { |
| 199 | fprintf(stderr, "DSO_dsobyaddr() failed\n"); |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 200 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 201 | } |
Richard Levitte | cfaad17 | 2018-03-23 01:05:41 +0100 | [diff] [blame] | 202 | myDSO_free(hndl); |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 203 | } |
| 204 | # endif /* DSO_DLFCN */ |
| 205 | } |
| 206 | |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 207 | if (!sd_close(cryptolib)) { |
Matt Caswell | 41999e7 | 2018-11-16 14:05:14 +0000 | [diff] [blame] | 208 | fprintf(stderr, "Failed to close libcrypto\n"); |
| 209 | goto end; |
| 210 | } |
Pauli | 65bf029 | 2021-03-18 10:45:35 +1000 | [diff] [blame] | 211 | cryptolib = SD_INIT; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 212 | |
Matt Caswell | 41999e7 | 2018-11-16 14:05:14 +0000 | [diff] [blame] | 213 | if (test_type == CRYPTO_FIRST || test_type == SSL_FIRST) { |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 214 | if (!sd_close(ssllib)) { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 215 | fprintf(stderr, "Failed to close libssl\n"); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 216 | goto end; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 217 | } |
Pauli | 65bf029 | 2021-03-18 10:45:35 +1000 | [diff] [blame] | 218 | ssllib = SD_INIT; |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Matt Caswell | 41999e7 | 2018-11-16 14:05:14 +0000 | [diff] [blame] | 221 | # if defined(OPENSSL_NO_PINSHARED) \ |
| 222 | && defined(__GLIBC__) \ |
| 223 | && defined(__GLIBC_PREREQ) \ |
| 224 | && defined(OPENSSL_SYS_LINUX) |
| 225 | # if __GLIBC_PREREQ(2, 3) |
| 226 | /* |
| 227 | * If we didn't pin the so then we are hopefully on a platform that supports |
| 228 | * running atexit() on so unload. If not we might crash. We know this is |
| 229 | * true on linux since glibc 2.2.3 |
| 230 | */ |
| 231 | if (test_type != NO_ATEXIT && atexit_handler_done != 1) { |
| 232 | fprintf(stderr, "atexit() handler did not run\n"); |
| 233 | goto end; |
| 234 | } |
| 235 | # endif |
| 236 | # endif |
| 237 | |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 238 | result = 1; |
| 239 | end: |
Pauli | 65bf029 | 2021-03-18 10:45:35 +1000 | [diff] [blame] | 240 | if (cryptolib != SD_INIT) |
| 241 | sd_close(cryptolib); |
| 242 | if (ssllib != SD_INIT) |
| 243 | sd_close(ssllib); |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 244 | return result; |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 245 | } |
Rich Salz | e0011aa | 2017-05-06 07:59:18 -0400 | [diff] [blame] | 246 | #endif |
| 247 | |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 248 | |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 249 | /* |
| 250 | * shlibloadtest should not use the normal test framework because we don't want |
| 251 | * it to link against libcrypto (which the framework uses). The point of the |
| 252 | * test is to check dynamic loading and unloading of libcrypto/libssl. |
| 253 | */ |
| 254 | int main(int argc, char *argv[]) |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 255 | { |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 256 | const char *p; |
| 257 | |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 258 | if (argc != 5) { |
| 259 | fprintf(stderr, "Incorrect number of arguments\n"); |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 260 | return 1; |
| 261 | } |
| 262 | |
| 263 | p = argv[1]; |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 264 | |
Pauli | ad88741 | 2017-07-18 11:48:27 +1000 | [diff] [blame] | 265 | if (strcmp(p, "-crypto_first") == 0) { |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 266 | test_type = CRYPTO_FIRST; |
Pauli | ad88741 | 2017-07-18 11:48:27 +1000 | [diff] [blame] | 267 | } else if (strcmp(p, "-ssl_first") == 0) { |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 268 | test_type = SSL_FIRST; |
Pauli | ad88741 | 2017-07-18 11:48:27 +1000 | [diff] [blame] | 269 | } else if (strcmp(p, "-just_crypto") == 0) { |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 270 | test_type = JUST_CRYPTO; |
Matthias Kraft | 4af14b7 | 2018-03-19 13:37:46 -0400 | [diff] [blame] | 271 | } else if (strcmp(p, "-dso_ref") == 0) { |
Matt Caswell | df5228e | 2018-11-15 14:50:52 +0000 | [diff] [blame] | 272 | test_type = DSO_REFTEST; |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 273 | } else if (strcmp(p, "-no_atexit") == 0) { |
| 274 | test_type = NO_ATEXIT; |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 275 | } else { |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 276 | fprintf(stderr, "Unrecognised argument\n"); |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 277 | return 1; |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 278 | } |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 279 | path_crypto = argv[2]; |
| 280 | path_ssl = argv[3]; |
Matt Caswell | 88d57bf | 2018-11-15 17:41:06 +0000 | [diff] [blame] | 281 | path_atexit = argv[4]; |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 282 | if (path_crypto == NULL || path_ssl == NULL) { |
| 283 | fprintf(stderr, "Invalid libcrypto/libssl path\n"); |
| 284 | return 1; |
| 285 | } |
Rich Salz | bdd07c7 | 2017-05-05 17:39:13 -0400 | [diff] [blame] | 286 | |
Richard Levitte | 9800b1a | 2020-11-25 07:56:08 +0100 | [diff] [blame] | 287 | #ifdef SD_INIT |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 288 | if (!test_lib()) |
| 289 | return 1; |
Rich Salz | e0011aa | 2017-05-06 07:59:18 -0400 | [diff] [blame] | 290 | #endif |
Matt Caswell | d0f2f20 | 2018-11-15 16:59:41 +0000 | [diff] [blame] | 291 | return 0; |
Matt Caswell | b987d74 | 2016-10-18 14:16:35 +0100 | [diff] [blame] | 292 | } |