Skip to content

Commit 70629c7

Browse files
committed
tpm: T7726: Prompt before overwriting existing TPM key
1 parent 794c8ea commit 70629c7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/helpers/vyos-config-encrypt.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,25 @@ def decrypt_config(key):
245245

246246
if not is_opened():
247247
if tpm_exists:
248+
existing_key = None
249+
250+
try:
251+
existing_key = read_tpm_key()
252+
except: pass
253+
248254
if args.enable:
249-
key = Fernet.generate_key()
255+
if existing_key:
256+
print('WARNING: An encryption key already exists in the TPM.')
257+
print('If you choose not to use the existing key, any system image')
258+
print('using the old key will need the recovery key.')
259+
if existing_key and ask_yes_no('Do you want to use the existing TPM key?'):
260+
key = existing_key
261+
else:
262+
key = Fernet.generate_key()
250263
elif args.disable or args.load:
251-
try:
252-
key = read_tpm_key()
264+
if existing_key:
253265
need_recovery = False
254-
except:
266+
else:
255267
print('Failed to read key from TPM, recovery key required')
256268
need_recovery = True
257269
else:

0 commit comments

Comments
 (0)