tools: Specify format of disks (RHBZ#642934,CVE-2010-3851).
[libguestfs.git] / regressions / test-luks.sh
1 #!/bin/bash -
2 # libguestfs
3 # Copyright (C) 2010 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 # Test LUKS device creation, opening, key slots.
20
21 set -e
22
23 rm -f test1.img
24
25 ../fish/guestfish --keys-from-stdin <<EOF
26 sparse test1.img 1G
27 run
28 part-disk /dev/sda mbr
29
30 # Create LUKS device with key "key0" in slot 0.
31 luks-format /dev/sda1 0
32 key0
33
34 # Open the device.
35 luks-open /dev/sda1 lukstest
36 key0
37
38 # Put some LVM structures on the encrypted device.
39 pvcreate /dev/mapper/lukstest
40 vgcreate VG /dev/mapper/lukstest
41 lvcreate LV1 VG 64
42 lvcreate LV2 VG 64
43 vg-activate-all false
44
45 # Close the device.
46 luks-close /dev/mapper/lukstest
47
48 # Add keys in other slots.
49 luks-add-key /dev/sda1 1
50 key0
51 key1
52 luks-add-key /dev/sda1 2
53 key1
54 key2
55 luks-add-key /dev/sda1 3
56 key2
57 key3
58
59 # Check we can open the device with one of the new keys.
60 luks-open /dev/sda1 lukstest
61 key1
62 luks-close /dev/mapper/lukstest
63 luks-open /dev/sda1 lukstest
64 key3
65 luks-close /dev/mapper/lukstest
66
67 # Remove a key.
68 luks-kill-slot /dev/sda1 1
69 key0
70
71 # This is expected to fail.
72 -luks-open /dev/sda1 lukstest
73 key1
74
75 # Replace a key slot.
76 luks-kill-slot /dev/sda1 3
77 key2
78 luks-add-key /dev/sda1 3
79 key2
80 newkey3
81
82 luks-open /dev/sda1 lukstest
83 newkey3
84 luks-close /dev/mapper/lukstest
85
86 EOF
87
88 rm -f test1.img