ext_internal_test.c 2.9 KB

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