3 # Python bindings to libcryptsetup test
5 # Copyright (C) 2011-2014, 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.
21 from __future__ import print_function
26 sys.path.insert(0, ".libs")
31 PASSWORD2 = "password2"
32 DEVICE = "pycryptsetup_test_dev"
35 if level == pycryptsetup.CRYPT_LOG_ERROR:
40 print("Question:", txt)
48 print("status :",end="")
49 if r == pycryptsetup.CRYPT_ACTIVE:
51 elif r == pycryptsetup.CRYPT_INACTIVE:
58 print("WARNING: You must be root to run this test, test skipped.")
61 os.system("dd if=/dev/zero of=" + IMG + " bs=1M count=32 >/dev/null 2>&1")
63 c = pycryptsetup.CryptSetup(
68 passwordDialog = askpassword)
70 #c.debugLevel(pycryptsetup.CRYPT_DEBUG_ALL);
71 c.debugLevel(pycryptsetup.CRYPT_DEBUG_NONE);
75 c.askyes(message = "Is there anybody out there?")
76 c.log(priority = pycryptsetup.CRYPT_LOG_ERROR, message = "Nobody there...\n")
77 c.luksFormat(cipher = "aes", cipherMode= "xts-plain64", keysize = 512)
78 print("isLuks :", c.isLuks())
79 print("luksUUID:", c.luksUUID())
80 print("addKeyVK:", c.addKeyByVolumeKey(newPassphrase = PASSWORD, slot = 2))
81 print("addKeyP :", c.addKeyByPassphrase(passphrase = PASSWORD,
82 newPassphrase = PASSWORD2, slot = 3))
83 print("removeP :", c.removePassphrase(passphrase = PASSWORD2))
84 print("addKeyP :", c.addKeyByPassphrase(PASSWORD, PASSWORD2))
85 # original api required wrong passphrase parameter here
86 # print "killSlot:", c.killSlot(passphrase = "xxx", slot = 0)
87 print("killSlot:", c.killSlot(slot = 0))
88 print("activate:", c.activate(name = DEVICE, passphrase = PASSWORD))
89 print("suspend :", c.suspend())
90 # os.system("dmsetup info -c " + DEVICE)
91 print("resume :", c.resume(passphrase = PASSWORD))
94 print("cipher :", info["cipher"])
95 print("cmode :", info["cipher_mode"])
96 print("keysize :", info["keysize"])
97 print("dir :", info["dir"])
98 print("device :", info["device"])
99 print("offset :", info["offset"])
100 print("name :", info["name"])
101 print("uuid :", info["uuid"])
102 # os.system("cryptsetup luksDump " + info["device"])
103 print("deact. :", c.deactivate())
107 c = pycryptsetup.CryptSetup(
112 passwordDialog = askpassword)
114 print("activate:", c.activate(name = DEVICE, passphrase = PASSWORD))
116 c2 = pycryptsetup.CryptSetup(
120 passwordDialog = askpassword)
123 print("cipher :", info["cipher"])
124 print("cmode :", info["cipher_mode"])
125 print("keysize :", info["keysize"])
127 print("deact. :", c.deactivate())