| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 # | 5 # |
| 6 # | 6 # |
| 7 # This uses the cryptohome script to initialize an "IMAGE_DIR". This directory | 7 # This uses the cryptohome script to initialize an "IMAGE_DIR". This directory |
| 8 # will contain the system salt, and three master keys for a user called | 8 # will contain the system salt, and three master keys for a user called |
| 9 # testuser@invalid.domain. | 9 # testuser@invalid.domain. |
| 10 # | 10 # |
| 11 # The three keys will have the passwords "zero", "one" and "two". You can use | 11 # The three keys will have the passwords "zero", "one" and "two". You can use |
| 12 # the check_cryptohome_data.sh script to verify that cryptohome can | 12 # the check_cryptohome_data.sh script to verify that cryptohome can |
| 13 # successfully decrypt these keys. The authenticator_unittest.cc testcases | 13 # successfully decrypt these keys. The authenticator_unittest.cc testcases |
| 14 # call this script to create their test data. | 14 # call this script to create their test data. |
| 15 # | 15 # |
| 16 | 16 |
| 17 # mock dmsetup because we don't have it in the chroot and don't need it here. | |
| 18 function dmsetup { exit 255; } | |
| 19 | |
| 20 CH_LIB="./lib" | |
| 21 source "$CH_LIB/common" | |
| 22 source "$CH_LIB/utils/declare_commands" | |
| 23 | |
| 24 utils::declare_commands sha256sum | |
| 25 | |
| 26 USERNAME="testuser@invalid.domain" | 17 USERNAME="testuser@invalid.domain" |
| 27 PASSWORDS="zero one two" | 18 PASSWORDS="zero one two" |
| 28 | 19 |
| 29 function usage { | 20 function usage { |
| 30 $echo "Usage: $0 [-q] <image-dir>" | 21 echo "Usage: $0 [-q] <image-dir>" |
| 31 $echo | 22 echo |
| 32 $echo "Initialize a directory of sample cryptohome data containing " | 23 echo "Initialize a directory of sample cryptohome data containing " |
| 33 $echo "system salt, and a single user named $USERNAME." | 24 echo "system salt, and a single user named $USERNAME." |
| 34 $echo "The user will have three master keys, encrypted with the " | 25 echo "The user will have three master keys, encrypted with the " |
| 35 $echo "passwords: $PASSWORDS." | 26 echo "passwords: $PASSWORDS." |
| 36 $echo | 27 echo |
| 37 $echo " -q Quiet mode" | 28 echo " -q Quiet mode" |
| 38 $echo " <image-dir> Directory to store cryptohome data" | 29 echo " <image-dir> Directory to store cryptohome data" |
| 39 $echo | 30 echo |
| 40 exit 1 | 31 exit 1 |
| 41 } | 32 } |
| 42 | 33 |
| 43 QUIET=0 | 34 QUIET=0 |
| 44 IMAGE_DIR="" | 35 IMAGE_DIR="" |
| 45 | 36 |
| 46 while [ ! -z "$1" ]; do | 37 while [ ! -z "$1" ]; do |
| 47 if [ "$1" == "-q" ]; then | 38 if [ "$1" == "-q" ]; then |
| 48 QUIET=1; shift | 39 QUIET=1; shift |
| 49 elif [ -z "$IMAGE_DIR" ]; then | 40 elif [ -z "$IMAGE_DIR" ]; then |
| (...skipping 18 matching lines...) Expand all Loading... |
| 68 info="no_echo" | 59 info="no_echo" |
| 69 fi | 60 fi |
| 70 | 61 |
| 71 if [ -d "$IMAGE_DIR" ]; then | 62 if [ -d "$IMAGE_DIR" ]; then |
| 72 $info "Image directory '$IMAGE_DIR' exists. Remove it if you would like to" | 63 $info "Image directory '$IMAGE_DIR' exists. Remove it if you would like to" |
| 73 $info "re-initialize the test data." | 64 $info "re-initialize the test data." |
| 74 exit 0 | 65 exit 0 |
| 75 fi | 66 fi |
| 76 | 67 |
| 77 $info "Initializing sample crpytohome image root: $IMAGE_DIR" | 68 $info "Initializing sample crpytohome image root: $IMAGE_DIR" |
| 78 $mkdir -p "$IMAGE_DIR" | 69 mkdir -p "$IMAGE_DIR" |
| 79 | 70 |
| 80 $info "Creating system salt." | 71 $info "Creating system salt." |
| 81 SYSTEM_SALT_FILE="$IMAGE_DIR/salt" | 72 SYSTEM_SALT_FILE="$IMAGE_DIR/salt" |
| 82 $head -c 16 /dev/urandom > $SYSTEM_SALT_FILE | 73 head -c 16 /dev/urandom > $SYSTEM_SALT_FILE |
| 83 | 74 |
| 84 $info "Creating user directory" | 75 $info "Creating user directory" |
| 85 | 76 |
| 86 USERID=$($cat "$SYSTEM_SALT_FILE" <($echo -n $USERNAME) \ | 77 USERID=$(cat "$SYSTEM_SALT_FILE" <(echo -n $USERNAME) \ |
| 87 | $openssl sha1) | 78 | openssl sha1) |
| 88 | 79 |
| 89 $info "USERNAME: $USERNAME" | 80 $info "USERNAME: $USERNAME" |
| 90 $info "USERID: $USERID" | 81 $info "USERID: $USERID" |
| 91 | 82 |
| 92 $mkdir -p "$IMAGE_DIR/skel/sub_path" | 83 mkdir -p "$IMAGE_DIR/skel/sub_path" |
| 93 echo -n "testfile" > "$IMAGE_DIR/skel/sub_path/.testfile" | 84 echo -n "testfile" > "$IMAGE_DIR/skel/sub_path/.testfile" |
| 94 | 85 |
| 95 $mkdir -p "$IMAGE_DIR/$USERID" | 86 mkdir -p "$IMAGE_DIR/$USERID" |
| 96 | 87 |
| 97 $info "Creating master keys..." | 88 $info "Creating master keys..." |
| 98 INDEX=0 | 89 INDEX=0 |
| 99 for PASSWORD in $PASSWORDS; do | 90 for PASSWORD in $PASSWORDS; do |
| 100 $info "PASSWORD: $PASSWORD" | 91 $info "PASSWORD: $PASSWORD" |
| 101 | 92 |
| 102 ASCII_SALT=$(cat "$SYSTEM_SALT_FILE" | xxd -p) | 93 ASCII_SALT=$(cat "$SYSTEM_SALT_FILE" | xxd -p) |
| 103 | 94 |
| 104 echo -n "${ASCII_SALT}${PASSWORD}" | sha256sum | head -c 32 \ | 95 echo -n "${ASCII_SALT}${PASSWORD}" | sha256sum | head -c 32 \ |
| 105 > "$IMAGE_DIR/$USERID/pwhash.$INDEX" | 96 > "$IMAGE_DIR/$USERID/pwhash.$INDEX" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 EXIT=$? | 131 EXIT=$? |
| 141 if [ $EXIT != 0 ]; then | 132 if [ $EXIT != 0 ]; then |
| 142 exit $EXIT | 133 exit $EXIT |
| 143 fi | 134 fi |
| 144 | 135 |
| 145 READABLE=$(cat "$IMAGE_DIR/$USERID/master.$INDEX" |xxd -p) | 136 READABLE=$(cat "$IMAGE_DIR/$USERID/master.$INDEX" |xxd -p) |
| 146 $info "MASTER_KEY: $READABLE" | 137 $info "MASTER_KEY: $READABLE" |
| 147 | 138 |
| 148 INDEX=$(($INDEX + 1)) | 139 INDEX=$(($INDEX + 1)) |
| 149 done | 140 done |
| OLD | NEW |