[rhel7-branch][PATCH] Unlock encrypted partitions before finding installations (#1043783)

Vratislav Podzimek vpodzime at redhat.com
Fri Jan 17 14:33:58 UTC 2014


Before trying to find existing installations, we should prompt user for
passphrase to unlock encrypted paritions and try to unlock them.

(port of 4f7b135ade6ad4df40541050ddc9d3379d343f09 from master)

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 pyanaconda/constants_text.py |  4 ++++
 pyanaconda/rescue.py         | 53 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/pyanaconda/constants_text.py b/pyanaconda/constants_text.py
index b4b4861..cad7216 100644
--- a/pyanaconda/constants_text.py
+++ b/pyanaconda/constants_text.py
@@ -40,6 +40,10 @@ TEXT_OK_STR = N_("OK")
 TEXT_OK_CHECK  = "ok"
 TEXT_OK_BUTTON = Translator(TEXT_OK_STR, TEXT_OK_CHECK)
 
+TEXT_CANCEL_STR = N_("Cancel")
+TEXT_CANCEL_CHECK = "cancel"
+TEXT_CANCEL_BUTTON = Translator(TEXT_CANCEL_STR, TEXT_CANCEL_CHECK)
+
 TEXT_YES_STR = N_("Yes")
 TEXT_YES_CHECK = "yes"
 TEXT_YES_BUTTON = Translator(TEXT_YES_STR, TEXT_YES_CHECK)
diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py
index 788eb25..ff74f6b 100644
--- a/pyanaconda/rescue.py
+++ b/pyanaconda/rescue.py
@@ -37,7 +37,23 @@ import time
 import re
 import network
 import subprocess
-from pykickstart.constants import *
+
+from snack import ButtonChoiceWindow, ListboxChoiceWindow,SnackScreen
+
+from constants import ANACONDA_CLEANUP, ROOT_PATH
+from constants_text import TEXT_OK_BUTTON, TEXT_NO_BUTTON, TEXT_YES_BUTTON
+from text import WaitWindow, OkCancelWindow, ProgressWindow, PassphraseEntryWindow
+from flags import flags
+from installinterfacebase import InstallInterfaceBase
+from i18n import _
+from kickstart import runPostScripts
+
+from blivet import mountExistingSystem
+from blivet.errors import StorageError
+from blivet.devices import LUKSDevice
+
+from pykickstart.constants import KS_REBOOT, KS_SHUTDOWN
+
 import meh.ui.text
 from pyanaconda.i18n import _
 
@@ -214,6 +230,40 @@ def _exception_handler_wrapper(orig_except_handler, screen, *args):
     screen.finish()
     return orig_except_handler(*args)
 
+def _unlock_devices(intf, storage):
+    try_passphrase = None
+    for device in storage.devices:
+        if device.format.type == "luks":
+            skip = False
+            unlocked = False
+            while not (skip or unlocked):
+                if try_passphrase is None:
+                    passphrase = intf.passphraseEntryWindow(device.name)
+                else:
+                    passphrase = try_passphrase
+
+                if passphrase is None:
+                    # canceled
+                    skip = True
+                else:
+                    device.format.passphrase = passphrase
+                    try:
+                        device.setup()
+                        device.format.setup()
+                        luks_dev = LUKSDevice(device.format.mapName,
+                                              parents=[device],
+                                              exists=True)
+                        storage.devicetree._addDevice(luks_dev)
+                        storage.devicetree.populate()
+                        unlocked = True
+                        # try to use the same passhprase for other devices
+                        try_passphrase = passphrase
+                    except StorageError as serr:
+                        log.error("Failed to unlock %s: %s", device.name, serr)
+                        device.teardown(recursive=True)
+                        device.format.passphrase = None
+                        try_passphrase = None
+
 def doRescue(intf, rescue_mount, ksdata):
     import blivet
 
@@ -271,6 +321,7 @@ def doRescue(intf, rescue_mount, ksdata):
 
     sto = blivet.Blivet(ksdata=ksdata)
     blivet.storageInitialize(sto, ksdata, [])
+    _unlock_devices(intf, sto)
     roots = blivet.findExistingInstallations(sto.devicetree)
 
     if not roots:
-- 
1.8.4.2



More information about the anaconda-patches mailing list