Skip to content

Commit 90f97d8

Browse files
committed
tpm: T7726: Prompt before overwriting existing TPM key
1 parent 54d110c commit 90f97d8

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
@@ -242,13 +242,25 @@ def decrypt_config(key):
242242

243243
if not is_opened():
244244
if tpm_exists:
245+
existing_key = None
246+
247+
try:
248+
existing_key = read_tpm_key()
249+
except: pass
250+
245251
if args.enable:
246-
key = Fernet.generate_key()
252+
if existing_key:
253+
print('WARNING: An encryption key already exists in the TPM.')
254+
print('If you choose not to use the existing key, any system image')
255+
print('using the old key will need the recovery key.')
256+
if existing_key and ask_yes_no('Do you want to use the existing TPM key?'):
257+
key = existing_key
258+
else:
259+
key = Fernet.generate_key()
247260
elif args.disable or args.load:
248-
try:
249-
key = read_tpm_key()
261+
if existing_key:
250262
need_recovery = False
251-
except:
263+
else:
252264
print('Failed to read key from TPM, recovery key required')
253265
need_recovery = True
254266
else:

0 commit comments

Comments
 (0)