setclock.sh 812 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. get_new_clock() {
  4. tpm2 readclock > clock.yaml
  5. local clock=$(yaml_get_kv clock.yaml clock_info clock)
  6. # the magic number is enough time where where setting the clock to a point
  7. # in the future from where we read it.
  8. clock=$(($clock + 100000))
  9. echo -n $clock
  10. }
  11. cleanup() {
  12. tpm2 changeauth -c o -p newowner 2>/dev/null || true
  13. tpm2 changeauth -c p -p newplatform 2>/dev/null || true
  14. rm -f clock.yaml
  15. if [ "$1" != "no-shut-down" ]; then
  16. shut_down
  17. fi
  18. }
  19. trap cleanup EXIT
  20. start_up
  21. tpm2 setclock $(get_new_clock)
  22. # validate hierarchies and passwords
  23. tpm2 changeauth -c o newowner
  24. tpm2 changeauth -c p newplatform
  25. tpm2 setclock -c o -p newowner $(get_new_clock)
  26. tpm2 setclock -c p -p newplatform $(get_new_clock)
  27. exit 0