Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit 790d2b1

Browse files
committed
Handle error when migrating configuration to >=0.3 format
1 parent 2f4fff6 commit 790d2b1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

nodecg-io-core/dashboard/crypto.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export async function setPassword(pw: string): Promise<boolean> {
8585
// Re-encrypt the configuration using our own derived key instead of the password.
8686
const newEncryptionKey = deriveEncryptionKey(pw, salt);
8787
const newEncryptionKeyArr = cryptoJS.enc.Hex.parse(newEncryptionKey);
88-
reEncryptData(encryptedData.value, pw, newEncryptionKeyArr);
88+
const res = reEncryptData(encryptedData.value, pw, newEncryptionKeyArr);
89+
if (res.failed) {
90+
throw new Error(`Failed to migrate config: ${res.errorMessage}`);
91+
}
8992
}
9093

9194
encryptedData.value.salt = salt;
@@ -127,7 +130,7 @@ export function isPasswordSet(): boolean {
127130

128131
/**
129132
* Decrypts the passed data using the global encryptionKey variable and saves it into `ConfigData`.
130-
* Unsets the encryption key if its wrong and also forwards `undefined` to `ConfigData` if the encryption key is unset.
133+
* Clears the encryption key if its wrong and also forwards `undefined` to `ConfigData` if the encryption key is unset.
131134
* @param data the data that should be decrypted.
132135
*/
133136
function updateDecryptedData(data: EncryptedData): void {

nodecg-io-core/extension/persistenceManager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function decryptData(
7070
}
7171

7272
/**
73-
* Encrypts the passed data objedt using the passed encryption key.
73+
* Encrypts the passed data object using the passed encryption key.
7474
*
7575
* @param data the data that needs to be encrypted.
7676
* @param encryptionKey the encryption key that should be used to encrypt the data.
@@ -395,7 +395,10 @@ export class PersistenceManager {
395395
// Re-encrypt the configuration using our own derived key instead of the password.
396396
const newEncryptionKey = deriveEncryptionKey(password, salt);
397397
const newEncryptionKeyArr = crypto.enc.Hex.parse(newEncryptionKey);
398-
reEncryptData(this.encryptedData.value, password, newEncryptionKeyArr);
398+
const res = reEncryptData(this.encryptedData.value, password, newEncryptionKeyArr);
399+
if (res.failed) {
400+
throw new Error(`Failed to migrate config: ${res.errorMessage}`);
401+
}
399402
}
400403

401404
this.encryptedData.value.salt = salt;
@@ -407,7 +410,7 @@ export class PersistenceManager {
407410
if (!loadResult.failed) {
408411
this.nodecg.log.info("Automatic login successful.");
409412
} else {
410-
throw loadResult.errorMessage;
413+
throw new Error(loadResult.errorMessage);
411414
}
412415
} catch (err) {
413416
const logMesssage = `Failed to automatically login: ${err}`;

0 commit comments

Comments
 (0)