File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 34
34
mount_path_old = f'{ mount_path } .old'
35
35
dm_device = '/dev/mapper/vyos_config'
36
36
37
+
37
38
def is_opened ():
38
39
return os .path .exists (dm_device )
39
40
@@ -146,6 +147,29 @@ def config_backup_folder(base):
146
147
idx += 1
147
148
return f'{ base } .{ idx } '
148
149
150
+ def test_decrypt (tpm_key ):
151
+ if not tpm_key :
152
+ return
153
+
154
+ persist_path = cmd (persistpath_cmd ).strip ()
155
+ image_name = get_running_image ()
156
+ image_path = os .path .join (persist_path , 'luks' , image_name )
157
+
158
+ key_file = None
159
+
160
+ if not is_opened ():
161
+ with NamedTemporaryFile (dir = '/dev/shm' , delete = False ) as f :
162
+ f .write (key )
163
+ key_file = f .name
164
+
165
+ try :
166
+ cmd (f'cryptsetup -q open { image_path } vyos_config --key-file={ key_file } ' )
167
+ os .unlink (key_file )
168
+ return True
169
+ except :
170
+ return False
171
+ return False
172
+
149
173
def decrypt_config (key ):
150
174
if not key :
151
175
return
@@ -258,10 +282,10 @@ def decrypt_config(key):
258
282
else :
259
283
key = Fernet .generate_key ()
260
284
elif args .disable or args .load :
261
- if existing_key :
285
+ if existing_key and test_decrypt ( existing_key ) :
262
286
need_recovery = False
263
287
else :
264
- print ('Failed to read key from TPM , recovery key required' )
288
+ print ('TPM key invalid or not found , recovery key required' )
265
289
need_recovery = True
266
290
else :
267
291
need_recovery = True
You can’t perform that action at this time.
0 commit comments