xref: /openssl/test/ext_internal_test.c (revision da1c088f)
1 /*
2  * Copyright 1995-2023 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(client_cert_type),
65     EXT_ENTRY(server_cert_type),
66     EXT_ENTRY(signature_algorithms),
67     EXT_ENTRY(supported_versions),
68     EXT_ENTRY(psk_kex_modes),
69     EXT_ENTRY(key_share),
70     EXT_ENTRY(cookie),
71     EXT_ENTRY(cryptopro_bug),
72     EXT_ENTRY(compress_certificate),
73     EXT_ENTRY(early_data),
74     EXT_ENTRY(certificate_authorities),
75     EXT_ENTRY(padding),
76     EXT_ENTRY(psk),
77     EXT_END(num_builtins)
78 };
79 
test_extension_list(void)80 static int test_extension_list(void)
81 {
82     size_t n = OSSL_NELEM(ext_list);
83     size_t i;
84     unsigned int type;
85     int retval = 1;
86 
87     for (i = 0; i < n; i++) {
88         if (!TEST_size_t_eq(i, ext_list[i].idx)) {
89             retval = 0;
90             TEST_error("TLSEXT_IDX_%s=%zd, found at=%zd\n",
91                        ext_list[i].name, ext_list[i].idx, i);
92         }
93         type = ossl_get_extension_type(ext_list[i].idx);
94         if (!TEST_uint_eq(type, ext_list[i].type)) {
95             retval = 0;
96             TEST_error("TLSEXT_IDX_%s=%zd expected=0x%05X got=0x%05X",
97                        ext_list[i].name, ext_list[i].idx, ext_list[i].type,
98                        type);
99         }
100     }
101     return retval;
102 }
103 
setup_tests(void)104 int setup_tests(void)
105 {
106     ADD_TEST(test_extension_list);
107     return 1;
108 }
109