Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | ### BEGIN INIT INFO |
| 3 | # Provides: urandom |
| 4 | # Required-Start: $local_fs mountvirtfs |
| 5 | # Required-Stop: $local_fs |
| 6 | # Default-Start: S |
| 7 | # Default-Stop: 0 6 |
| 8 | # Short-Description: Save and restore the random seed |
| 9 | # Description: Save the random seed on shutdown and restore it on boot, |
| 10 | # to ensure that the seed isn't predicable on startup |
| 11 | # (because the boot process is predictable) |
| 12 | ### END INIT INFO |
| 13 | |
| 14 | test -c /dev/urandom || exit 0 |
| 15 | |
| 16 | RANDOM_SEED_FILE=/var/lib/urandom/random-seed |
| 17 | |
| 18 | . /etc/default/rcS |
| 19 | [ -f /etc/default/urandom ] && . /etc/default/urandom |
| 20 | |
| 21 | case "$1" in |
| 22 | start|"") |
| 23 | test "$VERBOSE" != no && echo "Initializing random number generator..." |
| 24 | # Load and then save 512 bytes, which is the size of the entropy |
| 25 | # pool. Also load the current date, in case the seed file is |
| 26 | # empty. |
| 27 | ( date +%s.%N; [ -f "$RANDOM_SEED_FILE" ] && cat "$RANDOM_SEED_FILE" ) \ |
| 28 | >/dev/urandom |
| 29 | rm -f "$RANDOM_SEED_FILE" |
| 30 | umask 077 |
| 31 | dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \ |
| 32 | >/dev/null 2>&1 || echo "urandom start: failed." |
| 33 | umask 022 |
| 34 | ;; |
| 35 | stop) |
| 36 | # Carry a random seed from shut-down to start-up; |
| 37 | # see documentation in linux/drivers/char/random.c |
| 38 | test "$VERBOSE" != no && echo "Saving random seed..." |
| 39 | umask 077 |
| 40 | dd if=/dev/urandom of=$RANDOM_SEED_FILE count=1 \ |
| 41 | >/dev/null 2>&1 || echo "urandom stop: failed." |
| 42 | ;; |
| 43 | *) |
| 44 | echo "Usage: urandom {start|stop}" >&2 |
| 45 | exit 1 |
| 46 | ;; |
| 47 | esac |
| 48 | |
| 49 | exit 0 |