mindoodb 0.0.96 → 0.0.98
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 +1 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +7 -0
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +17 -9
- package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +12 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +19 -0
- package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
- package/dist/browser/index.mjs +73 -0
- package/dist/core/BaseMindooDB.d.ts +2 -0
- package/dist/core/BaseMindooDB.d.ts.map +1 -1
- package/dist/core/BaseMindooDB.js +73 -53
- package/dist/core/BaseMindooDB.js.map +1 -1
- package/dist/core/BaseMindooTenant.d.ts +33 -1
- package/dist/core/BaseMindooTenant.d.ts.map +1 -1
- package/dist/core/BaseMindooTenant.js +141 -41
- package/dist/core/BaseMindooTenant.js.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts +24 -1
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +161 -90
- package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
- package/dist/core/accesscontrol/directoryProjection.d.ts +7 -1
- package/dist/core/accesscontrol/directoryProjection.d.ts.map +1 -1
- package/dist/core/accesscontrol/directoryProjection.js +24 -0
- package/dist/core/accesscontrol/directoryProjection.js.map +1 -1
- package/dist/core/accesscontrol/types.d.ts +42 -2
- package/dist/core/accesscontrol/types.d.ts.map +1 -1
- package/dist/core/accesscontrol/types.js +77 -0
- package/dist/core/accesscontrol/types.js.map +1 -1
- package/dist/core/builtinDbInvariants.d.ts +26 -1
- package/dist/core/builtinDbInvariants.d.ts.map +1 -1
- package/dist/core/builtinDbInvariants.js +52 -2
- package/dist/core/builtinDbInvariants.js.map +1 -1
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +11 -5
- package/dist/core/index.js.map +1 -1
- package/dist/core/joinrequests/crypto.d.ts +110 -0
- package/dist/core/joinrequests/crypto.d.ts.map +1 -0
- package/dist/core/joinrequests/crypto.js +340 -0
- package/dist/core/joinrequests/crypto.js.map +1 -0
- package/dist/core/joinrequests/index.d.ts +4 -0
- package/dist/core/joinrequests/index.d.ts.map +1 -0
- package/dist/core/joinrequests/index.js +29 -0
- package/dist/core/joinrequests/index.js.map +1 -0
- package/dist/core/joinrequests/invitations.d.ts +257 -0
- package/dist/core/joinrequests/invitations.d.ts.map +1 -0
- package/dist/core/joinrequests/invitations.js +703 -0
- package/dist/core/joinrequests/invitations.js.map +1 -0
- package/dist/core/joinrequests/types.d.ts +208 -0
- package/dist/core/joinrequests/types.d.ts.map +1 -0
- package/dist/core/joinrequests/types.js +43 -0
- package/dist/core/joinrequests/types.js.map +1 -0
- package/dist/core/recovery/PaperRescueDevice.d.ts +92 -0
- package/dist/core/recovery/PaperRescueDevice.d.ts.map +1 -0
- package/dist/core/recovery/PaperRescueDevice.js +182 -0
- package/dist/core/recovery/PaperRescueDevice.js.map +1 -0
- package/dist/core/recovery/RecoveryContactsDocument.d.ts +91 -0
- package/dist/core/recovery/RecoveryContactsDocument.d.ts.map +1 -0
- package/dist/core/recovery/RecoveryContactsDocument.js +92 -0
- package/dist/core/recovery/RecoveryContactsDocument.js.map +1 -0
- package/dist/core/recovery/RecoveryContactsManager.d.ts +95 -0
- package/dist/core/recovery/RecoveryContactsManager.d.ts.map +1 -0
- package/dist/core/recovery/RecoveryContactsManager.js +322 -0
- package/dist/core/recovery/RecoveryContactsManager.js.map +1 -0
- package/dist/core/recovery/index.d.ts +8 -0
- package/dist/core/recovery/index.d.ts.map +1 -0
- package/dist/core/recovery/index.js +41 -0
- package/dist/core/recovery/index.js.map +1 -0
- package/dist/core/recovery/recoverWithContacts.d.ts +36 -0
- package/dist/core/recovery/recoverWithContacts.d.ts.map +1 -0
- package/dist/core/recovery/recoverWithContacts.js +103 -0
- package/dist/core/recovery/recoverWithContacts.js.map +1 -0
- package/dist/core/recovery/recoveryPackage.d.ts +72 -0
- package/dist/core/recovery/recoveryPackage.d.ts.map +1 -0
- package/dist/core/recovery/recoveryPackage.js +181 -0
- package/dist/core/recovery/recoveryPackage.js.map +1 -0
- package/dist/core/recovery/rescueDevice.d.ts +51 -0
- package/dist/core/recovery/rescueDevice.d.ts.map +1 -0
- package/dist/core/recovery/rescueDevice.js +201 -0
- package/dist/core/recovery/rescueDevice.js.map +1 -0
- package/dist/core/recovery/shamir.d.ts +30 -0
- package/dist/core/recovery/shamir.d.ts.map +1 -0
- package/dist/core/recovery/shamir.js +133 -0
- package/dist/core/recovery/shamir.js.map +1 -0
- package/dist/core/types.d.ts +80 -2
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/core/userkeys/UserKeyManager.d.ts +29 -0
- package/dist/core/userkeys/UserKeyManager.d.ts.map +1 -1
- package/dist/core/userkeys/UserKeyManager.js +76 -8
- package/dist/core/userkeys/UserKeyManager.js.map +1 -1
- package/dist/core/userkeys/generationSignature.d.ts +6 -0
- package/dist/core/userkeys/generationSignature.d.ts.map +1 -1
- package/dist/core/userkeys/generationSignature.js +1 -0
- package/dist/core/userkeys/generationSignature.js.map +1 -1
- package/dist/core/userkeys/resolveUserKeyDocument.d.ts.map +1 -1
- package/dist/core/userkeys/resolveUserKeyDocument.js +6 -6
- package/dist/core/userkeys/resolveUserKeyDocument.js.map +1 -1
- package/dist/core/userkeys/validateUserKeyDocument.d.ts +11 -1
- package/dist/core/userkeys/validateUserKeyDocument.d.ts.map +1 -1
- package/dist/core/userkeys/validateUserKeyDocument.js +18 -5
- package/dist/core/userkeys/validateUserKeyDocument.js.map +1 -1
- package/dist/node/server/MindooDBServer.d.ts +2 -0
- package/dist/node/server/MindooDBServer.d.ts.map +1 -1
- package/dist/node/server/MindooDBServer.js +46 -0
- package/dist/node/server/MindooDBServer.js.map +1 -1
- package/dist/node/server/StoreFactory.d.ts.map +1 -1
- package/dist/node/server/StoreFactory.js +4 -1
- package/dist/node/server/StoreFactory.js.map +1 -1
- package/dist/node/server/server.js +2 -0
- package/dist/node/server/server.js.map +1 -1
- package/dist/server/JoinRequestService.d.ts +108 -0
- package/dist/server/JoinRequestService.d.ts.map +1 -0
- package/dist/server/JoinRequestService.js +454 -0
- package/dist/server/JoinRequestService.js.map +1 -0
- package/dist/server/TenantManager.d.ts +50 -0
- package/dist/server/TenantManager.d.ts.map +1 -1
- package/dist/server/TenantManager.js +271 -33
- package/dist/server/TenantManager.js.map +1 -1
- package/dist/server/http/MindooDBServerCore.d.ts +18 -0
- package/dist/server/http/MindooDBServerCore.d.ts.map +1 -1
- package/dist/server/http/MindooDBServerCore.js +229 -137
- package/dist/server/http/MindooDBServerCore.js.map +1 -1
- package/dist/server/serverConfig.d.ts.map +1 -1
- package/dist/server/serverConfig.js +17 -0
- package/dist/server/serverConfig.js.map +1 -1
- package/dist/server/types.d.ts +15 -0
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js +6 -0
- package/dist/server/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseMindooTenantDirectory = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
4
|
+
const types_1 = require("./joinrequests/types");
|
|
5
|
+
const types_2 = require("./types");
|
|
5
6
|
const errors_1 = require("./errors");
|
|
6
7
|
const storeEntryTime_1 = require("./storeEntryTime");
|
|
7
8
|
const fingerprint_1 = require("./userkeys/fingerprint");
|
|
@@ -10,12 +11,12 @@ const timeSource_1 = require("./utils/timeSource");
|
|
|
10
11
|
const singleFlight_1 = require("./utils/singleFlight");
|
|
11
12
|
const logging_1 = require("./logging");
|
|
12
13
|
const grantKeys_1 = require("./accesscontrol/grantKeys");
|
|
13
|
-
const
|
|
14
|
+
const types_3 = require("./accesscontrol/types");
|
|
14
15
|
const builtinDbInvariants_1 = require("./builtinDbInvariants");
|
|
15
16
|
const DirectoryStateNode_1 = require("./accesscontrol/DirectoryStateNode");
|
|
16
17
|
const DirectoryTimeTravelIndex_1 = require("./accesscontrol/DirectoryTimeTravelIndex");
|
|
17
18
|
const directoryProjection_1 = require("./accesscontrol/directoryProjection");
|
|
18
|
-
const
|
|
19
|
+
const types_4 = require("./accesscontrol/types");
|
|
19
20
|
const evaluate_1 = require("./accesscontrol/evaluate");
|
|
20
21
|
const RSAEncryption_1 = require("./crypto/RSAEncryption");
|
|
21
22
|
const encryptedFields_1 = require("./crypto/encryptedFields");
|
|
@@ -273,7 +274,7 @@ class BaseMindooTenantDirectory {
|
|
|
273
274
|
const directoryDB = await this.getDirectoryDB();
|
|
274
275
|
// Create document with admin signing key so the initial entry is trusted
|
|
275
276
|
// Use PUBLIC_INFOS_KEY_ID so servers can validate users without full tenant access
|
|
276
|
-
const newDoc = await directoryDB.createDocumentWithSigningKey(adminSigningKeyPair, administrationPrivateKeyPassword,
|
|
277
|
+
const newDoc = await directoryDB.createDocumentWithSigningKey(adminSigningKeyPair, administrationPrivateKeyPassword, types_2.PUBLIC_INFOS_KEY_ID);
|
|
277
278
|
this.logger.debug(`Document created: ${newDoc.getId()}`);
|
|
278
279
|
try {
|
|
279
280
|
// Set the document data fields with the admin key at entry level
|
|
@@ -286,7 +287,7 @@ class BaseMindooTenantDirectory {
|
|
|
286
287
|
data.user_details_encrypted = userDetailsEncrypted;
|
|
287
288
|
// Follow the `_encrypted` / `_encrypted_key` convention so view formulas
|
|
288
289
|
// (v.decryptJson) can resolve the key id without hardcoding "default".
|
|
289
|
-
data.user_details_encrypted_key =
|
|
290
|
+
data.user_details_encrypted_key = types_2.DEFAULT_TENANT_KEY_ID;
|
|
290
291
|
// $publicinfos-readable identity-hash bundle (§6.5): the grant doc is
|
|
291
292
|
// encrypted under PUBLIC_INFOS_KEY_ID, so these plain fields are
|
|
292
293
|
// server-readable without the default tenant key.
|
|
@@ -318,7 +319,7 @@ class BaseMindooTenantDirectory {
|
|
|
318
319
|
// Push selected keys (default: tenant default) via key distribution so the
|
|
319
320
|
// joining device can bootstrap without a join-response URI once the
|
|
320
321
|
// server delivers `$publicinfos` (docs/accesscontrol.md §13).
|
|
321
|
-
const distributeKeyIds = options?.distributeKeyIds ?? [
|
|
322
|
+
const distributeKeyIds = options?.distributeKeyIds ?? [types_2.DEFAULT_TENANT_KEY_ID];
|
|
322
323
|
await this.autoDistributeKeysToUser(userId.username, distributeKeyIds, administrationPrivateKey, administrationPrivateKeyPassword);
|
|
323
324
|
}
|
|
324
325
|
/**
|
|
@@ -331,7 +332,7 @@ class BaseMindooTenantDirectory {
|
|
|
331
332
|
const filtered = [
|
|
332
333
|
...new Set(keyIds
|
|
333
334
|
.map((id) => (typeof id === "string" ? id.trim() : ""))
|
|
334
|
-
.filter((id) => id.length > 0 && !
|
|
335
|
+
.filter((id) => id.length > 0 && !types_4.PROTECTED_DISTRIBUTION_KEY_IDS.includes(id))),
|
|
335
336
|
];
|
|
336
337
|
if (filtered.length === 0)
|
|
337
338
|
return;
|
|
@@ -392,13 +393,13 @@ class BaseMindooTenantDirectory {
|
|
|
392
393
|
*/
|
|
393
394
|
async keyIdsNeedingDeviceWrap(username) {
|
|
394
395
|
const lower = username.trim().toLowerCase();
|
|
395
|
-
const ids = new Set([
|
|
396
|
+
const ids = new Set([types_2.DEFAULT_TENANT_KEY_ID]);
|
|
396
397
|
for (const view of await this.listKeyDistributions()) {
|
|
397
398
|
if (view.pushtoUsernames?.some((u) => u.trim().toLowerCase() === lower)) {
|
|
398
399
|
ids.add(view.keyId);
|
|
399
400
|
}
|
|
400
401
|
}
|
|
401
|
-
return [...ids].filter((id) => !
|
|
402
|
+
return [...ids].filter((id) => !types_4.PROTECTED_DISTRIBUTION_KEY_IDS.includes(id));
|
|
402
403
|
}
|
|
403
404
|
async findGrantAccessDocuments(username) {
|
|
404
405
|
this.logger.debug(`Finding grant access documents for username: ${username}`);
|
|
@@ -650,6 +651,16 @@ class BaseMindooTenantDirectory {
|
|
|
650
651
|
async isAdminSigningKeyAt(signingKey, T) {
|
|
651
652
|
return this.tenant.isAdminSigningKeyAt(signingKey, (0, adminKeys_1.adminDecisionTime)(T, (0, timeSource_1.semanticNow)()));
|
|
652
653
|
}
|
|
654
|
+
/** See {@link MindooTenantDirectory.isAdminSignedEntry}. */
|
|
655
|
+
async isAdminSignedEntry(entry, dbid) {
|
|
656
|
+
if ((0, DirectoryStateNode_1.signingKeysEqual)(entry.createdByPublicKey, this.getRootAdminPublicKey()))
|
|
657
|
+
return true;
|
|
658
|
+
const directoryDB = await this.getDirectoryDB();
|
|
659
|
+
const decision = await this.tenant
|
|
660
|
+
.getDirectoryAdminResolver(directoryDB.getStore())
|
|
661
|
+
.judgeEntry(entry, { dbid, allowLocalUnwitnessed: true });
|
|
662
|
+
return decision.allowed;
|
|
663
|
+
}
|
|
653
664
|
/**
|
|
654
665
|
* The delegated admin key `signingKey` as valid at `T` (its encryption key and
|
|
655
666
|
* window), or null when it is not a delegated admin then. Store-level like
|
|
@@ -748,12 +759,12 @@ class BaseMindooTenantDirectory {
|
|
|
748
759
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, rootPair, administrationPrivateKeyPassword);
|
|
749
760
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
750
761
|
const data = d.getData();
|
|
751
|
-
data.form =
|
|
762
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
752
763
|
data.type = adminKeys_1.ADMIN_KEY_TYPE;
|
|
753
764
|
data.signingPublicKey = admin.signingPublicKey;
|
|
754
765
|
data.encryptionPublicKey = admin.encryptionPublicKey;
|
|
755
766
|
data.name_encrypted = nameEncrypted;
|
|
756
|
-
data.name_encrypted_key =
|
|
767
|
+
data.name_encrypted_key = types_2.DEFAULT_TENANT_KEY_ID;
|
|
757
768
|
if (label)
|
|
758
769
|
data.label = label;
|
|
759
770
|
else
|
|
@@ -1026,7 +1037,7 @@ class BaseMindooTenantDirectory {
|
|
|
1026
1037
|
// singleton per keyId. Cache head state here so the revoked-key resolver
|
|
1027
1038
|
// and the KeyBag reconcile read it without re-scanning directory docs
|
|
1028
1039
|
// (docs/accesscontrol.md §13). A deleted distribution drops its entry.
|
|
1029
|
-
if (data.type ===
|
|
1040
|
+
if (data.type === types_4.KEY_DISTRIBUTION_TYPE && typeof data.keyId === "string") {
|
|
1030
1041
|
const keyId = data.keyId;
|
|
1031
1042
|
if (doc.isDeleted()) {
|
|
1032
1043
|
keyDistributionCache.delete(keyId);
|
|
@@ -1054,7 +1065,7 @@ class BaseMindooTenantDirectory {
|
|
|
1054
1065
|
// singleton per appId. Cache the recipient hash lists so the per-user
|
|
1055
1066
|
// reconcile reads membership without re-scanning directory docs
|
|
1056
1067
|
// (docs/accesscontrol.md §13). A deleted distribution drops its entry.
|
|
1057
|
-
if (data.type ===
|
|
1068
|
+
if (data.type === types_4.APP_DISTRIBUTION_TYPE && typeof data.appId === "string") {
|
|
1058
1069
|
const appId = data.appId;
|
|
1059
1070
|
if (doc.isDeleted()) {
|
|
1060
1071
|
appDistributionCache.delete(appId);
|
|
@@ -1073,7 +1084,7 @@ class BaseMindooTenantDirectory {
|
|
|
1073
1084
|
// doc per policy. Cache the recipient hash lists + enforcement mode so the
|
|
1074
1085
|
// per-user reconcile reads membership without re-scanning directory docs.
|
|
1075
1086
|
// A deleted policy drops its entry.
|
|
1076
|
-
if (data.type ===
|
|
1087
|
+
if (data.type === types_4.SYNC_SETUP_POLICY_TYPE && typeof data.policyId === "string") {
|
|
1077
1088
|
const policyId = data.policyId;
|
|
1078
1089
|
if (doc.isDeleted()) {
|
|
1079
1090
|
syncSetupPolicyCache.delete(policyId);
|
|
@@ -1327,11 +1338,11 @@ class BaseMindooTenantDirectory {
|
|
|
1327
1338
|
hashes.add(h);
|
|
1328
1339
|
}
|
|
1329
1340
|
}
|
|
1330
|
-
hashes.add(
|
|
1341
|
+
hashes.add(types_4.PSEUDO_TOKEN_EVERYONE);
|
|
1331
1342
|
if (opts.isAdmin)
|
|
1332
|
-
hashes.add(
|
|
1343
|
+
hashes.add(types_4.PSEUDO_TOKEN_ADMIN);
|
|
1333
1344
|
if (opts.isAuthor)
|
|
1334
|
-
hashes.add(
|
|
1345
|
+
hashes.add(types_4.PSEUDO_TOKEN_AUTHOR);
|
|
1335
1346
|
return { username, usernames, groups, hashes };
|
|
1336
1347
|
}
|
|
1337
1348
|
/**
|
|
@@ -1567,7 +1578,7 @@ class BaseMindooTenantDirectory {
|
|
|
1567
1578
|
return new Map();
|
|
1568
1579
|
let store;
|
|
1569
1580
|
try {
|
|
1570
|
-
store = baseTenant.getDocStoreForDb(
|
|
1581
|
+
store = baseTenant.getDocStoreForDb(types_2.USER_DIRECTORY_DB_ID);
|
|
1571
1582
|
}
|
|
1572
1583
|
catch {
|
|
1573
1584
|
return new Map();
|
|
@@ -1710,7 +1721,7 @@ class BaseMindooTenantDirectory {
|
|
|
1710
1721
|
const head = await this.getDirectoryStateHead();
|
|
1711
1722
|
if (head.defaultPolicy === null)
|
|
1712
1723
|
return undefined;
|
|
1713
|
-
const eff = (0,
|
|
1724
|
+
const eff = (0, types_4.effectivePolicy)(head.defaultPolicy, head.dbPolicies.get(dbid) ?? null);
|
|
1714
1725
|
if (eff.disableAllAccessChecksAndPolicies)
|
|
1715
1726
|
return undefined;
|
|
1716
1727
|
return eff.defaultCreateKeyId;
|
|
@@ -1761,6 +1772,29 @@ class BaseMindooTenantDirectory {
|
|
|
1761
1772
|
...(policy.llm.denyUse !== undefined ? { denyUse: policy.llm.denyUse } : {}),
|
|
1762
1773
|
};
|
|
1763
1774
|
}
|
|
1775
|
+
/**
|
|
1776
|
+
* The tenant's media gateway for calls: the `media` block of the default
|
|
1777
|
+
* policy at the directory head, or `null` when it names no gateway.
|
|
1778
|
+
*
|
|
1779
|
+
* Like the `llm` block it does not follow the master switch
|
|
1780
|
+
* `disableAllAccessChecksAndPolicies`; new tenants are created with that on.
|
|
1781
|
+
*
|
|
1782
|
+
* Only valid origins are returned (the same checks as on write), so an entry
|
|
1783
|
+
* a newer or a tampering writer got past another client's validation cannot
|
|
1784
|
+
* widen what a reader lets an app reach.
|
|
1785
|
+
*/
|
|
1786
|
+
async getMediaGatewayPolicy() {
|
|
1787
|
+
const head = await this.getDirectoryStateHead();
|
|
1788
|
+
const media = head.defaultPolicy?.media;
|
|
1789
|
+
if (!media?.gatewayUrl || !(0, types_4.isValidMediaGatewayUrl)(media.gatewayUrl)) {
|
|
1790
|
+
return null;
|
|
1791
|
+
}
|
|
1792
|
+
const mediaUrls = (media.mediaUrls ?? []).filter((entry) => (0, types_4.isValidMediaServerUrl)(entry));
|
|
1793
|
+
return {
|
|
1794
|
+
gatewayUrl: media.gatewayUrl,
|
|
1795
|
+
...(mediaUrls.length ? { mediaUrls } : {}),
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1764
1798
|
/**
|
|
1765
1799
|
* Whether the current user may use a client's AI assistant with this
|
|
1766
1800
|
* tenant's data (`llm_use`, §6.9), at the directory head. The baseline is
|
|
@@ -1833,7 +1867,7 @@ class BaseMindooTenantDirectory {
|
|
|
1833
1867
|
* bypass).
|
|
1834
1868
|
*/
|
|
1835
1869
|
async isDatabaseAllowed(dbid, opts) {
|
|
1836
|
-
if (dbid ===
|
|
1870
|
+
if (dbid === types_2.DIRECTORY_DB_ID || dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
1837
1871
|
return true;
|
|
1838
1872
|
const { mode, allowedDbIds } = await this.getDatabaseCreationPolicy();
|
|
1839
1873
|
if (mode === "open")
|
|
@@ -1863,7 +1897,7 @@ class BaseMindooTenantDirectory {
|
|
|
1863
1897
|
}
|
|
1864
1898
|
// The directory database is never read-gated (it must always sync so the
|
|
1865
1899
|
// policy that defines the read gate can be read at all).
|
|
1866
|
-
if (input.dbid ===
|
|
1900
|
+
if (input.dbid === types_2.DIRECTORY_DB_ID || input.dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
1867
1901
|
return true;
|
|
1868
1902
|
// Tenant admins (root and active delegated admins, §6.13) are exempt from the read gate.
|
|
1869
1903
|
if (await this.isAdminKeyNow(input.signingKey))
|
|
@@ -1890,7 +1924,7 @@ class BaseMindooTenantDirectory {
|
|
|
1890
1924
|
* scoped. Evaluated at the directory head, like the read gate.
|
|
1891
1925
|
*/
|
|
1892
1926
|
async evaluateReadScopeForSigningKey(input) {
|
|
1893
|
-
if (input.dbid ===
|
|
1927
|
+
if (input.dbid === types_2.DIRECTORY_DB_ID || input.dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
1894
1928
|
return "all";
|
|
1895
1929
|
if (await this.isAdminKeyNow(input.signingKey))
|
|
1896
1930
|
return "all";
|
|
@@ -1919,6 +1953,13 @@ class BaseMindooTenantDirectory {
|
|
|
1919
1953
|
* the matching deposit rule.
|
|
1920
1954
|
*/
|
|
1921
1955
|
async evaluateDbAccessModeForSigningKey(input) {
|
|
1956
|
+
// Join requests (docs/invitations.md): tenant admins only, whatever a
|
|
1957
|
+
// policy says. The server writes there with its own key, not via sync.
|
|
1958
|
+
if (input.dbid === types_1.JOIN_REQUESTS_DB_ID) {
|
|
1959
|
+
return (await this.isAdminKeyNow(input.signingKey))
|
|
1960
|
+
? { mode: "read", reason: "tenant admin" }
|
|
1961
|
+
: { mode: "none", reason: "joinrequests: tenant admins only" };
|
|
1962
|
+
}
|
|
1922
1963
|
// Built-in personal-database invariant (§6.11): decides first, and a
|
|
1923
1964
|
// configured policy can only take away what it grants.
|
|
1924
1965
|
const personal = await this.evaluatePersonalDatabaseAccess(input);
|
|
@@ -1962,7 +2003,7 @@ class BaseMindooTenantDirectory {
|
|
|
1962
2003
|
const rule = await this.depositRule(decision.matchedRuleId);
|
|
1963
2004
|
return {
|
|
1964
2005
|
mode: "deposit",
|
|
1965
|
-
maxRecipients: rule?.maxRecipients ??
|
|
2006
|
+
maxRecipients: rule?.maxRecipients ?? types_3.DEFAULT_DEPOSIT_MAX_RECIPIENTS,
|
|
1966
2007
|
...(rule?.docIdPrefixes?.length ? { docIdPrefixes: rule.docIdPrefixes } : {}),
|
|
1967
2008
|
};
|
|
1968
2009
|
}
|
|
@@ -2064,8 +2105,8 @@ class BaseMindooTenantDirectory {
|
|
|
2064
2105
|
maxRecipients: 1,
|
|
2065
2106
|
docIdPrefixes: [...(builtinDbInvariants_1.BUILTIN_PERSONAL_DEPOSIT_DOC_ID_PREFIXES.mmail_ ?? [])],
|
|
2066
2107
|
internalMail: {
|
|
2067
|
-
maxBytesPerMail: limits.maxBytesPerMail ??
|
|
2068
|
-
maxMailsPerHour: limits.maxMailsPerHour ??
|
|
2108
|
+
maxBytesPerMail: limits.maxBytesPerMail ?? types_3.DEFAULT_INTERNAL_MAIL_LIMITS.maxBytesPerMail,
|
|
2109
|
+
maxMailsPerHour: limits.maxMailsPerHour ?? types_3.DEFAULT_INTERNAL_MAIL_LIMITS.maxMailsPerHour,
|
|
2069
2110
|
},
|
|
2070
2111
|
reason: `internal mail (${mode})`,
|
|
2071
2112
|
};
|
|
@@ -2132,7 +2173,7 @@ class BaseMindooTenantDirectory {
|
|
|
2132
2173
|
if (!builtinDbInvariants_1.PERSONAL_DATABASE_PREFIX_REGEX.test(prefix)) {
|
|
2133
2174
|
throw new Error(`depositDocIdPrefixes: "${prefix}" is not a personal-database prefix like "mmail_"`);
|
|
2134
2175
|
}
|
|
2135
|
-
(0,
|
|
2176
|
+
(0, types_3.validateDocIdPrefixes)(ids, `depositDocIdPrefixes.${prefix}`);
|
|
2136
2177
|
}
|
|
2137
2178
|
const grants = (await this.findGrantAccessDocuments(username)).filter((doc) => !doc.isDeleted());
|
|
2138
2179
|
if (grants.length === 0)
|
|
@@ -2162,7 +2203,7 @@ class BaseMindooTenantDirectory {
|
|
|
2162
2203
|
* read gate; callers check {@link canReadDatabase} first.
|
|
2163
2204
|
*/
|
|
2164
2205
|
async canDepositDatabase(dbid) {
|
|
2165
|
-
if (dbid ===
|
|
2206
|
+
if (dbid === types_2.DIRECTORY_DB_ID || dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
2166
2207
|
return false;
|
|
2167
2208
|
const currentUser = await this.tenant.getCurrentUserId();
|
|
2168
2209
|
const access = await this.evaluateDbAccessModeForSigningKey({ dbid, signingKey: currentUser.userSigningPublicKey });
|
|
@@ -2184,7 +2225,7 @@ class BaseMindooTenantDirectory {
|
|
|
2184
2225
|
* ({@link isDatabaseAllowed}); callers enforce both gates.
|
|
2185
2226
|
*/
|
|
2186
2227
|
async canReadDatabase(dbid) {
|
|
2187
|
-
if (dbid ===
|
|
2228
|
+
if (dbid === types_2.DIRECTORY_DB_ID || dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
2188
2229
|
return true;
|
|
2189
2230
|
const currentUser = await this.tenant.getCurrentUserId();
|
|
2190
2231
|
if (await this.isAdminKeyNow(currentUser.userSigningPublicKey))
|
|
@@ -2208,8 +2249,8 @@ class BaseMindooTenantDirectory {
|
|
|
2208
2249
|
* written; omit a field to leave it unset (interpreted as its default).
|
|
2209
2250
|
*/
|
|
2210
2251
|
async setDefaultAccessPolicy(policy, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
2211
|
-
(0,
|
|
2212
|
-
await this.writePolicyDoc(
|
|
2252
|
+
(0, types_4.validateAccessPolicy)(policy);
|
|
2253
|
+
await this.writePolicyDoc(types_4.ACL_DEFAULT_POLICY_DOC_ID, policy, administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2213
2254
|
}
|
|
2214
2255
|
async requireV2EntrySignatures(administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
2215
2256
|
const head = await this.getDirectoryStateHead();
|
|
@@ -2231,14 +2272,17 @@ class BaseMindooTenantDirectory {
|
|
|
2231
2272
|
* override the tenant default for `dbid`; unset fields inherit it.
|
|
2232
2273
|
*/
|
|
2233
2274
|
async setDatabaseAccessPolicy(dbid, policy, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
2234
|
-
(0,
|
|
2275
|
+
(0, types_4.validateAccessPolicy)(policy);
|
|
2235
2276
|
if (policy.personalDatabasePrefixes !== undefined) {
|
|
2236
2277
|
throw new Error("personalDatabasePrefixes is a tenant-level setting; set it on the default policy");
|
|
2237
2278
|
}
|
|
2238
2279
|
if (policy.llm !== undefined) {
|
|
2239
2280
|
throw new Error("llm is a tenant-level setting; set it on the default policy");
|
|
2240
2281
|
}
|
|
2241
|
-
|
|
2282
|
+
if (policy.media !== undefined) {
|
|
2283
|
+
throw new Error("media is a tenant-level setting; set it on the default policy");
|
|
2284
|
+
}
|
|
2285
|
+
await this.writePolicyDoc((0, types_4.aclDbPolicyDocId)(dbid), policy, administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2242
2286
|
}
|
|
2243
2287
|
/** Shared writer for default / per-db policy documents. */
|
|
2244
2288
|
async writePolicyDoc(docId, policy, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
@@ -2248,7 +2292,7 @@ class BaseMindooTenantDirectory {
|
|
|
2248
2292
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
2249
2293
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
2250
2294
|
const data = d.getData();
|
|
2251
|
-
data.form =
|
|
2295
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
2252
2296
|
data.type = "defaultpolicy";
|
|
2253
2297
|
for (const [key, value] of Object.entries(policy)) {
|
|
2254
2298
|
if (value !== undefined)
|
|
@@ -2271,7 +2315,7 @@ class BaseMindooTenantDirectory {
|
|
|
2271
2315
|
// membership entries so they intersect the acting user's identity set.
|
|
2272
2316
|
const resolvedHashes = await this.resolveRuleTargetHashes(rule);
|
|
2273
2317
|
const ruleDoc = {
|
|
2274
|
-
form:
|
|
2318
|
+
form: types_4.ACCESS_CONTROL_FORM,
|
|
2275
2319
|
type: rule.type,
|
|
2276
2320
|
ruleId: rule.ruleId,
|
|
2277
2321
|
description: rule.description,
|
|
@@ -2287,14 +2331,14 @@ class BaseMindooTenantDirectory {
|
|
|
2287
2331
|
...(rule.docIdPrefixes !== undefined ? { docIdPrefixes: [...new Set(rule.docIdPrefixes)] } : {}),
|
|
2288
2332
|
};
|
|
2289
2333
|
// Fail fast on malformed clauses / operators (§6.3 closed set).
|
|
2290
|
-
(0,
|
|
2334
|
+
(0, types_4.validateAclRule)(ruleDoc);
|
|
2291
2335
|
const baseTenant = this.tenant;
|
|
2292
2336
|
const directoryDB = await this.getDirectoryDB();
|
|
2293
2337
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2294
|
-
const doc = await this.getOrCreateAclDoc(directoryDB, (0,
|
|
2338
|
+
const doc = await this.getOrCreateAclDoc(directoryDB, (0, types_4.aclRuleDocId)(rule.ruleId), adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
2295
2339
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
2296
2340
|
const data = d.getData();
|
|
2297
|
-
data.form =
|
|
2341
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
2298
2342
|
data.type = ruleDoc.type;
|
|
2299
2343
|
data.ruleId = ruleDoc.ruleId;
|
|
2300
2344
|
data.dbid = ruleDoc.dbid;
|
|
@@ -2344,7 +2388,7 @@ class BaseMindooTenantDirectory {
|
|
|
2344
2388
|
const directoryDB = await this.getDirectoryDB();
|
|
2345
2389
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2346
2390
|
try {
|
|
2347
|
-
await directoryDB.deleteDocument((0,
|
|
2391
|
+
await directoryDB.deleteDocument((0, types_4.aclRuleDocId)(ruleId), {
|
|
2348
2392
|
signingKeyPair: adminSigningKeyPair,
|
|
2349
2393
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
2350
2394
|
});
|
|
@@ -2365,10 +2409,10 @@ class BaseMindooTenantDirectory {
|
|
|
2365
2409
|
// Trusted witnesses decide whose receipt times count (§6.13): root only.
|
|
2366
2410
|
await this.rootKeyPair(administrationPrivateKey, administrationPrivateKeyPassword, "add trusted witnesses");
|
|
2367
2411
|
const fingerprint = await this.sha256Hex(witness.witnessPublicKey);
|
|
2368
|
-
const doc = await this.getOrCreateAclDoc(directoryDB, (0,
|
|
2412
|
+
const doc = await this.getOrCreateAclDoc(directoryDB, (0, types_3.aclTrustedWitnessDocId)(fingerprint), adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
2369
2413
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
2370
2414
|
const data = d.getData();
|
|
2371
|
-
data.form =
|
|
2415
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
2372
2416
|
data.type = "trustedwitness";
|
|
2373
2417
|
data.witnessPublicKey = witness.witnessPublicKey;
|
|
2374
2418
|
if (witness.serverUrl !== undefined)
|
|
@@ -2384,7 +2428,7 @@ class BaseMindooTenantDirectory {
|
|
|
2384
2428
|
await this.rootKeyPair(administrationPrivateKey, administrationPrivateKeyPassword, "remove trusted witnesses");
|
|
2385
2429
|
const fingerprint = await this.sha256Hex(witnessPublicKey);
|
|
2386
2430
|
try {
|
|
2387
|
-
await directoryDB.deleteDocument((0,
|
|
2431
|
+
await directoryDB.deleteDocument((0, types_3.aclTrustedWitnessDocId)(fingerprint), {
|
|
2388
2432
|
signingKeyPair: adminSigningKeyPair,
|
|
2389
2433
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
2390
2434
|
});
|
|
@@ -2613,7 +2657,7 @@ class BaseMindooTenantDirectory {
|
|
|
2613
2657
|
await this.editGrantArrays(username, administrationPrivateKey, administrationPrivateKeyPassword, (data) => {
|
|
2614
2658
|
if (userDetailsEncrypted !== null) {
|
|
2615
2659
|
data.user_details_encrypted = userDetailsEncrypted;
|
|
2616
|
-
data.user_details_encrypted_key =
|
|
2660
|
+
data.user_details_encrypted_key = types_2.DEFAULT_TENANT_KEY_ID;
|
|
2617
2661
|
}
|
|
2618
2662
|
// Recompute the $publicinfos-readable identity-hash bundle (§6.5).
|
|
2619
2663
|
data.identity_hashes = identityHashes;
|
|
@@ -2869,6 +2913,31 @@ class BaseMindooTenantDirectory {
|
|
|
2869
2913
|
devices: { [fingerprint]: wrappedByVersion },
|
|
2870
2914
|
};
|
|
2871
2915
|
}
|
|
2916
|
+
/**
|
|
2917
|
+
* Whether the distribution of `keyId` reaches `username` through a User-Key:
|
|
2918
|
+
* one of their wrap entries is addressed to a fingerprint that is not an
|
|
2919
|
+
* encryption key of their own grant devices. False when the person is not in
|
|
2920
|
+
* `pushto`, has no wrap entries, or only has per-device wraps from before
|
|
2921
|
+
* User-Keys (docs/userkeys.md §4.5).
|
|
2922
|
+
*/
|
|
2923
|
+
async isKeyDistributedViaUserKey(keyId, username) {
|
|
2924
|
+
await this.updateUnifiedCache();
|
|
2925
|
+
const entry = this.keyDistributionCache.get(keyId);
|
|
2926
|
+
if (!entry)
|
|
2927
|
+
return false;
|
|
2928
|
+
const myHashes = new Set(await this.usernameHashCandidates(username));
|
|
2929
|
+
const wrapFingerprints = Object.keys(entry.pushto_users_keys)
|
|
2930
|
+
.map((entryKey) => entryKey.split("|"))
|
|
2931
|
+
.filter(([hash, fingerprint]) => myHashes.has(hash) && Boolean(fingerprint))
|
|
2932
|
+
.map(([, fingerprint]) => fingerprint);
|
|
2933
|
+
if (wrapFingerprints.length === 0)
|
|
2934
|
+
return false;
|
|
2935
|
+
const deviceFingerprints = new Set();
|
|
2936
|
+
for (const pem of await this.getUserEncryptionPublicKeys(username)) {
|
|
2937
|
+
deviceFingerprints.add(await this.encryptionKeyFingerprint(pem));
|
|
2938
|
+
}
|
|
2939
|
+
return wrapFingerprints.some((fingerprint) => !deviceFingerprints.has(fingerprint));
|
|
2940
|
+
}
|
|
2872
2941
|
/**
|
|
2873
2942
|
* The canonical write-time hash for `username` (the value stored in
|
|
2874
2943
|
* `pushto_users_hashes` / `pullfrom_users_hashes`). Exposed so callers (the
|
|
@@ -2897,7 +2966,7 @@ class BaseMindooTenantDirectory {
|
|
|
2897
2966
|
/** Encrypt a UTF-8 string with the tenant default key, base64-encoded. */
|
|
2898
2967
|
async encryptToDefaultField(plaintext) {
|
|
2899
2968
|
const payload = new TextEncoder().encode(plaintext);
|
|
2900
|
-
const encrypted = await this.tenant.encryptPayload(payload,
|
|
2969
|
+
const encrypted = await this.tenant.encryptPayload(payload, types_2.DEFAULT_TENANT_KEY_ID);
|
|
2901
2970
|
return this.uint8ArrayToBase64(encrypted);
|
|
2902
2971
|
}
|
|
2903
2972
|
/**
|
|
@@ -2918,7 +2987,7 @@ class BaseMindooTenantDirectory {
|
|
|
2918
2987
|
}
|
|
2919
2988
|
const pushtoHashes = request.pushto.map((p) => p.username_hash);
|
|
2920
2989
|
const pullfromHashes = request.pullfrom.map((p) => p.username_hash);
|
|
2921
|
-
(0,
|
|
2990
|
+
(0, types_4.validateKeyDistribution)({
|
|
2922
2991
|
keyId,
|
|
2923
2992
|
keyVersions: request.keyVersions,
|
|
2924
2993
|
pushto_users_hashes: pushtoHashes,
|
|
@@ -2969,15 +3038,15 @@ class BaseMindooTenantDirectory {
|
|
|
2969
3038
|
: undefined;
|
|
2970
3039
|
const pushtoUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pushto.map((p) => p.username)));
|
|
2971
3040
|
const pullfromUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfrom.map((p) => p.username)));
|
|
2972
|
-
const docId = (0,
|
|
3041
|
+
const docId = (0, types_4.aclKeyDistributionDocId)(keyId);
|
|
2973
3042
|
const baseTenant = this.tenant;
|
|
2974
3043
|
const directoryDB = await this.getDirectoryDB();
|
|
2975
3044
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2976
3045
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
2977
3046
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
2978
3047
|
const data = d.getData();
|
|
2979
|
-
data.form =
|
|
2980
|
-
data.type =
|
|
3048
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
3049
|
+
data.type = types_4.KEY_DISTRIBUTION_TYPE;
|
|
2981
3050
|
data.keyId = keyId;
|
|
2982
3051
|
data.keyVersions = request.keyVersions.map((v) => ({
|
|
2983
3052
|
createdAt: v.createdAt,
|
|
@@ -3029,7 +3098,7 @@ class BaseMindooTenantDirectory {
|
|
|
3029
3098
|
}
|
|
3030
3099
|
/** Parse a raw distribution doc's data into a {@link KeyDistributionView}. */
|
|
3031
3100
|
async toKeyDistributionView(data) {
|
|
3032
|
-
if (data.type !==
|
|
3101
|
+
if (data.type !== types_4.KEY_DISTRIBUTION_TYPE || typeof data.keyId !== "string")
|
|
3033
3102
|
return null;
|
|
3034
3103
|
const keyVersions = Array.isArray(data.keyVersions)
|
|
3035
3104
|
? data.keyVersions
|
|
@@ -3067,7 +3136,7 @@ class BaseMindooTenantDirectory {
|
|
|
3067
3136
|
await directoryDB.syncStoreChanges();
|
|
3068
3137
|
await this.updateUnifiedCache();
|
|
3069
3138
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
3070
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
3139
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_KEY_DISTRIBUTION_PREFIX));
|
|
3071
3140
|
const views = [];
|
|
3072
3141
|
for (const id of ids) {
|
|
3073
3142
|
let doc;
|
|
@@ -3091,7 +3160,7 @@ class BaseMindooTenantDirectory {
|
|
|
3091
3160
|
const directoryDB = await this.getDirectoryDB();
|
|
3092
3161
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3093
3162
|
try {
|
|
3094
|
-
await directoryDB.deleteDocument((0,
|
|
3163
|
+
await directoryDB.deleteDocument((0, types_4.aclKeyDistributionDocId)(keyId), {
|
|
3095
3164
|
signingKeyPair: adminSigningKeyPair,
|
|
3096
3165
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3097
3166
|
});
|
|
@@ -3175,7 +3244,7 @@ class BaseMindooTenantDirectory {
|
|
|
3175
3244
|
this.logger.warn("reconcileKeyDistributionsWithKey: directory has no key-distribution documents in cache");
|
|
3176
3245
|
return { imported: [], removed: [] };
|
|
3177
3246
|
}
|
|
3178
|
-
if (!this.keyDistributionCache.has(
|
|
3247
|
+
if (!this.keyDistributionCache.has(types_2.DEFAULT_TENANT_KEY_ID)) {
|
|
3179
3248
|
this.logger.warn("reconcileKeyDistributionsWithKey: no acl_keydistribution_default in directory cache");
|
|
3180
3249
|
}
|
|
3181
3250
|
const myHashes = new Set(await this.usernameHashCandidates(username));
|
|
@@ -3201,7 +3270,7 @@ class BaseMindooTenantDirectory {
|
|
|
3201
3270
|
// keyId -> why this candidate key could not open any of its wraps.
|
|
3202
3271
|
const unopened = new Map();
|
|
3203
3272
|
for (const [keyId, entry] of this.keyDistributionCache.entries()) {
|
|
3204
|
-
if (
|
|
3273
|
+
if (types_4.PROTECTED_DISTRIBUTION_KEY_IDS.includes(keyId))
|
|
3205
3274
|
continue;
|
|
3206
3275
|
const manifest = entry.keyVersions;
|
|
3207
3276
|
const meInPull = entry.pullfrom_users_hashes.some((h) => myHashes.has(h));
|
|
@@ -3216,8 +3285,10 @@ class BaseMindooTenantDirectory {
|
|
|
3216
3285
|
continue;
|
|
3217
3286
|
}
|
|
3218
3287
|
if (!meInPush) {
|
|
3219
|
-
if (keyId ===
|
|
3220
|
-
|
|
3288
|
+
if (keyId === types_2.DEFAULT_TENANT_KEY_ID) {
|
|
3289
|
+
// Debug only: the server's own identity is never in pushto, so on a
|
|
3290
|
+
// server this is logged for every tenant it opens.
|
|
3291
|
+
this.logger.debug(`reconcileKeyDistributions: "${keyId}" exists but current user is not in pushto ` +
|
|
3221
3292
|
`(hashes=${entry.pushto_users_hashes.length})`);
|
|
3222
3293
|
}
|
|
3223
3294
|
continue;
|
|
@@ -3318,7 +3389,7 @@ class BaseMindooTenantDirectory {
|
|
|
3318
3389
|
const pullfromUserHashes = await Promise.all(request.pullfromUsernames.map((u) => this.hashUsernameForWrite(u)));
|
|
3319
3390
|
const pushtoGroupHashes = await Promise.all(request.pushtoGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3320
3391
|
const pullfromGroupHashes = await Promise.all(request.pullfromGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3321
|
-
(0,
|
|
3392
|
+
(0, types_4.validateAppDistribution)({
|
|
3322
3393
|
appId,
|
|
3323
3394
|
pushto_users_hashes: pushtoUserHashes,
|
|
3324
3395
|
pullfrom_users_hashes: pullfromUserHashes,
|
|
@@ -3343,15 +3414,15 @@ class BaseMindooTenantDirectory {
|
|
|
3343
3414
|
const pushtoGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pushtoGroups));
|
|
3344
3415
|
const pullfromUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromUsernames));
|
|
3345
3416
|
const pullfromGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromGroups));
|
|
3346
|
-
const docId = (0,
|
|
3417
|
+
const docId = (0, types_4.aclAppDistributionDocId)(appId);
|
|
3347
3418
|
const baseTenant = this.tenant;
|
|
3348
3419
|
const directoryDB = await this.getDirectoryDB();
|
|
3349
3420
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3350
3421
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
3351
3422
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
3352
3423
|
const data = d.getData();
|
|
3353
|
-
data.form =
|
|
3354
|
-
data.type =
|
|
3424
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
3425
|
+
data.type = types_4.APP_DISTRIBUTION_TYPE;
|
|
3355
3426
|
data.appId = appId;
|
|
3356
3427
|
data.appid_encrypted = appidEncrypted;
|
|
3357
3428
|
data.appid_encrypted_key = "default";
|
|
@@ -3390,7 +3461,7 @@ class BaseMindooTenantDirectory {
|
|
|
3390
3461
|
}
|
|
3391
3462
|
/** Parse a raw app-distribution doc's data into an {@link AppDistributionView}. */
|
|
3392
3463
|
async toAppDistributionView(data) {
|
|
3393
|
-
if (data.type !==
|
|
3464
|
+
if (data.type !== types_4.APP_DISTRIBUTION_TYPE || typeof data.appId !== "string")
|
|
3394
3465
|
return null;
|
|
3395
3466
|
const stringArray = (value) => Array.isArray(value) ? value.filter((h) => typeof h === "string") : [];
|
|
3396
3467
|
const title = await (0, encryptedFields_1.decryptEncryptedField)(this.tenant, data, "title_encrypted");
|
|
@@ -3433,7 +3504,7 @@ class BaseMindooTenantDirectory {
|
|
|
3433
3504
|
await directoryDB.syncStoreChanges();
|
|
3434
3505
|
await this.updateUnifiedCache();
|
|
3435
3506
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
3436
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
3507
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_APP_DISTRIBUTION_PREFIX));
|
|
3437
3508
|
const views = [];
|
|
3438
3509
|
for (const id of ids) {
|
|
3439
3510
|
let doc;
|
|
@@ -3457,7 +3528,7 @@ class BaseMindooTenantDirectory {
|
|
|
3457
3528
|
const directoryDB = await this.getDirectoryDB();
|
|
3458
3529
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3459
3530
|
try {
|
|
3460
|
-
await directoryDB.deleteDocument((0,
|
|
3531
|
+
await directoryDB.deleteDocument((0, types_4.aclAppDistributionDocId)(appId), {
|
|
3461
3532
|
signingKeyPair: adminSigningKeyPair,
|
|
3462
3533
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3463
3534
|
});
|
|
@@ -3550,7 +3621,7 @@ class BaseMindooTenantDirectory {
|
|
|
3550
3621
|
const pullfromUserHashes = await Promise.all(request.pullfromUsernames.map((u) => this.hashUsernameForWrite(u)));
|
|
3551
3622
|
const pushtoGroupHashes = await Promise.all(request.pushtoGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3552
3623
|
const pullfromGroupHashes = await Promise.all(request.pullfromGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3553
|
-
(0,
|
|
3624
|
+
(0, types_4.validateSyncSetupPolicy)({
|
|
3554
3625
|
policyId,
|
|
3555
3626
|
mode,
|
|
3556
3627
|
databaseIds,
|
|
@@ -3576,15 +3647,15 @@ class BaseMindooTenantDirectory {
|
|
|
3576
3647
|
const pushtoGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pushtoGroups));
|
|
3577
3648
|
const pullfromUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromUsernames));
|
|
3578
3649
|
const pullfromGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromGroups));
|
|
3579
|
-
const docId = (0,
|
|
3650
|
+
const docId = (0, types_4.aclSyncSetupPolicyDocId)(policyId);
|
|
3580
3651
|
const baseTenant = this.tenant;
|
|
3581
3652
|
const directoryDB = await this.getDirectoryDB();
|
|
3582
3653
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3583
3654
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
3584
3655
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
3585
3656
|
const data = d.getData();
|
|
3586
|
-
data.form =
|
|
3587
|
-
data.type =
|
|
3657
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
3658
|
+
data.type = types_4.SYNC_SETUP_POLICY_TYPE;
|
|
3588
3659
|
data.policyId = policyId;
|
|
3589
3660
|
data.policyid_encrypted = policyidEncrypted;
|
|
3590
3661
|
data.policyid_encrypted_key = "default";
|
|
@@ -3622,7 +3693,7 @@ class BaseMindooTenantDirectory {
|
|
|
3622
3693
|
}
|
|
3623
3694
|
/** Parse a raw sync-setup-policy doc's data into a {@link SyncSetupPolicyView}. */
|
|
3624
3695
|
async toSyncSetupPolicyView(data) {
|
|
3625
|
-
if (data.type !==
|
|
3696
|
+
if (data.type !== types_4.SYNC_SETUP_POLICY_TYPE || typeof data.policyId !== "string")
|
|
3626
3697
|
return null;
|
|
3627
3698
|
const stringArray = (value) => Array.isArray(value) ? value.filter((h) => typeof h === "string") : [];
|
|
3628
3699
|
const title = await (0, encryptedFields_1.decryptEncryptedField)(this.tenant, data, "title_encrypted");
|
|
@@ -3667,7 +3738,7 @@ class BaseMindooTenantDirectory {
|
|
|
3667
3738
|
await directoryDB.syncStoreChanges();
|
|
3668
3739
|
await this.updateUnifiedCache();
|
|
3669
3740
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
3670
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
3741
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_SYNC_SETUP_POLICY_PREFIX));
|
|
3671
3742
|
const views = [];
|
|
3672
3743
|
for (const id of ids) {
|
|
3673
3744
|
let doc;
|
|
@@ -3691,7 +3762,7 @@ class BaseMindooTenantDirectory {
|
|
|
3691
3762
|
const directoryDB = await this.getDirectoryDB();
|
|
3692
3763
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3693
3764
|
try {
|
|
3694
|
-
await directoryDB.deleteDocument((0,
|
|
3765
|
+
await directoryDB.deleteDocument((0, types_4.aclSyncSetupPolicyDocId)(policyId), {
|
|
3695
3766
|
signingKeyPair: adminSigningKeyPair,
|
|
3696
3767
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3697
3768
|
});
|
|
@@ -3809,7 +3880,7 @@ class BaseMindooTenantDirectory {
|
|
|
3809
3880
|
collectRevokedKeyIdsForHashes(myHashes) {
|
|
3810
3881
|
const revoked = [];
|
|
3811
3882
|
for (const [keyId, entry] of this.keyDistributionCache.entries()) {
|
|
3812
|
-
if (
|
|
3883
|
+
if (types_4.PROTECTED_DISTRIBUTION_KEY_IDS.includes(keyId))
|
|
3813
3884
|
continue;
|
|
3814
3885
|
if (entry.pullfrom_users_hashes.some((h) => myHashes.has(h))) {
|
|
3815
3886
|
revoked.push(keyId);
|
|
@@ -3869,7 +3940,7 @@ class BaseMindooTenantDirectory {
|
|
|
3869
3940
|
id: docId,
|
|
3870
3941
|
signingKeyPair: adminSigningKeyPair,
|
|
3871
3942
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3872
|
-
decryptionKeyId:
|
|
3943
|
+
decryptionKeyId: types_2.PUBLIC_INFOS_KEY_ID,
|
|
3873
3944
|
});
|
|
3874
3945
|
}
|
|
3875
3946
|
/**
|
|
@@ -3926,11 +3997,11 @@ class BaseMindooTenantDirectory {
|
|
|
3926
3997
|
*/
|
|
3927
3998
|
minimalIdentitySet(opts) {
|
|
3928
3999
|
const hashes = new Set();
|
|
3929
|
-
hashes.add(
|
|
4000
|
+
hashes.add(types_4.PSEUDO_TOKEN_EVERYONE);
|
|
3930
4001
|
if (opts.isAdmin)
|
|
3931
|
-
hashes.add(
|
|
4002
|
+
hashes.add(types_4.PSEUDO_TOKEN_ADMIN);
|
|
3932
4003
|
if (opts.isAuthor)
|
|
3933
|
-
hashes.add(
|
|
4004
|
+
hashes.add(types_4.PSEUDO_TOKEN_AUTHOR);
|
|
3934
4005
|
return { username: "", usernames: [], groups: [], hashes };
|
|
3935
4006
|
}
|
|
3936
4007
|
/**
|
|
@@ -3953,11 +4024,11 @@ class BaseMindooTenantDirectory {
|
|
|
3953
4024
|
hashes.add(h);
|
|
3954
4025
|
}
|
|
3955
4026
|
}
|
|
3956
|
-
hashes.add(
|
|
4027
|
+
hashes.add(types_4.PSEUDO_TOKEN_EVERYONE);
|
|
3957
4028
|
if (opts.isAdmin)
|
|
3958
|
-
hashes.add(
|
|
4029
|
+
hashes.add(types_4.PSEUDO_TOKEN_ADMIN);
|
|
3959
4030
|
if (opts.isAuthor)
|
|
3960
|
-
hashes.add(
|
|
4031
|
+
hashes.add(types_4.PSEUDO_TOKEN_AUTHOR);
|
|
3961
4032
|
return { username: "", usernames: [], groups, hashes };
|
|
3962
4033
|
}
|
|
3963
4034
|
/**
|
|
@@ -4244,7 +4315,7 @@ class BaseMindooTenantDirectory {
|
|
|
4244
4315
|
* own stores; only `reason` is encrypted with the tenant `default` key.
|
|
4245
4316
|
*/
|
|
4246
4317
|
async publishDocHistoryPurge(request, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
4247
|
-
(0,
|
|
4318
|
+
(0, types_4.validateDocHistoryPurge)({
|
|
4248
4319
|
requestId: request.requestId,
|
|
4249
4320
|
dbId: request.dbId,
|
|
4250
4321
|
docIds: request.docIds,
|
|
@@ -4253,7 +4324,7 @@ class BaseMindooTenantDirectory {
|
|
|
4253
4324
|
const reasonEncrypted = request.reason
|
|
4254
4325
|
? await this.encryptToDefaultField(request.reason)
|
|
4255
4326
|
: undefined;
|
|
4256
|
-
const docId = (0,
|
|
4327
|
+
const docId = (0, types_4.aclDocHistoryPurgeDocId)(request.requestId);
|
|
4257
4328
|
const requestedAt = (0, timeSource_1.semanticNow)();
|
|
4258
4329
|
const baseTenant = this.tenant;
|
|
4259
4330
|
const directoryDB = await this.getDirectoryDB();
|
|
@@ -4261,8 +4332,8 @@ class BaseMindooTenantDirectory {
|
|
|
4261
4332
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
4262
4333
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
4263
4334
|
const data = d.getData();
|
|
4264
|
-
data.form =
|
|
4265
|
-
data.type =
|
|
4335
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
4336
|
+
data.type = types_4.DOC_HISTORY_PURGE_TYPE;
|
|
4266
4337
|
data.requestId = request.requestId;
|
|
4267
4338
|
data.dbId = request.dbId;
|
|
4268
4339
|
data.docIds = [...request.docIds];
|
|
@@ -4284,7 +4355,7 @@ class BaseMindooTenantDirectory {
|
|
|
4284
4355
|
}
|
|
4285
4356
|
/** Parse a raw purge-request doc's data into a {@link DocHistoryPurgeView}. */
|
|
4286
4357
|
async toDocHistoryPurgeView(data, purgeRequestDocId) {
|
|
4287
|
-
if (data.type !==
|
|
4358
|
+
if (data.type !== types_4.DOC_HISTORY_PURGE_TYPE)
|
|
4288
4359
|
return null;
|
|
4289
4360
|
const dbId = data.dbId;
|
|
4290
4361
|
if (typeof dbId !== "string")
|
|
@@ -4314,7 +4385,7 @@ class BaseMindooTenantDirectory {
|
|
|
4314
4385
|
const directoryDB = await this.getDirectoryDB();
|
|
4315
4386
|
await directoryDB.syncStoreChanges();
|
|
4316
4387
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
4317
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
4388
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_DOC_HISTORY_PURGE_PREFIX));
|
|
4318
4389
|
const views = [];
|
|
4319
4390
|
for (const id of ids) {
|
|
4320
4391
|
let doc;
|
|
@@ -4338,7 +4409,7 @@ class BaseMindooTenantDirectory {
|
|
|
4338
4409
|
const directoryDB = await this.getDirectoryDB();
|
|
4339
4410
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
4340
4411
|
try {
|
|
4341
|
-
await directoryDB.deleteDocument((0,
|
|
4412
|
+
await directoryDB.deleteDocument((0, types_4.aclDocHistoryPurgeDocId)(requestId), {
|
|
4342
4413
|
signingKeyPair: adminSigningKeyPair,
|
|
4343
4414
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
4344
4415
|
});
|
|
@@ -4376,7 +4447,7 @@ class BaseMindooTenantDirectory {
|
|
|
4376
4447
|
const directoryDB = await this.getDirectoryDB();
|
|
4377
4448
|
await directoryDB.syncStoreChanges();
|
|
4378
4449
|
await this.updateUnifiedCache();
|
|
4379
|
-
const known = new Set([
|
|
4450
|
+
const known = new Set([types_2.DIRECTORY_DB_ID, types_2.USER_DIRECTORY_DB_ID]);
|
|
4380
4451
|
for (const dbId of this.dbSettingsCache.keys()) {
|
|
4381
4452
|
known.add(dbId);
|
|
4382
4453
|
}
|
|
@@ -4483,7 +4554,7 @@ class BaseMindooTenantDirectory {
|
|
|
4483
4554
|
}
|
|
4484
4555
|
else {
|
|
4485
4556
|
// Create new document with PUBLIC_INFOS_KEY_ID for server access
|
|
4486
|
-
groupDoc = await directoryDB.createDocumentWithSigningKey(adminSigningKeyPair, administrationPrivateKeyPassword,
|
|
4557
|
+
groupDoc = await directoryDB.createDocumentWithSigningKey(adminSigningKeyPair, administrationPrivateKeyPassword, types_2.PUBLIC_INFOS_KEY_ID);
|
|
4487
4558
|
}
|
|
4488
4559
|
// Apply changes and ensure form, type, and groupName fields are correct
|
|
4489
4560
|
await directoryDB.changeDoc(groupDoc, async (d) => {
|
|
@@ -4711,7 +4782,7 @@ class BaseMindooTenantDirectory {
|
|
|
4711
4782
|
async encryptUserDetailsForTenant(userDetails) {
|
|
4712
4783
|
const encoder = new TextEncoder();
|
|
4713
4784
|
const payload = encoder.encode(JSON.stringify(userDetails));
|
|
4714
|
-
const encrypted = await this.tenant.encryptPayload(payload,
|
|
4785
|
+
const encrypted = await this.tenant.encryptPayload(payload, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4715
4786
|
return this.uint8ArrayToBase64(encrypted);
|
|
4716
4787
|
}
|
|
4717
4788
|
/**
|
|
@@ -4783,7 +4854,7 @@ class BaseMindooTenantDirectory {
|
|
|
4783
4854
|
}
|
|
4784
4855
|
async encryptGroupMemberForTenant(plaintext) {
|
|
4785
4856
|
const encoder = new TextEncoder();
|
|
4786
|
-
const encrypted = await this.tenant.encryptPayload(encoder.encode(plaintext),
|
|
4857
|
+
const encrypted = await this.tenant.encryptPayload(encoder.encode(plaintext), types_2.DEFAULT_TENANT_KEY_ID);
|
|
4787
4858
|
return this.uint8ArrayToBase64(encrypted);
|
|
4788
4859
|
}
|
|
4789
4860
|
/**
|
|
@@ -4820,7 +4891,7 @@ class BaseMindooTenantDirectory {
|
|
|
4820
4891
|
return "";
|
|
4821
4892
|
}
|
|
4822
4893
|
const payload = new TextEncoder().encode(JSON.stringify({ usernames, groups }));
|
|
4823
|
-
const encrypted = await this.tenant.encryptPayload(payload,
|
|
4894
|
+
const encrypted = await this.tenant.encryptPayload(payload, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4824
4895
|
return this.uint8ArrayToBase64(encrypted);
|
|
4825
4896
|
}
|
|
4826
4897
|
/**
|
|
@@ -4833,7 +4904,7 @@ class BaseMindooTenantDirectory {
|
|
|
4833
4904
|
return null;
|
|
4834
4905
|
try {
|
|
4835
4906
|
const encrypted = this.base64ToUint8Array(encryptedBase64);
|
|
4836
|
-
const decrypted = await this.tenant.decryptPayload(encrypted,
|
|
4907
|
+
const decrypted = await this.tenant.decryptPayload(encrypted, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4837
4908
|
const parsed = JSON.parse(new TextDecoder().decode(decrypted));
|
|
4838
4909
|
const usernames = Array.isArray(parsed.usernames)
|
|
4839
4910
|
? parsed.usernames.filter((u) => typeof u === "string")
|
|
@@ -4851,7 +4922,7 @@ class BaseMindooTenantDirectory {
|
|
|
4851
4922
|
async decryptGroupMemberForTenant(encryptedBase64) {
|
|
4852
4923
|
try {
|
|
4853
4924
|
const encrypted = this.base64ToUint8Array(encryptedBase64);
|
|
4854
|
-
const decrypted = await this.tenant.decryptPayload(encrypted,
|
|
4925
|
+
const decrypted = await this.tenant.decryptPayload(encrypted, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4855
4926
|
const member = new TextDecoder().decode(decrypted).trim();
|
|
4856
4927
|
return member || null;
|
|
4857
4928
|
}
|