Add change of encryption key warning (#23570)

This commit is contained in:
Bram Kragten 2025-01-03 15:48:20 +01:00 committed by GitHub
parent 4ffec51a5e
commit 87884ac747
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -55,6 +55,8 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
@state() private _userPassword?: string; @state() private _userPassword?: string;
@state() private _usedUserInput = false;
@state() private _error?: string; @state() private _error?: string;
@state() private _state?: RestoreBackupState; @state() private _state?: RestoreBackupState;
@ -70,6 +72,7 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
this._formData = INITIAL_DATA; this._formData = INITIAL_DATA;
this._userPassword = undefined; this._userPassword = undefined;
this._usedUserInput = false;
this._error = undefined; this._error = undefined;
this._state = undefined; this._state = undefined;
this._stage = undefined; this._stage = undefined;
@ -94,6 +97,7 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
this._params = undefined; this._params = undefined;
this._backupEncryptionKey = undefined; this._backupEncryptionKey = undefined;
this._userPassword = undefined; this._userPassword = undefined;
this._usedUserInput = false;
this._error = undefined; this._error = undefined;
this._state = undefined; this._state = undefined;
this._stage = undefined; this._stage = undefined;
@ -159,15 +163,24 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
} }
private _renderEncryption() { private _renderEncryption() {
return html`<p> return html`${this._usedUserInput
${this._userPassword ? "The provided encryption key was incorrect, please try again."
? "The provided encryption key was incorrect, please try again." : this._backupEncryptionKey
: this._backupEncryptionKey ? html`The Backup is encrypted with a different encryption key than
? "The backup is encrypted with a different key or password than that is saved on this system. Please enter the key for this backup." that is saved on this system. Please enter the encryption key for
: "The backup is encrypted. Provide the encryption key to decrypt the backup."} this backup.<br />
</p> ${this._params!.selectedData.homeassistant_included
? html`<ha-alert alert-type="warning"
>After restoring the backup, your new backups will be
encrypted with the encryption key that was present during
the time of this backup.</ha-alert
>`
: nothing}`
: "The backup is encrypted. Provide the encryption key to decrypt the backup."}
<ha-password-field <ha-password-field
@change=${this._passwordChanged} @input=${this._passwordChanged}
label="Encryption key"
.value=${this._userPassword || ""} .value=${this._userPassword || ""}
></ha-password-field>`; ></ha-password-field>`;
} }
@ -196,6 +209,9 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
private async _restoreBackup() { private async _restoreBackup() {
this._unsubscribe(); this._unsubscribe();
this._state = undefined;
this._stage = undefined;
this._error = undefined;
try { try {
this._step = "progress"; this._step = "progress";
this._subscribeBackupEvents(); this._subscribeBackupEvents();
@ -206,6 +222,9 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
await this._unsubscribe(); await this._unsubscribe();
if (e.code === "password_incorrect") { if (e.code === "password_incorrect") {
this._error = undefined; this._error = undefined;
if (this._userPassword) {
this._usedUserInput = true;
}
this._step = "encryption"; this._step = "encryption";
} else { } else {
this._error = e.message; this._error = e.message;
@ -315,6 +334,14 @@ class DialogRestoreBackup extends LitElement implements HassDialog {
ha-circular-progress { ha-circular-progress {
margin-bottom: 16px; margin-bottom: 16px;
} }
ha-alert[alert-type="warning"] {
display: block;
margin-top: 16px;
}
ha-password-field {
display: block;
margin-top: 16px;
}
`, `,
]; ];
} }