|
3 | 3 | */
|
4 | 4 |
|
5 | 5 | #include <assert.h>
|
| 6 | +#include <stdint.h> |
6 | 7 | #include <stdio.h>
|
7 | 8 |
|
8 | 9 | #include <openssl/ssl.h>
|
@@ -403,6 +404,92 @@ void test_no_ticket(void) {
|
403 | 404 | SSL_free(ssl);
|
404 | 405 | }
|
405 | 406 |
|
| 407 | +void set_options_values(SSL_CONF_CTX *cctx, SSL_CTX *ctx, SSL *ssl, |
| 408 | + uint64_t opts, const char *values) { |
| 409 | + // Put the CTX and SSL_CTX into a known options state beforehand. |
| 410 | + if (ctx != NULL) { |
| 411 | + SSL_CTX_clear_options(ctx, UINT64_MAX); |
| 412 | + SSL_CTX_set_options(ctx, opts); |
| 413 | + printf("\t\tSSL_CTX_get_options before: 0x%lx\n", SSL_CTX_get_options(ctx)); |
| 414 | + } |
| 415 | + if (ssl != NULL) { |
| 416 | + SSL_clear_options(ssl, UINT64_MAX); |
| 417 | + SSL_set_options(ssl, opts); |
| 418 | + printf("\t\tSSL_get_options before: 0x%lx\n", SSL_get_options(ssl)); |
| 419 | + } |
| 420 | + |
| 421 | + // Apply the Options command |
| 422 | + printf("\t\tSSL_CONF_cmd Options %s == %d\n", |
| 423 | + values == NULL ? "NULL" : values, |
| 424 | + SSL_CONF_cmd(cctx, "Options", values)); |
| 425 | + |
| 426 | + if (ctx != NULL) { |
| 427 | + printf("\t\tSSL_CTX_get_options after: 0x%lx\n", SSL_CTX_get_options(ctx)); |
| 428 | + } |
| 429 | + if (ssl != NULL) { |
| 430 | + printf("\t\tSSL_get_options after: 0x%lx\n", SSL_get_options(ssl)); |
| 431 | + } |
| 432 | +} |
| 433 | + |
| 434 | +void test_options_session_ticket_variations(SSL_CONF_CTX *cctx, SSL_CTX *ctx, |
| 435 | + SSL *ssl) { |
| 436 | + // Try NULL |
| 437 | + set_options_values(cctx, ctx, ssl, 0, NULL); |
| 438 | + // NOTE: we don't try invalid/unknown values because Rustls will ignore them |
| 439 | + // without error |
| 440 | + // while OpenSSL will erorr. |
| 441 | + |
| 442 | + // Test enabling the option when it has not been disabled, and when it has |
| 443 | + // been disabled |
| 444 | + set_options_values(cctx, ctx, ssl, 0, "SessionTicket"); |
| 445 | + set_options_values(cctx, ctx, ssl, SSL_OP_NO_TICKET, "SessionTicket"); |
| 446 | + |
| 447 | + // Test disabling the option when it has been enabled, and when it has not |
| 448 | + // been enabled |
| 449 | + set_options_values(cctx, ctx, ssl, SSL_OP_NO_TICKET, "-SessionTicket"); |
| 450 | + set_options_values(cctx, ctx, ssl, 0, "-SessionTicket"); |
| 451 | + |
| 452 | + // Test enabling and disabling the option in the same command for both initial |
| 453 | + // states |
| 454 | + set_options_values(cctx, ctx, ssl, 0, "SessionTicket,-SessionTicket"); |
| 455 | + set_options_values(cctx, ctx, ssl, SSL_OP_NO_TICKET, |
| 456 | + "SessionTicket,-SessionTicket"); |
| 457 | + set_options_values(cctx, ctx, ssl, SSL_OP_NO_TICKET, |
| 458 | + "-SessionTicket,SessionTicket"); |
| 459 | + set_options_values(cctx, ctx, ssl, 0, "-SessionTicket,SessionTicket"); |
| 460 | +} |
| 461 | + |
| 462 | +void test_options_session_ticket(void) { |
| 463 | + SSL_CONF_CTX *cctx = SSL_CONF_CTX_new(); |
| 464 | + assert(cctx != NULL); |
| 465 | + |
| 466 | + SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_FILE); |
| 467 | + |
| 468 | + printf("\tPre-ctx, no server flag:\n"); |
| 469 | + test_options_session_ticket_variations(cctx, NULL, NULL); |
| 470 | + |
| 471 | + printf("\tPre-ctx, with server flag: \n"); |
| 472 | + SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_SERVER); |
| 473 | + test_options_session_ticket_variations(cctx, NULL, NULL); |
| 474 | + |
| 475 | + SSL_CTX *ctx = SSL_CTX_new(TLS_method()); |
| 476 | + assert(ctx != NULL); |
| 477 | + SSL_CONF_CTX_set_ssl_ctx(cctx, ctx); |
| 478 | + printf("\tWith ctx\n"); |
| 479 | + test_options_session_ticket_variations(cctx, ctx, NULL); |
| 480 | + |
| 481 | + SSL *ssl = SSL_new(ctx); |
| 482 | + assert(ssl != NULL); |
| 483 | + SSL_CONF_CTX_set_ssl(cctx, ssl); |
| 484 | + printf("\tWith ssl\n"); |
| 485 | + test_options_session_ticket_variations(cctx, NULL, ssl); |
| 486 | + |
| 487 | + assert(SSL_CONF_CTX_finish(cctx)); |
| 488 | + SSL_CONF_CTX_free(cctx); |
| 489 | + SSL_CTX_free(ctx); |
| 490 | + SSL_free(ssl); |
| 491 | +} |
| 492 | + |
406 | 493 | int main(void) {
|
407 | 494 | printf("Supported commands:\n");
|
408 | 495 | printf("no base flags, default prefix:\n");
|
@@ -437,4 +524,7 @@ int main(void) {
|
437 | 524 |
|
438 | 525 | printf("no_ticket\n");
|
439 | 526 | test_no_ticket();
|
| 527 | + |
| 528 | + printf("Options SessionTicket\n"); |
| 529 | + test_options_session_ticket(); |
440 | 530 | }
|
0 commit comments