3 # Python bindings to libcryptsetup test
5 # Copyright (C) 2011, Red Hat, Inc. All rights reserved.
7 # This file is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This file is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this file; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 sys.path.insert(0, ".libs")
29 PASSWORD2 = "password2"
30 DEVICE = "pycryptsetup_test_dev"
33 if level == pycryptsetup.CRYPT_LOG_ERROR:
38 print "Question:", txt
47 if r == pycryptsetup.CRYPT_ACTIVE:
49 elif r == pycryptsetup.CRYPT_INACTIVE:
56 print "WARNING: You must be root to run this test, test skipped."
59 os.system("dd if=/dev/zero of=" + IMG + " bs=1M count=32 >/dev/null 2>&1")
61 c = pycryptsetup.CryptSetup(
66 passwordDialog = askpassword)
68 #c.debugLevel(pycryptsetup.CRYPT_DEBUG_ALL);
69 c.debugLevel(pycryptsetup.CRYPT_DEBUG_NONE);
73 c.askyes(message = "Is there anybody out there?")
74 c.log(priority = pycryptsetup.CRYPT_LOG_ERROR, message = "Nobody there...\n")
75 c.luksFormat(cipher = "aes", cipherMode= "xts-plain64", keysize = 512)
76 print "isLuks :", c.isLuks()
77 print "luksUUID:", c.luksUUID()
78 print "addKeyVK:", c.addKeyByVolumeKey(newPassphrase = PASSWORD, slot = 2)
79 print "addKeyP :", c.addKeyByPassphrase(passphrase = PASSWORD,
80 newPassphrase = PASSWORD2, slot = 3)
81 print "removeP :", c.removePassphrase(passphrase = PASSWORD2)
82 print "addKeyP :", c.addKeyByPassphrase(PASSWORD, PASSWORD2)
83 # original api required wrong passphrase parameter here
84 # print "killSlot:", c.killSlot(passphrase = "xxx", slot = 0)
85 print "killSlot:", c.killSlot(slot = 0)
86 print "activate:", c.activate(name = DEVICE, passphrase = PASSWORD)
87 print "suspend :", c.suspend()
88 # os.system("dmsetup info -c " + DEVICE)
89 print "resume :", c.resume(passphrase = PASSWORD)
92 print "cipher :", info["cipher"]
93 print "cmode :", info["cipher_mode"]
94 print "keysize :", info["keysize"]
95 print "dir :", info["dir"]
96 print "device :", info["device"]
97 print "offset :", info["offset"]
98 print "name :", info["name"]
99 print "uuid :", info["uuid"]
100 # os.system("cryptsetup luksDump " + info["device"])
101 print "deact. :", c.deactivate()
105 c = pycryptsetup.CryptSetup(
110 passwordDialog = askpassword)
112 print "activate:", c.activate(name = DEVICE, passphrase = PASSWORD)
114 c2 = pycryptsetup.CryptSetup(
118 passwordDialog = askpassword)
121 print "cipher :", info["cipher"]
122 print "cmode :", info["cipher_mode"]
123 print "keysize :", info["keysize"]
125 print "deact. :", c.deactivate()