summaryrefslogtreecommitdiff
path: root/bugfix-add-SM3-with-tui.patch
blob: 01d77d988cff0549f0dc8c015921d0f4f6510c36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
From 1a11874c57156e576620dd396b4357ec9bab2cc4 Mon Sep 17 00:00:00 2001
From: sun_hai_10 <sunhai10@huawei.com>
Date: Tue, 29 Nov 2022 09:34:09 +0800
Subject: [PATCH] add SM3 with tui

---
 pyanaconda/ui/tui/spokes/root_password.py | 81 ++++++++++++++++++++---
 pyanaconda/ui/tui/tuiobject.py            |  7 +-
 2 files changed, 77 insertions(+), 11 deletions(-)

diff --git a/pyanaconda/ui/tui/spokes/root_password.py b/pyanaconda/ui/tui/spokes/root_password.py
index 3c5ba16..dfaca4e 100644
--- a/pyanaconda/ui/tui/spokes/root_password.py
+++ b/pyanaconda/ui/tui/spokes/root_password.py
@@ -26,7 +26,11 @@ from pyanaconda.core.i18n import N_, _
 from pyanaconda.modules.common.constants.services import USERS
 from pyanaconda.core.constants import PASSWORD_POLICY_ROOT
 
-from simpleline.render.widgets import TextWidget
+from simpleline.render.containers import ListColumnContainer
+from simpleline.render.prompt import Prompt
+from simpleline.render.screen import InputState
+from simpleline.render.screen_handler import ScreenHandler
+from simpleline.render.widgets import TextWidget, CheckboxWidget
 
 
 class PasswordSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
@@ -50,20 +54,18 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
         return FirstbootSpokeMixIn.should_run(environment, data)
 
     def __init__(self, data, storage, payload):
-        NormalTUISpoke.__init__(self, data, storage, payload)
-        self.initialize_start()
+        super().__init__(data, storage, payload)
         self.title = N_("Root password")
-        self.input_required = False
-
-        self._password = None
-
         self._users_module = USERS.get_proxy()
-        self.initialize_done()
+        self._sm3_config = False
+    
+    def _set_sm3_config(self, args):
+        self._sm3_config = not self._sm3_config
 
     @property
     def completed(self):
         return self._users_module.IsRootPasswordSet
-
+    
     @property
     def showable(self):
         return can_modify_root_configuration(self._users_module)
@@ -77,6 +79,59 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
     def status(self):
         return get_root_configuration_status(self._users_module)
 
+    def initialize(self):
+        self.initialize_start()
+        NormalTUISpoke.initialize(self)
+        self.initialize_done()
+
+    def refresh(self, args=None):
+        """ Refresh screen. """
+        NormalTUISpoke.refresh(self, args)
+
+        self._container = ListColumnContainer(1)
+
+        msg = _("SM3 encrypt")
+        sm3_check = CheckboxWidget(title=msg, completed=self._sm3_config)
+        self._container.add(sm3_check, self._set_sm3_config)
+
+        self.window.add_with_separator(self._container)
+
+    def input(self, args, key):
+        """Handle the user input."""
+        if self._container.process_user_input(key):
+            return InputState.PROCESSED_AND_REDRAW
+
+        if key.lower() == Prompt.CONTINUE:
+            spoke = RootPasswordSpoke(
+                self.data,
+                self.storage,
+                self.payload,
+                self._sm3_config,
+            )
+            ScreenHandler.push_screen_modal(spoke)
+            return InputState.PROCESSED_AND_CLOSE
+
+        return super().input(args, key)
+
+
+class RootPasswordSpoke(NormalTUISpoke):
+    """
+       .. inheritance-diagram:: PasswordSpoke
+          :parts: 3
+    """
+
+    def __init__(self, data, storage, payload, sm3_config):
+        NormalTUISpoke.__init__(self, data, storage, payload)
+        self.initialize_start()
+        self.title = N_("Root password")
+        self.input_required = False
+
+        self._password = None
+        self._sm3_config = sm3_config
+
+        self._users_module = USERS.get_proxy()
+        self.initialize_done()
+
     def refresh(self, args=None):
         NormalTUISpoke.refresh(self, args)
 
@@ -85,10 +140,15 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
 
     def show_all(self):
         super().show_all()
+        if self._sm3_config:
+            algo = "sm3"
+        else:
+            algo = None
 
         password_dialog = PasswordDialog(
             title=_("Password"),
-            policy_name=PASSWORD_POLICY_ROOT
+            policy_name=PASSWORD_POLICY_ROOT,
+            func_args=(algo,)
         )
         password_dialog.no_separator = True
         self._password = password_dialog.run()
@@ -101,6 +161,7 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
             self.close()
 
     def apply(self):
+        
         self._users_module.SetCryptedRootPassword(self._password)
         if self._password:
             self._users_module.SetRootAccountLocked(False)
diff --git a/pyanaconda/ui/tui/tuiobject.py b/pyanaconda/ui/tui/tuiobject.py
index 6cb439b..c642931 100644
--- a/pyanaconda/ui/tui/tuiobject.py
+++ b/pyanaconda/ui/tui/tuiobject.py
@@ -209,12 +209,14 @@ class PasswordDialog(Dialog):
                  report_func=reporting_callback,
                  process_func=crypt_password,
                  secret_type=constants.SecretType.PASSWORD,
+                 func_args=None,
                  message=None):
         super().__init__(title, report_func=report_func)
         self._no_separator = False
         self._policy = input_checking.get_policy(policy_name)
         self._secret_type = secret_type
         self._process_password = process_func
+        self._func_args = func_args
         self._dialog_message = message
 
     def run(self):
@@ -292,7 +294,10 @@ class PasswordDialog(Dialog):
         if any(char not in constants.PW_ASCII_CHARS for char in password):
             self._report(_(constants.SECRET_ASCII[self._secret_type]))
 
-        return self._process_password(password)
+        if self._func_args == None:
+            return self._process_password(password)
+        else:
+            return self._process_password(password, *self._func_args)
 
     def _report(self, message):
         if self._report_func:
-- 
2.28.0.windows.1