Skip to content

Commit ff821d7

Browse files
committed
perflib, handshake: do not use OSSL_LIB_CTX on OpenSSL < 3.0
OSSL_LIB_CTX object and related APIs have been introduced in OpenSSL 3.0, and its usage prevents compiling perftools with OpenSSL 1.1.1. So far, it is limited to specific handshake testing modes, so just put the relevant code into conditional preprocessor sections. Resolves: #54 Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
1 parent af6fc94 commit ff821d7

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

source/handshake.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
int err = 0;
2929

30+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
3031
typedef enum {
3132
INIT_LIB_CTX,
3233
INIT_LIB_AND_SSL_CTX,
@@ -38,11 +39,13 @@ struct ctxs {
3839
SSL_CTX *cctx;
3940
};
4041

42+
static struct ctxs **ctx_pool = NULL;
43+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
44+
4145
static SSL_CTX *sctx = NULL, *cctx = NULL;
4246
static int share_ctx = 1;
4347
static char *cert = NULL;
4448
static char *privkey = NULL;
45-
static struct ctxs **ctx_pool = NULL;
4649

4750
size_t *counts;
4851

@@ -52,9 +55,11 @@ static long pool_size = 16;
5255

5356
typedef enum {
5457
TC_SSL_CTX,
58+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
5559
TC_OSSL_LIB_CTX_PER_THREAD,
5660
TC_OSSL_LIB_CTX_POOL,
5761
TC_SSL_CTX_POOL,
62+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
5863
} test_case_t;
5964
OSSL_TIME max_time;
6065
static test_case_t test_case = TC_SSL_CTX;
@@ -105,6 +110,8 @@ static void do_handshake(size_t num)
105110
err = 1;
106111
}
107112

113+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
114+
108115
static void do_handshake_ossl_lib_ctx_per_thread(size_t num)
109116
{
110117
SSL *clientssl = NULL, *serverssl = NULL;
@@ -315,17 +322,21 @@ static int test_ossl_lib_ctx_pool(size_t threadcount, OSSL_TIME *duration)
315322
free_ctx_pool();
316323

317324
return ret;
318-
}
325+
}
326+
327+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
319328

320329
void usage(const char *progname)
321330
{
322331
printf("Usage: %s [options] certsdir threadcount\n", progname);
323332
printf("-t - terse output\n");
324333
printf("-s - disable context sharing\n");
334+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
325335
printf("-p - use ossl_lib_ctx per thread\n");
326336
printf("-P - use ossl_lib_ctx pool\n");
327337
printf("-l - use ssl ctx pool\n");
328338
printf("-o - set ossl_lib_ctx pool size\n");
339+
#endif
329340
printf("-S [n] - use secure memory\n");
330341
}
331342

@@ -342,14 +353,21 @@ int main(int argc, char * const argv[])
342353
int p_flag = 0, P_flag = 0, l_flag = 0;
343354
char *endptr = NULL;
344355

345-
while ((opt = getopt(argc, argv, "tspPo:lS:")) != -1) {
356+
while ((opt = getopt(argc, argv,
357+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
358+
"tspPo:lS:"
359+
#else
360+
"tsS:"
361+
#endif
362+
)) != -1) {
346363
switch (opt) {
347364
case 't':
348365
terse = 1;
349366
break;
350367
case 's':
351368
share_ctx = 0;
352369
break;
370+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
353371
case 'p':
354372
p_flag = 1;
355373
test_case = TC_OSSL_LIB_CTX_PER_THREAD;
@@ -381,6 +399,7 @@ int main(int argc, char * const argv[])
381399
l_flag = 1;
382400
test_case = TC_SSL_CTX_POOL;
383401
break;
402+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
384403
case 'S': {
385404
char *end = NULL;
386405
int sec_mem_size;
@@ -408,12 +427,14 @@ int main(int argc, char * const argv[])
408427
}
409428
}
410429

430+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
411431
if ((p_flag + P_flag + l_flag) > 1) {
412432
fprintf(stderr, "Error: -p, -P, and -l are mutually exclusive."
413433
" Choose only one.\n\n");
414434
usage(basename(argv[0]));
415435
return EXIT_FAILURE;
416436
}
437+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
417438

418439
if (argv[optind] == NULL) {
419440
printf("certsdir is missing\n");
@@ -461,6 +482,7 @@ int main(int argc, char * const argv[])
461482
}
462483
break;
463484
}
485+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
464486
case TC_OSSL_LIB_CTX_PER_THREAD: {
465487
if (!perflib_run_multi_thread_test(do_handshake_ossl_lib_ctx_per_thread,
466488
threadcount, &duration)) {
@@ -477,6 +499,7 @@ int main(int argc, char * const argv[])
477499
}
478500
break;
479501
}
502+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
480503
default:
481504
fprintf(stderr, "Invalid test case\n");
482505
goto err;

source/perflib/perflib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ int perflib_create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
4848
int min_proto_version, int max_proto_version,
4949
SSL_CTX **sctx, SSL_CTX **cctx, char *certfile,
5050
char *privkeyfile);
51+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
5152
int perflib_create_ossl_lib_ctx_pair(OSSL_LIB_CTX *libctx, const SSL_METHOD *sm,
5253
const SSL_METHOD *cm, int min_proto_version,
5354
int max_proto_version, SSL_CTX **sctx, SSL_CTX **cctx,
5455
char *certfile, char *privkeyfile);
56+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
5557
int perflib_create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx,
5658
SSL **sssl, SSL **cssl, BIO *s_to_c_fbio,
5759
BIO *c_to_s_fbio);

source/perflib/perfsslhelper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static int perflib_use_certificate(SSL_CTX *serverctx, SSL_CTX *clientctx,
6161
return 0;
6262
}
6363

64+
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
6465
int perflib_create_ossl_lib_ctx_pair(OSSL_LIB_CTX *libctx, const SSL_METHOD *sm,
6566
const SSL_METHOD *cm, int min_proto_version,
6667
int max_proto_version, SSL_CTX **sctx, SSL_CTX **cctx,
@@ -90,6 +91,7 @@ int perflib_create_ossl_lib_ctx_pair(OSSL_LIB_CTX *libctx, const SSL_METHOD *sm,
9091
err:
9192
return 0;
9293
}
94+
#endif /* OPENSSL_VERSION_NUMBER >= 0x30000000L */
9395

9496
int perflib_create_ssl_ctx_pair(const SSL_METHOD *sm,
9597
const SSL_METHOD *cm, int min_proto_version,

0 commit comments

Comments
 (0)