Fix keyfile=- processing in create command (1.3.0, issue 104)
authorMilan Broz <gmazyland@gmail.com>
Tue, 17 May 2011 15:34:40 +0000 (15:34 +0000)
committerMilan Broz <gmazyland@gmail.com>
Tue, 17 May 2011 15:34:40 +0000 (15:34 +0000)
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@524 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/setup.c
tests/password-hash-test

index 8476788..072fee6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2011-05-17  Milan Broz  <mbroz@redhat.com>
+       * Fix keyfile=- processing in create command (1.3.0).
+
 2011-05-03  Milan Broz  <mbroz@redhat.com>
        * Do not ignore size argument for create command (1.2.0).
 
index d4ad063..77c0d58 100644 (file)
@@ -2003,8 +2003,14 @@ int crypt_activate_by_keyfile(struct crypt_device *cd,
                return -EINVAL;
 
        if (isPLAIN(cd->type)) {
-               r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read,
-                                 &passphrase_size_read, keyfile, keyfile_size);
+               if (cd->plain_hdr.hash)
+                       r = crypt_get_key(_("Enter passphrase: "),
+                                         &passphrase_read, &passphrase_size_read,
+                                         0, keyfile, cd->timeout, 0, cd);
+               else
+                       r = key_from_file(cd, _("Enter passphrase: "),
+                                         &passphrase_read, &passphrase_size_read,
+                                         keyfile, keyfile_size);
                if (r < 0)
                        goto out;
                r = create_device_helper(cd, name, cd->plain_hdr.hash,
index 4036ff1..e45f559 100755 (executable)
@@ -34,10 +34,14 @@ crypt_key() # hash keysize pwd/file name outkey [limit]
                echo -e -n "$4" | $CRYPTSETUP create -c $MODE -h $1 -s $2 $LIMIT $DEV2 /dev/mapper/$DEV_NAME 2>/dev/null
                ret=$?
                ;;
-       stdin)
+       std-)
                echo -e -n "$4" | $CRYPTSETUP create -c $MODE -d "-" -h $1 -s $2 $LIMIT $DEV2 /dev/mapper/$DEV_NAME 2>/dev/null
                ret=$?
                ;;
+       stdin)
+               echo -e -n "$4" | $CRYPTSETUP create -c $MODE -h $1 -s $2 $LIMIT $DEV2 /dev/mapper/$DEV_NAME 2>/dev/null
+               ret=$?
+               ;;
        cat)
                cat $4 | $CRYPTSETUP create -c $MODE -h $1 -s $2 $LIMIT $DEV2 /dev/mapper/$DEV_NAME 2>/dev/null
                ret=$?
@@ -51,9 +55,12 @@ crypt_key() # hash keysize pwd/file name outkey [limit]
                ;;
        esac
 
-       if [ $ret -ne 0 ] ; then
-               echo " [n/a]"
-               return
+       # ignore these cases, not all libs/kernel supports it
+       if [ "$1" == "ripemd160" -o $2 -gt 256 ] ; then
+               if [ $ret -ne 0 ] ; then
+                       echo " [N/A] ($ret, SKIPPED)"
+                       return
+               fi
        fi
 
        VKEY=$(dmsetup table $DEV2 --showkeys 2>/dev/null | cut -d' '  -f 5)
@@ -84,12 +91,17 @@ crypt_key sha1      128 pwd "xxx" b60d121b438a380c343d5ec3c2037564
 crypt_key sha256    256 pwd "xxx" cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf6860
 crypt_key sha256    128 pwd "xxx" cd2eb0837c9b4c962c22d2ff8b5441b7
 
-crypt_key ripemd160   0 stdin "xxx"   aeb26d1f69eb6dddfb9381eed4d7299f091e99aa5d3ff06866d4ce9f620f7aca
-crypt_key ripemd160 256 stdin "xxx\n" 625ce2a8dbdf08f1de400dba7ab9fab246f2a55ad6136e6cafd6703732dab8cf
+crypt_key sha256   0 std- "xxx"    cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf6860
+crypt_key sha256 256 std- "xxx\n"  042aea10a0f14f2d391373599be69d53a75dde9951fc3d3cd10b6100aa7a9f24
+crypt_key sha256 128 std- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" \
+                                  2a42b97084779dcedf2c66405c5d296c
+crypt_key sha256 256 stdin "xxx"   cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf6860
+crypt_key sha256   0 stdin "xxx\n" cd2eb0837c9b4c962c22d2ff8b5441b7b45805887f051d39bf133b583baf6860
 
 # with keyfile, hash is ignored
 crypt_key ripemd160 256 file /dev/zero 0000000000000000000000000000000000000000000000000000000000000000
 crypt_key sha256    256 file /dev/zero 0000000000000000000000000000000000000000000000000000000000000000
+crypt_key unknown*  256 file /dev/zero 0000000000000000000000000000000000000000000000000000000000000000
 
 # limiting key
 crypt_key sha256:20 256 pwd "xxx" cd2eb0837c9b4c962c22d2ff8b5441b7b4580588000000000000000000000000