geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

185 lines
6.2 KiB

  1. # Copyright (c) 2014-2016 Alexander Lamaison <alexander.lamaison@gmail.com>
  2. #
  3. # Redistribution and use in source and binary forms,
  4. # with or without modification, are permitted provided
  5. # that the following conditions are met:
  6. #
  7. # Redistributions of source code must retain the above
  8. # copyright notice, this list of conditions and the
  9. # following disclaimer.
  10. #
  11. # Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following
  13. # disclaimer in the documentation and/or other materials
  14. # provided with the distribution.
  15. #
  16. # Neither the name of the copyright holder nor the names
  17. # of any other contributors may be used to endorse or
  18. # promote products derived from this software without
  19. # specific prior written permission.
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  22. # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  23. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24. # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  29. # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  33. # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  34. # OF SUCH DAMAGE.
  35. include(CheckIncludeFiles)
  36. include(CheckFunctionExists)
  37. include(CheckSymbolExists)
  38. include(BundleUtilities)
  39. include(CopyRuntimeDependencies)
  40. include(SocketLibraries)
  41. ## Platform checks
  42. check_include_files(inttypes.h HAVE_INTTYPES_H)
  43. check_include_files(unistd.h HAVE_UNISTD_H)
  44. check_include_files(sys/param.h HAVE_SYS_PARAM_H)
  45. check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
  46. check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
  47. check_include_files(windows.h HAVE_WINDOWS_H)
  48. check_include_files(winsock2.h HAVE_WINSOCK2_H)
  49. check_include_files(netinet/in.h HAVE_NETINET_IN_H)
  50. configure_file(
  51. "${CMAKE_CURRENT_SOURCE_DIR}/libssh2_config_cmake.h.in"
  52. "${CMAKE_CURRENT_BINARY_DIR}/libssh2_config.h")
  53. append_needed_socket_libraries(LIBRARIES)
  54. ## Cryptography backend choice
  55. set(CRYPTO_BACKEND
  56. ""
  57. CACHE
  58. STRING
  59. "The backend to use for cryptography: OpenSSL, Libgcrypt or WinCNG, mbedTLS
  60. or empty to try any available")
  61. # If the crypto backend was given, rather than searching for the first
  62. # we are able to find, the find_package commands must abort configuration
  63. # and report to the user.
  64. if(CRYPTO_BACKEND)
  65. set(SPECIFIC_CRYPTO_REQUIREMENT REQUIRED)
  66. endif()
  67. if(CRYPTO_BACKEND STREQUAL "OpenSSL" OR NOT CRYPTO_BACKEND)
  68. find_package(OpenSSL ${SPECIFIC_CRYPTO_REQUIREMENT})
  69. if(OPENSSL_FOUND)
  70. set(CRYPTO_BACKEND "OpenSSL")
  71. endif()
  72. endif()
  73. if(CRYPTO_BACKEND STREQUAL "Libgcrypt" OR NOT CRYPTO_BACKEND)
  74. find_package(Libgcrypt ${SPECIFIC_CRYPTO_REQUIREMENT})
  75. if(LIBGCRYPT_FOUND)
  76. set(CRYPTO_BACKEND "Libgcrypt")
  77. endif()
  78. endif()
  79. if(CRYPTO_BACKEND STREQUAL "WinCNG" OR NOT CRYPTO_BACKEND)
  80. # The check actually compiles the header. This requires windows.h.
  81. check_include_files("windows.h;bcrypt.h" HAVE_BCRYPT_H)
  82. if(HAVE_BCRYPT_H)
  83. set(CRYPTO_BACKEND "WinCNG")
  84. endif()
  85. endif()
  86. if(CRYPTO_BACKEND STREQUAL "mbedTLS" OR NOT CRYPTO_BACKEND)
  87. find_package(mbedTLS ${SPECIFIC_CRYPTO_REQUIREMENT})
  88. if(MBEDTLS_FOUND)
  89. set(CRYPTO_BACKEND "mbedTLS")
  90. endif()
  91. endif()
  92. set(TESTS
  93. hostkey
  94. hostkey_hash
  95. password_auth_succeeds_with_correct_credentials
  96. password_auth_fails_with_wrong_password
  97. password_auth_fails_with_wrong_username
  98. public_key_auth_fails_with_wrong_key
  99. public_key_auth_succeeds_with_correct_rsa_key
  100. public_key_auth_succeeds_with_correct_encrypted_rsa_key
  101. keyboard_interactive_auth_fails_with_wrong_response
  102. keyboard_interactive_auth_succeeds_with_correct_response
  103. agent_forward_succeeds
  104. )
  105. if(CRYPTO_BACKEND STREQUAL "OpenSSL")
  106. list(APPEND TESTS
  107. public_key_auth_succeeds_with_correct_rsa_openssh_key
  108. )
  109. if(OPENSSL_VERSION VERSION_GREATER "1.1.0")
  110. list(APPEND TESTS
  111. public_key_auth_succeeds_with_correct_ed25519_key
  112. public_key_auth_succeeds_with_correct_encrypted_ed25519_key
  113. public_key_auth_succeeds_with_correct_ed25519_key_from_mem
  114. )
  115. endif()
  116. endif()
  117. if(NOT CRYPTO_BACKEND STREQUAL "mbedTLS")
  118. list(APPEND TESTS
  119. public_key_auth_succeeds_with_correct_dsa_key
  120. )
  121. endif()
  122. add_library(openssh_fixture STATIC openssh_fixture.h openssh_fixture.c)
  123. target_link_libraries(openssh_fixture ${LIBRARIES})
  124. target_include_directories(openssh_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
  125. add_library(session_fixture STATIC session_fixture.h session_fixture.c)
  126. target_link_libraries(session_fixture ${LIBRARIES} openssh_fixture libssh2)
  127. target_include_directories(session_fixture PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
  128. add_library(runner STATIC runner.c)
  129. target_link_libraries(runner session_fixture)
  130. target_include_directories(runner PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
  131. foreach(test ${TESTS})
  132. add_executable(test_${test} test_${test}.c)
  133. target_link_libraries(test_${test} libssh2 runner ${LIBRARIES})
  134. target_include_directories(test_${test} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
  135. list(APPEND TEST_TARGETS test_${test})
  136. add_definitions(-DFIXTURE_WORKDIR="${CMAKE_CURRENT_SOURCE_DIR}")
  137. add_test(
  138. NAME test_${test} COMMAND $<TARGET_FILE:test_${test}>
  139. WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
  140. endforeach()
  141. add_target_to_copy_dependencies(
  142. TARGET copy_test_dependencies
  143. DEPENDENCIES ${RUNTIME_DEPENDENCIES}
  144. BEFORE_TARGETS ${TEST_TARGETS})
  145. # TODO convert mansyntax.sh into CMake script.
  146. # XXX Just because we can find all three programs, doesn't mean sh can
  147. # find man and grep
  148. find_program(SH_EXECUTABLE sh)
  149. find_program(MAN_EXECUTABLE man)
  150. find_program(GREP_EXECUTABLE grep)
  151. mark_as_advanced(SH_EXECUTABLE MAN_EXECUTABLE GREP_EXECUTABLE)
  152. if(SH_EXECUTABLE AND MAN_EXECUTABLE AND GREP_EXECUTABLE)
  153. set(cmd "srcdir=${CMAKE_CURRENT_SOURCE_DIR}")
  154. set(cmd "${cmd} ${CMAKE_CURRENT_SOURCE_DIR}/mansyntax.sh")
  155. add_test(mansyntax ${SH_EXECUTABLE} -c "${cmd}")
  156. endif()