tor.postinst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh -e
  2. # checking debian-tor account
  3. uid=`getent passwd debian-tor | cut -d ":" -f 3`
  4. home=`getent passwd debian-tor | cut -d ":" -f 6`
  5. # if there is the uid the account is there and we can do
  6. # the sanit(ar)y checks otherwise we can safely create it.
  7. if [ "$uid" ]; then
  8. if [ "$home" = "/var/lib/tor" ]; then
  9. :
  10. #echo "debian-tor homedir check: ok"
  11. else
  12. echo "ERROR: debian-tor account has an unexpected home directory!"
  13. echo "It should be '/var/lib/tor', but it is '$home'."
  14. echo "Removing the debian-tor user might fix this, but the question"
  15. echo "remains how you got into this mess to begin with."
  16. exit 1
  17. fi
  18. else
  19. adduser --quiet \
  20. --system \
  21. --disabled-password \
  22. --home /var/lib/tor \
  23. --no-create-home \
  24. --shell /bin/bash \
  25. --group \
  26. debian-tor
  27. fi
  28. for i in lib run log; do
  29. if ! [ -d "/var/$i/tor" ]; then
  30. echo "Something or somebody made /var/$i/tor disappear."
  31. echo "Creating one for you again."
  32. mkdir "/var/$i/tor"
  33. fi
  34. done
  35. find /var/lib/tor \( \( ! -user debian-tor \) -o \( ! -group debian-tor \) \) -print0 | xargs -0 --no-run-if-empty chown debian-tor:debian-tor
  36. find /var/lib/tor -type d -print0 | xargs -0 --no-run-if-empty chmod 02700
  37. find /var/lib/tor -type f -print0 | xargs -0 --no-run-if-empty chmod 00600
  38. if [ -e /var/run/tor ]; then
  39. find /var/run/tor \( \( ! -user debian-tor \) -o \( ! -group debian-tor \) \) -print0 | xargs -0 --no-run-if-empty chown debian-tor:debian-tor
  40. find /var/run/tor -type d -print0 | xargs -0 --no-run-if-empty chmod 02750
  41. find /var/run/tor -type f -print0 | xargs -0 --no-run-if-empty chmod 00600
  42. fi
  43. find /var/log/tor \( \( ! -user debian-tor \) -o \( ! -group adm \) \) -print0 | xargs -0 --no-run-if-empty chown debian-tor:adm
  44. find /var/log/tor -type d -print0 | xargs -0 --no-run-if-empty chmod 02750
  45. find /var/log/tor -type f -print0 | xargs -0 --no-run-if-empty chmod 00640
  46. move_away_keys=0
  47. if [ "$1" = "configure" ] &&
  48. [ -e /var/lib/tor/keys ] &&
  49. [ ! -z "$2" ]; then
  50. if dpkg --compare-versions "$2" lt 0.1.2.19-2; then
  51. move_away_keys=1
  52. elif dpkg --compare-versions "$2" gt 0.2.0 &&
  53. dpkg --compare-versions "$2" lt 0.2.0.26-rc; then
  54. move_away_keys=1
  55. fi
  56. fi
  57. if [ "$move_away_keys" = "1" ]; then
  58. echo "Retiring possibly compromised keys. See /usr/share/doc/tor/NEWS.Debian.gz"
  59. echo "and /var/lib/tor/keys/moved-away-by-tor-package/README.REALLY for"
  60. echo "further information."
  61. if ! [ -d /var/lib/tor/keys/moved-away-by-tor-package ]; then
  62. mkdir /var/lib/tor/keys/moved-away-by-tor-package
  63. cat > /var/lib/tor/keys/moved-away-by-tor-package/README.REALLY << EOF
  64. It has been discovered that the random number generator in Debian's
  65. openssl package is predictable. This is caused by an incorrect
  66. Debian-specific change to the openssl package (CVE-2008-0166). As a
  67. result, cryptographic key material may be guessable.
  68. See Debian Security Advisory number 1571 (DSA-1571) for more information:
  69. http://lists.debian.org/debian-security-announce/2008/msg00152.html
  70. The Debian package for Tor has moved away the onion keys upon package
  71. upgrade, and it will have moved away your identity key if it was created
  72. in the affected timeframe. There is no sure way to automatically tell
  73. if your key was created with an affected openssl library, so this move
  74. is done unconditionally.
  75. If you have restarted Tor since this change (and the package probably
  76. did that for you already unless you configured your system differently)
  77. then the Tor daemon already created new keys for itself and in all
  78. likelyhood is already working just fine with new keys.
  79. If you are absolutely certain that your identity key was created with
  80. a non-affected version of openssl and for some reason you have to retain
  81. the old identity, then you can move back the copy of secret_id_key to
  82. /var/lib/tor/keys. Do not move back the onion keys, they were created
  83. only recently since they are temporary keys with a lifetime of only a few
  84. days anyway.
  85. Sincerely,
  86. Peter Palfrader, Tue, 13 May 2008 13:32:23 +0200
  87. EOF
  88. fi
  89. for f in secret_onion_key secret_onion_key.old; do
  90. if [ -e /var/lib/tor/keys/"$f" ]; then
  91. mv -v /var/lib/tor/keys/"$f" /var/lib/tor/keys/moved-away-by-tor-package/"$f"
  92. fi
  93. done
  94. if [ -e /var/lib/tor/keys/secret_id_key ]; then
  95. id_mtime=`/usr/bin/stat -c %Y /var/lib/tor/keys/secret_id_key`
  96. sept=`date -d '2006-09-10' +%s`
  97. if [ "$id_mtime" -gt "$sept" ] ; then
  98. mv -v /var/lib/tor/keys/secret_id_key /var/lib/tor/keys/moved-away-by-tor-package/secret_id_key
  99. fi
  100. fi
  101. fi
  102. #DEBHELPER#
  103. exit 0