Home | History | Annotate | Line # | Download | only in test
      1  1.1  christos /*
      2  1.1  christos  * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
      3  1.1  christos  *
      4  1.1  christos  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5  1.1  christos  * this file except in compliance with the License.  You can obtain a copy
      6  1.1  christos  * in the file LICENSE in the source distribution or at
      7  1.1  christos  * https://www.openssl.org/source/license.html
      8  1.1  christos  */
      9  1.1  christos 
     10  1.1  christos #include "internal/nelem.h"
     11  1.1  christos #include "../ssl/ssl_local.h"
     12  1.1  christos #include "../ssl/statem/statem_local.h"
     13  1.1  christos #include "testutil.h"
     14  1.1  christos 
     15  1.1  christos #define EXT_ENTRY(name) { TLSEXT_IDX_##name, TLSEXT_TYPE_##name, #name }
     16  1.1  christos #define EXT_EXCEPTION(name) { TLSEXT_IDX_##name, TLSEXT_TYPE_invalid, #name }
     17  1.1  christos #define EXT_END(name) { TLSEXT_IDX_##name, TLSEXT_TYPE_out_of_range, #name }
     18  1.1  christos 
     19  1.1  christos typedef struct {
     20  1.1  christos     size_t idx;
     21  1.1  christos     unsigned int type;
     22  1.1  christos     char *name;
     23  1.1  christos } EXT_LIST;
     24  1.1  christos 
     25  1.1  christos /* The order here does matter! */
     26  1.1  christos static EXT_LIST ext_list[] = {
     27  1.1  christos 
     28  1.1  christos     EXT_ENTRY(renegotiate),
     29  1.1  christos     EXT_ENTRY(server_name),
     30  1.1  christos     EXT_ENTRY(max_fragment_length),
     31  1.1  christos #ifndef OPENSSL_NO_SRP
     32  1.1  christos     EXT_ENTRY(srp),
     33  1.1  christos #else
     34  1.1  christos     EXT_EXCEPTION(srp),
     35  1.1  christos #endif
     36  1.1  christos     EXT_ENTRY(ec_point_formats),
     37  1.1  christos     EXT_ENTRY(supported_groups),
     38  1.1  christos     EXT_ENTRY(session_ticket),
     39  1.1  christos #ifndef OPENSSL_NO_OCSP
     40  1.1  christos     EXT_ENTRY(status_request),
     41  1.1  christos #else
     42  1.1  christos     EXT_EXCEPTION(status_request),
     43  1.1  christos #endif
     44  1.1  christos #ifndef OPENSSL_NO_NEXTPROTONEG
     45  1.1  christos     EXT_ENTRY(next_proto_neg),
     46  1.1  christos #else
     47  1.1  christos     EXT_EXCEPTION(next_proto_neg),
     48  1.1  christos #endif
     49  1.1  christos     EXT_ENTRY(application_layer_protocol_negotiation),
     50  1.1  christos #ifndef OPENSSL_NO_SRTP
     51  1.1  christos     EXT_ENTRY(use_srtp),
     52  1.1  christos #else
     53  1.1  christos     EXT_EXCEPTION(use_srtp),
     54  1.1  christos #endif
     55  1.1  christos     EXT_ENTRY(encrypt_then_mac),
     56  1.1  christos #ifndef OPENSSL_NO_CT
     57  1.1  christos     EXT_ENTRY(signed_certificate_timestamp),
     58  1.1  christos #else
     59  1.1  christos     EXT_EXCEPTION(signed_certificate_timestamp),
     60  1.1  christos #endif
     61  1.1  christos     EXT_ENTRY(extended_master_secret),
     62  1.1  christos     EXT_ENTRY(signature_algorithms_cert),
     63  1.1  christos     EXT_ENTRY(post_handshake_auth),
     64  1.1  christos     EXT_ENTRY(signature_algorithms),
     65  1.1  christos     EXT_ENTRY(supported_versions),
     66  1.1  christos     EXT_ENTRY(psk_kex_modes),
     67  1.1  christos     EXT_ENTRY(key_share),
     68  1.1  christos     EXT_ENTRY(cookie),
     69  1.1  christos     EXT_ENTRY(cryptopro_bug),
     70  1.1  christos     EXT_ENTRY(early_data),
     71  1.1  christos     EXT_ENTRY(certificate_authorities),
     72  1.1  christos     EXT_ENTRY(padding),
     73  1.1  christos     EXT_ENTRY(psk),
     74  1.1  christos     EXT_END(num_builtins)
     75  1.1  christos };
     76  1.1  christos 
     77  1.1  christos static int test_extension_list(void)
     78  1.1  christos {
     79  1.1  christos     size_t n = OSSL_NELEM(ext_list);
     80  1.1  christos     size_t i;
     81  1.1  christos     unsigned int type;
     82  1.1  christos     int retval = 1;
     83  1.1  christos 
     84  1.1  christos     for (i = 0; i < n; i++) {
     85  1.1  christos         if (!TEST_size_t_eq(i, ext_list[i].idx)) {
     86  1.1  christos             retval = 0;
     87  1.1  christos             TEST_error("TLSEXT_IDX_%s=%zd, found at=%zd\n",
     88  1.1  christos                        ext_list[i].name, ext_list[i].idx, i);
     89  1.1  christos         }
     90  1.1  christos         type = ossl_get_extension_type(ext_list[i].idx);
     91  1.1  christos         if (!TEST_uint_eq(type, ext_list[i].type)) {
     92  1.1  christos             retval = 0;
     93  1.1  christos             TEST_error("TLSEXT_IDX_%s=%zd expected=0x%05X got=0x%05X",
     94  1.1  christos                        ext_list[i].name, ext_list[i].idx, ext_list[i].type,
     95  1.1  christos                        type);
     96  1.1  christos         }
     97  1.1  christos     }
     98  1.1  christos     return retval;
     99  1.1  christos }
    100  1.1  christos 
    101  1.1  christos int setup_tests(void)
    102  1.1  christos {
    103  1.1  christos     ADD_TEST(test_extension_list);
    104  1.1  christos     return 1;
    105  1.1  christos }
    106