meson.build 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # SPDX-FileCopyrightText: 2021 Andrea Pappacoda
  2. #
  3. # SPDX-License-Identifier: MIT
  4. gtest_dep = dependency('gtest', main: true)
  5. libcurl_dep = dependency('libcurl')
  6. openssl = find_program('openssl')
  7. test_conf = files('test.conf')
  8. req_x509_flag = openssl.version().version_compare('>=3.2.0') ? '-x509v1' : '-x509'
  9. key_pem = custom_target(
  10. 'key_pem',
  11. output: 'key.pem',
  12. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  13. )
  14. temp_req = custom_target(
  15. 'temp_req',
  16. input: key_pem,
  17. output: 'temp_req',
  18. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  19. )
  20. cert_pem = custom_target(
  21. 'cert_pem',
  22. input: [temp_req, key_pem],
  23. output: 'cert.pem',
  24. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '3650', '-req', '-signkey', '@INPUT1@', '-out', '@OUTPUT@']
  25. )
  26. cert2_pem = custom_target(
  27. 'cert2_pem',
  28. input: key_pem,
  29. output: 'cert2.pem',
  30. command: [openssl, 'req', req_x509_flag, '-config', test_conf, '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-out', '@OUTPUT@', '-extensions', 'SAN']
  31. )
  32. key_encrypted_pem = custom_target(
  33. 'key_encrypted_pem',
  34. output: 'key_encrypted.pem',
  35. command: [openssl, 'genrsa', '-passout', 'pass:test123!', '-out', '@OUTPUT@', '2048']
  36. )
  37. cert_encrypted_pem = custom_target(
  38. 'cert_encrypted_pem',
  39. input: key_encrypted_pem,
  40. output: 'cert_encrypted.pem',
  41. command: [openssl, 'req', req_x509_flag, '-config', test_conf, '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-out', '@OUTPUT@', '-extensions', 'SAN']
  42. )
  43. rootca_key_pem = custom_target(
  44. 'rootca_key_pem',
  45. output: 'rootCA.key.pem',
  46. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  47. )
  48. rootca_cert_pem = custom_target(
  49. 'rootca_cert_pem',
  50. input: rootca_key_pem,
  51. output: 'rootCA.cert.pem',
  52. command: [openssl, 'req', req_x509_flag, '-new', '-batch', '-config', files('test.rootCA.conf'), '-key', '@INPUT@', '-days', '1024', '-out', '@OUTPUT@']
  53. )
  54. client_key_pem = custom_target(
  55. 'client_key_pem',
  56. output: 'client.key.pem',
  57. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  58. )
  59. client_temp_req = custom_target(
  60. 'client_temp_req',
  61. input: client_key_pem,
  62. output: 'client_temp_req',
  63. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  64. )
  65. client_cert_pem = custom_target(
  66. 'client_cert_pem',
  67. input: [client_temp_req, rootca_cert_pem, rootca_key_pem],
  68. output: 'client.cert.pem',
  69. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '370', '-req', '-CA', '@INPUT1@', '-CAkey', '@INPUT2@', '-CAcreateserial', '-out', '@OUTPUT@']
  70. )
  71. # Encrypted client key: make an unencrypted key + cert first, then wrap the same
  72. # key two ways. Mbed TLS 4.x dropped DES/PBES1, while Ubuntu's Mbed TLS 2.28 has
  73. # no PBES2-AES, so ship both and let test.cc pick by version.
  74. client_encrypted_tmp_key_pem = custom_target(
  75. 'client_encrypted_tmp_key_pem',
  76. output: 'client_encrypted.tmp.key.pem',
  77. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  78. )
  79. client_encrypted_temp_req = custom_target(
  80. 'client_encrypted_temp_req',
  81. input: client_encrypted_tmp_key_pem,
  82. output: 'client_encrypted_temp_req',
  83. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  84. )
  85. client_encrypted_cert_pem = custom_target(
  86. 'client_encrypted_cert_pem',
  87. input: [client_encrypted_temp_req, rootca_cert_pem, rootca_key_pem],
  88. output: 'client_encrypted.cert.pem',
  89. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '370', '-req', '-CA', '@INPUT1@', '-CAkey', '@INPUT2@', '-CAcreateserial', '-out', '@OUTPUT@']
  90. )
  91. client_encrypted_key_pem = custom_target(
  92. 'client_encrypted_key_pem',
  93. input: client_encrypted_tmp_key_pem,
  94. output: 'client_encrypted.key.pem',
  95. command: [openssl, 'pkcs8', '-topk8', '-v2', 'aes-256-cbc', '-in', '@INPUT@', '-passout', 'pass:test012!', '-out', '@OUTPUT@']
  96. )
  97. client_encrypted_pbes1_key_pem = custom_target(
  98. 'client_encrypted_pbes1_key_pem',
  99. input: client_encrypted_tmp_key_pem,
  100. output: 'client_encrypted_pbes1.key.pem',
  101. command: [openssl, 'pkcs8', '-topk8', '-v1', 'PBE-SHA1-3DES', '-in', '@INPUT@', '-passout', 'pass:test012!', '-out', '@OUTPUT@']
  102. )
  103. # Certificates for IP-host hostname verification regression tests.
  104. # cert_ip_cn.pem: CN is an IPv4 literal with NO subjectAltName, so verifying an
  105. # IP host against it must fail (an IP is never matched via the CN).
  106. cert_ip_cn_pem = custom_target(
  107. 'cert_ip_cn_pem',
  108. input: key_pem,
  109. output: 'cert_ip_cn.pem',
  110. command: [openssl, 'req', '-x509', '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-subj', '/CN=127.0.0.1', '-out', '@OUTPUT@']
  111. )
  112. # cert_ipv6.pem: CN is an IPv6 literal plus a different IPv6 iPAddress SAN; the
  113. # SAN address must match and the CN address must be ignored.
  114. cert_ipv6_pem = custom_target(
  115. 'cert_ipv6_pem',
  116. input: key_pem,
  117. output: 'cert_ipv6.pem',
  118. command: [openssl, 'req', '-x509', '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-subj', '/CN=::1', '-addext', 'subjectAltName=IP:2001:db8::1', '-out', '@OUTPUT@']
  119. )
  120. # Copy test files to the build directory
  121. configure_file(input: 'ca-bundle.crt', output: 'ca-bundle.crt', copy: true)
  122. configure_file(input: 'image.jpg', output: 'image.jpg', copy: true)
  123. subdir('www')
  124. subdir('www2'/'dir')
  125. subdir('www3'/'dir')
  126. # New GoogleTest versions require new C++ standards
  127. test_options = []
  128. if gtest_dep.version().version_compare('>=1.17.0')
  129. test_options += 'cpp_std=c++17'
  130. elif gtest_dep.version().version_compare('>=1.13.0')
  131. test_options += 'cpp_std=c++14'
  132. endif
  133. test(
  134. 'main',
  135. executable(
  136. 'main',
  137. 'test.cc',
  138. dependencies: [
  139. cpp_httplib_dep,
  140. gtest_dep,
  141. libcurl_dep
  142. ],
  143. override_options: test_options
  144. ),
  145. depends: [
  146. key_pem,
  147. cert_pem,
  148. cert2_pem,
  149. key_encrypted_pem,
  150. cert_encrypted_pem,
  151. rootca_key_pem,
  152. rootca_cert_pem,
  153. client_key_pem,
  154. client_cert_pem,
  155. client_encrypted_key_pem,
  156. client_encrypted_pbes1_key_pem,
  157. client_encrypted_cert_pem,
  158. cert_ip_cn_pem,
  159. cert_ipv6_pem
  160. ],
  161. workdir: meson.current_build_dir(),
  162. timeout: 300
  163. )