3 # This is the script that was used to create the image.gz in this directory.
5 # This requires a patched version of debugfs that understands the "fscrypt."
6 # xattr name prefix, so that the encryption xattrs can be manipulated.
17 create_encrypted_file() {
23 # not needed, but makes image more compressible
24 ino=$(stat -c %i "$file")
25 do_debugfs -R "zap_block -f <$ino> 0"
28 set_encryption_xattr() {
33 ino=$(stat -c %i "$file")
34 do_debugfs -R "ea_set <$ino> fscrypt.c $value"
37 rm_encryption_xattr() {
41 ino=$(stat -c %i "$file")
42 do_debugfs -R "ea_rm <$ino> fscrypt.c"
45 clear_encrypt_flag() {
49 ino=$(stat -c %i "$file")
50 do_debugfs -R "set_inode_field <$ino> flags 0"
56 local is_symlink=false
58 if [ -L "$file" ]; then
61 ino=$(stat -c %i "$file")
63 do_debugfs -R "ea_rm <$ino> fscrypt.c"
64 do_debugfs -R "set_inode_field <$ino> flags 0"
66 do_debugfs -R "set_inode_field <$ino> block[0] 0xAAAAAAAA"
67 do_debugfs -R "set_inode_field <$ino> block[1] 0"
68 do_debugfs -R "set_inode_field <$ino> size 4"
73 umount mnt &> /dev/null || true
75 dd if=/dev/zero of=image bs=4096 count=128
76 mke2fs -O encrypt -b 4096 -N 128 image
79 # Create an encrypted directory (ino 12)
82 echo password | e4crypt add_key $dir
84 # Control cases: valid encrypted regular file, dir, and symlink (ino 13-15)
85 create_encrypted_file $dir/encrypted_file
86 mkdir $dir/encrypted_dir
87 ln -s target $dir/encrypted_symlink
89 # Control case: file type that is never encrypted (ino 16)
92 # Inodes with missing encryption xattr (ino 17-18).
93 # e2fsck should offer to clear the encrypt flag on these inodes.
95 create_encrypted_file $dir/missing_xattr_file
96 rm_encryption_xattr $dir/missing_xattr_file
98 mkdir $dir/missing_xattr_dir
99 rm_encryption_xattr $dir/missing_xattr_dir
101 # Inodes with corrupt encryption xattr (ino 19-22).
102 # e2fsck should offer to clear these inodes.
104 create_encrypted_file $dir/corrupt_xattr_1
105 set_encryption_xattr $dir/corrupt_xattr_1 '\0'
107 create_encrypted_file $dir/corrupt_xattr_2
108 set_encryption_xattr $dir/corrupt_xattr_2 \
109 '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'
111 create_encrypted_file $dir/corrupt_xattr_3
112 set_encryption_xattr $dir/corrupt_xattr_3 '\1'
114 create_encrypted_file $dir/corrupt_xattr_4
115 set_encryption_xattr $dir/corrupt_xattr_4 '\2'
117 # Unencrypted inodes in encrypted directory (ino 23-25).
118 # e2fsck should offer to clear these directory entries.
120 create_encrypted_file $dir/unencrypted_file
121 clear_encryption $dir/unencrypted_file
123 mkdir $dir/unencrypted_dir
124 clear_encryption $dir/unencrypted_dir
126 ln -s target $dir/unencrypted_symlink
127 clear_encryption $dir/unencrypted_symlink
129 # Inodes with different encryption policy in encrypted directory (ino 26-29).
130 # e2fsck should offer to clear these directory entries.
132 xattr='\1\1\4\0AAAAAAAABBBBBBBBBBBBBBBB'
134 create_encrypted_file $dir/inconsistent_file_1
135 set_encryption_xattr $dir/inconsistent_file_1 $xattr
137 mkdir $dir/inconsistent_dir
138 set_encryption_xattr $dir/inconsistent_dir $xattr
140 ln -s target $dir/inconsistent_symlink
141 set_encryption_xattr $dir/inconsistent_symlink $xattr
143 xattr='\2\1\4\0\0\0\0\0AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB'
144 create_encrypted_file $dir/inconsistent_file_2
145 set_encryption_xattr $dir/inconsistent_file_2 $xattr
147 # Encrypted file and directory with valid v2 encryption policy (ino 30-31).
148 # e2fsck shouldn't change these.
151 echo password | e4crypt add_key $dir2
152 xattr='\2\1\4\0\0\0\0\0AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB'
153 create_encrypted_file $dir2/file
154 set_encryption_xattr $dir2/file $xattr
155 set_encryption_xattr $dir2 $xattr
157 # Encrypted file and directory with unrecognized encryption policy version
158 # (ino 32-33). e2fsck shouldn't change these.
161 echo password | e4crypt add_key $dir3
163 create_encrypted_file $dir3/file
164 set_encryption_xattr $dir3/file $xattr
165 set_encryption_xattr $dir3 $xattr