08-passphrase-file.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. ### Constants
  3. c_valgrind_min=1
  4. reference_file="${scriptdir}/verify-strings/test_scrypt.good"
  5. passphrase_file="${s_basename}-passphrase.txt"
  6. bad_passphrase_file="${s_basename}-passphrase-bad.txt"
  7. encrypted_reference_file="${scriptdir}/verify-strings/test_scrypt_good.enc"
  8. decrypted_reference_file="${s_basename}-attempt_reference.txt"
  9. decrypted_badpass_file="${s_basename}-decrypt-badpass.txt"
  10. decrypted_badpass_log="${s_basename}-decrypt-badpass.log"
  11. decrypted_no_file_log="${s_basename}-decrypt-no-file.log"
  12. scenario_cmd() {
  13. # Create the passphrase file.
  14. echo "${password}" > "${passphrase_file}"
  15. # Decrypt a reference file using --passphrase file:FILENAME.
  16. setup_check "scrypt dec file"
  17. ${c_valgrind_cmd} "${bindir}/scrypt" \
  18. dec --passphrase file:"${passphrase_file}" \
  19. "${encrypted_reference_file}" "${decrypted_reference_file}"
  20. echo $? > "${c_exitfile}"
  21. # The decrypted reference file should match the reference.
  22. setup_check "scrypt dec file output against reference"
  23. cmp -s "${decrypted_reference_file}" "${reference_file}"
  24. echo $? > "${c_exitfile}"
  25. # Attempt to decrypt the reference file with a non-existent file.
  26. # We want this command to fail with 1.
  27. setup_check "scrypt dec file none"
  28. ${c_valgrind_cmd} "${bindir}/scrypt" \
  29. dec --passphrase file:THIS_FILE_DOES_NOT_EXIST \
  30. "${encrypted_reference_file}" "${decrypted_reference_file}" \
  31. 2> "${decrypted_no_file_log}"
  32. expected_exitcode 1 $? > "${c_exitfile}"
  33. # We should have received an error message.
  34. setup_check "scrypt dec file none error"
  35. grep -q "scrypt: fopen(THIS_FILE_DOES_NOT_EXIST)" \
  36. "${decrypted_no_file_log}"
  37. echo "$?" > "${c_exitfile}"
  38. # We should not have created a file.
  39. setup_check "scrypt dec file none no file"
  40. test -e "${decrypted_badpass_file}"
  41. expected_exitcode 1 $? > "${c_exitfile}"
  42. # Attempt to decrypt the reference file with an incorrect passphrase.
  43. # We want this command to fail with 1.
  44. setup_check "scrypt dec file bad"
  45. echo "bad-pass" > "${bad_passphrase_file}"
  46. ${c_valgrind_cmd} "${bindir}/scrypt" \
  47. dec --passphrase file:"${bad_passphrase_file}" \
  48. "${encrypted_reference_file}" "${decrypted_reference_file}" \
  49. 2> "${decrypted_badpass_log}"
  50. expected_exitcode 1 $? > "${c_exitfile}"
  51. # We should have received an error message.
  52. setup_check "scrypt dec file bad error"
  53. grep -q "scrypt: Passphrase is incorrect" "${decrypted_badpass_log}"
  54. echo "$?" > "${c_exitfile}"
  55. # We should not have created a file.
  56. setup_check "scrypt dec file bad no file"
  57. test -e "${decrypted_badpass_file}"
  58. expected_exitcode 1 $? > "${c_exitfile}"
  59. }