xref: /freebsd/crypto/openssl/test/sysdefaulttest.c (revision a689bfa4e25af8307709dc12f75b0e02a65abf18)
1 /*
2  * Copyright 2016-2024 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
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 <openssl/opensslconf.h>
12 
13 #include <string.h>
14 #include <openssl/evp.h>
15 #include <openssl/ssl.h>
16 #include <openssl/tls1.h>
17 #include "testutil.h"
18 
19 static int expect_failure = 0;
20 
21 static int test_func(void)
22 {
23     int ret = 0;
24     SSL_CTX *ctx;
25 
26     ctx = SSL_CTX_new(TLS_method());
27     if (expect_failure) {
28         if (!TEST_ptr_null(ctx))
29             goto err;
30     } else {
31         if (!TEST_ptr(ctx))
32             return 0;
33         if (!TEST_int_eq(SSL_CTX_get_min_proto_version(ctx), TLS1_2_VERSION)
34             && !TEST_int_eq(SSL_CTX_get_max_proto_version(ctx), TLS1_2_VERSION)) {
35             TEST_info("min/max version setting incorrect");
36             goto err;
37         }
38     }
39     ret = 1;
40 err:
41     SSL_CTX_free(ctx);
42     return ret;
43 }
44 
45 int global_init(void)
46 {
47     if (!OPENSSL_init_ssl(OPENSSL_INIT_ENGINE_ALL_BUILTIN
48                 | OPENSSL_INIT_LOAD_CONFIG,
49             NULL))
50         return 0;
51     return 1;
52 }
53 
54 typedef enum OPTION_choice {
55     OPT_ERR = -1,
56     OPT_EOF = 0,
57     OPT_FAIL,
58     OPT_TEST_ENUM
59 } OPTION_CHOICE;
60 
61 const OPTIONS *test_get_options(void)
62 {
63     static const OPTIONS test_options[] = {
64         OPT_TEST_OPTIONS_DEFAULT_USAGE,
65         { "f", OPT_FAIL, '-', "A failure is expected" },
66         { NULL }
67     };
68     return test_options;
69 }
70 
71 int setup_tests(void)
72 {
73     OPTION_CHOICE o;
74 
75     while ((o = opt_next()) != OPT_EOF) {
76         switch (o) {
77         case OPT_FAIL:
78             expect_failure = 1;
79             break;
80         case OPT_TEST_CASES:
81             break;
82         default:
83             return 0;
84         }
85     }
86 
87     ADD_TEST(test_func);
88     return 1;
89 }
90