mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Encrypt message data at rest
This commit is contained in:
parent
3f3d6af4ed
commit
baa3a5640e
10 changed files with 121 additions and 3 deletions
|
@ -0,0 +1,25 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
import { decrypt, encrypt } from "../utils/crypt";
|
||||
|
||||
export class EncryptExistingMessages1600283341726 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<any> {
|
||||
// 1. Delete non-permanent messages
|
||||
await queryRunner.query("DELETE FROM messages WHERE is_permanent = 0");
|
||||
|
||||
// 2. Encrypt all permanent messages
|
||||
const messages = await queryRunner.query("SELECT id, data FROM messages");
|
||||
for (const message of messages) {
|
||||
const encryptedData = encrypt(message.data);
|
||||
await queryRunner.query("UPDATE messages SET data = ? WHERE id = ?", [encryptedData, message.id]);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<any> {
|
||||
// Decrypt all messages
|
||||
const messages = await queryRunner.query("SELECT id, data FROM messages");
|
||||
for (const message of messages) {
|
||||
const decryptedData = decrypt(message.data);
|
||||
await queryRunner.query("UPDATE messages SET data = ? WHERE id = ?", [decryptedData, message.id]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue