From 6e50fae9ec6dea35e12a65dbc46228a1e6276e07 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Tue, 22 Nov 2016 15:38:43 +0100 Subject: ipautil: move file encryption functions to installutils The encrypt_file() and decrypt_file() functions depend on ipaplatform. Move them to ipaserver.install.installutils, as they are only used for the server installer. https://fedorahosted.org/freeipa/ticket/6474 Reviewed-By: Stanislav Laznicka --- ipapython/ipautil.py | 57 ---------------------------------------------------- 1 file changed, 57 deletions(-) (limited to 'ipapython') diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 6a2118bc8..654fdd97e 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -49,7 +49,6 @@ from six.moves import input from six.moves import urllib from ipapython.ipa_log_manager import root_logger -from ipaplatform.paths import paths from ipapython.dn import DN GEN_PWD_LEN = 22 @@ -535,62 +534,6 @@ def backup_file(fname): if file_exists(fname): os.rename(fname, fname + ".orig") -def _ensure_nonempty_string(string, message): - if not isinstance(string, str) or not string: - raise ValueError(message) - -# uses gpg to compress and encrypt a file -def encrypt_file(source, dest, password, workdir = None): - _ensure_nonempty_string(source, 'Missing Source File') - #stat it so that we get back an exception if it does no t exist - os.stat(source) - - _ensure_nonempty_string(dest, 'Missing Destination File') - _ensure_nonempty_string(password, 'Missing Password') - - #create a tempdir so that we can clean up with easily - tempdir = tempfile.mkdtemp('', 'ipa-', workdir) - gpgdir = tempdir+"/.gnupg" - - try: - try: - #give gpg a fake dir so that we can leater remove all - #the cruft when we clean up the tempdir - os.mkdir(gpgdir) - args = [paths.GPG_AGENT, '--batch', '--homedir', gpgdir, '--daemon', paths.GPG, '--batch', '--homedir', gpgdir, '--passphrase-fd', '0', '--yes', '--no-tty', '-o', dest, '-c', source] - run(args, password, skip_output=True) - except: - raise - finally: - #job done, clean up - shutil.rmtree(tempdir, ignore_errors=True) - - -def decrypt_file(source, dest, password, workdir = None): - _ensure_nonempty_string(source, 'Missing Source File') - #stat it so that we get back an exception if it does no t exist - os.stat(source) - - _ensure_nonempty_string(dest, 'Missing Destination File') - _ensure_nonempty_string(password, 'Missing Password') - - #create a tempdir so that we can clean up with easily - tempdir = tempfile.mkdtemp('', 'ipa-', workdir) - gpgdir = tempdir+"/.gnupg" - - try: - try: - #give gpg a fake dir so that we can leater remove all - #the cruft when we clean up the tempdir - os.mkdir(gpgdir) - args = [paths.GPG_AGENT, '--batch', '--homedir', gpgdir, '--daemon', paths.GPG, '--batch', '--homedir', gpgdir, '--passphrase-fd', '0', '--yes', '--no-tty', '-o', dest, '-d', source] - run(args, password, skip_output=True) - except: - raise - finally: - #job done, clean up - shutil.rmtree(tempdir, ignore_errors=True) - class CIDict(dict): """ -- cgit