@vrtmrz/livesync-commonlib 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/API/DirectFileManipulatorV2.d.ts +1 -0
- package/dist/API/DirectFileManipulatorV2.js +3 -1
- package/dist/API/processSetting.d.ts +1 -0
- package/dist/API/processSetting.js +3 -0
- package/dist/common/models/setting.const.defaults.js +1 -0
- package/dist/common/models/setting.const.qr.js +2 -1
- package/dist/common/models/setting.encryption.d.ts +2 -0
- package/dist/common/models/setting.encryption.js +6 -0
- package/dist/common/models/setting.lifecycle.js +7 -2
- package/dist/common/models/setting.policy.d.ts +4 -0
- package/dist/common/models/setting.policy.js +9 -0
- package/dist/common/models/setting.type.d.ts +2 -0
- package/dist/common/models/shared.definition.configNames.js +5 -0
- package/dist/common/models/tweak.definition.d.ts +1 -0
- package/dist/common/settingConstants.d.ts +1 -0
- package/dist/common/utils.js +5 -4
- package/dist/diagnostics/couchdb.js +4 -2
- package/dist/managers/ChunkFetcher.js +27 -4
- package/dist/managers/chunkFetcher.helper.js +1 -1
- package/dist/pouchdb/StreamingFetch.d.ts +1 -2
- package/dist/pouchdb/encryption.d.ts +5 -10
- package/dist/pouchdb/encryption.eden.d.ts +11 -0
- package/dist/pouchdb/encryption.eden.js +37 -0
- package/dist/pouchdb/encryption.js +67 -63
- package/dist/pouchdb/encryption.policy.d.ts +9 -0
- package/dist/pouchdb/encryption.policy.js +125 -0
- package/dist/replication/UnencryptedContentRejectedError.d.ts +16 -0
- package/dist/replication/UnencryptedContentRejectedError.js +44 -0
- package/dist/replication/couchdb/LiveSyncReplicator.js +41 -4
- package/dist/replication/index.d.ts +2 -0
- package/dist/replication/index.js +3 -0
- package/dist/replication/trystero/TrysteroReplicator.d.ts +2 -0
- package/dist/replication/unencryptedContentMessages.d.ts +8 -0
- package/dist/replication/unencryptedContentMessages.js +12 -0
- package/dist/serviceModules/Rebuilder.js +28 -4
- package/dist/services/base/RemoteConnection.d.ts +2 -0
- package/dist/services/base/RemoteService.js +2 -1
- package/dist/services/base/SettingService.js +2 -0
- package/dist/settings.d.ts +2 -1
- package/dist/settings.js +2 -0
- package/dist/worker/bgWorker.js +1 -1
- package/docs/offline-scanner.md +2 -1
- package/docs/settings-lifecycle.md +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,9 +14,9 @@ This package is primarily for maintainers of those clients and for integrations
|
|
|
14
14
|
|
|
15
15
|
## Status and versioning
|
|
16
16
|
|
|
17
|
-
Commonlib [0.4.
|
|
17
|
+
Commonlib [0.4.2](https://www.npmjs.com/package/@vrtmrz/livesync-commonlib/v/0.4.2)
|
|
18
18
|
is published on npm through `latest` and `next`
|
|
19
|
-
([release notes](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.4.
|
|
19
|
+
([release notes](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.4.2)).
|
|
20
20
|
|
|
21
21
|
Self-hosted LiveSync
|
|
22
22
|
[1.0.44](https://github.com/vrtmrz/obsidian-livesync/releases/tag/1.0.44)
|
|
@@ -272,10 +272,12 @@ standardIo.writeStdout("ready\n");
|
|
|
272
272
|
|
|
273
273
|
See [the standard-I/O contract](docs/platform-standard-io.md) for host composition and test-double examples.
|
|
274
274
|
|
|
275
|
-
|
|
275
|
+
<a id="ordinary-deletion-recovery-unreleased"></a>
|
|
276
276
|
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
## Ordinary deletion recovery
|
|
278
|
+
|
|
279
|
+
Available in Commonlib 0.4.2. Hosts using the ordinary file handler can opt in to
|
|
280
|
+
recovery of retained logical deletions by supplying provenance key enumeration. Recovery preserves edited or
|
|
279
281
|
unproven files, uses existing Chunk delivery policy, and reports physical removal
|
|
280
282
|
and interrupted bookkeeping separately. Hosts which do not opt in retain their
|
|
281
283
|
existing scanner policy. See [the recovery contract](docs/deletion-recovery.md)
|
|
@@ -17,6 +17,7 @@ export type DirectFileManipulatorOptions = {
|
|
|
17
17
|
idDerivationKey?: string;
|
|
18
18
|
pathNormalizationVersion?: 0 | 1;
|
|
19
19
|
encryptInternalMetadata?: boolean;
|
|
20
|
+
acceptUnencryptedContent?: boolean;
|
|
20
21
|
useDynamicIterationCount?: boolean;
|
|
21
22
|
customChunkSize?: number;
|
|
22
23
|
minimumChunkSize?: number;
|
|
@@ -195,7 +195,8 @@ class DirectFileManipulator {
|
|
|
195
195
|
false,
|
|
196
196
|
async () => await this.getReplicationPBKDF2Salt(this.getSettings()),
|
|
197
197
|
this.options.E2EEAlgorithm ?? E2EEAlgorithms.V2,
|
|
198
|
-
usesEncryptedInternalMetadata(this.settings)
|
|
198
|
+
usesEncryptedInternalMetadata(this.settings),
|
|
199
|
+
this.options.acceptUnencryptedContent ?? false
|
|
199
200
|
);
|
|
200
201
|
}
|
|
201
202
|
return Promise.resolve(true);
|
|
@@ -249,6 +250,7 @@ class DirectFileManipulator {
|
|
|
249
250
|
handleFilenameCaseSensitive: this.options.handleFilenameCaseSensitive ?? DEFAULT_SETTINGS.handleFilenameCaseSensitive,
|
|
250
251
|
usePathObfuscation: !!this.options.obfuscatePassphrase,
|
|
251
252
|
encryptInternalMetadata: this.options.encryptInternalMetadata ?? false,
|
|
253
|
+
acceptUnencryptedContent: this.options.acceptUnencryptedContent ?? DEFAULT_SETTINGS.acceptUnencryptedContent,
|
|
252
254
|
syncInternalFiles: this.options.syncInternalFiles ?? DEFAULT_SETTINGS.syncInternalFiles,
|
|
253
255
|
E2EEAlgorithm: this.options.E2EEAlgorithm ?? E2EEAlgorithms.V2
|
|
254
256
|
}
|
|
@@ -54,6 +54,7 @@ export declare function encodeSettingsToSetupURI(settingString: ObsidianLiveSync
|
|
|
54
54
|
/** Generate a Setup URI for the current UTC window or in the existing persistent format. */
|
|
55
55
|
export declare function encodeTimeBoundSetupURI(settingString: ObsidianLiveSyncSettings, passphrase: string, options?: TimeBoundSetupURIOptions): Promise<TimeBoundSetupURIResult>;
|
|
56
56
|
export declare function decodeSettingsFromSetupURI(uri: string, passphrase: string): Promise<false | Omit<{
|
|
57
|
+
acceptUnencryptedContent: boolean;
|
|
57
58
|
encryptInternalMetadata: boolean;
|
|
58
59
|
idDerivationVersion: 0 | 1;
|
|
59
60
|
idDerivationKey: string;
|
|
@@ -11,6 +11,7 @@ import { decryptString, encryptString } from "../encryption/stringEncryption.js"
|
|
|
11
11
|
import { LOG_LEVEL_VERBOSE, Logger } from "octagonal-wheels/common/logger";
|
|
12
12
|
import { configuredIdKey } from "../common/idDerivation.js";
|
|
13
13
|
import { assertSupportedPathNormalizationVersion, getPathNormalizationVersion } from "../common/pathNormalization.js";
|
|
14
|
+
import { normaliseAcceptUnencryptedContent } from "../common/models/setting.encryption.js";
|
|
14
15
|
function encodeSettingsToQRCodeData(settings) {
|
|
15
16
|
settings = omitP2PRuntimeSettings(settings);
|
|
16
17
|
configuredIdKey(settings);
|
|
@@ -54,6 +55,7 @@ function decodeSettingsFromQRCodeData(qr) {
|
|
|
54
55
|
LOG_LEVEL_VERBOSE
|
|
55
56
|
);
|
|
56
57
|
}
|
|
58
|
+
newSettings.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(newSettings.acceptUnencryptedContent);
|
|
57
59
|
configuredIdKey(newSettings);
|
|
58
60
|
newSettings.pathNormalizationVersion = getPathNormalizationVersion(newSettings);
|
|
59
61
|
return omitP2PRuntimeSettings(newSettings);
|
|
@@ -213,6 +215,7 @@ async function decodeSettingsFromSetupURI(uri, passphrase) {
|
|
|
213
215
|
const imported = JSON.parse(decrypted);
|
|
214
216
|
const settings = {
|
|
215
217
|
...imported,
|
|
218
|
+
acceptUnencryptedContent: normaliseAcceptUnencryptedContent(imported.acceptUnencryptedContent),
|
|
216
219
|
encryptInternalMetadata: typeof imported.encryptInternalMetadata === "boolean" ? imported.encryptInternalMetadata : false,
|
|
217
220
|
idDerivationVersion: imported.idDerivationVersion ?? 0,
|
|
218
221
|
idDerivationKey: imported.idDerivationKey ?? "",
|
|
@@ -185,7 +185,8 @@ const KeyIndexOfSettings = {
|
|
|
185
185
|
pathNormalizationVersion: 168,
|
|
186
186
|
batchSaveInLiveSync: 169,
|
|
187
187
|
useCouchDBCacheControlHeadersOnly: 170,
|
|
188
|
-
encryptedIdDerivationKey: -1
|
|
188
|
+
encryptedIdDerivationKey: -1,
|
|
189
|
+
acceptUnencryptedContent: 171
|
|
189
190
|
};
|
|
190
191
|
export {
|
|
191
192
|
KeyIndexOfSettings
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
SETTING_VERSION_SUPPORT_CASE_INSENSITIVE
|
|
6
6
|
} from "./setting.const.js";
|
|
7
7
|
import { omitP2PRuntimeSettings } from "./setting.p2p.js";
|
|
8
|
+
import { normaliseAcceptUnencryptedContent } from "./setting.encryption.js";
|
|
8
9
|
const SettingsMigrationReviewCodes = {
|
|
9
10
|
LegacyUpdatePending: "legacy-update-review-pending",
|
|
10
11
|
FutureSchema: "settings-schema-newer-than-runtime",
|
|
@@ -73,8 +74,10 @@ function prepareSettingsForLoad(storedSettings) {
|
|
|
73
74
|
toVersion: CURRENT_SETTING_VERSION
|
|
74
75
|
}
|
|
75
76
|
];
|
|
77
|
+
const settings = cloneSettings(source, SETTINGS_SCHEMA_DEFAULTS);
|
|
78
|
+
settings.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(source.acceptUnencryptedContent);
|
|
76
79
|
return {
|
|
77
|
-
settings
|
|
80
|
+
settings,
|
|
78
81
|
sourceVersion,
|
|
79
82
|
targetVersion: sourceVersion,
|
|
80
83
|
isNewVault: false,
|
|
@@ -108,13 +111,15 @@ function prepareSettingsForLoad(storedSettings) {
|
|
|
108
111
|
if (normalisedFilenameCase) migrated = { ...migrated, handleFilenameCaseSensitive: false };
|
|
109
112
|
const normalisedInternalMetadata = typeof migrated.encryptInternalMetadata !== "boolean";
|
|
110
113
|
if (normalisedInternalMetadata) migrated = { ...migrated, encryptInternalMetadata: false };
|
|
114
|
+
const normalisedAcceptUnencryptedContent = typeof migrated.acceptUnencryptedContent !== "boolean";
|
|
115
|
+
if (normalisedAcceptUnencryptedContent) migrated = { ...migrated, acceptUnencryptedContent: false };
|
|
111
116
|
return {
|
|
112
117
|
settings: cloneSettings(migrated, SETTINGS_SCHEMA_DEFAULTS),
|
|
113
118
|
sourceVersion,
|
|
114
119
|
targetVersion,
|
|
115
120
|
isNewVault: false,
|
|
116
121
|
isFromFutureSchema: false,
|
|
117
|
-
changed: sourceVersion !== targetVersion || normalisedConfiguredState || normalisedFilenameCase || normalisedInternalMetadata,
|
|
122
|
+
changed: sourceVersion !== targetVersion || normalisedConfiguredState || normalisedFilenameCase || normalisedInternalMetadata || normalisedAcceptUnencryptedContent,
|
|
118
123
|
requiresSyncReview: reviewReasons.length > 0,
|
|
119
124
|
reviewReasons
|
|
120
125
|
};
|
|
@@ -489,6 +489,10 @@ export declare const SETTINGS_PROPERTY_POLICY: {
|
|
|
489
489
|
readonly markdown: "include";
|
|
490
490
|
readonly persistence: "include";
|
|
491
491
|
};
|
|
492
|
+
readonly acceptUnencryptedContent: {
|
|
493
|
+
readonly markdown: "include";
|
|
494
|
+
readonly persistence: "include";
|
|
495
|
+
};
|
|
492
496
|
readonly passphrase: {
|
|
493
497
|
readonly markdown: "credentials";
|
|
494
498
|
readonly persistence: "passphrase";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_SETTINGS } from "./setting.const.defaults.js";
|
|
2
|
+
import { normaliseAcceptUnencryptedContent } from "./setting.encryption.js";
|
|
2
3
|
const SettingPolicies = {
|
|
3
4
|
Default: { markdown: "include", persistence: "include" },
|
|
4
5
|
LocalOnly: { markdown: "omit", persistence: "include" },
|
|
@@ -123,6 +124,7 @@ const SETTINGS_PROPERTY_POLICY = {
|
|
|
123
124
|
forcePathStyle: SettingPolicies.Default,
|
|
124
125
|
remoteType: SettingPolicies.Default,
|
|
125
126
|
encrypt: SettingPolicies.Default,
|
|
127
|
+
acceptUnencryptedContent: SettingPolicies.Default,
|
|
126
128
|
passphrase: SettingPolicies.E2EEPassphrase,
|
|
127
129
|
idDerivationVersion: SettingPolicies.MarkdownCredentials,
|
|
128
130
|
pathNormalizationVersion: SettingPolicies.MarkdownCredentials,
|
|
@@ -230,6 +232,9 @@ function createMarkdownSettings(settings, includeCredentials = settings.writeCre
|
|
|
230
232
|
copySetting(output, settings, key);
|
|
231
233
|
}
|
|
232
234
|
if (output.remoteConfigurations) output.remoteConfigurations = cloneProfiles(output);
|
|
235
|
+
if ("acceptUnencryptedContent" in output) {
|
|
236
|
+
output.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(output.acceptUnencryptedContent);
|
|
237
|
+
}
|
|
233
238
|
return output;
|
|
234
239
|
}
|
|
235
240
|
function mergeMarkdownSettings(incoming, current) {
|
|
@@ -241,6 +246,9 @@ function mergeMarkdownSettings(incoming, current) {
|
|
|
241
246
|
}
|
|
242
247
|
}
|
|
243
248
|
merged.remoteConfigurations = cloneProfiles(merged);
|
|
249
|
+
merged.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(
|
|
250
|
+
Object.prototype.hasOwnProperty.call(incoming, "acceptUnencryptedContent") ? incoming.acceptUnencryptedContent : current.acceptUnencryptedContent
|
|
251
|
+
);
|
|
244
252
|
return merged;
|
|
245
253
|
}
|
|
246
254
|
function selectConnectionSettings(settings) {
|
|
@@ -271,6 +279,7 @@ function requireConfigurationCiphertext(value) {
|
|
|
271
279
|
return value;
|
|
272
280
|
}
|
|
273
281
|
function prepareSettingsForPersistence(settings) {
|
|
282
|
+
settings.acceptUnencryptedContent = normaliseAcceptUnencryptedContent(settings.acceptUnencryptedContent);
|
|
274
283
|
if (hasConnectionSettings(settings)) throw new Error("Connection settings were not prepared for persistence.");
|
|
275
284
|
if (settings.encrypt && settings.passphrase !== "")
|
|
276
285
|
throw new Error("The passphrase was not prepared for persistence.");
|
|
@@ -598,6 +598,8 @@ export interface EncryptionSettings {
|
|
|
598
598
|
* Indicates whether E2EE is enabled.
|
|
599
599
|
*/
|
|
600
600
|
encrypt: boolean;
|
|
601
|
+
/** Accept plaintext file content from the remote while E2EE is enabled. */
|
|
602
|
+
acceptUnencryptedContent: boolean;
|
|
601
603
|
/**
|
|
602
604
|
* The passphrase used for E2EE.
|
|
603
605
|
*/
|
|
@@ -20,6 +20,11 @@ const configurationNames = {
|
|
|
20
20
|
name: "Encrypt internal file Properties",
|
|
21
21
|
desc: "Encrypt file properties (paths, times, sizes, and Chunk references) used by Hidden File Sync and Customisation Sync. This affects future writes; manually rebuild the remote database to protect existing properties. Requires E2EE V2, Property Encryption, and compatible clients on every device."
|
|
22
22
|
},
|
|
23
|
+
acceptUnencryptedContent: {
|
|
24
|
+
name: "Accept unencrypted content",
|
|
25
|
+
desc: "When E2EE is enabled, accept unencrypted content written by third-party tools which do not use the E2EE passphrase. Anyone with write access to the database can inject plaintext. Content sent by this plug-in remains encrypted.",
|
|
26
|
+
isAdvanced: true
|
|
27
|
+
},
|
|
23
28
|
enableCompression: {
|
|
24
29
|
name: "Data Compression",
|
|
25
30
|
level: LEVEL_ADVANCED
|
|
@@ -249,6 +249,7 @@ export declare const TweakValuesTemplate: {
|
|
|
249
249
|
bucketPrefix?: string;
|
|
250
250
|
forcePathStyle?: boolean;
|
|
251
251
|
remoteType?: import("./setting.type.js").RemoteType;
|
|
252
|
+
acceptUnencryptedContent?: boolean;
|
|
252
253
|
passphrase?: string;
|
|
253
254
|
idDerivationKey?: string;
|
|
254
255
|
doNotUseFixedRevisionForChunks?: boolean;
|
|
@@ -139,6 +139,7 @@ export declare const AllSettingDefault: {
|
|
|
139
139
|
remoteType: import("./types.js").RemoteType;
|
|
140
140
|
pathNormalizationVersion: import("./models/setting.type.js").PathNormalizationVersion;
|
|
141
141
|
encrypt: boolean;
|
|
142
|
+
acceptUnencryptedContent: boolean;
|
|
142
143
|
passphrase: string;
|
|
143
144
|
idDerivationVersion: 0 | 1;
|
|
144
145
|
idDerivationKey: string;
|
package/dist/common/utils.js
CHANGED
|
@@ -3,11 +3,11 @@ import { isPlainText } from "../string_and_binary/path.js";
|
|
|
3
3
|
import { Semaphore } from "octagonal-wheels/concurrency/semaphore";
|
|
4
4
|
import { arrayBufferToBase64Single, decodeBinary, writeString } from "../string_and_binary/convert.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
PREFIX_OBFUSCATED,
|
|
6
|
+
IDPrefixes,
|
|
8
7
|
SYNCINFO_ID
|
|
9
8
|
} from "./types.js";
|
|
10
9
|
import { normaliseP2PConnectionPath, normaliseP2PMaxWirePayloadBytes } from "./models/setting.p2p.js";
|
|
10
|
+
import { normaliseAcceptUnencryptedContent } from "./models/setting.encryption.js";
|
|
11
11
|
import { isErrorOfMissingDoc } from "../pouchdb/utils_couchdb.js";
|
|
12
12
|
import { joinDelimitedList, replaceAll, replaceAllPairs, splitDelimitedList } from "octagonal-wheels/string";
|
|
13
13
|
import { formatDuration } from "octagonal-wheels/notation/duration";
|
|
@@ -94,13 +94,13 @@ async function isDocContentSame(docA, docB) {
|
|
|
94
94
|
return isBlobContentEqual(blob1, blob2, isArrayBufferContentEqual);
|
|
95
95
|
}
|
|
96
96
|
function isObfuscatedEntry(doc) {
|
|
97
|
-
if (doc._id.startsWith(
|
|
97
|
+
if (doc._id.startsWith(IDPrefixes.Obfuscated)) {
|
|
98
98
|
return true;
|
|
99
99
|
}
|
|
100
100
|
return false;
|
|
101
101
|
}
|
|
102
102
|
function isEncryptedChunkEntry(doc) {
|
|
103
|
-
if (doc._id.startsWith(
|
|
103
|
+
if (doc._id.startsWith(IDPrefixes.EncryptedChunk)) {
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
106
|
return false;
|
|
@@ -418,6 +418,7 @@ function pickEncryptionSettings(setting) {
|
|
|
418
418
|
passphrase: setting.passphrase,
|
|
419
419
|
usePathObfuscation: setting.usePathObfuscation,
|
|
420
420
|
encryptInternalMetadata: setting.encryptInternalMetadata,
|
|
421
|
+
acceptUnencryptedContent: normaliseAcceptUnencryptedContent(setting.acceptUnencryptedContent),
|
|
421
422
|
idDerivationVersion: setting.idDerivationVersion,
|
|
422
423
|
idDerivationKey: setting.idDerivationKey
|
|
423
424
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DOCID_SYNC_PARAMETERS } from "../common/types.js";
|
|
2
2
|
import { isObfuscatedEntry, parseHeaderValues } from "../common/utils.js";
|
|
3
3
|
import { getConfiguredFunctionsForEncryption, isEncryptedMeta } from "../pouchdb/encryption.js";
|
|
4
|
+
import { isUnencryptedContentRejectedError } from "../replication/UnencryptedContentRejectedError.js";
|
|
4
5
|
import { isPathProbablyObfuscated } from "octagonal-wheels/encryption/encryption";
|
|
5
6
|
import { decompressDoc } from "../pouchdb/compress.js";
|
|
6
7
|
import { AuthorizationHeaderGenerator, generateCredentialObject } from "../replication/httplib.js";
|
|
@@ -76,7 +77,8 @@ function createCouchDBDiagnosticSource({
|
|
|
76
77
|
settings.E2EEAlgorithm,
|
|
77
78
|
false,
|
|
78
79
|
() => {
|
|
79
|
-
}
|
|
80
|
+
},
|
|
81
|
+
settings.acceptUnencryptedContent
|
|
80
82
|
).outgoing : async (doc) => doc;
|
|
81
83
|
const decode = async (id, value) => {
|
|
82
84
|
if (!value || typeof value !== "object" || !("_id" in value) || value._id !== id || !("_rev" in value) || typeof value._rev !== "string") {
|
|
@@ -157,7 +159,7 @@ function createCouchDBDiagnosticSource({
|
|
|
157
159
|
checkCancelled();
|
|
158
160
|
return {
|
|
159
161
|
id,
|
|
160
|
-
error: error instanceof DiagnosticReadError ? error : new DiagnosticReadError("document-unreadable")
|
|
162
|
+
error: error instanceof DiagnosticReadError || isUnencryptedContentRejectedError(error) ? error : new DiagnosticReadError("document-unreadable")
|
|
161
163
|
};
|
|
162
164
|
}
|
|
163
165
|
})
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { getUnencryptedContentRejectionMessage } from "../replication/unencryptedContentMessages.js";
|
|
2
|
+
import {
|
|
3
|
+
getUnencryptedContentRejection,
|
|
4
|
+
isUnencryptedContentRejectedError
|
|
5
|
+
} from "../replication/UnencryptedContentRejectedError.js";
|
|
1
6
|
import { delay, promiseWithResolvers } from "octagonal-wheels/promises";
|
|
2
7
|
import { unique } from "octagonal-wheels/collection";
|
|
3
|
-
import { LOG_LEVEL_VERBOSE, Logger } from "../common/logger.js";
|
|
8
|
+
import { LOG_LEVEL_NOTICE, LOG_LEVEL_VERBOSE, Logger } from "../common/logger.js";
|
|
4
9
|
import { DEFAULT_SETTINGS } from "../common/types.js";
|
|
5
10
|
import {} from "./ChunkManager.js";
|
|
6
11
|
import { compatGlobal } from "../common/coreEnvFunctions.js";
|
|
@@ -251,7 +256,11 @@ class ChunkFetcher {
|
|
|
251
256
|
LOG_LEVEL_VERBOSE
|
|
252
257
|
);
|
|
253
258
|
for (const chunk of invalidChunks) {
|
|
254
|
-
|
|
259
|
+
const id = typeof chunk === "object" && chunk !== null && "_id" in chunk && typeof chunk._id === "string" ? chunk._id : void 0;
|
|
260
|
+
Logger(
|
|
261
|
+
id === void 0 ? "Invalid chunk without a string document ID." : `Invalid chunk document: ${JSON.stringify(id)}`,
|
|
262
|
+
LOG_LEVEL_VERBOSE
|
|
263
|
+
);
|
|
255
264
|
}
|
|
256
265
|
}
|
|
257
266
|
if (chunks.length === 0) {
|
|
@@ -397,8 +406,22 @@ class ChunkFetcher {
|
|
|
397
406
|
}
|
|
398
407
|
this.applyMissingChunkResults(missingIds, requestClaims, requestCompletionVersion);
|
|
399
408
|
} catch (error) {
|
|
400
|
-
|
|
401
|
-
|
|
409
|
+
if (isUnencryptedContentRejectedError(error)) {
|
|
410
|
+
Logger(
|
|
411
|
+
getUnencryptedContentRejectionMessage("on-demand"),
|
|
412
|
+
LOG_LEVEL_NOTICE,
|
|
413
|
+
"unencrypted-content-rejected"
|
|
414
|
+
);
|
|
415
|
+
const rejection = getUnencryptedContentRejection(error);
|
|
416
|
+
const identifiers = rejection ? [rejection.documentId] : requestIDs;
|
|
417
|
+
Logger(
|
|
418
|
+
`On-demand retrieval rejected unencrypted content: ${identifiers.join(", ")}`,
|
|
419
|
+
LOG_LEVEL_VERBOSE
|
|
420
|
+
);
|
|
421
|
+
} else {
|
|
422
|
+
Logger("An error occurred while fetching remote chunks.", LOG_LEVEL_VERBOSE);
|
|
423
|
+
Logger(error, LOG_LEVEL_VERBOSE);
|
|
424
|
+
}
|
|
402
425
|
} finally {
|
|
403
426
|
for (const [id, pending] of requestClaims) {
|
|
404
427
|
if (pending.inFlight) this.settleClaim(id, pending);
|
|
@@ -17,7 +17,7 @@ function decideMissingChunkAction({
|
|
|
17
17
|
}
|
|
18
18
|
function isValidChunk(chunk) {
|
|
19
19
|
const candidate = chunk;
|
|
20
|
-
return !!candidate && typeof candidate._id === "string" && typeof candidate.data === "string";
|
|
20
|
+
return !!candidate && candidate.type === "leaf" && typeof candidate._id === "string" && !candidate._id.startsWith("_local/") && typeof candidate.data === "string";
|
|
21
21
|
}
|
|
22
22
|
function classifyFetchedChunks(requestedIds, fetched) {
|
|
23
23
|
const chunks = [];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { EntryDoc } from "../common/models/db.definition.js";
|
|
2
|
-
import type { AnyEntry, EntryLeaf } from "../common/models/db.type.js";
|
|
3
2
|
type DBSequence = number | string;
|
|
4
3
|
/**
|
|
5
4
|
* Identifies the boundary at which Fast Fetch stopped.
|
|
@@ -56,7 +55,7 @@ export type FetchChangesForInitialSyncProgress = {
|
|
|
56
55
|
* @param customHeaders Additional request headers required by the CouchDB endpoint or its reverse proxy.
|
|
57
56
|
* @param onStoredRevisions Observes revision identities after their complete local batch is persisted.
|
|
58
57
|
*/
|
|
59
|
-
export declare function fetchChangesForInitialSync(downloadToDB: PouchDB.Database, remoteDbUrl: string, authHeader: string, decryptFunction: (doc: EntryDoc) => Promise<
|
|
58
|
+
export declare function fetchChangesForInitialSync(downloadToDB: PouchDB.Database, remoteDbUrl: string, authHeader: string, decryptFunction: (doc: EntryDoc) => Promise<EntryDoc>, since?: number | string, onProgress?: (progress: FetchChangesForInitialSyncProgress) => void, onCheckpoint?: (sequence: DBSequence) => void | Promise<void>, customHeaders?: Record<string, string>, onStoredRevisions?: (revisions: readonly {
|
|
60
59
|
id: string;
|
|
61
60
|
rev: string;
|
|
62
61
|
}[]) => void | Promise<void>): Promise<void>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type EntryDoc, type AnyEntry, type EntryLeaf, type DocumentID, type E2EEAlgorithm } from "../common/types.js";
|
|
1
|
+
import { type EntryDoc, type AnyEntry, type EntryLeaf, type E2EEAlgorithm } from "../common/types.js";
|
|
3
2
|
import { encryptWorker, decryptWorker, encryptHKDFWorker, decryptHKDFWorker } from "#worker";
|
|
3
|
+
import type { LogFunction } from "../services/lib/logUtils.js";
|
|
4
|
+
export { EDEN_ENCRYPTED_KEY, EDEN_ENCRYPTED_KEY_HKDF, shouldEncryptEden, shouldEncryptEdenHKDF, shouldDecryptEden, shouldDecryptEdenHKDF, } from "./encryption.eden.js";
|
|
4
5
|
export declare const encrypt: typeof encryptWorker;
|
|
5
6
|
export declare const decrypt: typeof decryptWorker;
|
|
6
7
|
export declare const encryptHKDF: typeof encryptHKDFWorker;
|
|
@@ -8,15 +9,9 @@ export declare const decryptHKDF: typeof decryptHKDFWorker;
|
|
|
8
9
|
export declare function isEncryptedMeta<T extends AnyEntry>(doc: T): boolean;
|
|
9
10
|
export declare let preprocessOutgoing: (doc: AnyEntry | EntryLeaf) => Promise<AnyEntry | EntryLeaf>;
|
|
10
11
|
export declare let preprocessIncoming: (doc: EntryDoc) => Promise<EntryDoc>;
|
|
11
|
-
export declare function getConfiguredFunctionsForEncryption(passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean, log?:
|
|
12
|
+
export declare function getConfiguredFunctionsForEncryption(passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean, log?: LogFunction, acceptUnencryptedContent?: boolean): {
|
|
12
13
|
incoming: (doc: AnyEntry | EntryLeaf) => Promise<AnyEntry | EntryLeaf>;
|
|
13
14
|
outgoing: (doc: EntryDoc) => Promise<AnyEntry | EntryLeaf>;
|
|
14
15
|
};
|
|
15
|
-
export declare const enableEncryption: (db: PouchDB.Database<EntryDoc>, passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean) => void;
|
|
16
|
+
export declare const enableEncryption: (db: PouchDB.Database<EntryDoc>, passphrase: string, useDynamicIterationCount: boolean, migrationDecrypt: boolean, getPBKDF2Salt: () => Promise<Uint8Array<ArrayBuffer>>, algorithm: E2EEAlgorithm, encryptInternalMetadata?: boolean, acceptUnencryptedContent?: boolean) => void;
|
|
16
17
|
export declare function disableEncryption(): void;
|
|
17
|
-
export declare const EDEN_ENCRYPTED_KEY: DocumentID;
|
|
18
|
-
export declare const EDEN_ENCRYPTED_KEY_HKDF: DocumentID;
|
|
19
|
-
export declare function shouldEncryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
20
|
-
export declare function shouldEncryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
21
|
-
export declare function shouldDecryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
22
|
-
export declare function shouldDecryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eden is being phased out. Avoid proactive refactoring or enhancements;
|
|
3
|
+
* limit changes to necessary fixes and compatibility maintenance.
|
|
4
|
+
*/
|
|
5
|
+
import type { AnyEntry, EntryLeaf, DocumentID } from "../common/types.js";
|
|
6
|
+
export declare const EDEN_ENCRYPTED_KEY: DocumentID;
|
|
7
|
+
export declare const EDEN_ENCRYPTED_KEY_HKDF: DocumentID;
|
|
8
|
+
export declare function shouldEncryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
9
|
+
export declare function shouldEncryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
10
|
+
export declare function shouldDecryptEden(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
11
|
+
export declare function shouldDecryptEdenHKDF(doc: AnyEntry | EntryLeaf): doc is AnyEntry;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const EDEN_ENCRYPTED_KEY = "h:++encrypted";
|
|
2
|
+
const EDEN_ENCRYPTED_KEY_HKDF = "h:++encrypted-hkdf";
|
|
3
|
+
function shouldEncryptEden(doc) {
|
|
4
|
+
if ("eden" in doc && !(EDEN_ENCRYPTED_KEY in doc.eden)) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
function shouldEncryptEdenHKDF(doc) {
|
|
10
|
+
if ("eden" in doc && !(EDEN_ENCRYPTED_KEY_HKDF in doc.eden)) {
|
|
11
|
+
if (Object.keys(doc.eden).length === 0) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
function shouldDecryptEden(doc) {
|
|
19
|
+
if ("eden" in doc && EDEN_ENCRYPTED_KEY in doc.eden) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
function shouldDecryptEdenHKDF(doc) {
|
|
25
|
+
if ("eden" in doc && EDEN_ENCRYPTED_KEY_HKDF in doc.eden) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
EDEN_ENCRYPTED_KEY,
|
|
32
|
+
EDEN_ENCRYPTED_KEY_HKDF,
|
|
33
|
+
shouldDecryptEden,
|
|
34
|
+
shouldDecryptEdenHKDF,
|
|
35
|
+
shouldEncryptEden,
|
|
36
|
+
shouldEncryptEdenHKDF
|
|
37
|
+
};
|