02-decrypt-reference-file.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. ### Constants
  3. c_valgrind_min=1
  4. reference_file="${scriptdir}/verify-strings/test_scrypt.good"
  5. encrypted_reference_file="${scriptdir}/verify-strings/test_scrypt_good.enc"
  6. decrypted_reference_file="${out}/attempt_reference.txt"
  7. decrypted_badpass_file="${out}/decrypt-badpass.txt"
  8. decrypted_badpass_log="${out}/decrypt-badpass.log"
  9. scenario_cmd() {
  10. # Decrypt a reference file.
  11. setup_check_variables
  12. (
  13. echo ${password} | ${c_valgrind_cmd} ${bindir}/scrypt \
  14. dec -P ${encrypted_reference_file} \
  15. ${decrypted_reference_file}
  16. echo $? > ${c_exitfile}
  17. )
  18. # The decrypted reference file should match the reference.
  19. setup_check_variables
  20. cmp -s ${decrypted_reference_file} ${reference_file}
  21. echo $? > ${c_exitfile}
  22. # Attempt to decrypt the reference file with an incorrect passphrase.
  23. # We want this command to fail with 1.
  24. setup_check_variables
  25. (
  26. echo "bad-pass" | ${c_valgrind_cmd} ${bindir}/scrypt \
  27. dec -P ${encrypted_reference_file} \
  28. ${decrypted_badpass_file} \
  29. 2> ${decrypted_badpass_log}
  30. expected_exitcode 1 $? > ${c_exitfile}
  31. )
  32. # We should have received an error message.
  33. setup_check_variables
  34. if grep -q "scrypt: Passphrase is incorrect" \
  35. ${decrypted_badpass_log}; then
  36. echo "0"
  37. else
  38. echo "1"
  39. fi > ${c_exitfile}
  40. setup_check_variables
  41. # We should not have created a file.
  42. if [ -e ${decrypted_badpass_file}} ]; then
  43. echo "1"
  44. else
  45. echo "0"
  46. fi > ${c_exitfile}
  47. }