mindoodb 0.0.97 → 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 +70 -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 +11 -0
- package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
- package/dist/core/BaseMindooTenantDirectory.js +137 -92
- package/dist/core/BaseMindooTenantDirectory.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 +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -0
- 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 +64 -1
- 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;
|
|
@@ -1775,10 +1786,10 @@ class BaseMindooTenantDirectory {
|
|
|
1775
1786
|
async getMediaGatewayPolicy() {
|
|
1776
1787
|
const head = await this.getDirectoryStateHead();
|
|
1777
1788
|
const media = head.defaultPolicy?.media;
|
|
1778
|
-
if (!media?.gatewayUrl || !(0,
|
|
1789
|
+
if (!media?.gatewayUrl || !(0, types_4.isValidMediaGatewayUrl)(media.gatewayUrl)) {
|
|
1779
1790
|
return null;
|
|
1780
1791
|
}
|
|
1781
|
-
const mediaUrls = (media.mediaUrls ?? []).filter((entry) => (0,
|
|
1792
|
+
const mediaUrls = (media.mediaUrls ?? []).filter((entry) => (0, types_4.isValidMediaServerUrl)(entry));
|
|
1782
1793
|
return {
|
|
1783
1794
|
gatewayUrl: media.gatewayUrl,
|
|
1784
1795
|
...(mediaUrls.length ? { mediaUrls } : {}),
|
|
@@ -1856,7 +1867,7 @@ class BaseMindooTenantDirectory {
|
|
|
1856
1867
|
* bypass).
|
|
1857
1868
|
*/
|
|
1858
1869
|
async isDatabaseAllowed(dbid, opts) {
|
|
1859
|
-
if (dbid ===
|
|
1870
|
+
if (dbid === types_2.DIRECTORY_DB_ID || dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
1860
1871
|
return true;
|
|
1861
1872
|
const { mode, allowedDbIds } = await this.getDatabaseCreationPolicy();
|
|
1862
1873
|
if (mode === "open")
|
|
@@ -1886,7 +1897,7 @@ class BaseMindooTenantDirectory {
|
|
|
1886
1897
|
}
|
|
1887
1898
|
// The directory database is never read-gated (it must always sync so the
|
|
1888
1899
|
// policy that defines the read gate can be read at all).
|
|
1889
|
-
if (input.dbid ===
|
|
1900
|
+
if (input.dbid === types_2.DIRECTORY_DB_ID || input.dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
1890
1901
|
return true;
|
|
1891
1902
|
// Tenant admins (root and active delegated admins, §6.13) are exempt from the read gate.
|
|
1892
1903
|
if (await this.isAdminKeyNow(input.signingKey))
|
|
@@ -1913,7 +1924,7 @@ class BaseMindooTenantDirectory {
|
|
|
1913
1924
|
* scoped. Evaluated at the directory head, like the read gate.
|
|
1914
1925
|
*/
|
|
1915
1926
|
async evaluateReadScopeForSigningKey(input) {
|
|
1916
|
-
if (input.dbid ===
|
|
1927
|
+
if (input.dbid === types_2.DIRECTORY_DB_ID || input.dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
1917
1928
|
return "all";
|
|
1918
1929
|
if (await this.isAdminKeyNow(input.signingKey))
|
|
1919
1930
|
return "all";
|
|
@@ -1942,6 +1953,13 @@ class BaseMindooTenantDirectory {
|
|
|
1942
1953
|
* the matching deposit rule.
|
|
1943
1954
|
*/
|
|
1944
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
|
+
}
|
|
1945
1963
|
// Built-in personal-database invariant (§6.11): decides first, and a
|
|
1946
1964
|
// configured policy can only take away what it grants.
|
|
1947
1965
|
const personal = await this.evaluatePersonalDatabaseAccess(input);
|
|
@@ -1985,7 +2003,7 @@ class BaseMindooTenantDirectory {
|
|
|
1985
2003
|
const rule = await this.depositRule(decision.matchedRuleId);
|
|
1986
2004
|
return {
|
|
1987
2005
|
mode: "deposit",
|
|
1988
|
-
maxRecipients: rule?.maxRecipients ??
|
|
2006
|
+
maxRecipients: rule?.maxRecipients ?? types_3.DEFAULT_DEPOSIT_MAX_RECIPIENTS,
|
|
1989
2007
|
...(rule?.docIdPrefixes?.length ? { docIdPrefixes: rule.docIdPrefixes } : {}),
|
|
1990
2008
|
};
|
|
1991
2009
|
}
|
|
@@ -2087,8 +2105,8 @@ class BaseMindooTenantDirectory {
|
|
|
2087
2105
|
maxRecipients: 1,
|
|
2088
2106
|
docIdPrefixes: [...(builtinDbInvariants_1.BUILTIN_PERSONAL_DEPOSIT_DOC_ID_PREFIXES.mmail_ ?? [])],
|
|
2089
2107
|
internalMail: {
|
|
2090
|
-
maxBytesPerMail: limits.maxBytesPerMail ??
|
|
2091
|
-
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,
|
|
2092
2110
|
},
|
|
2093
2111
|
reason: `internal mail (${mode})`,
|
|
2094
2112
|
};
|
|
@@ -2155,7 +2173,7 @@ class BaseMindooTenantDirectory {
|
|
|
2155
2173
|
if (!builtinDbInvariants_1.PERSONAL_DATABASE_PREFIX_REGEX.test(prefix)) {
|
|
2156
2174
|
throw new Error(`depositDocIdPrefixes: "${prefix}" is not a personal-database prefix like "mmail_"`);
|
|
2157
2175
|
}
|
|
2158
|
-
(0,
|
|
2176
|
+
(0, types_3.validateDocIdPrefixes)(ids, `depositDocIdPrefixes.${prefix}`);
|
|
2159
2177
|
}
|
|
2160
2178
|
const grants = (await this.findGrantAccessDocuments(username)).filter((doc) => !doc.isDeleted());
|
|
2161
2179
|
if (grants.length === 0)
|
|
@@ -2185,7 +2203,7 @@ class BaseMindooTenantDirectory {
|
|
|
2185
2203
|
* read gate; callers check {@link canReadDatabase} first.
|
|
2186
2204
|
*/
|
|
2187
2205
|
async canDepositDatabase(dbid) {
|
|
2188
|
-
if (dbid ===
|
|
2206
|
+
if (dbid === types_2.DIRECTORY_DB_ID || dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
2189
2207
|
return false;
|
|
2190
2208
|
const currentUser = await this.tenant.getCurrentUserId();
|
|
2191
2209
|
const access = await this.evaluateDbAccessModeForSigningKey({ dbid, signingKey: currentUser.userSigningPublicKey });
|
|
@@ -2207,7 +2225,7 @@ class BaseMindooTenantDirectory {
|
|
|
2207
2225
|
* ({@link isDatabaseAllowed}); callers enforce both gates.
|
|
2208
2226
|
*/
|
|
2209
2227
|
async canReadDatabase(dbid) {
|
|
2210
|
-
if (dbid ===
|
|
2228
|
+
if (dbid === types_2.DIRECTORY_DB_ID || dbid === types_2.USER_DIRECTORY_DB_ID)
|
|
2211
2229
|
return true;
|
|
2212
2230
|
const currentUser = await this.tenant.getCurrentUserId();
|
|
2213
2231
|
if (await this.isAdminKeyNow(currentUser.userSigningPublicKey))
|
|
@@ -2231,8 +2249,8 @@ class BaseMindooTenantDirectory {
|
|
|
2231
2249
|
* written; omit a field to leave it unset (interpreted as its default).
|
|
2232
2250
|
*/
|
|
2233
2251
|
async setDefaultAccessPolicy(policy, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
2234
|
-
(0,
|
|
2235
|
-
await this.writePolicyDoc(
|
|
2252
|
+
(0, types_4.validateAccessPolicy)(policy);
|
|
2253
|
+
await this.writePolicyDoc(types_4.ACL_DEFAULT_POLICY_DOC_ID, policy, administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2236
2254
|
}
|
|
2237
2255
|
async requireV2EntrySignatures(administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
2238
2256
|
const head = await this.getDirectoryStateHead();
|
|
@@ -2254,7 +2272,7 @@ class BaseMindooTenantDirectory {
|
|
|
2254
2272
|
* override the tenant default for `dbid`; unset fields inherit it.
|
|
2255
2273
|
*/
|
|
2256
2274
|
async setDatabaseAccessPolicy(dbid, policy, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
2257
|
-
(0,
|
|
2275
|
+
(0, types_4.validateAccessPolicy)(policy);
|
|
2258
2276
|
if (policy.personalDatabasePrefixes !== undefined) {
|
|
2259
2277
|
throw new Error("personalDatabasePrefixes is a tenant-level setting; set it on the default policy");
|
|
2260
2278
|
}
|
|
@@ -2264,7 +2282,7 @@ class BaseMindooTenantDirectory {
|
|
|
2264
2282
|
if (policy.media !== undefined) {
|
|
2265
2283
|
throw new Error("media is a tenant-level setting; set it on the default policy");
|
|
2266
2284
|
}
|
|
2267
|
-
await this.writePolicyDoc((0,
|
|
2285
|
+
await this.writePolicyDoc((0, types_4.aclDbPolicyDocId)(dbid), policy, administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2268
2286
|
}
|
|
2269
2287
|
/** Shared writer for default / per-db policy documents. */
|
|
2270
2288
|
async writePolicyDoc(docId, policy, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
@@ -2274,7 +2292,7 @@ class BaseMindooTenantDirectory {
|
|
|
2274
2292
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
2275
2293
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
2276
2294
|
const data = d.getData();
|
|
2277
|
-
data.form =
|
|
2295
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
2278
2296
|
data.type = "defaultpolicy";
|
|
2279
2297
|
for (const [key, value] of Object.entries(policy)) {
|
|
2280
2298
|
if (value !== undefined)
|
|
@@ -2297,7 +2315,7 @@ class BaseMindooTenantDirectory {
|
|
|
2297
2315
|
// membership entries so they intersect the acting user's identity set.
|
|
2298
2316
|
const resolvedHashes = await this.resolveRuleTargetHashes(rule);
|
|
2299
2317
|
const ruleDoc = {
|
|
2300
|
-
form:
|
|
2318
|
+
form: types_4.ACCESS_CONTROL_FORM,
|
|
2301
2319
|
type: rule.type,
|
|
2302
2320
|
ruleId: rule.ruleId,
|
|
2303
2321
|
description: rule.description,
|
|
@@ -2313,14 +2331,14 @@ class BaseMindooTenantDirectory {
|
|
|
2313
2331
|
...(rule.docIdPrefixes !== undefined ? { docIdPrefixes: [...new Set(rule.docIdPrefixes)] } : {}),
|
|
2314
2332
|
};
|
|
2315
2333
|
// Fail fast on malformed clauses / operators (§6.3 closed set).
|
|
2316
|
-
(0,
|
|
2334
|
+
(0, types_4.validateAclRule)(ruleDoc);
|
|
2317
2335
|
const baseTenant = this.tenant;
|
|
2318
2336
|
const directoryDB = await this.getDirectoryDB();
|
|
2319
2337
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2320
|
-
const doc = await this.getOrCreateAclDoc(directoryDB, (0,
|
|
2338
|
+
const doc = await this.getOrCreateAclDoc(directoryDB, (0, types_4.aclRuleDocId)(rule.ruleId), adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
2321
2339
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
2322
2340
|
const data = d.getData();
|
|
2323
|
-
data.form =
|
|
2341
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
2324
2342
|
data.type = ruleDoc.type;
|
|
2325
2343
|
data.ruleId = ruleDoc.ruleId;
|
|
2326
2344
|
data.dbid = ruleDoc.dbid;
|
|
@@ -2370,7 +2388,7 @@ class BaseMindooTenantDirectory {
|
|
|
2370
2388
|
const directoryDB = await this.getDirectoryDB();
|
|
2371
2389
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
2372
2390
|
try {
|
|
2373
|
-
await directoryDB.deleteDocument((0,
|
|
2391
|
+
await directoryDB.deleteDocument((0, types_4.aclRuleDocId)(ruleId), {
|
|
2374
2392
|
signingKeyPair: adminSigningKeyPair,
|
|
2375
2393
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
2376
2394
|
});
|
|
@@ -2391,10 +2409,10 @@ class BaseMindooTenantDirectory {
|
|
|
2391
2409
|
// Trusted witnesses decide whose receipt times count (§6.13): root only.
|
|
2392
2410
|
await this.rootKeyPair(administrationPrivateKey, administrationPrivateKeyPassword, "add trusted witnesses");
|
|
2393
2411
|
const fingerprint = await this.sha256Hex(witness.witnessPublicKey);
|
|
2394
|
-
const doc = await this.getOrCreateAclDoc(directoryDB, (0,
|
|
2412
|
+
const doc = await this.getOrCreateAclDoc(directoryDB, (0, types_3.aclTrustedWitnessDocId)(fingerprint), adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
2395
2413
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
2396
2414
|
const data = d.getData();
|
|
2397
|
-
data.form =
|
|
2415
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
2398
2416
|
data.type = "trustedwitness";
|
|
2399
2417
|
data.witnessPublicKey = witness.witnessPublicKey;
|
|
2400
2418
|
if (witness.serverUrl !== undefined)
|
|
@@ -2410,7 +2428,7 @@ class BaseMindooTenantDirectory {
|
|
|
2410
2428
|
await this.rootKeyPair(administrationPrivateKey, administrationPrivateKeyPassword, "remove trusted witnesses");
|
|
2411
2429
|
const fingerprint = await this.sha256Hex(witnessPublicKey);
|
|
2412
2430
|
try {
|
|
2413
|
-
await directoryDB.deleteDocument((0,
|
|
2431
|
+
await directoryDB.deleteDocument((0, types_3.aclTrustedWitnessDocId)(fingerprint), {
|
|
2414
2432
|
signingKeyPair: adminSigningKeyPair,
|
|
2415
2433
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
2416
2434
|
});
|
|
@@ -2639,7 +2657,7 @@ class BaseMindooTenantDirectory {
|
|
|
2639
2657
|
await this.editGrantArrays(username, administrationPrivateKey, administrationPrivateKeyPassword, (data) => {
|
|
2640
2658
|
if (userDetailsEncrypted !== null) {
|
|
2641
2659
|
data.user_details_encrypted = userDetailsEncrypted;
|
|
2642
|
-
data.user_details_encrypted_key =
|
|
2660
|
+
data.user_details_encrypted_key = types_2.DEFAULT_TENANT_KEY_ID;
|
|
2643
2661
|
}
|
|
2644
2662
|
// Recompute the $publicinfos-readable identity-hash bundle (§6.5).
|
|
2645
2663
|
data.identity_hashes = identityHashes;
|
|
@@ -2895,6 +2913,31 @@ class BaseMindooTenantDirectory {
|
|
|
2895
2913
|
devices: { [fingerprint]: wrappedByVersion },
|
|
2896
2914
|
};
|
|
2897
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
|
+
}
|
|
2898
2941
|
/**
|
|
2899
2942
|
* The canonical write-time hash for `username` (the value stored in
|
|
2900
2943
|
* `pushto_users_hashes` / `pullfrom_users_hashes`). Exposed so callers (the
|
|
@@ -2923,7 +2966,7 @@ class BaseMindooTenantDirectory {
|
|
|
2923
2966
|
/** Encrypt a UTF-8 string with the tenant default key, base64-encoded. */
|
|
2924
2967
|
async encryptToDefaultField(plaintext) {
|
|
2925
2968
|
const payload = new TextEncoder().encode(plaintext);
|
|
2926
|
-
const encrypted = await this.tenant.encryptPayload(payload,
|
|
2969
|
+
const encrypted = await this.tenant.encryptPayload(payload, types_2.DEFAULT_TENANT_KEY_ID);
|
|
2927
2970
|
return this.uint8ArrayToBase64(encrypted);
|
|
2928
2971
|
}
|
|
2929
2972
|
/**
|
|
@@ -2944,7 +2987,7 @@ class BaseMindooTenantDirectory {
|
|
|
2944
2987
|
}
|
|
2945
2988
|
const pushtoHashes = request.pushto.map((p) => p.username_hash);
|
|
2946
2989
|
const pullfromHashes = request.pullfrom.map((p) => p.username_hash);
|
|
2947
|
-
(0,
|
|
2990
|
+
(0, types_4.validateKeyDistribution)({
|
|
2948
2991
|
keyId,
|
|
2949
2992
|
keyVersions: request.keyVersions,
|
|
2950
2993
|
pushto_users_hashes: pushtoHashes,
|
|
@@ -2995,15 +3038,15 @@ class BaseMindooTenantDirectory {
|
|
|
2995
3038
|
: undefined;
|
|
2996
3039
|
const pushtoUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pushto.map((p) => p.username)));
|
|
2997
3040
|
const pullfromUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfrom.map((p) => p.username)));
|
|
2998
|
-
const docId = (0,
|
|
3041
|
+
const docId = (0, types_4.aclKeyDistributionDocId)(keyId);
|
|
2999
3042
|
const baseTenant = this.tenant;
|
|
3000
3043
|
const directoryDB = await this.getDirectoryDB();
|
|
3001
3044
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3002
3045
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
3003
3046
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
3004
3047
|
const data = d.getData();
|
|
3005
|
-
data.form =
|
|
3006
|
-
data.type =
|
|
3048
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
3049
|
+
data.type = types_4.KEY_DISTRIBUTION_TYPE;
|
|
3007
3050
|
data.keyId = keyId;
|
|
3008
3051
|
data.keyVersions = request.keyVersions.map((v) => ({
|
|
3009
3052
|
createdAt: v.createdAt,
|
|
@@ -3055,7 +3098,7 @@ class BaseMindooTenantDirectory {
|
|
|
3055
3098
|
}
|
|
3056
3099
|
/** Parse a raw distribution doc's data into a {@link KeyDistributionView}. */
|
|
3057
3100
|
async toKeyDistributionView(data) {
|
|
3058
|
-
if (data.type !==
|
|
3101
|
+
if (data.type !== types_4.KEY_DISTRIBUTION_TYPE || typeof data.keyId !== "string")
|
|
3059
3102
|
return null;
|
|
3060
3103
|
const keyVersions = Array.isArray(data.keyVersions)
|
|
3061
3104
|
? data.keyVersions
|
|
@@ -3093,7 +3136,7 @@ class BaseMindooTenantDirectory {
|
|
|
3093
3136
|
await directoryDB.syncStoreChanges();
|
|
3094
3137
|
await this.updateUnifiedCache();
|
|
3095
3138
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
3096
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
3139
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_KEY_DISTRIBUTION_PREFIX));
|
|
3097
3140
|
const views = [];
|
|
3098
3141
|
for (const id of ids) {
|
|
3099
3142
|
let doc;
|
|
@@ -3117,7 +3160,7 @@ class BaseMindooTenantDirectory {
|
|
|
3117
3160
|
const directoryDB = await this.getDirectoryDB();
|
|
3118
3161
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3119
3162
|
try {
|
|
3120
|
-
await directoryDB.deleteDocument((0,
|
|
3163
|
+
await directoryDB.deleteDocument((0, types_4.aclKeyDistributionDocId)(keyId), {
|
|
3121
3164
|
signingKeyPair: adminSigningKeyPair,
|
|
3122
3165
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3123
3166
|
});
|
|
@@ -3201,7 +3244,7 @@ class BaseMindooTenantDirectory {
|
|
|
3201
3244
|
this.logger.warn("reconcileKeyDistributionsWithKey: directory has no key-distribution documents in cache");
|
|
3202
3245
|
return { imported: [], removed: [] };
|
|
3203
3246
|
}
|
|
3204
|
-
if (!this.keyDistributionCache.has(
|
|
3247
|
+
if (!this.keyDistributionCache.has(types_2.DEFAULT_TENANT_KEY_ID)) {
|
|
3205
3248
|
this.logger.warn("reconcileKeyDistributionsWithKey: no acl_keydistribution_default in directory cache");
|
|
3206
3249
|
}
|
|
3207
3250
|
const myHashes = new Set(await this.usernameHashCandidates(username));
|
|
@@ -3227,7 +3270,7 @@ class BaseMindooTenantDirectory {
|
|
|
3227
3270
|
// keyId -> why this candidate key could not open any of its wraps.
|
|
3228
3271
|
const unopened = new Map();
|
|
3229
3272
|
for (const [keyId, entry] of this.keyDistributionCache.entries()) {
|
|
3230
|
-
if (
|
|
3273
|
+
if (types_4.PROTECTED_DISTRIBUTION_KEY_IDS.includes(keyId))
|
|
3231
3274
|
continue;
|
|
3232
3275
|
const manifest = entry.keyVersions;
|
|
3233
3276
|
const meInPull = entry.pullfrom_users_hashes.some((h) => myHashes.has(h));
|
|
@@ -3242,8 +3285,10 @@ class BaseMindooTenantDirectory {
|
|
|
3242
3285
|
continue;
|
|
3243
3286
|
}
|
|
3244
3287
|
if (!meInPush) {
|
|
3245
|
-
if (keyId ===
|
|
3246
|
-
|
|
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 ` +
|
|
3247
3292
|
`(hashes=${entry.pushto_users_hashes.length})`);
|
|
3248
3293
|
}
|
|
3249
3294
|
continue;
|
|
@@ -3344,7 +3389,7 @@ class BaseMindooTenantDirectory {
|
|
|
3344
3389
|
const pullfromUserHashes = await Promise.all(request.pullfromUsernames.map((u) => this.hashUsernameForWrite(u)));
|
|
3345
3390
|
const pushtoGroupHashes = await Promise.all(request.pushtoGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3346
3391
|
const pullfromGroupHashes = await Promise.all(request.pullfromGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3347
|
-
(0,
|
|
3392
|
+
(0, types_4.validateAppDistribution)({
|
|
3348
3393
|
appId,
|
|
3349
3394
|
pushto_users_hashes: pushtoUserHashes,
|
|
3350
3395
|
pullfrom_users_hashes: pullfromUserHashes,
|
|
@@ -3369,15 +3414,15 @@ class BaseMindooTenantDirectory {
|
|
|
3369
3414
|
const pushtoGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pushtoGroups));
|
|
3370
3415
|
const pullfromUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromUsernames));
|
|
3371
3416
|
const pullfromGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromGroups));
|
|
3372
|
-
const docId = (0,
|
|
3417
|
+
const docId = (0, types_4.aclAppDistributionDocId)(appId);
|
|
3373
3418
|
const baseTenant = this.tenant;
|
|
3374
3419
|
const directoryDB = await this.getDirectoryDB();
|
|
3375
3420
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3376
3421
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
3377
3422
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
3378
3423
|
const data = d.getData();
|
|
3379
|
-
data.form =
|
|
3380
|
-
data.type =
|
|
3424
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
3425
|
+
data.type = types_4.APP_DISTRIBUTION_TYPE;
|
|
3381
3426
|
data.appId = appId;
|
|
3382
3427
|
data.appid_encrypted = appidEncrypted;
|
|
3383
3428
|
data.appid_encrypted_key = "default";
|
|
@@ -3416,7 +3461,7 @@ class BaseMindooTenantDirectory {
|
|
|
3416
3461
|
}
|
|
3417
3462
|
/** Parse a raw app-distribution doc's data into an {@link AppDistributionView}. */
|
|
3418
3463
|
async toAppDistributionView(data) {
|
|
3419
|
-
if (data.type !==
|
|
3464
|
+
if (data.type !== types_4.APP_DISTRIBUTION_TYPE || typeof data.appId !== "string")
|
|
3420
3465
|
return null;
|
|
3421
3466
|
const stringArray = (value) => Array.isArray(value) ? value.filter((h) => typeof h === "string") : [];
|
|
3422
3467
|
const title = await (0, encryptedFields_1.decryptEncryptedField)(this.tenant, data, "title_encrypted");
|
|
@@ -3459,7 +3504,7 @@ class BaseMindooTenantDirectory {
|
|
|
3459
3504
|
await directoryDB.syncStoreChanges();
|
|
3460
3505
|
await this.updateUnifiedCache();
|
|
3461
3506
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
3462
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
3507
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_APP_DISTRIBUTION_PREFIX));
|
|
3463
3508
|
const views = [];
|
|
3464
3509
|
for (const id of ids) {
|
|
3465
3510
|
let doc;
|
|
@@ -3483,7 +3528,7 @@ class BaseMindooTenantDirectory {
|
|
|
3483
3528
|
const directoryDB = await this.getDirectoryDB();
|
|
3484
3529
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3485
3530
|
try {
|
|
3486
|
-
await directoryDB.deleteDocument((0,
|
|
3531
|
+
await directoryDB.deleteDocument((0, types_4.aclAppDistributionDocId)(appId), {
|
|
3487
3532
|
signingKeyPair: adminSigningKeyPair,
|
|
3488
3533
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3489
3534
|
});
|
|
@@ -3576,7 +3621,7 @@ class BaseMindooTenantDirectory {
|
|
|
3576
3621
|
const pullfromUserHashes = await Promise.all(request.pullfromUsernames.map((u) => this.hashUsernameForWrite(u)));
|
|
3577
3622
|
const pushtoGroupHashes = await Promise.all(request.pushtoGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3578
3623
|
const pullfromGroupHashes = await Promise.all(request.pullfromGroups.map((g) => this.hashUsernameForWrite(this.normalizeGroupName(g))));
|
|
3579
|
-
(0,
|
|
3624
|
+
(0, types_4.validateSyncSetupPolicy)({
|
|
3580
3625
|
policyId,
|
|
3581
3626
|
mode,
|
|
3582
3627
|
databaseIds,
|
|
@@ -3602,15 +3647,15 @@ class BaseMindooTenantDirectory {
|
|
|
3602
3647
|
const pushtoGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pushtoGroups));
|
|
3603
3648
|
const pullfromUsernamesEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromUsernames));
|
|
3604
3649
|
const pullfromGroupsEncrypted = await this.encryptToDefaultField(JSON.stringify(request.pullfromGroups));
|
|
3605
|
-
const docId = (0,
|
|
3650
|
+
const docId = (0, types_4.aclSyncSetupPolicyDocId)(policyId);
|
|
3606
3651
|
const baseTenant = this.tenant;
|
|
3607
3652
|
const directoryDB = await this.getDirectoryDB();
|
|
3608
3653
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3609
3654
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
3610
3655
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
3611
3656
|
const data = d.getData();
|
|
3612
|
-
data.form =
|
|
3613
|
-
data.type =
|
|
3657
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
3658
|
+
data.type = types_4.SYNC_SETUP_POLICY_TYPE;
|
|
3614
3659
|
data.policyId = policyId;
|
|
3615
3660
|
data.policyid_encrypted = policyidEncrypted;
|
|
3616
3661
|
data.policyid_encrypted_key = "default";
|
|
@@ -3648,7 +3693,7 @@ class BaseMindooTenantDirectory {
|
|
|
3648
3693
|
}
|
|
3649
3694
|
/** Parse a raw sync-setup-policy doc's data into a {@link SyncSetupPolicyView}. */
|
|
3650
3695
|
async toSyncSetupPolicyView(data) {
|
|
3651
|
-
if (data.type !==
|
|
3696
|
+
if (data.type !== types_4.SYNC_SETUP_POLICY_TYPE || typeof data.policyId !== "string")
|
|
3652
3697
|
return null;
|
|
3653
3698
|
const stringArray = (value) => Array.isArray(value) ? value.filter((h) => typeof h === "string") : [];
|
|
3654
3699
|
const title = await (0, encryptedFields_1.decryptEncryptedField)(this.tenant, data, "title_encrypted");
|
|
@@ -3693,7 +3738,7 @@ class BaseMindooTenantDirectory {
|
|
|
3693
3738
|
await directoryDB.syncStoreChanges();
|
|
3694
3739
|
await this.updateUnifiedCache();
|
|
3695
3740
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
3696
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
3741
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_SYNC_SETUP_POLICY_PREFIX));
|
|
3697
3742
|
const views = [];
|
|
3698
3743
|
for (const id of ids) {
|
|
3699
3744
|
let doc;
|
|
@@ -3717,7 +3762,7 @@ class BaseMindooTenantDirectory {
|
|
|
3717
3762
|
const directoryDB = await this.getDirectoryDB();
|
|
3718
3763
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
3719
3764
|
try {
|
|
3720
|
-
await directoryDB.deleteDocument((0,
|
|
3765
|
+
await directoryDB.deleteDocument((0, types_4.aclSyncSetupPolicyDocId)(policyId), {
|
|
3721
3766
|
signingKeyPair: adminSigningKeyPair,
|
|
3722
3767
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3723
3768
|
});
|
|
@@ -3835,7 +3880,7 @@ class BaseMindooTenantDirectory {
|
|
|
3835
3880
|
collectRevokedKeyIdsForHashes(myHashes) {
|
|
3836
3881
|
const revoked = [];
|
|
3837
3882
|
for (const [keyId, entry] of this.keyDistributionCache.entries()) {
|
|
3838
|
-
if (
|
|
3883
|
+
if (types_4.PROTECTED_DISTRIBUTION_KEY_IDS.includes(keyId))
|
|
3839
3884
|
continue;
|
|
3840
3885
|
if (entry.pullfrom_users_hashes.some((h) => myHashes.has(h))) {
|
|
3841
3886
|
revoked.push(keyId);
|
|
@@ -3895,7 +3940,7 @@ class BaseMindooTenantDirectory {
|
|
|
3895
3940
|
id: docId,
|
|
3896
3941
|
signingKeyPair: adminSigningKeyPair,
|
|
3897
3942
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
3898
|
-
decryptionKeyId:
|
|
3943
|
+
decryptionKeyId: types_2.PUBLIC_INFOS_KEY_ID,
|
|
3899
3944
|
});
|
|
3900
3945
|
}
|
|
3901
3946
|
/**
|
|
@@ -3952,11 +3997,11 @@ class BaseMindooTenantDirectory {
|
|
|
3952
3997
|
*/
|
|
3953
3998
|
minimalIdentitySet(opts) {
|
|
3954
3999
|
const hashes = new Set();
|
|
3955
|
-
hashes.add(
|
|
4000
|
+
hashes.add(types_4.PSEUDO_TOKEN_EVERYONE);
|
|
3956
4001
|
if (opts.isAdmin)
|
|
3957
|
-
hashes.add(
|
|
4002
|
+
hashes.add(types_4.PSEUDO_TOKEN_ADMIN);
|
|
3958
4003
|
if (opts.isAuthor)
|
|
3959
|
-
hashes.add(
|
|
4004
|
+
hashes.add(types_4.PSEUDO_TOKEN_AUTHOR);
|
|
3960
4005
|
return { username: "", usernames: [], groups: [], hashes };
|
|
3961
4006
|
}
|
|
3962
4007
|
/**
|
|
@@ -3979,11 +4024,11 @@ class BaseMindooTenantDirectory {
|
|
|
3979
4024
|
hashes.add(h);
|
|
3980
4025
|
}
|
|
3981
4026
|
}
|
|
3982
|
-
hashes.add(
|
|
4027
|
+
hashes.add(types_4.PSEUDO_TOKEN_EVERYONE);
|
|
3983
4028
|
if (opts.isAdmin)
|
|
3984
|
-
hashes.add(
|
|
4029
|
+
hashes.add(types_4.PSEUDO_TOKEN_ADMIN);
|
|
3985
4030
|
if (opts.isAuthor)
|
|
3986
|
-
hashes.add(
|
|
4031
|
+
hashes.add(types_4.PSEUDO_TOKEN_AUTHOR);
|
|
3987
4032
|
return { username: "", usernames: [], groups, hashes };
|
|
3988
4033
|
}
|
|
3989
4034
|
/**
|
|
@@ -4270,7 +4315,7 @@ class BaseMindooTenantDirectory {
|
|
|
4270
4315
|
* own stores; only `reason` is encrypted with the tenant `default` key.
|
|
4271
4316
|
*/
|
|
4272
4317
|
async publishDocHistoryPurge(request, administrationPrivateKey, administrationPrivateKeyPassword) {
|
|
4273
|
-
(0,
|
|
4318
|
+
(0, types_4.validateDocHistoryPurge)({
|
|
4274
4319
|
requestId: request.requestId,
|
|
4275
4320
|
dbId: request.dbId,
|
|
4276
4321
|
docIds: request.docIds,
|
|
@@ -4279,7 +4324,7 @@ class BaseMindooTenantDirectory {
|
|
|
4279
4324
|
const reasonEncrypted = request.reason
|
|
4280
4325
|
? await this.encryptToDefaultField(request.reason)
|
|
4281
4326
|
: undefined;
|
|
4282
|
-
const docId = (0,
|
|
4327
|
+
const docId = (0, types_4.aclDocHistoryPurgeDocId)(request.requestId);
|
|
4283
4328
|
const requestedAt = (0, timeSource_1.semanticNow)();
|
|
4284
4329
|
const baseTenant = this.tenant;
|
|
4285
4330
|
const directoryDB = await this.getDirectoryDB();
|
|
@@ -4287,8 +4332,8 @@ class BaseMindooTenantDirectory {
|
|
|
4287
4332
|
const doc = await this.getOrCreateAclDoc(directoryDB, docId, adminSigningKeyPair, administrationPrivateKeyPassword);
|
|
4288
4333
|
await directoryDB.changeDoc(doc, async (d) => {
|
|
4289
4334
|
const data = d.getData();
|
|
4290
|
-
data.form =
|
|
4291
|
-
data.type =
|
|
4335
|
+
data.form = types_4.ACCESS_CONTROL_FORM;
|
|
4336
|
+
data.type = types_4.DOC_HISTORY_PURGE_TYPE;
|
|
4292
4337
|
data.requestId = request.requestId;
|
|
4293
4338
|
data.dbId = request.dbId;
|
|
4294
4339
|
data.docIds = [...request.docIds];
|
|
@@ -4310,7 +4355,7 @@ class BaseMindooTenantDirectory {
|
|
|
4310
4355
|
}
|
|
4311
4356
|
/** Parse a raw purge-request doc's data into a {@link DocHistoryPurgeView}. */
|
|
4312
4357
|
async toDocHistoryPurgeView(data, purgeRequestDocId) {
|
|
4313
|
-
if (data.type !==
|
|
4358
|
+
if (data.type !== types_4.DOC_HISTORY_PURGE_TYPE)
|
|
4314
4359
|
return null;
|
|
4315
4360
|
const dbId = data.dbId;
|
|
4316
4361
|
if (typeof dbId !== "string")
|
|
@@ -4340,7 +4385,7 @@ class BaseMindooTenantDirectory {
|
|
|
4340
4385
|
const directoryDB = await this.getDirectoryDB();
|
|
4341
4386
|
await directoryDB.syncStoreChanges();
|
|
4342
4387
|
const allIds = await directoryDB.getAllDocumentIds();
|
|
4343
|
-
const ids = allIds.filter((id) => id.startsWith(
|
|
4388
|
+
const ids = allIds.filter((id) => id.startsWith(types_4.ACL_DOC_HISTORY_PURGE_PREFIX));
|
|
4344
4389
|
const views = [];
|
|
4345
4390
|
for (const id of ids) {
|
|
4346
4391
|
let doc;
|
|
@@ -4364,7 +4409,7 @@ class BaseMindooTenantDirectory {
|
|
|
4364
4409
|
const directoryDB = await this.getDirectoryDB();
|
|
4365
4410
|
const adminSigningKeyPair = await this.adminKeyPair(administrationPrivateKey, administrationPrivateKeyPassword);
|
|
4366
4411
|
try {
|
|
4367
|
-
await directoryDB.deleteDocument((0,
|
|
4412
|
+
await directoryDB.deleteDocument((0, types_4.aclDocHistoryPurgeDocId)(requestId), {
|
|
4368
4413
|
signingKeyPair: adminSigningKeyPair,
|
|
4369
4414
|
signingKeyPassword: administrationPrivateKeyPassword,
|
|
4370
4415
|
});
|
|
@@ -4402,7 +4447,7 @@ class BaseMindooTenantDirectory {
|
|
|
4402
4447
|
const directoryDB = await this.getDirectoryDB();
|
|
4403
4448
|
await directoryDB.syncStoreChanges();
|
|
4404
4449
|
await this.updateUnifiedCache();
|
|
4405
|
-
const known = new Set([
|
|
4450
|
+
const known = new Set([types_2.DIRECTORY_DB_ID, types_2.USER_DIRECTORY_DB_ID]);
|
|
4406
4451
|
for (const dbId of this.dbSettingsCache.keys()) {
|
|
4407
4452
|
known.add(dbId);
|
|
4408
4453
|
}
|
|
@@ -4509,7 +4554,7 @@ class BaseMindooTenantDirectory {
|
|
|
4509
4554
|
}
|
|
4510
4555
|
else {
|
|
4511
4556
|
// Create new document with PUBLIC_INFOS_KEY_ID for server access
|
|
4512
|
-
groupDoc = await directoryDB.createDocumentWithSigningKey(adminSigningKeyPair, administrationPrivateKeyPassword,
|
|
4557
|
+
groupDoc = await directoryDB.createDocumentWithSigningKey(adminSigningKeyPair, administrationPrivateKeyPassword, types_2.PUBLIC_INFOS_KEY_ID);
|
|
4513
4558
|
}
|
|
4514
4559
|
// Apply changes and ensure form, type, and groupName fields are correct
|
|
4515
4560
|
await directoryDB.changeDoc(groupDoc, async (d) => {
|
|
@@ -4737,7 +4782,7 @@ class BaseMindooTenantDirectory {
|
|
|
4737
4782
|
async encryptUserDetailsForTenant(userDetails) {
|
|
4738
4783
|
const encoder = new TextEncoder();
|
|
4739
4784
|
const payload = encoder.encode(JSON.stringify(userDetails));
|
|
4740
|
-
const encrypted = await this.tenant.encryptPayload(payload,
|
|
4785
|
+
const encrypted = await this.tenant.encryptPayload(payload, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4741
4786
|
return this.uint8ArrayToBase64(encrypted);
|
|
4742
4787
|
}
|
|
4743
4788
|
/**
|
|
@@ -4809,7 +4854,7 @@ class BaseMindooTenantDirectory {
|
|
|
4809
4854
|
}
|
|
4810
4855
|
async encryptGroupMemberForTenant(plaintext) {
|
|
4811
4856
|
const encoder = new TextEncoder();
|
|
4812
|
-
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);
|
|
4813
4858
|
return this.uint8ArrayToBase64(encrypted);
|
|
4814
4859
|
}
|
|
4815
4860
|
/**
|
|
@@ -4846,7 +4891,7 @@ class BaseMindooTenantDirectory {
|
|
|
4846
4891
|
return "";
|
|
4847
4892
|
}
|
|
4848
4893
|
const payload = new TextEncoder().encode(JSON.stringify({ usernames, groups }));
|
|
4849
|
-
const encrypted = await this.tenant.encryptPayload(payload,
|
|
4894
|
+
const encrypted = await this.tenant.encryptPayload(payload, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4850
4895
|
return this.uint8ArrayToBase64(encrypted);
|
|
4851
4896
|
}
|
|
4852
4897
|
/**
|
|
@@ -4859,7 +4904,7 @@ class BaseMindooTenantDirectory {
|
|
|
4859
4904
|
return null;
|
|
4860
4905
|
try {
|
|
4861
4906
|
const encrypted = this.base64ToUint8Array(encryptedBase64);
|
|
4862
|
-
const decrypted = await this.tenant.decryptPayload(encrypted,
|
|
4907
|
+
const decrypted = await this.tenant.decryptPayload(encrypted, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4863
4908
|
const parsed = JSON.parse(new TextDecoder().decode(decrypted));
|
|
4864
4909
|
const usernames = Array.isArray(parsed.usernames)
|
|
4865
4910
|
? parsed.usernames.filter((u) => typeof u === "string")
|
|
@@ -4877,7 +4922,7 @@ class BaseMindooTenantDirectory {
|
|
|
4877
4922
|
async decryptGroupMemberForTenant(encryptedBase64) {
|
|
4878
4923
|
try {
|
|
4879
4924
|
const encrypted = this.base64ToUint8Array(encryptedBase64);
|
|
4880
|
-
const decrypted = await this.tenant.decryptPayload(encrypted,
|
|
4925
|
+
const decrypted = await this.tenant.decryptPayload(encrypted, types_2.DEFAULT_TENANT_KEY_ID);
|
|
4881
4926
|
const member = new TextDecoder().decode(decrypted).trim();
|
|
4882
4927
|
return member || null;
|
|
4883
4928
|
}
|