Skip to content

Commit

Permalink
cleaner salt
Browse files Browse the repository at this point in the history
  • Loading branch information
nmalzieu committed Sep 13, 2024
1 parent bb3ff79 commit 63db076
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions data/db/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ export const typeORMDriver = (
const initialDbPath = options.location
? path.join(options.location, options.name)
: options.name;
// First check if we can open it without an encryption key
let db = open(options);
db.execute(`PRAGMA cipher_plaintext_header_size = 32;`);
db.execute(`PRAGMA cipher_salt = "x'${encryptionSalt}'";`);
try {
// Try to execute a query with an encryption key
// Try to execute a query with the encryption key
db.execute("SELECT name FROM sqlite_master WHERE type='table';");
} catch (e: any) {
logger.warn(
Expand Down
2 changes: 1 addition & 1 deletion utils/keychain/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const getDbEncryptionKey = async () => {
export const getDbEncryptionSalt = async () => {
const existingSalt = await getSecureItemAsync("CONVERSE_DB_ENCRYPTION_SALT");
if (existingSalt) {
return existingSalt.slice(0, 32);
return existingSalt;
}
const newKey = Buffer.from(await getRandomBytesAsync(16));
const newKeyHex = newKey.toString("hex");
Expand Down

0 comments on commit 63db076

Please sign in to comment.