ext_internal_test.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 1995-2021 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(signature_algorithms),
  60. EXT_ENTRY(supported_versions),
  61. EXT_ENTRY(psk_kex_modes),
  62. EXT_ENTRY(key_share),
  63. EXT_ENTRY(cookie),
  64. EXT_ENTRY(cryptopro_bug),
  65. EXT_ENTRY(compress_certificate),
  66. EXT_ENTRY(early_data),
  67. EXT_ENTRY(certificate_authorities),
  68. EXT_ENTRY(padding),
  69. EXT_ENTRY(psk),
  70. EXT_END(num_builtins)
  71. };
  72. static int test_extension_list(void)
  73. {
  74. size_t n = OSSL_NELEM(ext_list);
  75. size_t i;
  76. unsigned int type;
  77. int retval = 1;
  78. for (i = 0; i < n; i++) {
  79. if (!TEST_size_t_eq(i, ext_list[i].idx)) {
  80. retval = 0;
  81. TEST_error("TLSEXT_IDX_%s=%zd, found at=%zd\n",
  82. ext_list[i].name, ext_list[i].idx, i);
  83. }
  84. type = ossl_get_extension_type(ext_list[i].idx);
  85. if (!TEST_uint_eq(type, ext_list[i].type)) {
  86. retval = 0;
  87. TEST_error("TLSEXT_IDX_%s=%zd expected=0x%05X got=0x%05X",
  88. ext_list[i].name, ext_list[i].idx, ext_list[i].type,
  89. type);
  90. }
  91. }
  92. return retval;
  93. }
  94. int setup_tests(void)
  95. {
  96. ADD_TEST(test_extension_list);
  97. return 1;
  98. }