aria-cmake-build-test.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. ./examples/client/client -V
  108. if [ $? -eq 0 ]; then
  109. echo "Confirmed ./examples/client/client operational."
  110. else
  111. echo "ERROR ./examples/client/client error = $?"
  112. return $ARIA_ERROR_CLIENT_FAIL
  113. fi
  114. # now see if we have ARIA ciphers
  115. if ./examples/client/client -e | awk '/ARIA/{found=1} END{exit !found}'; then
  116. if [ "$EXPECTED_ARIA" == "Y" ]; then
  117. echo "Found ARIA ciphers as expected."
  118. else
  119. echo "ERROR: Found ARIA ciphers when NOT expected."
  120. return $ARIA_ERROR_CIPHER_FAIL
  121. fi
  122. else
  123. if [ "$EXPECTED_ARIA" == "N" ]; then
  124. echo "No ARIA ciphers found as expected with ./examples/client/client -e"
  125. else
  126. echo "ERROR: No ARIA ciphers found, EXPECTED_ARIA parameter = \"$EXPECTED_ARIA\"; expected \"N\"."
  127. return $ARIA_ERROR_CONFIG_FAIL
  128. fi
  129. fi
  130. ./examples/client/client -e
  131. echo "Return to working directory."
  132. popd
  133. echo "********************************************************************"
  134. echo "Completed $BUILD_MESSAGE"
  135. echo "********************************************************************"
  136. echo ""
  137. }
  138. set -e
  139. # No ARIA Environment Variable
  140. export ARIA_DIR=
  141. export THIS_MESSAGE="No ARIA Environment Variable, ARIA not enabled."
  142. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  143. export ARIA_DIR=
  144. export THIS_MESSAGE="No ARIA Environment Variable, ARIA Enabled"
  145. build_aria_test 0 Y "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  146. # ARIA Environment Variable with MagicCrypto in local user directory
  147. export ARIA_DIR=~/MagicCrypto
  148. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in local user directory, ARIA not enabled."
  149. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  150. export ARIA_DIR=~/MagicCrypto
  151. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in local user directory, ARIA Enabled"
  152. build_aria_test 0 Y "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  153. # ARIA Environment Variable with MagicCrypto in wolfssl directory
  154. export ARIA_DIR=~/MagicCrypto
  155. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in wolfssl directory, ARIA not enabled."
  156. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  157. export ARIA_DIR=./MagicCrypto
  158. export THIS_MESSAGE="ARIA Environment Variable with MagicCrypto in wolfssl, ARIA Enabled"
  159. build_aria_test 0 Y "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  160. # ARIA Environment Variable with bad directory, ARIA not enabled so bad directory ignored
  161. export ARIA_DIR=./UnknownDirectory
  162. export THIS_MESSAGE="ARIA Environment Variable with bad directory, ARIA not enabled."
  163. build_aria_test 0 N "$THIS_MESSAGE" "$ARIA_BUILD_DIR"
  164. # ARIA Environment Variable with bad directory, ARIA enabled so bad directory should fail
  165. set +e
  166. export ARIA_DIR=./UnknownDirectory
  167. export THIS_MESSAGE="ARIA Environment Variable with bad directory, ARIA Enabled"
  168. build_aria_test $ARIA_ERROR_CMAKE_FAIL N "$THIS_MESSAGE" "$ARIA_BUILD_DIR" "-DWOLFSSL_ARIA=yes"
  169. if [ $? -eq $ARIA_ERROR_CMAKE_FAIL ]; then
  170. echo "Properly detected bad directory and failed as expected."
  171. else
  172. echo "Error: expected failure not detected."
  173. exit 1
  174. fi
  175. echo "Done. aria_cmake_build_test completed successfully!"
  176. exit 0