Skip to content

Commit

Permalink
[#316] Make data export encryption based on parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
SRichner committed Oct 21, 2024
1 parent 1001f35 commit 50778a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/electron/electron/ipc/IpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ export class IpcHandler {
private async startDataExport(
windowActivityExportType: DataExportType,
userInputExportType: DataExportType,
obfuscationTerms: string[]
obfuscationTerms: string[],
encryptData: boolean
): Promise<string> {
return this.dataExportService.startDataExport(
windowActivityExportType,
userInputExportType,
obfuscationTerms
obfuscationTerms,
encryptData
);
}

Expand Down
13 changes: 8 additions & 5 deletions src/electron/electron/main/services/DataExportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class DataExportService {
public async startDataExport(
windowActivityExportType: DataExportType,
userInputExportType: DataExportType,
obfuscationTerms: string[]
obfuscationTerms: string[],
encryptData: boolean
): Promise<string> {
LOG.info('startDataExport called');
await UsageDataService.createNewUsageDataEvent(
Expand Down Expand Up @@ -59,11 +60,13 @@ export class DataExportService {
// see https://github.com/WiseLibs/better-sqlite3/blob/master/docs/performance.md
db.pragma('journal_mode = WAL');

// see https://github.com/m4heshd/better-sqlite3-multiple-ciphers/issues/5#issuecomment-1008330548
db.pragma(`cipher='sqlcipher'`);
db.pragma(`legacy=4`);
if (encryptData) {
// see https://github.com/m4heshd/better-sqlite3-multiple-ciphers/issues/5#issuecomment-1008330548
db.pragma(`cipher='sqlcipher'`);
db.pragma(`legacy=4`);

db.pragma(`rekey='PersonalAnalytics_${settings.subjectId}'`);
db.pragma(`rekey='PersonalAnalytics_${settings.subjectId}'`);
}

if (
windowActivityExportType === DataExportType.Obfuscate ||
Expand Down
3 changes: 2 additions & 1 deletion src/electron/src/utils/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type Commands = {
startDataExport: (
windowActivityExportType: DataExportType,
userInputExportType: DataExportType,
obfuscationTerms: string[]
obfuscationTerms: string[],
encryptData: boolean
) => Promise<string>;
revealItemInFolder: (path: string) => Promise<void>;
startAllTrackers: () => void;
Expand Down
3 changes: 2 additions & 1 deletion src/electron/src/views/DataExportView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ async function handleNextStep() {
'startDataExport',
exportWindowActivitySelectedOption.value,
exportUserInputSelectedOption.value,
obfuscationTerms
obfuscationTerms,
studyConfig.dataExportEncrypted
);
hasExportError.value = false;
const now = new Date();
Expand Down

0 comments on commit 50778a6

Please sign in to comment.