07-passphrase-env.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_badpass_file="${s_basename}-decrypt-badpass.txt"
  8. decrypted_badpass_log="${s_basename}-decrypt-badpass.log"
  9. decrypted_no_envvar_log="${s_basename}-decrypt-no-envvar.log"
  10. scenario_cmd() {
  11. # Decrypt a reference file using --passphrase env:VAR.
  12. setup_check "scrypt dec env"
  13. PASSPHRASE="${password}" \
  14. ${c_valgrind_cmd} "${bindir}/scrypt" \
  15. dec --passphrase env:PASSPHRASE \
  16. "${encrypted_reference_file}" "${decrypted_reference_file}"
  17. echo $? > "${c_exitfile}"
  18. # The decrypted reference file should match the reference.
  19. setup_check "scrypt dec env output against reference"
  20. cmp -s "${decrypted_reference_file}" "${reference_file}"
  21. echo $? > "${c_exitfile}"
  22. # Attempt to decrypt the reference file with a non-existent envvar.
  23. # We want this command to fail with 1.
  24. setup_check "scrypt dec env none"
  25. ${c_valgrind_cmd} "${bindir}/scrypt" \
  26. dec --passphrase env:THIS_ENVVAR_DOES_NOT_EXIST \
  27. "${encrypted_reference_file}" "${decrypted_reference_file}" \
  28. 2> "${decrypted_no_envvar_log}"
  29. expected_exitcode 1 $? > "${c_exitfile}"
  30. # We should have received an error message.
  31. setup_check "scrypt dec env none error"
  32. grep -q \
  33. "scrypt: Failed to read from \${THIS_ENVVAR_DOES_NOT_EXIST}" \
  34. "${decrypted_no_envvar_log}"
  35. echo "$?" > "${c_exitfile}"
  36. # We should not have created a file.
  37. setup_check "scrypt dec env no file"
  38. test -e "${decrypted_badpass_file}"
  39. expected_exitcode 1 $? > "${c_exitfile}"
  40. # Attempt to decrypt the reference file with an incorrect passphrase.
  41. # We want this command to fail with 1.
  42. setup_check "scrypt dec env bad"
  43. PASSPHRASE="bad-pass" \
  44. ${c_valgrind_cmd} "${bindir}/scrypt" \
  45. dec --passphrase env:PASSPHRASE \
  46. "${encrypted_reference_file}" "${decrypted_reference_file}" \
  47. 2> "${decrypted_badpass_log}"
  48. expected_exitcode 1 $? > "${c_exitfile}"
  49. # We should have received an error message.
  50. setup_check "scrypt dec env bad error"
  51. grep -q "scrypt: Passphrase is incorrect" "${decrypted_badpass_log}"
  52. echo "$?" > "${c_exitfile}"
  53. setup_check "scrypt dec env bad no file"
  54. # We should not have created a file.
  55. test -e "${decrypted_badpass_file}"
  56. expected_exitcode 1 $? > "${c_exitfile}"
  57. }