Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Fixes #9985: Filter Sync Target Info Logs #10014

Merged
merged 7 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 83 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,89 @@ describe('syncInfoUtils', () => {
logger.enabled = true;
});

// cSpell:disable
it('should filter unnecessary sync info', async () => {
const initialData = {
'version': 3,
'e2ee': {
'value': true,
'updatedTime': 0,
},
'activeMasterKeyId': {
'value': '400227d2222c4d3bb7346514861c643b',
'updatedTime': 0,
},
'masterKeys': [
{
'id': '400227d8a77c4d3bb7346514861c643b',
'created_time': 1515008161362,
'updated_time': 1708103706234,
'source_application': 'net.cozic.joplin-desktop',
'encryption_method': 4,
'checksum': '',
'content': '{"iv":"M1uezlW1Pu1g3dwrCTqcHg==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"0dqWvU/PUVQ=","ct":"wHXN5pk1s7qKX+2Y9puEGZGkojI1Pvc+TvZUKC6QCfwxtMK6C1Hmgvm53vAaeCMcCXPvGVLo9JwqINFhEgb0ux+KUFcCqgT1pNO2Sf/hJsH8PjaUvl0kwpC511zdnvY7Hk3WIpgXVKUevsQt9TkMK5e8y1JMsuuTD3fW7bEiv/ehe4CBSQ9eH1tWjr1qQ=="}',
'hasBeenUsed': true,
},
],
'ppk': {
'value': {
'id': 'SNQ5ZCs61KDVUW2qqqqHd3',
'keySize': 2048,
'privateKey': {
'encryptionMethod': 4,
'ciphertext': '{"iv":"Z2y11b4nCYvpmQ9gvxELug==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"0dqWvU/PUVQ=","ct":"8CvjYayXMpLsrAMwtu18liRfewKfZVpRlC0D0I2FYziyFhRf4Cjqi2+Uy8kIC8au7oBSBUnNU6jd04ooNozneKv2MzkhbGlXo3izxqCMVHboqa2vkPWbBAxGlvUYQUg213xG61FjZ19ZJdpti+AQy7qpQU7/h5kyC0iJ2aXG5TIGcBuDq3lbGAVfG/RlL/abMKLYb8KouFYAJe+0bUajUXa1KJsey+eD+2hFVc+nAxKOLe1UoZysB77Lq43DRTBFGH2gTSC1zOXxuZeSbFPPN0Cj+FvV7D5pF9LhUSLPDsIiRwF/q+E506YgDjirSZAvW1Y2EEM22F2Mh0I0pbVPFXhhBafqPLRwXmUGULCnA64gkGwctK5mEs985VVSrpQ0nMvf/drg2vUQrJ3exgl43ddVSOCjeJuF7F06IBL5FQ34iAujsOheRNvlWtG9xm008Vc19NxvhtzIl1RO7XLXrrTBzbFHDrcHjda/xNWNEKwU/LZrH0xPgwEcwBmLItvy/NojI/JKNeck8R431QWooFb7cTplO4qsgCQNL9MJ9avpmNSXJAUQx8VnifKVbzcY4T7X7TmJWSrpvBWV8MLfi3TOF4kahR75vg47kCrMbthFMw5bvrjvMmGOtyKxheqbS5IlSnSSz5x7wIVz0g3vzMbcbb5rF5MuzNhU97wNiz3L1Aonjmnu8r3vCyXTB/4GSiwYH7KfixwYM68T4crqJ0VneNy+owznCdJQXnG4cmjxek1wmJMEmurQ1JtANNv/m43gzoqd62V6Dq05vLJF+n7CS9HgJ3FTqYVCZLGGYrSilIYnEjhdaBpkcnFrCitbfYj+IpNC6eN6qg2hpGAbmKId7RLOGwJyda0jkuNP9mTqWOF+6eYn8Q+Y3YIY"}',
},
'publicKey': '-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAiSTY5wBscae/WmU3PfVP5FYQiuTi5V7BjPcge/6pXvgF3zwe43uy\nTWdzO2YgK/a8f3H507clcGlZN4e0e1jZ/rh4lMfaN\nugfNo0RAvuwn8Yniqfb69reygJywbFBIauxbBpVKbc21MLuCbPkVFjKG7qGNYdF4\nc17mQ8nQsbFPZcuvxsZvgvvbza1q0rqVETdDUClyIrY8plAjMgTKCRwq2gafP6eX\nWpkENAyIbOFxSKXjWy0yFidvZfYLz4mIRwIDAQAB\n-----END RSA PUBLIC KEY-----',
'createdTime': 1633274368892,
},
'updatedTime': 1633274368892,
},
'appMinVersion': '0.0.0',
};

const syncInfo = new SyncInfo();
syncInfo.load(JSON.stringify(initialData));

const filteredSyncInfo = syncInfo.filterSyncInfo();

expect(filteredSyncInfo).toEqual({
'activeMasterKeyId': {
'updatedTime': 0,
'value': '400227d2222c4d3bb7346514861c643b',
},
'appMinVersion': '0.0.0',
'e2ee': {
'updatedTime': 0,
'value': true,
},
'masterKeys': [
{
'created_time': 1515008161362,
'encryption_method': 4,
'hasBeenUsed': true,
'id': '400227d8a77c4d3bb7346514861c643b',
'source_application': 'net.cozic.joplin-desktop',
'updated_time': 1708103706234,
},
],
'ppk': {
'updatedTime': 1633274368892,
'value': {
'createdTime': 1633274368892,
'id': 'SNQ5ZCs61KDVUW2qqqqHd3',
'keySize': 2048,
'privateKey': {
'ciphertext': '{"iv":"Z2y11b4nCYvpm...TqWOF+6eYn8Q+Y3YIY"}',
'encryptionMethod': 4,
},
'publicKey': '-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCA...',
},
},
'version': 3,
});
});
laurent22 marked this conversation as resolved.
Show resolved Hide resolved
// cSpell:enable

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

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

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

// Truncate the private key and public key
if (filtered.ppk.value) {
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
Loading