fips-check.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/bash
  2. # fips-check.sh
  3. # This script checks the current revision of the code against the
  4. # previous release of the FIPS code. While wolfSSL and wolfCrypt
  5. # may be advancing, they must work correctly with the last tested
  6. # copy of our FIPS approved code.
  7. #
  8. # This should check out all the approved versions. The command line
  9. # option selects the version.
  10. #
  11. # $ ./fips-check [version]
  12. #
  13. # - version: linux (default), ios, android, windows
  14. #
  15. function Usage() {
  16. echo "Usage: $0 [platform]"
  17. echo "Where \"platform\" is one of linux (default), ios, android, windows"
  18. }
  19. LINUX_FIPS_VERSION=v3.2.6
  20. LINUX_FIPS_REPO=git@github.com:wolfSSL/fips.git
  21. LINUX_CTAO_VERSION=v3.2.6
  22. LINUX_CTAO_REPO=git@github.com:cyassl/cyassl.git
  23. IOS_FIPS_VERSION=v3.4.8a
  24. IOS_FIPS_REPO=git@github.com:wolfSSL/fips.git
  25. IOS_CTAO_VERSION=v3.4.8.fips
  26. IOS_CTAO_REPO=git@github.com:cyassl/cyassl.git
  27. ANDROID_FIPS_VERSION=v3.5.0
  28. ANDROID_FIPS_REPO=git@github.com:wolfSSL/fips.git
  29. ANDROID_CTAO_VERSION=v3.5.0
  30. ANDROID_CTAO_REPO=git@github.com:cyassl/cyassl.git
  31. #WINDOWS_FIPS_VERSION=v3.6.0
  32. WINDOWS_FIPS_VERSION=master
  33. WINDOWS_FIPS_REPO=git@github.com:wolfSSL/fips.git
  34. WINDOWS_CTAO_VERSION=v3.6.0
  35. WINDOWS_CTAO_REPO=git@github.com:cyassl/cyassl.git
  36. FIPS_SRCS=( fips.c fips_test.c )
  37. WC_MODS=( aes des3 sha sha256 sha512 rsa hmac random )
  38. TEST_DIR=XXX-fips-test
  39. WC_INC_PATH=cyassl/ctaocrypt
  40. WC_SRC_PATH=ctaocrypt/src
  41. if [ "x$1" == "x" ]; then PLATFORM="linux"; else PLATFORM=$1; fi
  42. case $PLATFORM in
  43. ios)
  44. FIPS_VERSION=$IOS_FIPS_VERSION
  45. FIPS_REPO=$IOS_FIPS_REPO
  46. CTAO_VERSION=$IOS_CTAO_VERSION
  47. CTAO_REPO=$IOS_CTAO_REPO
  48. ;;
  49. android)
  50. FIPS_VERSION=$ANDROID_FIPS_VERSION
  51. FIPS_REPO=$ANDROID_FIPS_REPO
  52. CTAO_VERSION=$ANDROID_CTAO_VERSION
  53. CTAO_REPO=$ANDROID_CTAO_REPO
  54. ;;
  55. windows)
  56. FIPS_VERSION=$WINDOWS_FIPS_VERSION
  57. FIPS_REPO=$WINDOWS_FIPS_REPO
  58. CTAO_VERSION=$WINDOWS_CTAO_VERSION
  59. CTAO_REPO=$WINDOWS_CTAO_REPO
  60. ;;
  61. linux)
  62. FIPS_VERSION=$LINUX_FIPS_VERSION
  63. FIPS_REPO=$LINUX_FIPS_REPO
  64. CTAO_VERSION=$LINUX_CTAO_VERSION
  65. CTAO_REPO=$LINUX_CTAO_REPO
  66. ;;
  67. *)
  68. Usage
  69. exit 1
  70. esac
  71. git clone . $TEST_DIR
  72. [ $? -ne 0 ] && echo "\n\nCouldn't duplicate current working directory.\n\n" && exit 1
  73. pushd $TEST_DIR
  74. # make a clone of the last FIPS release tag
  75. git clone -b $CTAO_VERSION $CTAO_REPO old-tree
  76. [ $? -ne 0 ] && echo "\n\nCouldn't checkout the FIPS release.\n\n" && exit 1
  77. for MOD in ${WC_MODS[@]}
  78. do
  79. cp old-tree/$WC_SRC_PATH/${MOD}.c $WC_SRC_PATH
  80. cp old-tree/$WC_INC_PATH/${MOD}.h $WC_INC_PATH
  81. done
  82. # The following is temporary. We are using random.c from a separate release
  83. pushd old-tree
  84. git checkout v3.6.0
  85. popd
  86. cp old-tree/$WC_SRC_PATH/random.c $WC_SRC_PATH
  87. cp old-tree/$WC_INC_PATH/random.h $WC_INC_PATH
  88. # clone the FIPS repository
  89. git clone -b $FIPS_VERSION $FIPS_REPO fips
  90. [ $? -ne 0 ] && echo "\n\nCouldn't checkout the FIPS repository.\n\n" && exit 1
  91. for SRC in ${FIPS_SRCS[@]}
  92. do
  93. cp fips/$SRC $WC_SRC_PATH
  94. done
  95. # run the make test
  96. ./autogen.sh
  97. ./configure --enable-fips
  98. make
  99. [ $? -ne 0 ] && echo "\n\nMake failed. Debris left for analysis." && exit 1
  100. NEWHASH=`./wolfcrypt/test/testwolfcrypt | sed -n 's/hash = \(.*\)/\1/p'`
  101. if [ -n "$NEWHASH" ]; then
  102. sed -i.bak "s/^\".*\";/\"${NEWHASH}\";/" $WC_SRC_PATH/fips_test.c
  103. make clean
  104. fi
  105. make test
  106. [ $? -ne 0 ] && echo "\n\nTest failed. Debris left for analysis." && exit 1
  107. # Clean up
  108. popd
  109. rm -rf $TEST_DIR