02-decrypt-reference-file.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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="${s_basename}-attempt_reference.txt"
  7. decrypted_reference_file_stderr="${s_basename}-attempt_reference.stderr"
  8. decrypted_badpass_file="${s_basename}-decrypt-badpass.txt"
  9. decrypted_badpass_log="${s_basename}-decrypt-badpass.log"
  10. scenario_cmd() {
  11. # Decrypt a reference file.
  12. setup_check_variables "scrypt dec"
  13. (
  14. echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
  15. dec -P "${encrypted_reference_file}" \
  16. "${decrypted_reference_file}" \
  17. 2> "${decrypted_reference_file_stderr}"
  18. echo $? > "${c_exitfile}"
  19. )
  20. # The decrypted reference file should match the reference.
  21. setup_check_variables "scrypt dec output against reference"
  22. cmp -s "${decrypted_reference_file}" "${reference_file}"
  23. echo $? > "${c_exitfile}"
  24. # We should not have any output on stderr.
  25. setup_check_variables "scrypt dec no stderr"
  26. test -s "${decrypted_reference_file_stderr}"
  27. expected_exitcode 1 $? > "${c_exitfile}"
  28. # Attempt to decrypt the reference file with an incorrect passphrase.
  29. # We want this command to fail with 1.
  30. setup_check_variables "scrypt dec bad passphrase"
  31. (
  32. echo "bad-pass" | ${c_valgrind_cmd} "${bindir}/scrypt" \
  33. dec -P "${encrypted_reference_file}" \
  34. "${decrypted_badpass_file}" \
  35. 2> "${decrypted_badpass_log}"
  36. expected_exitcode 1 $? > "${c_exitfile}"
  37. )
  38. # We should have received an error message.
  39. setup_check_variables "scrypt dec bad passphrase error"
  40. if grep -q "scrypt: Passphrase is incorrect" \
  41. "${decrypted_badpass_log}"; then
  42. echo "0"
  43. else
  44. echo "1"
  45. fi > "${c_exitfile}"
  46. # We should not have created a file.
  47. setup_check_variables "scrypt dec bad passphrase no file"
  48. if [ -e "${decrypted_badpass_file}" ]; then
  49. echo "1"
  50. else
  51. echo "0"
  52. fi > "${c_exitfile}"
  53. }