xref: /freebsd/crypto/openssl/test/ext_internal_test.c (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /*
2  * Copyright 1995-2022 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 "internal/nelem.h"
11 #include "../ssl/ssl_local.h"
12 #include "../ssl/statem/statem_local.h"
13 #include "testutil.h"
14 
15 #define EXT_ENTRY(name) { TLSEXT_IDX_##name, TLSEXT_TYPE_##name, #name }
16 #define EXT_EXCEPTION(name) { TLSEXT_IDX_##name, TLSEXT_TYPE_invalid, #name }
17 #define EXT_END(name) { TLSEXT_IDX_##name, TLSEXT_TYPE_out_of_range, #name }
18 
19 typedef struct {
20     size_t idx;
21     unsigned int type;
22     char *name;
23 } EXT_LIST;
24 
25 /* The order here does matter! */
26 static EXT_LIST ext_list[] = {
27 
28     EXT_ENTRY(renegotiate),
29     EXT_ENTRY(server_name),
30     EXT_ENTRY(max_fragment_length),
31 #ifndef OPENSSL_NO_SRP
32     EXT_ENTRY(srp),
33 #else
34     EXT_EXCEPTION(srp),
35 #endif
36     EXT_ENTRY(ec_point_formats),
37     EXT_ENTRY(supported_groups),
38     EXT_ENTRY(session_ticket),
39 #ifndef OPENSSL_NO_OCSP
40     EXT_ENTRY(status_request),
41 #else
42     EXT_EXCEPTION(status_request),
43 #endif
44 #ifndef OPENSSL_NO_NEXTPROTONEG
45     EXT_ENTRY(next_proto_neg),
46 #else
47     EXT_EXCEPTION(next_proto_neg),
48 #endif
49     EXT_ENTRY(application_layer_protocol_negotiation),
50 #ifndef OPENSSL_NO_SRTP
51     EXT_ENTRY(use_srtp),
52 #else
53     EXT_EXCEPTION(use_srtp),
54 #endif
55     EXT_ENTRY(encrypt_then_mac),
56 #ifndef OPENSSL_NO_CT
57     EXT_ENTRY(signed_certificate_timestamp),
58 #else
59     EXT_EXCEPTION(signed_certificate_timestamp),
60 #endif
61     EXT_ENTRY(extended_master_secret),
62     EXT_ENTRY(signature_algorithms_cert),
63     EXT_ENTRY(post_handshake_auth),
64     EXT_ENTRY(signature_algorithms),
65     EXT_ENTRY(supported_versions),
66     EXT_ENTRY(psk_kex_modes),
67     EXT_ENTRY(key_share),
68     EXT_ENTRY(cookie),
69     EXT_ENTRY(cryptopro_bug),
70     EXT_ENTRY(early_data),
71     EXT_ENTRY(certificate_authorities),
72     EXT_ENTRY(padding),
73     EXT_ENTRY(psk),
74     EXT_END(num_builtins)
75 };
76 
test_extension_list(void)77 static int test_extension_list(void)
78 {
79     size_t n = OSSL_NELEM(ext_list);
80     size_t i;
81     unsigned int type;
82     int retval = 1;
83 
84     for (i = 0; i < n; i++) {
85         if (!TEST_size_t_eq(i, ext_list[i].idx)) {
86             retval = 0;
87             TEST_error("TLSEXT_IDX_%s=%zd, found at=%zd\n",
88                        ext_list[i].name, ext_list[i].idx, i);
89         }
90         type = ossl_get_extension_type(ext_list[i].idx);
91         if (!TEST_uint_eq(type, ext_list[i].type)) {
92             retval = 0;
93             TEST_error("TLSEXT_IDX_%s=%zd expected=0x%05X got=0x%05X",
94                        ext_list[i].name, ext_list[i].idx, ext_list[i].type,
95                        type);
96         }
97     }
98     return retval;
99 }
100 
setup_tests(void)101 int setup_tests(void)
102 {
103     ADD_TEST(test_extension_list);
104     return 1;
105 }
106