tpm-dad-lock 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash -e
  2. #
  3. # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. # Attempt to trigger the TPM Dictionary Attack Defense Lock and measure its
  7. # behavior.
  8. if [ -f /sys/class/misc/tpm0/device/owned ]; then
  9. owned=$(cat /sys/class/misc/tpm0/device/owned)
  10. else
  11. owned=$(cat /sys/class/tpm/tpm0/device/owned)
  12. fi
  13. if [ "$owned" = "" ]; then
  14. echo "TPM is not functional"
  15. exit 1
  16. fi
  17. if [ "$owned" = "0" ]; then
  18. echo "please use random, non-empty passwords"
  19. tpm_takeownership || exit 1
  20. fi
  21. attempts=0
  22. max=1
  23. e=/tmp/x$$
  24. while true; do
  25. attempts=$(( $attempts + 1 ))
  26. before=$(date +%s)
  27. defending=1
  28. while [ $defending -eq 1 ]; do
  29. if tpm_getpubek -z 2> $e; then
  30. echo "unexpected success of tpm_getpubek"
  31. exit 1
  32. fi
  33. if grep -q communication $e; then
  34. echo "communication failure"
  35. exit 1
  36. fi
  37. if ! grep -q dictionary $e; then
  38. defending=0
  39. fi
  40. done
  41. after=$(date +%s)
  42. elapsed=$(( $after - $before ))
  43. if [ $elapsed -gt $max ]; then
  44. echo delay of $elapsed seconds after $attempts attempts
  45. max=$elapsed
  46. fi
  47. done