Skip to content

Commit

Permalink
Desktop: Fixes laurent22#9985: Filter Sync Target Info Logs
Browse files Browse the repository at this point in the history
  • Loading branch information
criticic committed Feb 27, 2024
1 parent 3c31b2b commit 054b988
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/lib/Synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export default class Synchronizer {

try {
let remoteInfo = await fetchSyncInfo(this.api());
logger.info('Sync target remote info:', remoteInfo);
logger.info('Sync target remote info:', remoteInfo.filterSyncInfo());
eventManager.emit(EventName.SessionEstablished);

let syncTargetIsNew = false;
Expand All @@ -471,8 +471,7 @@ export default class Synchronizer {
if (appVersion !== 'unknown') checkIfCanSync(remoteInfo, appVersion);

let localInfo = await localSyncInfo();

logger.info('Sync target local info:', localInfo);
logger.info('Sync target local info:', localInfo.filterSyncInfo());

localInfo = await this.setPpkIfNotExist(localInfo, remoteInfo);

Expand Down
26 changes: 26 additions & 0 deletions packages/lib/services/synchronizer/syncInfoUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,32 @@ describe('syncInfoUtils', () => {
logger.enabled = true;
});

it('should filter unnecessary sync info', async () => {
const syncInfo = new SyncInfo();
syncInfo.masterKeys = [{
id: '1',
content: 'longstringverylongstringlongstringverylongstringlongstringverylongstring',
checksum: 'longstringverylongstringlongstringverylongstringlongstringverylongstring',
}];
syncInfo.ppk = {
id: '1',
publicKey: 'longstringverylongstringlongstringverylongstringlongstringverylongstring',
privateKey: {
encryptionMethod: 1,
ciphertext: 'longstringverylongstringlongstringverylongstringlongstringverylongstring',
},
createdTime: 0,
keySize: 0,
};
const filteredSyncInfo = syncInfo.filterSyncInfo();

expect(filteredSyncInfo.masterKeys_[0].content).toBeUndefined();
expect(filteredSyncInfo.masterKeys_[0].checksum).toBeUndefined();

expect(filteredSyncInfo.ppk_.value.publicKey).toBe('longstringverylongstringlongstringverylo');
expect(filteredSyncInfo.ppk_.value.privateKey.ciphertext).toBe('longstringverylongst...stringverylongstring');
});

test.each([
['1.0.0', '1.0.4', true],
['1.0.0', '0.0.5', false],
Expand Down
16 changes: 16 additions & 0 deletions packages/lib/services/synchronizer/syncInfoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ export class SyncInfo {
};
}

public filterSyncInfo() {
const filtered = JSON.parse(JSON.stringify(this));

// Filter content and checksum properties from master keys
filtered.masterKeys_ = filtered.masterKeys_.map((mk: MasterKeyEntity) => {
delete mk.content;
delete mk.checksum;
return mk;
});

// Truncate the private key and public key
filtered.ppk_.value.privateKey.ciphertext = `${filtered.ppk_.value.privateKey.ciphertext.substr(0, 20)}...${filtered.ppk_.value.privateKey.ciphertext.substr(-20)}`;
filtered.ppk_.value.publicKey = filtered.ppk_.value.publicKey.substr(0, 40);
return filtered;
}

public serialize(): string {
return JSON.stringify(this.toObject(), null, '\t');
}
Expand Down

0 comments on commit 054b988

Please sign in to comment.