aria-cmake-build-test.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/bin/bash
  2. #
  3. # aria_cmake_build_test.sh
  4. #
  5. # This is a test script for building wolfSSL examples with various settings
  6. # for the ARIA Magic Crypto ciphers.
  7. #
  8. # See https://github.com/wolfSSL/wolfssl/pull/6400 and
  9. # https://github.com/wolfSSL/wolfssl/pull/6600
  10. #
  11. # The basic steps for building:
  12. #
  13. # # set to your path
  14. # export ARIA_DIR=/mnt/c/workspace/MagicCrypto
  15. #
  16. # mkdir -p out
  17. # pushd out
  18. # cmake .. -DWOLFSSL_ARIA=yes
  19. # cmake --build .
  20. #
  21. # # View the available ciphers with:
  22. # ./examples/client/client -e
  23. #
  24. # or with grep:
  25. # ./examples/client/client -e | grep -i ARIA
  26. #
  27. # Note the OPENSSL_EXTRA and WOLF_CRYPTOCB macros may need to be defined
  28. # in certain circumstances. The LD_LIBRARY_PATH=$ARIA_DIR may also be needed.
  29. #
  30. export ARIA_BUILD_DIR=./out_temp
  31. export ARIA_ERROR_RM_FAIL=1
  32. export ARIA_ERROR_MKDIR_FAIL=2
  33. export ARIA_ERROR_CMAKE_FAIL=3
  34. export ARIA_ERROR_BUILD_FAIL=4
  35. export ARIA_ERROR_CLIENT_FAIL=5
  36. export ARIA_ERROR_CIPHER_FAIL=6
  37. export ARIA_ERROR_CONFIG_FAIL=7
  38. #
  39. # function build_aria_test()
  40. #
  41. build_aria_test() {
  42. local EXPECTED_ERROR=$1 # First parameter; 0, 1, 2, etc
  43. local EXPECTED_ARIA=$2 # Second parameter: typically "Y" or "N"
  44. local BUILD_MESSAGE=$3 # Third parameter; "some message"
  45. local BUILD_DIR=$4 # Fourth parameter: "./someDirectory"
  46. local BUILD_OPTION=$5 # Fifth parameter. Optional: ""
  47. echo "********************************************************************"
  48. echo "Starting $BUILD_MESSAGE"
  49. echo "********************************************************************"
  50. if [[ -z "$BUILD_DIR" ]]; then
  51. local BUILD_DIR=out
  52. fi
  53. echo "BUILD_DIR=$BUILD_DIR"
  54. echo "BUILD_OPTION=$BUILD_OPTION"
  55. # remove build directory
  56. rm -rf $BUILD_DIR
  57. if [ $? -eq 0 ]; then
  58. echo "$BUILD_DIR removed."
  59. else
  60. echo "Failed to remove directory."
  61. return $ARIA_ERROR_RM_FAIL
  62. fi
  63. # create a fresh directory
  64. mkdir -p $BUILD_DIR
  65. if [ $? -eq 0 ]; then
  66. echo "$BUILD_DIR created."
  67. else
  68. echo "Failed to create directory $BUILD_DIR"
  69. return $ARIA_ERROR_MKDIR_FAIL
  70. fi
  71. # change into build directory
  72. pushd $BUILD_DIR
  73. # initial cmake
  74. echo "********************************************************************"
  75. echo "CMake for $BUILD_MESSAGE"
  76. if [ -z "$BUILD_OPTION" ]; then
  77. echo "(No additional build options)"
  78. else
  79. echo "Using build option: $BUILD_OPTION"
  80. fi
  81. echo "********************************************************************"
  82. cmake .. $BUILD_OPTION
  83. if [ $? -eq 0 ]; then
  84. echo "cmake successful."
  85. else
  86. echo "ERROR: cmake failed"
  87. return $ARIA_ERROR_CMAKE_FAIL
  88. fi
  89. # build
  90. echo "********************************************************************"
  91. echo "Build for $BUILD_MESSAGE"
  92. if [ -z "$BUILD_OPTION" ]; then
  93. echo "(No additional build options)"
  94. else
  95. echo "Using build option: $BUILD_OPTION"
  96. fi
  97. echo "********************************************************************"
  98. cmake --build .
  99. if [ $? -eq 0 ]; then
  100. echo "cmake build successful."
  101. else
  102. echo "ERROR: cmake build failed"
  103. return $ARIA_ERROR_BUILD_FAIL
  104. fi
  105. # View the available ciphers with:
  106. echo "checking wolfsl client ssl version numbers SSLv3(0) - TLS1.3(4):"
  107. if ./examples/client/client -V; then
  108. echo "Confirmed ./examples/client/client operational."
  109. else
  110. echo "ERROR ./examples/client/client error = $?"
  111. return $ARIA_ERROR_CLIENT_FAIL
  112. fi
  113. # now see if we have ARIA ciphers
  114. if ./examples/client/client -e | awk '/ARIA/{found=1} END{exit !found}'; then
  115. if [ "$EXPECTED_ARIA" == "Y" ]; then
  116. echo "Found ARIA ciphers as expected."
  117. else
  118. echo "ERROR: Found ARIA ciphers when NOT expected."
  119. return $ARIA_ERROR_CIPHER_FAIL
  120. fi
  121. else
  122. if [ "$EXPECTED_ARIA" == "N" ]; then
  123. echo "No ARIA ciphers found as expected with ./examples/client/client -e"
  124. else
  125. echo "ERROR: No ARIA ciphers found, EXPECTED_ARIA parameter = \"$EXPECTED_ARIA\"; expected \"N\"."
  126. return $ARIA_ERROR_CONFIG_FAIL
  127. fi
  128. fi
  129. ./examples/client/client -e
  130. echo "Return to working directory."
  131. popd
  132. echo "********************************************************************"
  133. echo "Completed $BUILD_MESSAGE"
  134. echo "********************************************************************"
  135. echo ""
  136. }
  137. set -e
  138. # No ARIA Environment Variable
  139. export ARIA_DIR=
  140. export THIS_MESSAGE="No ARIA Environment Variable, ARIA not enabled."
  141. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  142. export ARIA_DIR=
  143. export THIS_MESSAGE="No ARIA Environment Variable, ARIA Enabled"
  144. build_aria_test 0 Y "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  145. # ARIA Environment Variable with MagicCrypto in local user directory
  146. export ARIA_DIR=~/MagicCrypto
  147. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in local user directory, ARIA not enabled."
  148. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  149. export ARIA_DIR=~/MagicCrypto
  150. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in local user directory, ARIA Enabled"
  151. build_aria_test 0 Y "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  152. # ARIA Environment Variable with MagicCrypto in wolfssl directory
  153. export ARIA_DIR=~/MagicCrypto
  154. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in wolfssl directory, ARIA not enabled."
  155. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  156. export ARIA_DIR=./MagicCrypto
  157. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in wolfssl, ARIA Enabled"
  158. build_aria_test 0 Y "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  159. # ARIA Environment Variable with bad directory, ARIA not enabled so bad directory ignored
  160. export ARIA_DIR=./UnknownDirectory
  161. export THIS_MESSAGE="ARIA Environment Variable with bad directory, ARIA not enabled."
  162. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  163. # ARIA Environment Variable with bad directory, ARIA enabled so bad directory should fail
  164. set +e
  165. export ARIA_DIR=./UnknownDirectory
  166. export THIS_MESSAGE="ARIA Environment Variable with bad directory, ARIA Enabled"
  167. build_aria_test $ARIA_ERROR_CMAKE_FAIL N "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  168. if [ $? -eq $ARIA_ERROR_CMAKE_FAIL ]; then
  169. echo "Properly detected bad directory and failed as expected."
  170. else
  171. echo "Error: expected failure not detected."
  172. exit 1
  173. fi
  174. echo "Done. aria_cmake_build_test completed successfully!"
  175. exit 0