2
0

unit1397.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "curlcheck.h"
  25. static CURLcode unit_setup(void)
  26. {
  27. return CURLE_OK;
  28. }
  29. static void unit_stop(void)
  30. {
  31. }
  32. /* only these backends define the tested functions */
  33. #if defined(USE_OPENSSL) || defined(USE_SCHANNEL)
  34. #include "vtls/hostcheck.h"
  35. struct testcase {
  36. const char *host;
  37. const char *pattern;
  38. bool match;
  39. };
  40. static struct testcase tests[] = {
  41. {"", "", FALSE},
  42. {"a", "", FALSE},
  43. {"", "b", FALSE},
  44. {"a", "b", FALSE},
  45. {"aa", "bb", FALSE},
  46. {"\xff", "\xff", TRUE},
  47. {"aa.aa.aa", "aa.aa.bb", FALSE},
  48. {"aa.aa.aa", "aa.aa.aa", TRUE},
  49. {"aa.aa.aa", "*.aa.bb", FALSE},
  50. {"aa.aa.aa", "*.aa.aa", TRUE},
  51. {"192.168.0.1", "192.168.0.1", TRUE},
  52. {"192.168.0.1", "*.168.0.1", FALSE},
  53. {"192.168.0.1", "*.0.1", FALSE},
  54. {"h.ello", "*.ello", FALSE},
  55. {"h.ello.", "*.ello", FALSE},
  56. {"h.ello", "*.ello.", FALSE},
  57. {"h.e.llo", "*.e.llo", TRUE},
  58. {"h.e.llo", " *.e.llo", FALSE},
  59. {" h.e.llo", "*.e.llo", TRUE},
  60. {"h.e.llo.", "*.e.llo", TRUE},
  61. {"*.e.llo.", "*.e.llo", TRUE},
  62. {"************.e.llo.", "*.e.llo", TRUE},
  63. {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
  64. "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
  65. "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
  66. "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
  67. "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
  68. ".e.llo.", "*.e.llo", TRUE},
  69. {"\xfe\xfe.e.llo.", "*.e.llo", TRUE},
  70. {"h.e.llo.", "*.e.llo.", TRUE},
  71. {"h.e.llo", "*.e.llo.", TRUE},
  72. {".h.e.llo", "*.e.llo.", FALSE},
  73. {"h.e.llo", "*.*.llo.", FALSE},
  74. {"h.e.llo", "h.*.llo", FALSE},
  75. {"h.e.llo", "h.e.*", FALSE},
  76. {"hello", "*.ello", FALSE},
  77. {"hello", "**llo", FALSE},
  78. {"bar.foo.example.com", "*.example.com", FALSE},
  79. {"foo.example.com", "*.example.com", TRUE},
  80. {"baz.example.net", "b*z.example.net", FALSE},
  81. {"foobaz.example.net", "*baz.example.net", FALSE},
  82. {"xn--l8j.example.local", "x*.example.local", FALSE},
  83. {"xn--l8j.example.net", "*.example.net", TRUE},
  84. {"xn--l8j.example.net", "*j.example.net", FALSE},
  85. {"xn--l8j.example.net", "xn--l8j.example.net", TRUE},
  86. {"xn--l8j.example.net", "xn--l8j.*.net", FALSE},
  87. {"xl8j.example.net", "*.example.net", TRUE},
  88. {"fe80::3285:a9ff:fe46:b619", "*::3285:a9ff:fe46:b619", FALSE},
  89. {"fe80::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619", TRUE},
  90. {NULL, NULL, FALSE}
  91. };
  92. UNITTEST_START
  93. {
  94. int i;
  95. for(i = 0; tests[i].host; i++) {
  96. if(tests[i].match != Curl_cert_hostcheck(tests[i].pattern,
  97. strlen(tests[i].pattern),
  98. tests[i].host,
  99. strlen(tests[i].host))) {
  100. fprintf(stderr,
  101. "HOST: %s\n"
  102. "PTRN: %s\n"
  103. "did %sMATCH\n",
  104. tests[i].host,
  105. tests[i].pattern,
  106. tests[i].match ? "NOT ": "");
  107. unitfail++;
  108. }
  109. }
  110. }
  111. UNITTEST_STOP
  112. #else
  113. UNITTEST_START
  114. UNITTEST_STOP
  115. #endif