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:
55 os.system("dd if=/dev/zero of=" + IMG + " bs=1M count=32 >/dev/null 2>&1")
57 c = pycryptsetup.CryptSetup(
62 passwordDialog = askpassword)
64 #c.debugLevel(pycryptsetup.CRYPT_DEBUG_ALL);
65 c.debugLevel(pycryptsetup.CRYPT_DEBUG_NONE);
69 c.askyes(message = "Is there anybody out there?")
70 c.log(priority = pycryptsetup.CRYPT_LOG_ERROR, message = "Nobody there...\n")
71 c.luksFormat(cipher = "aes", cipherMode= "xts-plain64", keysize = 512)
72 print "isLuks :", c.isLuks()
73 print "luksUUID:", c.luksUUID()
74 print "addKeyVK:", c.addKeyByVolumeKey(newPassphrase = PASSWORD, slot = 2)
75 print "addKeyP :", c.addKeyByPassphrase(passphrase = PASSWORD,
76 newPassphrase = PASSWORD2, slot = 3)
77 print "removeP :", c.removePassphrase(passphrase = PASSWORD2)
78 print "addKeyP :", c.addKeyByPassphrase(PASSWORD, PASSWORD2)
79 # original api required wrong passphrase parameter here
80 # print "killSlot:", c.killSlot(passphrase = "xxx", slot = 0)
81 print "killSlot:", c.killSlot(slot = 0)
82 print "activate:", c.activate(name = DEVICE, passphrase = PASSWORD)
83 print "suspend :", c.suspend()
84 # os.system("dmsetup info -c " + DEVICE)
85 print "resume :", c.resume(passphrase = PASSWORD)
88 print "cipher :", info["cipher"]
89 print "cmode :", info["cipher_mode"]
90 print "keysize :", info["keysize"]
91 print "dir :", info["dir"]
92 print "device :", info["device"]
93 print "offset :", info["offset"]
94 print "name :", info["name"]
95 print "uuid :", info["uuid"]
96 # os.system("cryptsetup luksDump " + info["device"])
97 print "deact. :", c.deactivate()
101 c = pycryptsetup.CryptSetup(
106 passwordDialog = askpassword)
108 print "activate:", c.activate(name = DEVICE, passphrase = PASSWORD)
110 c2 = pycryptsetup.CryptSetup(
114 passwordDialog = askpassword)
117 print "cipher :", info["cipher"]
118 print "cmode :", info["cipher_mode"]
119 print "keysize :", info["keysize"]
121 print "deact. :", c.deactivate()