Cherry-pick: stateful recovery: simplify and add unittests

At present stateful encryption should spend some time enabled but trivially
bypassable.  This will give it additional time to bake while keeping risks
at a minimum.  Once all the tooling is in place, we can renable owner and
write-protect checking in this class to enable proper enforcement of
stateful disk encryption.

It also adds reboot-to-recovery after the copy is complete.  This does mean
that until the flag file is removed, the system will continously copy and
reboot to recovery.

This change also adds the missing Copy and ReadFileToString Platform mock.

TEST=new unittests pass (surprise!)
[----------] 4 tests from StatefulRecovery
[ RUN      ] StatefulRecovery.ValidRequest
[       OK ] StatefulRecovery.ValidRequest (0 ms)
[ RUN      ] StatefulRecovery.InvalidFlagFileContents
[0906/222329:ERROR:stateful_recovery.cc(47)] Bogus stateful recovery request file: 0 hello
[       OK ] StatefulRecovery.InvalidFlagFileContents (0 ms)
[ RUN      ] StatefulRecovery.UnreadableFlagFile
[       OK ] StatefulRecovery.UnreadableFlagFile (0 ms)
[ RUN      ] StatefulRecovery.UncopyableData
[       OK ] StatefulRecovery.UncopyableData (0 ms)
[----------] 4 tests from StatefulRecovery (1 ms total)

 echo -n "1" > /mnt/stateful_partition/decrypt_stateful && reboot
BUG=chromium-os:34218

Reviewed-on: https://gerrit.chromium.org/gerrit/32496
Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Will Drewry <wad@chromium.org>
Commit-Ready: Will Drewry <wad@chromium.org>

(Cherry-picked from I4f9c22b514b711ad68dc892f759afaf27da92307)

Change-Id: I14dc0e6d88752fb30fb6b6598648b269a5096de4
Reviewed-on: https://gerrit.chromium.org/gerrit/32931
Tested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Will Drewry <wad@chromium.org>
5 files changed
tree: f9b53166a4cdf1bb8a271eeadb1eb78b66695651
  1. etc/
  2. share/
  3. attestation.cc
  4. attestation.h
  5. attestation.proto
  6. attestation_unittest.cc
  7. common.mk
  8. credentials.h
  9. crypto.cc
  10. crypto.h
  11. crypto_unittest.cc
  12. cryptohome-path.cc
  13. cryptohome.cc
  14. cryptohome.xml
  15. cryptohome_common.h
  16. cryptohome_event_source.cc
  17. cryptohome_event_source.h
  18. cryptohome_event_source_unittest.cc
  19. cryptohome_testrunner.cc
  20. cryptohomed.cc
  21. cryptolib.cc
  22. cryptolib.h
  23. email_to_image
  24. homedirs.cc
  25. homedirs.h
  26. homedirs_unittest.cc
  27. inherit-review-settings-ok
  28. install_attributes.cc
  29. install_attributes.h
  30. install_attributes.proto
  31. install_attributes_unittest.cc
  32. interface.cc
  33. interface.h
  34. LICENSE
  35. lockbox.cc
  36. lockbox.h
  37. lockbox_unittest.cc
  38. make_tests.cc
  39. make_tests.h
  40. make_tests.sh
  41. Makefile
  42. marshal.list
  43. mock_homedirs.h
  44. mock_install_attributes.h
  45. mock_lockbox.h
  46. mock_mount.h
  47. mock_platform.h
  48. mock_tpm.h
  49. mock_user_session.h
  50. mount.cc
  51. mount.h
  52. mount_stack.cc
  53. mount_stack.h
  54. mount_stack_unittest.cc
  55. mount_task.cc
  56. mount_task.h
  57. mount_task_unittest.cc
  58. mount_unittest.cc
  59. OWNERS
  60. pam_mount.conf.xml
  61. pkcs11_init.cc
  62. pkcs11_init.h
  63. platform.cc
  64. platform.h
  65. README
  66. README.dbus
  67. README.homedirs
  68. README.lockbox
  69. README.tpm
  70. service.cc
  71. service.h
  72. service_unittest.cc
  73. stateful_recovery.cc
  74. stateful_recovery.h
  75. stateful_recovery_unittest.cc
  76. tpm.cc
  77. tpm.h
  78. tpm_init.cc
  79. tpm_init.h
  80. tpm_status.proto
  81. user_oldest_activity_timestamp_cache.cc
  82. user_oldest_activity_timestamp_cache.h
  83. user_oldest_activity_timestamp_cache_unittest.cc
  84. user_session.cc
  85. user_session.h
  86. user_session_unittest.cc
  87. username_passkey.cc
  88. username_passkey.h
  89. username_passkey_unittest.cc
  90. vault_keyset.cc
  91. vault_keyset.h
  92. vault_keyset.proto
  93. vault_keyset_unittest.cc
  94. WATCHLISTS