@rapidmx/web-client 0.34.0 → 0.36.0
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/apps/escrow/matters/[uid].tsx +4 -3
- package/apps/shared/calendar/calendarLiveUpdates.ts +2 -5
- package/apps/shared/calendar/sealedEvents.ts +80 -0
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +61 -3
- package/apps/shared/components/contacts/ContactsSidebar.tsx +5 -1
- package/apps/shared/components/contacts/contactCardData.ts +8 -4
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +23 -1
- package/apps/shared/components/layout/SharedMailboxKeyManager.tsx +91 -0
- package/apps/shared/components/layout/UnlockPromptProvider.tsx +34 -0
- package/apps/shared/components/mail/ConversationList.tsx +1 -1
- package/apps/shared/components/mail/MessageDetailPane.tsx +91 -20
- package/apps/shared/components/mail/compose/draftResume.ts +28 -3
- package/apps/shared/components/mail/compose/quotedBody.ts +31 -15
- package/apps/shared/components/mail/invite/inviteStore.ts +7 -1
- package/apps/shared/components/mail/layout/MailShell.tsx +2 -0
- package/apps/shared/components/mail/reading/MessageBody.tsx +4 -1
- package/apps/shared/components/mail/reading/bodyContent.ts +27 -17
- package/apps/shared/components/mail/reading/conversationPrint.ts +7 -5
- package/apps/shared/components/mail/reading/useMessageActions.ts +4 -1
- package/apps/shared/components/settings/KeyExportSetting.tsx +170 -0
- package/apps/shared/components/settings/PolicyLockedNotice.tsx +23 -0
- package/apps/shared/components/settings/ZeroAccessSetting.tsx +117 -0
- package/apps/shared/live/useFolderLiveUpdates.ts +59 -0
- package/apps/shared/mail/decryptedMessages.ts +11 -3
- package/apps/shared/mail/outbox/sendJob.ts +2 -2
- package/apps/shared/mail/outbox/sendOutcomes.ts +1 -3
- package/apps/shared/mail/reportNotices.ts +3 -1
- package/apps/shared/mail/zeroAccessSource.ts +27 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +31 -0
- package/apps/shared/search/localIndexBuilder.ts +27 -1
- package/apps/shared/search/localIndexRpcClient.ts +8 -4
- package/apps/shared/search/localIndexSchema.ts +2 -2
- package/apps/shared/search/localIndexTransport.ts +2 -1
- package/apps/shared/search/localIndexWorker.ts +6 -4
- package/apps/shared/search/zeroAccessIndexSync.ts +487 -0
- package/apps/www/calendar/index.tsx +180 -58
- package/apps/www/contacts/index.tsx +58 -2
- package/apps/www/index.tsx +10 -3
- package/apps/www/settings/encryption/index.tsx +5 -0
- package/apps/www/settings/privacy/index.tsx +2 -1
- package/apps/www/tasks/index.tsx +42 -0
- package/dist/apps/escrow/matters/[uid].js +2 -2
- package/dist/apps/shared/calendar/calendarLiveUpdates.js +2 -5
- package/dist/apps/shared/calendar/sealedEvents.d.ts +13 -0
- package/dist/apps/shared/calendar/sealedEvents.js +54 -0
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +18 -2
- package/dist/apps/shared/components/contacts/ContactsSidebar.d.ts +3 -1
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +2 -2
- package/dist/apps/shared/components/contacts/contactCardData.d.ts +2 -2
- package/dist/apps/shared/components/contacts/contactCardData.js +8 -4
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +21 -2
- package/dist/apps/shared/components/layout/SharedMailboxKeyManager.d.ts +15 -0
- package/dist/apps/shared/components/layout/SharedMailboxKeyManager.js +72 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.d.ts +3 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.js +32 -0
- package/dist/apps/shared/components/mail/ConversationList.js +1 -1
- package/dist/apps/shared/components/mail/MessageDetailPane.js +73 -17
- package/dist/apps/shared/components/mail/compose/draftResume.d.ts +2 -0
- package/dist/apps/shared/components/mail/compose/draftResume.js +28 -3
- package/dist/apps/shared/components/mail/compose/quotedBody.d.ts +4 -3
- package/dist/apps/shared/components/mail/compose/quotedBody.js +28 -15
- package/dist/apps/shared/components/mail/invite/inviteStore.js +6 -1
- package/dist/apps/shared/components/mail/layout/MailShell.js +2 -1
- package/dist/apps/shared/components/mail/reading/MessageBody.js +4 -1
- package/dist/apps/shared/components/mail/reading/bodyContent.d.ts +4 -2
- package/dist/apps/shared/components/mail/reading/bodyContent.js +27 -16
- package/dist/apps/shared/components/mail/reading/conversationPrint.d.ts +3 -2
- package/dist/apps/shared/components/mail/reading/conversationPrint.js +7 -5
- package/dist/apps/shared/components/mail/reading/useMessageActions.js +4 -1
- package/dist/apps/shared/components/settings/KeyExportSetting.d.ts +13 -0
- package/dist/apps/shared/components/settings/KeyExportSetting.js +88 -0
- package/dist/apps/shared/components/settings/PolicyLockedNotice.d.ts +11 -0
- package/dist/apps/shared/components/settings/PolicyLockedNotice.js +9 -0
- package/dist/apps/shared/components/settings/ZeroAccessSetting.d.ts +14 -0
- package/dist/apps/shared/components/settings/ZeroAccessSetting.js +71 -0
- package/dist/apps/shared/live/useFolderLiveUpdates.d.ts +19 -0
- package/dist/apps/shared/live/useFolderLiveUpdates.js +41 -0
- package/dist/apps/shared/mail/decryptedMessages.d.ts +1 -1
- package/dist/apps/shared/mail/decryptedMessages.js +11 -3
- package/dist/apps/shared/mail/outbox/sendJob.js +2 -2
- package/dist/apps/shared/mail/outbox/sendOutcomes.js +1 -3
- package/dist/apps/shared/mail/reportNotices.js +3 -1
- package/dist/apps/shared/mail/zeroAccessSource.d.ts +8 -0
- package/dist/apps/shared/mail/zeroAccessSource.js +26 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.d.ts +2 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +28 -0
- package/dist/apps/shared/search/localIndexBuilder.d.ts +5 -0
- package/dist/apps/shared/search/localIndexBuilder.js +24 -2
- package/dist/apps/shared/search/localIndexRpcClient.d.ts +1 -1
- package/dist/apps/shared/search/localIndexRpcClient.js +6 -4
- package/dist/apps/shared/search/localIndexSchema.d.ts +1 -1
- package/dist/apps/shared/search/localIndexSchema.js +2 -2
- package/dist/apps/shared/search/localIndexTransport.d.ts +2 -1
- package/dist/apps/shared/search/localIndexWorker.d.ts +2 -0
- package/dist/apps/shared/search/localIndexWorker.js +4 -4
- package/dist/apps/shared/search/zeroAccessIndexSync.d.ts +71 -0
- package/dist/apps/shared/search/zeroAccessIndexSync.js +382 -0
- package/dist/apps/www/calendar/index.js +48 -22
- package/dist/apps/www/contacts/index.js +49 -3
- package/dist/apps/www/index.js +10 -3
- package/dist/apps/www/settings/encryption/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.js +1 -1
- package/dist/apps/www/tasks/index.js +29 -1
- package/dist/lib/admin/escrowAccessRequestsApi.d.ts +6 -0
- package/dist/lib/calendar/calendarApi.d.ts +6 -0
- package/dist/lib/calendar/inviteApi.js +27 -5
- package/dist/lib/calendar/sealedInvites.d.ts +11 -0
- package/dist/lib/calendar/sealedInvites.js +28 -0
- package/dist/lib/crypto/keyExport.d.ts +54 -0
- package/dist/lib/crypto/keyExport.js +161 -0
- package/dist/lib/crypto/keySession.d.ts +45 -1
- package/dist/lib/crypto/keySession.js +93 -2
- package/dist/lib/crypto/keyvaultApi.d.ts +88 -3
- package/dist/lib/crypto/keyvaultApi.js +32 -0
- package/dist/lib/crypto/messageSecurity.d.ts +30 -1
- package/dist/lib/crypto/messageSecurity.js +80 -4
- package/dist/lib/crypto/mime.d.ts +5 -0
- package/dist/lib/crypto/mime.js +25 -0
- package/dist/lib/crypto/sharedMailboxKeys.d.ts +50 -0
- package/dist/lib/crypto/sharedMailboxKeys.js +264 -0
- package/dist/lib/crypto/zeroAccessKey.d.ts +32 -0
- package/dist/lib/crypto/zeroAccessKey.js +66 -0
- package/dist/lib/mail/conversationsApi.d.ts +6 -0
- package/dist/lib/mail/mailApi.d.ts +30 -2
- package/dist/lib/mail/mailApi.js +5 -1
- package/dist/lib/mail/pushClient.d.ts +10 -3
- package/dist/lib/mail/pushClient.js +18 -4
- package/dist/lib/search/zeroAccessIndexApi.d.ts +81 -0
- package/dist/lib/search/zeroAccessIndexApi.js +35 -0
- package/dist/lib/tasks/tasksApi.d.ts +1 -0
- package/dist/lib/tasks/tasksApi.js +3 -0
- package/lib/admin/escrowAccessRequestsApi.ts +6 -0
- package/lib/calendar/calendarApi.ts +3 -0
- package/lib/calendar/inviteApi.ts +28 -5
- package/lib/calendar/sealedInvites.ts +33 -0
- package/lib/crypto/keyExport.ts +229 -0
- package/lib/crypto/keySession.ts +117 -3
- package/lib/crypto/keyvaultApi.ts +125 -3
- package/lib/crypto/messageSecurity.ts +110 -3
- package/lib/crypto/mime.ts +26 -0
- package/lib/crypto/sharedMailboxKeys.ts +324 -0
- package/lib/crypto/zeroAccessKey.ts +97 -0
- package/lib/mail/conversationsApi.ts +3 -0
- package/lib/mail/mailApi.ts +33 -3
- package/lib/mail/pushClient.ts +18 -4
- package/lib/search/zeroAccessIndexApi.ts +119 -0
- package/lib/tasks/tasksApi.ts +4 -0
- package/package.json +3 -3
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
/**
|
|
6
|
+
* "Export keys for Outlook/phone" (restapi `specs/search.md` §3, *Clients that don't run RapidMX*): a passphrase-protected
|
|
7
|
+
* PKCS#12 file holding the private keys a mail client needs to read this mailbox's mail on its own - every zero-access key
|
|
8
|
+
* (mail at rest is S/MIME `enveloped-data` to these) and every end-to-end encryption key (current and retained), plus, only
|
|
9
|
+
* when asked, the active signing key. Built entirely here from a fresh master-password unlock: the session's own private
|
|
10
|
+
* keys are non-extractable, and the server never sees the file or the passphrase. restapi only records that an export
|
|
11
|
+
* happened (`key_vault.export`), with the fingerprints exported and nothing else.
|
|
12
|
+
*/
|
|
13
|
+
import "reflect-metadata";
|
|
14
|
+
import * as asn1js from "asn1js";
|
|
15
|
+
import * as pkijs from "pkijs";
|
|
16
|
+
import type { ApiClient } from "../util/api.js";
|
|
17
|
+
import { fromBase64 } from "./encoding.js";
|
|
18
|
+
import { type KeyVault, type PublicKey, findActivePublicKey, recordKeyExport, type WrappedPrivateKey } from "./keyvaultApi.js";
|
|
19
|
+
import {
|
|
20
|
+
ENCRYPTION_PRIVATE_KEY_AAD_PURPOSE,
|
|
21
|
+
MAX_RETAINED_ENCRYPTION_KEYS,
|
|
22
|
+
openMasterKeyWithPassword,
|
|
23
|
+
SIGNING_PRIVATE_KEY_AAD_PURPOSE,
|
|
24
|
+
ZERO_ACCESS_PRIVATE_KEY_AAD_PURPOSE,
|
|
25
|
+
} from "./keySession.js";
|
|
26
|
+
import { buildAad, openWithKey } from "./masterKey.js";
|
|
27
|
+
|
|
28
|
+
/** PBKDF2 iterations for the shrouded key bags and the PKCS#12 MAC. Windows, macOS and iOS all accept this. */
|
|
29
|
+
export const KEY_EXPORT_ITERATIONS = 100_000;
|
|
30
|
+
|
|
31
|
+
/** The shortest export passphrase accepted. The file grants read access to all of this mailbox's mail. */
|
|
32
|
+
export const MIN_EXPORT_PASSPHRASE_LENGTH = 12;
|
|
33
|
+
|
|
34
|
+
const PKCS8_SHROUDED_KEY_BAG = "1.2.840.113549.1.12.10.1.2";
|
|
35
|
+
const CERT_BAG = "1.2.840.113549.1.12.10.1.3";
|
|
36
|
+
const X509_CERTIFICATE = "1.2.840.113549.1.9.22.1";
|
|
37
|
+
const FRIENDLY_NAME = "1.2.840.113549.1.9.20";
|
|
38
|
+
const LOCAL_KEY_ID = "1.2.840.113549.1.9.21";
|
|
39
|
+
|
|
40
|
+
/** The shrouded key bags' cipher. pkijs's type wants an `iv`, but it generates a fresh one for every bag and ignores this one. */
|
|
41
|
+
const AES_256_CBC = { name: "AES-CBC", length: 256, iv: new Uint8Array(16) } as pkijs.ContentEncryptionAlgorithm;
|
|
42
|
+
|
|
43
|
+
/** Which key a bag holds, for its friendly name and the export's audit record. */
|
|
44
|
+
export type ExportedKeyKind = "zero-access" | "encrypt" | "sign";
|
|
45
|
+
|
|
46
|
+
/** What `exportKeysAsPkcs12()` takes. */
|
|
47
|
+
export interface KeyExportInput {
|
|
48
|
+
mailboxUid: string;
|
|
49
|
+
/** The mailbox's address, used in each key's friendly name. */
|
|
50
|
+
mailboxAddress: string;
|
|
51
|
+
/** The mailbox's published keys (`Mailbox.keys`): the encryption and signing certificates. */
|
|
52
|
+
mailboxKeys: PublicKey[];
|
|
53
|
+
/** The master password, for the fresh unlock every export needs. */
|
|
54
|
+
masterPassword: string;
|
|
55
|
+
/** Protects the PKCS#12 file. At least `MIN_EXPORT_PASSPHRASE_LENGTH` characters. */
|
|
56
|
+
exportPassphrase: string;
|
|
57
|
+
/** Whether to include the active signing key, for clients that will sign. Off unless the user opts in. */
|
|
58
|
+
includeSigningKey?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** One key in the export. */
|
|
62
|
+
export interface ExportedKey {
|
|
63
|
+
kind: ExportedKeyKind;
|
|
64
|
+
fingerprint: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What `exportKeysAsPkcs12()` resolves with. */
|
|
68
|
+
export interface KeyExport {
|
|
69
|
+
/** The DER-encoded PKCS#12 (`.p12`) file. */
|
|
70
|
+
pkcs12: Uint8Array;
|
|
71
|
+
/** The keys it holds, zero-access keys first. */
|
|
72
|
+
keys: ExportedKey[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** One private key opened from the vault, before it goes into a bag. Its `pkcs8` is zeroed once the file is built. */
|
|
76
|
+
interface OpenedKey extends ExportedKey {
|
|
77
|
+
certDer: Uint8Array;
|
|
78
|
+
pkcs8: Uint8Array;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The export has nothing to hold - the vault has no zero-access or encryption private key this password opens. */
|
|
82
|
+
export class NothingToExportError extends Error {
|
|
83
|
+
constructor() {
|
|
84
|
+
super("This mailbox has no keys to export yet.");
|
|
85
|
+
this.name = "NothingToExportError";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function toArrayBuffer(bytes: Uint8Array): ArrayBuffer {
|
|
90
|
+
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function hexBytes(hex: string): Uint8Array {
|
|
94
|
+
const out = new Uint8Array(hex.length >> 1);
|
|
95
|
+
for (let i = 0; i < out.length; i++) {
|
|
96
|
+
out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function bagAttributes(friendlyName: string, localKeyId: Uint8Array): pkijs.Attribute[] {
|
|
102
|
+
return [
|
|
103
|
+
new pkijs.Attribute({ type: FRIENDLY_NAME, values: [new asn1js.BmpString({ value: friendlyName })] }),
|
|
104
|
+
new pkijs.Attribute({ type: LOCAL_KEY_ID, values: [new asn1js.OctetString({ valueHex: toArrayBuffer(localKeyId) })] }),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function friendlyName(kind: ExportedKeyKind, address: string, index: number): string {
|
|
109
|
+
const label = kind === "zero-access" ? "zero-access key" : kind === "encrypt" ? "encryption key" : "signing key";
|
|
110
|
+
return `RapidMX ${label} (${address})${index > 0 ? ` ${index + 1}` : ""}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Opens one wrapped private key to its raw PKCS#8, or `undefined` when it won't open under this master key - an export
|
|
114
|
+
* carries what it can rather than failing on one stale wrap. */
|
|
115
|
+
async function openPkcs8(masterKey: Uint8Array, wrapped: WrappedPrivateKey, aad: Uint8Array): Promise<Uint8Array | undefined> {
|
|
116
|
+
try {
|
|
117
|
+
return await openWithKey(masterKey, wrapped, aad);
|
|
118
|
+
} catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Opens every key the export holds, in order: zero-access keys (unrevoked newest first), the encryption keys (active
|
|
124
|
+
* first, then retained newest first), then the active signing key if asked. Each list is capped like the session's. */
|
|
125
|
+
async function openExportedKeys(input: KeyExportInput, vault: KeyVault, masterKey: Uint8Array): Promise<OpenedKey[]> {
|
|
126
|
+
const opened: OpenedKey[] = [];
|
|
127
|
+
const wrappedFor = (fingerprint: string) => vault.wrappedKeys.find((k) => k.fingerprint === fingerprint);
|
|
128
|
+
const take = async (kind: ExportedKeyKind, keys: { fingerprint: string; publicKey: string }[], purpose: string, max: number) => {
|
|
129
|
+
const aad = buildAad(input.mailboxUid, purpose);
|
|
130
|
+
const seen = new Set<string>();
|
|
131
|
+
for (const key of keys) {
|
|
132
|
+
const wrapped = wrappedFor(key.fingerprint);
|
|
133
|
+
if (!wrapped || seen.has(key.fingerprint) || seen.size === max) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const pkcs8 = await openPkcs8(masterKey, wrapped, aad);
|
|
137
|
+
if (pkcs8) {
|
|
138
|
+
seen.add(key.fingerprint);
|
|
139
|
+
opened.push({ kind, fingerprint: key.fingerprint, certDer: fromBase64(key.publicKey), pkcs8 });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const zeroAccess = [...(vault.zeroAccessKeys ?? [])].sort((a, b) => Number(!!a.revokedAt) - Number(!!b.revokedAt) || b.notBefore - a.notBefore);
|
|
145
|
+
await take("zero-access", zeroAccess, ZERO_ACCESS_PRIVATE_KEY_AAD_PURPOSE, MAX_RETAINED_ENCRYPTION_KEYS + 1);
|
|
146
|
+
|
|
147
|
+
const active = findActivePublicKey(input.mailboxKeys, "encrypt");
|
|
148
|
+
const encryption = [
|
|
149
|
+
...(active ? [active] : []),
|
|
150
|
+
...input.mailboxKeys.filter((k) => k.useType === "encrypt" && k !== active).sort((a, b) => b.notBefore - a.notBefore),
|
|
151
|
+
];
|
|
152
|
+
await take("encrypt", encryption, ENCRYPTION_PRIVATE_KEY_AAD_PURPOSE, MAX_RETAINED_ENCRYPTION_KEYS + 1);
|
|
153
|
+
|
|
154
|
+
if (input.includeSigningKey) {
|
|
155
|
+
const signing = findActivePublicKey(input.mailboxKeys, "sign");
|
|
156
|
+
await take("sign", signing ? [signing] : [], SIGNING_PRIVATE_KEY_AAD_PURPOSE, 1);
|
|
157
|
+
}
|
|
158
|
+
return opened;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Builds the PKCS#12 file: one PBES2 (PBKDF2-SHA256, AES-256-CBC) shrouded key bag and one certificate bag per key,
|
|
162
|
+
* paired by `localKeyID`, in an unencrypted SafeContents, under a SHA-256 MAC. */
|
|
163
|
+
async function buildPkcs12(keys: OpenedKey[], address: string, passphrase: string): Promise<Uint8Array> {
|
|
164
|
+
const crypto = pkijs.getCrypto(true);
|
|
165
|
+
// UTF-8 for both: pkijs re-encodes it as the BMPString the PKCS#12 MAC derivation (RFC 7292 Appendix B) takes.
|
|
166
|
+
const utf8 = toArrayBuffer(new TextEncoder().encode(passphrase));
|
|
167
|
+
const bags: pkijs.SafeBag[] = [];
|
|
168
|
+
const shrouded: pkijs.PKCS8ShroudedKeyBag[] = [];
|
|
169
|
+
const counts: Record<ExportedKeyKind, number> = { "zero-access": 0, encrypt: 0, sign: 0 };
|
|
170
|
+
|
|
171
|
+
for (const key of keys) {
|
|
172
|
+
const name = friendlyName(key.kind, address, counts[key.kind]++);
|
|
173
|
+
const localKeyId = hexBytes(key.fingerprint).slice(0, 20);
|
|
174
|
+
const keyBag = new pkijs.PKCS8ShroudedKeyBag({ parsedValue: pkijs.PrivateKeyInfo.fromBER(toArrayBuffer(key.pkcs8)) });
|
|
175
|
+
shrouded.push(keyBag);
|
|
176
|
+
bags.push(new pkijs.SafeBag({ bagId: PKCS8_SHROUDED_KEY_BAG, bagValue: keyBag, bagAttributes: bagAttributes(name, localKeyId) }));
|
|
177
|
+
const certBag = new pkijs.CertBag({ certId: X509_CERTIFICATE, parsedValue: pkijs.Certificate.fromBER(toArrayBuffer(key.certDer)) });
|
|
178
|
+
bags.push(new pkijs.SafeBag({ bagId: CERT_BAG, bagValue: certBag, bagAttributes: bagAttributes(name, localKeyId) }));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (const keyBag of shrouded) {
|
|
182
|
+
await keyBag.makeInternalValues(
|
|
183
|
+
{ password: utf8, contentEncryptionAlgorithm: AES_256_CBC, hmacHashAlgorithm: "SHA-256", iterationCount: KEY_EXPORT_ITERATIONS },
|
|
184
|
+
crypto,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const pfx = new pkijs.PFX({
|
|
189
|
+
parsedValue: {
|
|
190
|
+
integrityMode: 0,
|
|
191
|
+
authenticatedSafe: new pkijs.AuthenticatedSafe({ parsedValue: { safeContents: [{ privacyMode: 0, value: new pkijs.SafeContents({ safeBags: bags }) }] } }),
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
await pfx.parsedValue!.authenticatedSafe!.makeInternalValues({ safeContents: [{}] }, crypto);
|
|
195
|
+
await pfx.makeInternalValues(
|
|
196
|
+
{ password: utf8, iterations: KEY_EXPORT_ITERATIONS, pbkdf2HashAlgorithm: { name: "SHA-256" }, hmacHashAlgorithm: "SHA-256" },
|
|
197
|
+
crypto,
|
|
198
|
+
);
|
|
199
|
+
return new Uint8Array(pfx.toSchema().toBER(false));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Builds the "Export keys for Outlook/phone" PKCS#12 for `input.mailboxUid` (see this module's comment) and records the
|
|
204
|
+
* export with restapi. Re-opens the vault with `masterPassword` - rejecting as `unlockWithPassword()` does on a wrong
|
|
205
|
+
* one - and never touches the in-memory session. Every opened private key and the master key are zeroed before this
|
|
206
|
+
* returns, whether or not it succeeds. Throws `NothingToExportError` when no key opens.
|
|
207
|
+
*/
|
|
208
|
+
export async function exportKeysAsPkcs12(input: KeyExportInput, client?: ApiClient): Promise<KeyExport> {
|
|
209
|
+
if (input.exportPassphrase.length < MIN_EXPORT_PASSPHRASE_LENGTH) {
|
|
210
|
+
throw new Error(`The export passphrase must be at least ${MIN_EXPORT_PASSPHRASE_LENGTH} characters.`);
|
|
211
|
+
}
|
|
212
|
+
const { vault, masterKey } = await openMasterKeyWithPassword(input.mailboxUid, input.masterPassword, client);
|
|
213
|
+
let opened: OpenedKey[] = [];
|
|
214
|
+
try {
|
|
215
|
+
opened = await openExportedKeys(input, vault, masterKey);
|
|
216
|
+
if (!opened.some((k) => k.kind !== "sign")) {
|
|
217
|
+
throw new NothingToExportError();
|
|
218
|
+
}
|
|
219
|
+
const pkcs12 = await buildPkcs12(opened, input.mailboxAddress, input.exportPassphrase);
|
|
220
|
+
const keys = opened.map(({ kind, fingerprint }) => ({ kind, fingerprint }));
|
|
221
|
+
await recordKeyExport(input.mailboxUid, keys, client);
|
|
222
|
+
return { pkcs12, keys };
|
|
223
|
+
} finally {
|
|
224
|
+
masterKey.fill(0);
|
|
225
|
+
for (const key of opened) {
|
|
226
|
+
key.pkcs8.fill(0);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
package/lib/crypto/keySession.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* module today.
|
|
23
23
|
*/
|
|
24
24
|
import { type KeyVault, type PublicKey, type WrappedPrivateKey, findActivePublicKey, getKeyVault } from "./keyvaultApi.js";
|
|
25
|
+
import type { ApiClient } from "../util/api.js";
|
|
25
26
|
import { fromBase64 } from "./encoding.js";
|
|
26
27
|
import { importPrivateKeyPkcs8 } from "./keys.js";
|
|
27
28
|
import { KeysLockedError, buildAad, openWithKey } from "./masterKey.js";
|
|
@@ -34,6 +35,7 @@ import { RECOVERY_KDF_LABEL, deriveFromRecoveryCode } from "./recoveryCode.js";
|
|
|
34
35
|
export const MASTER_KEY_AAD_PURPOSE = "master-key";
|
|
35
36
|
export const SIGNING_PRIVATE_KEY_AAD_PURPOSE = "sign-private-key";
|
|
36
37
|
export const ENCRYPTION_PRIVATE_KEY_AAD_PURPOSE = "encrypt-private-key";
|
|
38
|
+
export const ZERO_ACCESS_PRIVATE_KEY_AAD_PURPOSE = "zero-access-private-key";
|
|
37
39
|
|
|
38
40
|
export { KeysLockedError };
|
|
39
41
|
|
|
@@ -73,6 +75,17 @@ export interface UnlockedKeys {
|
|
|
73
75
|
* that). A compromised key is kept because reading one's own mail encrypted to it is still needed. Absent when there
|
|
74
76
|
* are none. */
|
|
75
77
|
retainedEncryptionKeys?: RetainedEncryptionKey[];
|
|
78
|
+
/** The mailbox's zero-access private keys (restapi `specs/search.md` §3) - the keys the server encrypts mail at rest,
|
|
79
|
+
* index entries and sealed summaries to - the active one first, then retained ones newest first, at most
|
|
80
|
+
* `MAX_RETAINED_ENCRYPTION_KEYS + 1`. Decryption only. Absent when the mailbox has none (or none opened). */
|
|
81
|
+
zeroAccessKeys?: RetainedEncryptionKey[];
|
|
82
|
+
/** A shared mailbox opened through this user's member key wraps (`sharedMailboxKeys.ts`), not with its own master key: it holds
|
|
83
|
+
* only `zeroAccessKeys`, and `masterKey` is a per-key secret derived from its zero-access private key (what the local search
|
|
84
|
+
* index's key is derived from), never a key that opens the mailbox's vault. */
|
|
85
|
+
shared?: boolean;
|
|
86
|
+
/** A shared session only: the user's own mailboxes whose zero-access keys opened its member key wraps. Locking any of them locks it too -
|
|
87
|
+
* it was opened with their keys, so it doesn't outlive them. */
|
|
88
|
+
openedWith?: string[];
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
const sessions = new Map<string, UnlockedKeys>();
|
|
@@ -146,6 +159,52 @@ export function subscribeKeySession(listener: KeySessionListener): () => void {
|
|
|
146
159
|
};
|
|
147
160
|
}
|
|
148
161
|
|
|
162
|
+
/**
|
|
163
|
+
* Makes a zero-access key this device has just enrolled (`zeroAccessKey.ts`'s `provisionZeroAccessKey()`) the active one
|
|
164
|
+
* of `unlocked` - the session object the key's private half was sealed under - so zero-access mail encrypted to it reads
|
|
165
|
+
* without another unlock. Does nothing when `unlocked` is no longer this mailbox's session (it was locked or replaced
|
|
166
|
+
* meanwhile; the next unlock opens the key from the vault anyway).
|
|
167
|
+
*/
|
|
168
|
+
export function addZeroAccessKey(mailboxUid: string, unlocked: UnlockedKeys, key: RetainedEncryptionKey): void {
|
|
169
|
+
if (unlocked.destroyed || sessions.get(mailboxUid) !== unlocked) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
unlocked.zeroAccessKeys = [key, ...(unlocked.zeroAccessKeys ?? []).filter((k) => k.fingerprint !== key.fingerprint)];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Stores the keys of a shared mailbox opened through member key wraps (`sharedMailboxKeys.ts`'s `unlockSharedMailbox()`) as that mailbox's
|
|
177
|
+
* session, exactly as an unlock would - tracked for `destroyUnlockedKeys()`, and notified - unless the mailbox was locked since `generation`
|
|
178
|
+
* was taken (`sharedUnlockGeneration()`), when they are destroyed instead and `KeysLockedError` is thrown.
|
|
179
|
+
*/
|
|
180
|
+
export function installSharedSession(mailboxUid: string, unlocked: UnlockedKeys, generation: string): void {
|
|
181
|
+
if (lockGeneration(mailboxUid) !== generation) {
|
|
182
|
+
destroyObject(unlocked);
|
|
183
|
+
throw new KeysLockedError();
|
|
184
|
+
}
|
|
185
|
+
unlocked.shared = true;
|
|
186
|
+
sessions.set(mailboxUid, unlocked);
|
|
187
|
+
const objects = issued.get(mailboxUid) ?? new Set<WeakHandle<UnlockedKeys>>();
|
|
188
|
+
objects.add(weakHandle(unlocked));
|
|
189
|
+
issued.set(mailboxUid, objects);
|
|
190
|
+
notify({ mailboxUid, state: "unlocked" });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The lock generation to pass `installSharedSession()`, taken before a shared unlock starts its requests. */
|
|
194
|
+
export function sharedUnlockGeneration(mailboxUid: string): string {
|
|
195
|
+
return lockGeneration(mailboxUid);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Every mailbox unlocked this session with its own keys (not a shared one opened through member key wraps). */
|
|
199
|
+
export function personallyUnlockedKeys(): UnlockedKeys[] {
|
|
200
|
+
return personalSessions().map((session) => session.unlocked);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** `personallyUnlockedKeys()` with each mailbox's uid. */
|
|
204
|
+
export function personalSessions(): { mailboxUid: string; unlocked: UnlockedKeys }[] {
|
|
205
|
+
return [...sessions].filter(([, unlocked]) => !unlocked.shared).map(([mailboxUid, unlocked]) => ({ mailboxUid, unlocked }));
|
|
206
|
+
}
|
|
207
|
+
|
|
149
208
|
/** Reads back a mailbox's already-unlocked keys this session, or `undefined` if it hasn't been
|
|
150
209
|
* unlocked yet (or was destroyed). Never triggers an unlock itself. */
|
|
151
210
|
export function getUnlockedKeys(mailboxUid: string): UnlockedKeys | undefined {
|
|
@@ -189,6 +248,14 @@ export function destroyUnlockedKeys(mailboxUid?: string): void {
|
|
|
189
248
|
sessions.delete(uid);
|
|
190
249
|
notify({ mailboxUid: uid, state: "locked" });
|
|
191
250
|
}
|
|
251
|
+
// The shared mailboxes opened with this mailbox's keys go with it.
|
|
252
|
+
if (mailboxUid) {
|
|
253
|
+
for (const [uid, unlocked] of [...sessions]) {
|
|
254
|
+
if (unlocked.shared && unlocked.openedWith?.includes(mailboxUid)) {
|
|
255
|
+
destroyUnlockedKeys(uid);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
192
259
|
}
|
|
193
260
|
|
|
194
261
|
function destroyObject(unlocked: UnlockedKeys): void {
|
|
@@ -201,6 +268,10 @@ function destroyObject(unlocked: UnlockedKeys): void {
|
|
|
201
268
|
unlocked.retainedEncryptionKeys.length = 0;
|
|
202
269
|
delete unlocked.retainedEncryptionKeys;
|
|
203
270
|
}
|
|
271
|
+
if (unlocked.zeroAccessKeys) {
|
|
272
|
+
unlocked.zeroAccessKeys.length = 0;
|
|
273
|
+
delete unlocked.zeroAccessKeys;
|
|
274
|
+
}
|
|
204
275
|
}
|
|
205
276
|
|
|
206
277
|
/** Finds the wrapped private key whose fingerprint matches a given published public key. */
|
|
@@ -297,6 +368,35 @@ async function openRetainedEncryptionKeys(
|
|
|
297
368
|
}
|
|
298
369
|
}
|
|
299
370
|
|
|
371
|
+
/**
|
|
372
|
+
* Opens the mailbox's zero-access private keys into `unlocked.zeroAccessKeys`: the vault's `zeroAccessKeys` that have a
|
|
373
|
+
* wrapped private key, the unrevoked one with the latest `notBefore` first, then the rest newest first, at most
|
|
374
|
+
* `MAX_RETAINED_ENCRYPTION_KEYS + 1`. A key that won't open is listed in `unopenableKeys` and skipped - zero-access mail
|
|
375
|
+
* encrypted to it doesn't decrypt on this device, but nothing else about the unlock depends on it.
|
|
376
|
+
*/
|
|
377
|
+
async function openZeroAccessKeys(mailboxUid: string, vault: KeyVault, unlocked: UnlockedKeys, unopenableKeys: string[]): Promise<void> {
|
|
378
|
+
const ordered = [...(vault.zeroAccessKeys ?? [])].sort(
|
|
379
|
+
(a, b) => Number(!!a.revokedAt) - Number(!!b.revokedAt) || b.notBefore - a.notBefore,
|
|
380
|
+
);
|
|
381
|
+
const aad = buildAad(mailboxUid, ZERO_ACCESS_PRIVATE_KEY_AAD_PURPOSE);
|
|
382
|
+
let opened = 0;
|
|
383
|
+
for (const publicKey of ordered) {
|
|
384
|
+
const wrapped = findWrappedPrivateKey(vault, publicKey.fingerprint);
|
|
385
|
+
if (!wrapped || wrapped.useType !== "zero-access") {
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const privateKey = await openPrivateKey(unlocked.masterKey, wrapped, aad, { name: "ECDH", namedCurve: "P-256" }, ["deriveBits"], false);
|
|
390
|
+
(unlocked.zeroAccessKeys ??= []).push({ fingerprint: publicKey.fingerprint, certDer: fromBase64(publicKey.publicKey), privateKey });
|
|
391
|
+
} catch {
|
|
392
|
+
unopenableKeys.push(publicKey.fingerprint);
|
|
393
|
+
}
|
|
394
|
+
if (++opened === MAX_RETAINED_ENCRYPTION_KEYS + 1) {
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
300
400
|
/**
|
|
301
401
|
* Unlocks a mailbox's key vault with its password unlock method: fetches the vault, derives the
|
|
302
402
|
* wrapping key from `password` using the *exact* KDF parameters that wrap was created with, unwraps
|
|
@@ -315,7 +415,21 @@ async function openRetainedEncryptionKeys(
|
|
|
315
415
|
*/
|
|
316
416
|
export async function unlockWithPassword(mailboxUid: string, mailboxKeys: PublicKey[], password: string): Promise<UnlockResult> {
|
|
317
417
|
const generation = lockGeneration(mailboxUid);
|
|
318
|
-
const vault = await
|
|
418
|
+
const { vault, masterKey } = await openMasterKeyWithPassword(mailboxUid, password);
|
|
419
|
+
return openSession(mailboxUid, mailboxKeys, vault, masterKey, generation);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Fetches `mailboxUid`'s vault and opens its master key with the password wrap, touching no session - for an operation that
|
|
424
|
+
* must re-prove the password even while the mailbox is unlocked (`keyExport.ts`). Rejects exactly as `unlockWithPassword()`
|
|
425
|
+
* does on a missing wrap, an unknown KDF or a wrong password. The caller owns the returned master key and must zero it.
|
|
426
|
+
*/
|
|
427
|
+
export async function openMasterKeyWithPassword(
|
|
428
|
+
mailboxUid: string,
|
|
429
|
+
password: string,
|
|
430
|
+
client?: ApiClient,
|
|
431
|
+
): Promise<{ vault: KeyVault; masterKey: Uint8Array }> {
|
|
432
|
+
const vault = await getKeyVault(mailboxUid, client);
|
|
319
433
|
const passwordWrap = vault.masterKeyWraps.find((w) => w.method === "password");
|
|
320
434
|
if (!passwordWrap) {
|
|
321
435
|
throw new Error("This mailbox has no password unlock method enrolled.");
|
|
@@ -332,8 +446,7 @@ export async function unlockWithPassword(mailboxUid: string, mailboxKeys: Public
|
|
|
332
446
|
{ ciphertext: passwordWrap.ciphertext, nonce: passwordWrap.nonce },
|
|
333
447
|
buildAad(mailboxUid, MASTER_KEY_AAD_PURPOSE),
|
|
334
448
|
);
|
|
335
|
-
|
|
336
|
-
return openSession(mailboxUid, mailboxKeys, vault, masterKey, generation);
|
|
449
|
+
return { vault, masterKey };
|
|
337
450
|
}
|
|
338
451
|
|
|
339
452
|
/** What `unlockWithRecoveryCode()` resolves with. */
|
|
@@ -453,6 +566,7 @@ async function openSession(
|
|
|
453
566
|
}
|
|
454
567
|
|
|
455
568
|
await openRetainedEncryptionKeys(mailboxUid, mailboxKeys, vault, unlocked, encryptionPublicKey?.fingerprint, unopenableKeys);
|
|
569
|
+
await openZeroAccessKeys(mailboxUid, vault, unlocked, unopenableKeys);
|
|
456
570
|
if (lockGeneration(mailboxUid) !== generation) {
|
|
457
571
|
// Locked (e.g. logout) while this unlock was awaiting - never restore keys after that.
|
|
458
572
|
throw new KeysLockedError();
|
|
@@ -47,7 +47,18 @@ export interface WrappedPrivateKey {
|
|
|
47
47
|
/** AEAD algorithm identifier (e.g. `AES-256-GCM`). */
|
|
48
48
|
algorithm: string;
|
|
49
49
|
fingerprint: string;
|
|
50
|
-
useType:
|
|
50
|
+
useType: KeyUseType;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** What a mailbox's own key is used for. `sign`/`encrypt` keys are published (`Mailbox.keys`); `zero-access` keys never are.
|
|
54
|
+
* Mirrors `@rapidmx/restapi`'s `KeyUseType`. */
|
|
55
|
+
export type KeyUseType = "sign" | "encrypt" | "zero-access";
|
|
56
|
+
|
|
57
|
+
/** A mailbox's zero-access key (restapi `specs/search.md` §3): the certificate the server encrypts mail at rest to on
|
|
58
|
+
* arrival. Same shape as `PublicKey`, but never published - only the vault's reader gets it (`KeyVault.zeroAccessKeys`).
|
|
59
|
+
* Mirrors `@rapidmx/restapi`'s `ZeroAccessKey`. */
|
|
60
|
+
export interface ZeroAccessKey extends Omit<PublicKey, "useType" | "issuerCertificate"> {
|
|
61
|
+
useType: "zero-access";
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
/** One wrapped copy of the mailbox master key (MK), per unlock method. Mirrors `@rapidmx/restapi`'s
|
|
@@ -114,6 +125,9 @@ export interface KeyVault {
|
|
|
114
125
|
* (`enrollKey()`, `startSignEnrollment()`, `addMasterKeyWrap()`, `rekey()`), so restapi refuses it with `409` if
|
|
115
126
|
* another device rotated the master key meanwhile. Absent from servers that don't track it yet. */
|
|
116
127
|
masterKeyGeneration?: number;
|
|
128
|
+
/** The mailbox's zero-access certificates, newest last - returned with the vault because they are never published and
|
|
129
|
+
* an unlock needs them to decrypt zero-access mail. Absent from servers without zero-access encryption. */
|
|
130
|
+
zeroAccessKeys?: ZeroAccessKey[];
|
|
117
131
|
}
|
|
118
132
|
|
|
119
133
|
/** The optional optimistic check restapi applies to vault writes carrying key material sealed under the master key. */
|
|
@@ -179,8 +193,8 @@ export function signingKeyFingerprints(keys: PublicKey[] | undefined, previousKe
|
|
|
179
193
|
}
|
|
180
194
|
|
|
181
195
|
export interface EnrollKeyInput extends ExpectedMasterKeyGeneration {
|
|
182
|
-
useType:
|
|
183
|
-
/** PEM-encoded PKCS#10 CSR — required (and only meaningful) for `useType: "encrypt"`; the server
|
|
196
|
+
useType: KeyUseType;
|
|
197
|
+
/** PEM-encoded PKCS#10 CSR — required (and only meaningful) for `useType: "encrypt"` and `"zero-access"`; the server
|
|
184
198
|
* calls its own internal CA against this CSR. */
|
|
185
199
|
csr?: string;
|
|
186
200
|
/** An already-issued PEM certificate — required (and only meaningful) for `useType: "sign"`. */
|
|
@@ -508,6 +522,110 @@ export function removeMasterKeyWrap(mailboxUid: string, method: string, methodId
|
|
|
508
522
|
});
|
|
509
523
|
}
|
|
510
524
|
|
|
525
|
+
/** One member's copy of a shared mailbox's zero-access private key: base64 CMS of its PKCS#8, to the member's own zero-access certificate. */
|
|
526
|
+
export interface MemberKeyWrap {
|
|
527
|
+
memberUserUid: string;
|
|
528
|
+
recipientFingerprint: string;
|
|
529
|
+
zeroAccessKeyFingerprint: string;
|
|
530
|
+
cms: string;
|
|
531
|
+
createdAt?: number;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** One member in `SharedKeyStatus`. */
|
|
535
|
+
export interface SharedKeyMember {
|
|
536
|
+
userUid: string;
|
|
537
|
+
full: boolean;
|
|
538
|
+
/** Their own zero-access certificate - absent until they first sign in and get one. */
|
|
539
|
+
certificate?: ZeroAccessKey;
|
|
540
|
+
/** The mailbox's zero-access keys they hold a wrap of. */
|
|
541
|
+
wrapped: string[];
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** Where a shared mailbox's zero-access key stands with its members - restapi `GET /mail/mailboxes/:id/keyvault/members`. */
|
|
545
|
+
export interface SharedKeyStatus {
|
|
546
|
+
ownerless: boolean;
|
|
547
|
+
/** The caller: the mailbox's owner, one of its members, or neither (an administrator acting through a role). */
|
|
548
|
+
role?: "owner" | "member" | "other";
|
|
549
|
+
activeKeyFingerprint?: string;
|
|
550
|
+
zeroAccessKeys: ZeroAccessKey[];
|
|
551
|
+
members: SharedKeyMember[];
|
|
552
|
+
/** Members with a certificate but no wrap of the active key. */
|
|
553
|
+
pending: string[];
|
|
554
|
+
/** Users holding wraps who are no longer members. */
|
|
555
|
+
departed: string[];
|
|
556
|
+
/** A departed user holds the active key: a new key must be provisioned. */
|
|
557
|
+
rotationPending: boolean;
|
|
558
|
+
/** The caller may change the wraps. */
|
|
559
|
+
manager: boolean;
|
|
560
|
+
/** A mailbox without an owner assigned to an escrow scope: that scope. */
|
|
561
|
+
escrowScopeId?: string;
|
|
562
|
+
/** Its zero-access keys (fingerprints) with no escrow copy for `escrowScopeId` yet. Absent from servers that predate it. */
|
|
563
|
+
escrowPending?: string[];
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
/** An escrow copy of a mailbox-without-an-owner's zero-access private key, as `putZeroAccessEscrowWraps()` sends it: CMS of its PKCS#8 to
|
|
567
|
+
* the escrow scope's certificate (`getEscrowInfo()`). */
|
|
568
|
+
export interface ZeroAccessEscrowWrapInput {
|
|
569
|
+
escrowScopeId: string;
|
|
570
|
+
zeroAccessKeyFingerprint: string;
|
|
571
|
+
/** Base64 DER CMS `EnvelopedData`. */
|
|
572
|
+
cms: string;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const vaultPath = (mailboxUid: string): string => `/mail/mailboxes/${encodeURIComponent(mailboxUid)}/keyvault`;
|
|
576
|
+
|
|
577
|
+
export function getSharedKeyStatus(mailboxUid: string, client?: ApiClient): Promise<SharedKeyStatus> {
|
|
578
|
+
return withClient(client, `${vaultPath(mailboxUid)}/members`);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/** The caller's own member key wraps of `mailboxUid` (`[]` for its owner and for a member still waiting). */
|
|
582
|
+
export function getMyMemberKeyWraps(mailboxUid: string, client?: ApiClient): Promise<MemberKeyWrap[]> {
|
|
583
|
+
return withClient(client, `${vaultPath(mailboxUid)}/member-wraps`);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
export function putMemberKeyWraps(mailboxUid: string, wraps: MemberKeyWrap[], client?: ApiClient): Promise<SharedKeyStatus> {
|
|
587
|
+
return withClient(client, `${vaultPath(mailboxUid)}/member-wraps`, { method: "PUT", body: JSON.stringify({ wraps }) });
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/** Removes every wrap of a user who is no longer a member - the last step of a rotation. */
|
|
591
|
+
export function removeMemberKeyWraps(mailboxUid: string, memberUserUid: string, client?: ApiClient): Promise<SharedKeyStatus> {
|
|
592
|
+
return withClient(client, `${vaultPath(mailboxUid)}/member-wraps/${encodeURIComponent(memberUserUid)}`, { method: "DELETE" });
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** Provisions (or rotates) a mailbox-without-an-owner's zero-access key with its member wraps, in one write - and, for a mailbox assigned to
|
|
596
|
+
* an escrow scope, its escrow copy (required then). */
|
|
597
|
+
export function enrollSharedZeroAccessKey(
|
|
598
|
+
mailboxUid: string,
|
|
599
|
+
input: {
|
|
600
|
+
csr: string;
|
|
601
|
+
wraps: Omit<MemberKeyWrap, "zeroAccessKeyFingerprint">[];
|
|
602
|
+
escrowWrap?: Omit<ZeroAccessEscrowWrapInput, "zeroAccessKeyFingerprint">;
|
|
603
|
+
},
|
|
604
|
+
client?: ApiClient,
|
|
605
|
+
): Promise<SharedKeyStatus> {
|
|
606
|
+
return withClient(client, `${vaultPath(mailboxUid)}/shared-zero-access-key`, { method: "POST", body: JSON.stringify(input) });
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/** Adds the escrow copies of a mailbox-without-an-owner's zero-access keys its escrow scope is missing (`SharedKeyStatus.escrowPending`). */
|
|
610
|
+
export function putZeroAccessEscrowWraps(mailboxUid: string, wraps: ZeroAccessEscrowWrapInput[], client?: ApiClient): Promise<SharedKeyStatus> {
|
|
611
|
+
return withClient(client, `${vaultPath(mailboxUid)}/escrow-wraps`, { method: "PUT", body: JSON.stringify({ wraps }) });
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/** One key a "Export keys for Outlook/phone" file held, as `recordKeyExport()` reports it. */
|
|
615
|
+
export interface ExportedKeyRecord {
|
|
616
|
+
kind: "zero-access" | "encrypt" | "sign";
|
|
617
|
+
fingerprint: string;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/** Records with restapi that the owner exported these private keys (`key_vault.export` in the audit log). `keyExport.ts`
|
|
621
|
+
* calls it before handing over the file, so an export the server refuses to record isn't handed over. Owner-only. */
|
|
622
|
+
export async function recordKeyExport(mailboxUid: string, keys: ExportedKeyRecord[], client?: ApiClient): Promise<void> {
|
|
623
|
+
await withClient(client, `/mail/mailboxes/${encodeURIComponent(mailboxUid)}/keyvault/exports`, {
|
|
624
|
+
method: "POST",
|
|
625
|
+
body: JSON.stringify({ keys }),
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
|
|
511
629
|
export interface RekeyInput extends ExpectedMasterKeyGeneration {
|
|
512
630
|
wrappedKeys: WrappedPrivateKey[];
|
|
513
631
|
/** Every wrap of the new master key. For a mailbox assigned an escrow scope, this must include a fresh escrow wrap
|
|
@@ -657,6 +775,10 @@ export interface EncryptionPolicy {
|
|
|
657
775
|
encryptSameOrg: PolicyState;
|
|
658
776
|
encryptFederated: PolicyState;
|
|
659
777
|
encryptExternal: PolicyState;
|
|
778
|
+
/** "Allow zero-access encryption": whether mailboxes may store mail encrypted at rest. Always present from a server that
|
|
779
|
+
* supports zero-access encryption (its stored value or the server default); absent from one that doesn't, which a
|
|
780
|
+
* caller treats as not allowed. */
|
|
781
|
+
allowZeroAccess?: boolean;
|
|
660
782
|
}
|
|
661
783
|
|
|
662
784
|
/** The system-wide encryption policy (readable by any authenticated user, used to decide what encryption
|