def init(self): self.name = sha256(self.path.encode()).hexdigest() try: self.path = str(PosixPath(self.path).resolve()) except Exception as e: log_to_systemd( pycryptsetup.CRYPT_LOG_ERROR, "Can't get absolute path for '{}': {}".format(self.path, e)) return False try: self.c = pycryptsetup.CryptSetup(device=self.path, name=self.name, logFunc=log_to_systemd) except Exception as e: log_to_systemd( pycryptsetup.CRYPT_LOG_ERROR, "Device {} with path {} error: {}".format( self.path, self.name, e)) return False self.c.debugLevel( CRYPT_DEBUG_ALL if DEBUG_MSG_ENABLE else CRYPT_DEBUG_NONE) log_to_systemd( pycryptsetup.CRYPT_LOG_DEBUG, "Instance correctly initialized with path: {}".format(self.path)) return True
def get_cryptsetup_obj(device, map_name): ''' Initialize and return a CryptSetup object ''' crs = pycryptsetup.CryptSetup(device=device, name=map_name, yesDialog=askyes, logFunc=log) crs.debugLevel(pycryptsetup.CRYPT_DEBUG_NONE) return crs
r = c.status() print "status :", if r == pycryptsetup.CRYPT_ACTIVE: print "ACTIVE" elif r == pycryptsetup.CRYPT_INACTIVE: print "INACTIVE" else: print "ERROR" return os.system("dd if=/dev/zero of=" + IMG + " bs=1M count=32 >/dev/null 2>&1") c = pycryptsetup.CryptSetup(device=IMG, name=DEVICE, yesDialog=askyes, logFunc=log, passwordDialog=askpassword) #c.debugLevel(pycryptsetup.CRYPT_DEBUG_ALL); c.debugLevel(pycryptsetup.CRYPT_DEBUG_NONE) c.iterationTime(1) r = c.isLuks() print "isLuks :", r c.askyes(message="Is there anybody out there?") c.log(priority=pycryptsetup.CRYPT_LOG_ERROR, message="Nobody there...\n") c.luksFormat(cipher="aes", cipherMode="xts-plain64", keysize=512) print "isLuks :", c.isLuks() print "luksUUID:", c.luksUUID() print "addKeyVK:", c.addKeyByVolumeKey(newPassphrase=PASSWORD, slot=2) print "addKeyP :", c.addKeyByPassphrase(passphrase=PASSWORD,