@rapidmx/web-client 0.3.1 → 0.5.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/admin/audit-log/index.tsx +35 -8
- package/apps/admin/branding/index.tsx +39 -404
- package/apps/admin/data-requests/index.tsx +480 -485
- package/apps/admin/distribution-lists/[uid].tsx +19 -1
- package/apps/admin/domains/[uid].tsx +92 -259
- package/apps/admin/encryption-policy/index.tsx +19 -0
- package/apps/admin/escrow-scopes/[uid].tsx +348 -237
- package/apps/admin/escrow-scopes/new/index.tsx +8 -2
- package/apps/admin/index.tsx +118 -82
- package/apps/admin/ingest-queue/index.tsx +44 -5
- package/apps/admin/mailbox-policy/index.tsx +19 -0
- package/apps/admin/mailboxes/[uid].tsx +211 -184
- package/apps/admin/mailboxes/new/index.tsx +28 -291
- package/apps/admin/plugins/index.tsx +15 -0
- package/apps/admin/quarantine/index.tsx +46 -14
- package/apps/admin/retention-policy/index.tsx +39 -132
- package/apps/admin/setup/index.tsx +15 -0
- package/apps/admin/transport-rules/[uid].tsx +30 -1
- package/apps/admin/transport-rules/_transportRuleConfig.tsx +38 -2
- package/apps/admin/transport-rules/index.tsx +24 -6
- package/apps/admin/transport-rules/new/index.tsx +30 -1
- package/apps/escrow/_layout.tsx +2 -3
- package/apps/escrow/audit-log/index.tsx +196 -168
- package/apps/escrow/matters/[uid].tsx +621 -521
- package/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.tsx +22 -1
- package/apps/shared/components/admin/layout/AdminShell.tsx +251 -210
- package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -0
- package/apps/shared/components/admin/mailboxes/ResourceSettingsCard.tsx +3 -3
- package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +55 -11
- package/apps/shared/components/admin/settings/BrandingForm.tsx +385 -0
- package/apps/shared/components/admin/settings/DomainDnsSetup.tsx +187 -0
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +112 -0
- package/apps/shared/components/admin/settings/LoadedSettingsForm.tsx +34 -0
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +308 -0
- package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +152 -0
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1235 -0
- package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +174 -0
- package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +290 -0
- package/apps/shared/components/admin/setup/SetupWizard.tsx +416 -0
- package/apps/shared/components/admin/signOut.ts +79 -0
- package/apps/shared/components/admin/usePagedList.tsx +129 -0
- package/apps/shared/components/calendar/CalendarListSidebar.tsx +120 -76
- package/apps/shared/components/calendar/EventModal.tsx +717 -513
- package/apps/shared/components/calendar/MonthView.tsx +173 -139
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +222 -180
- package/apps/shared/components/calendar/SplitDayView.tsx +143 -137
- package/apps/shared/components/calendar/TimeGridView.tsx +244 -198
- package/apps/shared/components/calendar/allDay.ts +124 -0
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +80 -99
- package/apps/shared/components/contacts/ContactDetailPane.tsx +100 -21
- package/apps/shared/components/contacts/ContactForm.tsx +377 -314
- package/apps/shared/components/contacts/ContactsSidebar.tsx +6 -2
- package/apps/shared/components/contacts/KeyChangeReview.tsx +192 -0
- package/apps/shared/components/contacts/contactKeys.ts +78 -0
- package/apps/shared/components/escrow/layout/EscrowShell.tsx +148 -134
- package/apps/shared/components/layout/AppShell.tsx +270 -169
- package/apps/shared/components/layout/BrandingChrome.tsx +48 -10
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +150 -26
- package/apps/shared/components/layout/MailboxProvisioning.tsx +19 -3
- package/apps/shared/components/layout/RecoveryCodeUnlock.tsx +350 -0
- package/apps/shared/components/layout/UnlockPromptProvider.tsx +257 -0
- package/apps/shared/components/mail/ConversationThreadPane.tsx +216 -181
- package/apps/shared/components/mail/MessageDetailPane.tsx +799 -76
- package/apps/shared/components/mail/compose/ComposeContext.tsx +26 -16
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1652 -765
- package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +418 -302
- package/apps/shared/components/mail/pinnedSigners.ts +124 -0
- package/apps/shared/components/mail/verificationSeals.ts +125 -0
- package/apps/shared/components/mail/writableMailboxes.ts +101 -0
- package/apps/shared/components/rules/RuleBuilder.tsx +311 -276
- package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
- package/apps/shared/mail/findWellKnownFolderUid.ts +13 -0
- package/apps/shared/mail/listAllPages.ts +39 -0
- package/apps/shared/search/LocalIndexLifecycle.tsx +98 -0
- package/apps/shared/search/localIndexBlockCipher.ts +83 -0
- package/apps/shared/search/localIndexBuilder.ts +481 -0
- package/apps/shared/search/localIndexKey.ts +27 -0
- package/apps/shared/search/localIndexRpcClient.ts +316 -0
- package/apps/shared/search/localIndexSchema.ts +236 -0
- package/apps/shared/search/localIndexSizePreference.ts +88 -0
- package/apps/shared/search/localIndexStorage.ts +98 -0
- package/apps/shared/search/localIndexVFS.ts +266 -0
- package/apps/shared/search/localIndexWorker.ts +926 -0
- package/apps/shared/search/searchTier2.ts +79 -0
- package/apps/shared/search/wa-sqlite-shims.d.ts +44 -0
- package/apps/www/calendar/index.tsx +438 -407
- package/apps/www/contacts/[uid].tsx +21 -2
- package/apps/www/contacts/index.tsx +148 -17
- package/apps/www/index.tsx +1314 -486
- package/apps/www/messages/[uid].tsx +23 -7
- package/apps/www/settings/auto-reply/index.tsx +134 -129
- package/apps/www/settings/booking-types/[uid].tsx +306 -300
- package/apps/www/settings/encryption/index.tsx +800 -215
- package/apps/www/settings/filters/[uid].tsx +171 -155
- package/apps/www/settings/filters/new/index.tsx +8 -1
- package/apps/www/settings/focused-inbox/index.tsx +150 -148
- package/apps/www/settings/privacy/index.tsx +494 -436
- package/apps/www/settings/read-receipts/index.tsx +148 -125
- package/apps/www/settings/sharing/index.tsx +274 -0
- package/apps/www/tasks/index.tsx +638 -530
- package/dist/apps/admin/audit-log/index.js +38 -8
- package/dist/apps/admin/branding/index.js +4 -98
- package/dist/apps/admin/data-requests/index.js +52 -72
- package/dist/apps/admin/distribution-lists/[uid].js +1 -1
- package/dist/apps/admin/domains/[uid].js +5 -68
- package/dist/apps/admin/encryption-policy/index.js +8 -0
- package/dist/apps/admin/escrow-scopes/[uid].js +91 -12
- package/dist/apps/admin/escrow-scopes/new/index.js +8 -3
- package/dist/apps/admin/index.js +17 -1
- package/dist/apps/admin/ingest-queue/index.js +24 -6
- package/dist/apps/admin/mailbox-policy/index.js +8 -0
- package/dist/apps/admin/mailboxes/[uid].js +20 -4
- package/dist/apps/admin/mailboxes/new/index.js +4 -89
- package/dist/apps/admin/plugins/index.js +6 -0
- package/dist/apps/admin/quarantine/index.js +20 -11
- package/dist/apps/admin/retention-policy/index.js +3 -36
- package/dist/apps/admin/setup/index.js +6 -0
- package/dist/apps/admin/transport-rules/[uid].js +18 -2
- package/dist/apps/admin/transport-rules/_transportRuleConfig.js +19 -0
- package/dist/apps/admin/transport-rules/index.js +22 -6
- package/dist/apps/admin/transport-rules/new/index.js +18 -2
- package/dist/apps/escrow/_layout.js +3 -3
- package/dist/apps/escrow/audit-log/index.js +26 -1
- package/dist/apps/escrow/matters/[uid].js +77 -42
- package/dist/apps/shared/components/admin/escrowScopes/EscrowScopeKeyAndHoldersFields.js +11 -2
- package/dist/apps/shared/components/admin/layout/AdminShell.js +37 -4
- package/dist/apps/shared/components/admin/mailboxes/EscrowScopeCard.js +72 -0
- package/dist/apps/shared/components/admin/mailboxes/ResourceSettingsCard.js +3 -3
- package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +22 -4
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +116 -0
- package/dist/apps/shared/components/admin/settings/DomainDnsSetup.js +83 -0
- package/dist/apps/shared/components/admin/settings/EncryptionPolicyForm.js +62 -0
- package/dist/apps/shared/components/admin/settings/LoadedSettingsForm.js +25 -0
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +112 -0
- package/dist/apps/shared/components/admin/settings/MailboxPolicyForm.js +74 -0
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +572 -0
- package/dist/apps/shared/components/admin/settings/RetentionPolicyForm.js +73 -0
- package/dist/apps/shared/components/admin/setup/EscrowSetupStep.js +147 -0
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +208 -0
- package/dist/apps/shared/components/admin/signOut.js +75 -0
- package/dist/apps/shared/components/admin/usePagedList.js +99 -0
- package/dist/apps/shared/components/calendar/CalendarListSidebar.js +24 -13
- package/dist/apps/shared/components/calendar/EventModal.js +154 -21
- package/dist/apps/shared/components/calendar/MonthView.js +12 -5
- package/dist/apps/shared/components/calendar/RecurrenceEditor.js +40 -5
- package/dist/apps/shared/components/calendar/SplitDayView.js +10 -4
- package/dist/apps/shared/components/calendar/TimeGridView.js +23 -7
- package/dist/apps/shared/components/calendar/allDay.js +111 -0
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +47 -39
- package/dist/apps/shared/components/contacts/ContactDetailPane.js +43 -5
- package/dist/apps/shared/components/contacts/ContactForm.js +45 -12
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +2 -2
- package/dist/apps/shared/components/contacts/KeyChangeReview.js +63 -0
- package/dist/apps/shared/components/contacts/contactKeys.js +64 -0
- package/dist/apps/shared/components/escrow/layout/EscrowShell.js +24 -5
- package/dist/apps/shared/components/layout/AppShell.js +100 -8
- package/dist/apps/shared/components/layout/BrandingChrome.js +45 -10
- package/dist/apps/shared/components/layout/KeyEnrollmentGate.js +63 -14
- package/dist/apps/shared/components/layout/MailboxProvisioning.js +10 -2
- package/dist/apps/shared/components/layout/RecoveryCodeUnlock.js +174 -0
- package/dist/apps/shared/components/layout/UnlockPromptProvider.js +136 -0
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +50 -12
- package/dist/apps/shared/components/mail/MessageDetailPane.js +464 -34
- package/dist/apps/shared/components/mail/compose/ComposeContext.js +9 -6
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +807 -116
- package/dist/apps/shared/components/mail/compose/composeFlushRegistry.js +50 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +116 -41
- package/dist/apps/shared/components/mail/pinnedSigners.js +98 -0
- package/dist/apps/shared/components/mail/verificationSeals.js +112 -0
- package/dist/apps/shared/components/mail/writableMailboxes.js +87 -0
- package/dist/apps/shared/components/rules/RuleBuilder.js +34 -6
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
- package/dist/apps/shared/mail/findWellKnownFolderUid.js +12 -0
- package/dist/apps/shared/mail/listAllPages.js +25 -0
- package/dist/apps/shared/search/LocalIndexLifecycle.js +80 -0
- package/dist/apps/shared/search/localIndexBlockCipher.js +63 -0
- package/dist/apps/shared/search/localIndexBuilder.js +408 -0
- package/dist/apps/shared/search/localIndexKey.js +25 -0
- package/dist/apps/shared/search/localIndexRpcClient.js +241 -0
- package/dist/apps/shared/search/localIndexSchema.js +185 -0
- package/dist/apps/shared/search/localIndexSizePreference.js +78 -0
- package/dist/apps/shared/search/localIndexStorage.js +86 -0
- package/dist/apps/shared/search/localIndexVFS.js +258 -0
- package/dist/apps/shared/search/localIndexWorker.js +687 -0
- package/dist/apps/shared/search/searchTier2.js +38 -0
- package/dist/apps/www/calendar/index.js +38 -18
- package/dist/apps/www/contacts/[uid].js +13 -2
- package/dist/apps/www/contacts/index.js +94 -15
- package/dist/apps/www/index.js +770 -137
- package/dist/apps/www/messages/[uid].js +23 -7
- package/dist/apps/www/settings/auto-reply/index.js +9 -4
- package/dist/apps/www/settings/booking-types/[uid].js +17 -12
- package/dist/apps/www/settings/encryption/index.js +541 -96
- package/dist/apps/www/settings/filters/[uid].js +22 -7
- package/dist/apps/www/settings/filters/new/index.js +8 -2
- package/dist/apps/www/settings/focused-inbox/index.js +3 -1
- package/dist/apps/www/settings/privacy/index.js +57 -22
- package/dist/apps/www/settings/read-receipts/index.js +10 -3
- package/dist/apps/www/settings/sharing/index.js +124 -0
- package/dist/apps/www/tasks/index.js +76 -14
- package/package.json +3 -2
|
@@ -7,17 +7,20 @@ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
|
7
7
|
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
8
8
|
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
9
9
|
import FormField from "@rapidmx/react-shared/components/forms/FormField.js";
|
|
10
|
-
import { enrollKey, getKeyVault, PublicKey } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
|
|
10
|
+
import { enrollKey, getKeyVault, PublicKey, VaultAlreadyInitializedError } from "@rapidmx/react-shared/crypto/keyvaultApi.js";
|
|
11
|
+
import { UnopenableKeysNotice, unlockErrorMessage } from "./UnlockPromptProvider.js";
|
|
12
|
+
import { RecoveryFollowUp, RecoveryFollowUpModal, UnlockModeToggle, startRecoveryUnlock } from "./RecoveryCodeUnlock.js";
|
|
11
13
|
import {
|
|
12
14
|
ENCRYPTION_PRIVATE_KEY_AAD_PURPOSE,
|
|
13
15
|
getUnlockedKeys,
|
|
14
16
|
unlockWithPassword,
|
|
17
|
+
type UnlockResult,
|
|
15
18
|
} from "@rapidmx/react-shared/crypto/keySession.js";
|
|
16
19
|
import { buildAad, generateMasterKey, sealWithKey } from "@rapidmx/react-shared/crypto/masterKey.js";
|
|
17
20
|
import { buildPasswordWrap, buildRecoveryWraps } from "@rapidmx/react-shared/crypto/masterKeyWraps.js";
|
|
18
21
|
import { exportPrivateKeyPkcs8, generateKeyPairWithCsr } from "@rapidmx/react-shared/crypto/keys.js";
|
|
19
22
|
|
|
20
|
-
type Status = "checking" | "setup_password" | "enrolling" | "show_recovery_codes" | "unlock" | "unlocking" | "ready";
|
|
23
|
+
type Status = "checking" | "setup_password" | "enrolling" | "already_set_up" | "show_recovery_codes" | "unlock" | "unlocking" | "ready";
|
|
21
24
|
|
|
22
25
|
const MIN_PASSWORD_LENGTH = 8;
|
|
23
26
|
|
|
@@ -59,6 +62,26 @@ export interface KeyEnrollmentGateProps {
|
|
|
59
62
|
* one. Treated as empty when undefined - a mailbox with no public keys published yet has nothing to
|
|
60
63
|
* unlock, so this only affects the already-enrolled path. */
|
|
61
64
|
mailboxKeys?: PublicKey[];
|
|
65
|
+
/**
|
|
66
|
+
* `true` (default) preserves this component's original behavior: a mailbox with an existing vault
|
|
67
|
+
* but no unlocked session blocks `children` behind a full-page unlock form. Set to `false` for a
|
|
68
|
+
* mount point that shouldn't block merely because a mailbox resolved - `MailShell` does this, since
|
|
69
|
+
* unlocking is only actually required to sign/encrypt a compose, read an already-encrypted message,
|
|
70
|
+
* or change encryption settings (see `UnlockPromptProvider.tsx`'s `useUnlockPrompt()`, which those
|
|
71
|
+
* specific call sites use instead). Has no effect on first-time provisioning
|
|
72
|
+
* (`setup_password`/`enrolling`/`show_recovery_codes`), which still always blocks regardless - that
|
|
73
|
+
* only ever happens once per mailbox and is a genuine prerequisite, not the source of "unlock keeps
|
|
74
|
+
* popping up" friction this prop exists to avoid.
|
|
75
|
+
*/
|
|
76
|
+
blocking?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* `true` when the caller may provision this mailbox's first encryption key - i.e. they own it and aren't
|
|
79
|
+
* an administrator impersonating them. `false` (default, so a caller that forgets it never provisions) for
|
|
80
|
+
* a shared/delegated mailbox the caller doesn't own, or an impersonated session: a mailbox with no vault yet then
|
|
81
|
+
* renders `children` instead of the "Protect your mailbox" setup, so a delegate never enrolls keys
|
|
82
|
+
* (and recovery codes) for someone else's mailbox. Unlocking an existing vault is unaffected.
|
|
83
|
+
*/
|
|
84
|
+
canProvision?: boolean;
|
|
62
85
|
children: React.ReactNode;
|
|
63
86
|
}
|
|
64
87
|
|
|
@@ -77,13 +100,26 @@ export interface KeyEnrollmentGateProps {
|
|
|
77
100
|
* `children` unchanged rather than blocking mail entirely - encryption is optional and gradual by design
|
|
78
101
|
* (the spec's own "near zero frictionless experience" goal), not a hard prerequisite for reading mail.
|
|
79
102
|
*/
|
|
80
|
-
export default function KeyEnrollmentGate({
|
|
103
|
+
export default function KeyEnrollmentGate({
|
|
104
|
+
mailboxUid,
|
|
105
|
+
mailboxAddress,
|
|
106
|
+
mailboxKeys,
|
|
107
|
+
blocking = true,
|
|
108
|
+
canProvision = false,
|
|
109
|
+
children,
|
|
110
|
+
}: KeyEnrollmentGateProps) {
|
|
81
111
|
const [status, setStatus] = useState<Status>(mailboxUid ? "checking" : "ready");
|
|
82
112
|
const [password, setPassword] = useState("");
|
|
83
113
|
const [confirmPassword, setConfirmPassword] = useState("");
|
|
84
114
|
const [error, setError] = useState<string | null>(null);
|
|
85
115
|
const [recoveryCodes, setRecoveryCodes] = useState<string[]>([]);
|
|
86
116
|
const [codesSaved, setCodesSaved] = useState(false);
|
|
117
|
+
const [codesCopied, setCodesCopied] = useState(false);
|
|
118
|
+
const [unopenableKeys, setUnopenableKeys] = useState<string[] | null>(null);
|
|
119
|
+
const [unlockMode, setUnlockMode] = useState<"password" | "recovery">("password");
|
|
120
|
+
const [recoveryCode, setRecoveryCode] = useState("");
|
|
121
|
+
// Set after a recovery-code unlock: `children` render at once, with the follow-up steps in a dialog on top.
|
|
122
|
+
const [followUp, setFollowUp] = useState<RecoveryFollowUp | null>(null);
|
|
87
123
|
|
|
88
124
|
useEffect(() => {
|
|
89
125
|
if (!mailboxUid) {
|
|
@@ -100,7 +136,7 @@ export default function KeyEnrollmentGate({ mailboxUid, mailboxAddress, mailboxK
|
|
|
100
136
|
getKeyVault(mailboxUid)
|
|
101
137
|
.then((vault) => {
|
|
102
138
|
if (!cancelled) {
|
|
103
|
-
setStatus(vault.wrappedKeys.length > 0 ? "unlock" : "setup_password");
|
|
139
|
+
setStatus(vault.wrappedKeys.length > 0 ? "unlock" : canProvision ? "setup_password" : "ready");
|
|
104
140
|
}
|
|
105
141
|
})
|
|
106
142
|
.catch(() => {
|
|
@@ -111,7 +147,7 @@ export default function KeyEnrollmentGate({ mailboxUid, mailboxAddress, mailboxK
|
|
|
111
147
|
return () => {
|
|
112
148
|
cancelled = true;
|
|
113
149
|
};
|
|
114
|
-
}, [mailboxUid]);
|
|
150
|
+
}, [mailboxUid, canProvision]);
|
|
115
151
|
|
|
116
152
|
async function handleUnlock(e: React.FormEvent) {
|
|
117
153
|
e.preventDefault();
|
|
@@ -120,13 +156,20 @@ export default function KeyEnrollmentGate({ mailboxUid, mailboxAddress, mailboxK
|
|
|
120
156
|
try {
|
|
121
157
|
// Only reachable via "unlock", which the effect above only ever sets once mailboxUid was
|
|
122
158
|
// defined.
|
|
123
|
-
await
|
|
159
|
+
const result: UnlockResult | RecoveryFollowUp = await (unlockMode === "recovery"
|
|
160
|
+
? startRecoveryUnlock(mailboxUid!, mailboxKeys ?? [], recoveryCode)
|
|
161
|
+
: unlockWithPassword(mailboxUid!, mailboxKeys ?? [], password));
|
|
162
|
+
const recovery = unlockMode === "recovery" ? (result as RecoveryFollowUp) : null;
|
|
163
|
+
if (result.unopenableKeys.length > 0) {
|
|
164
|
+
setUnopenableKeys(result.unopenableKeys);
|
|
165
|
+
}
|
|
166
|
+
setRecoveryCode("");
|
|
167
|
+
setFollowUp(recovery);
|
|
124
168
|
setStatus("ready");
|
|
125
|
-
} catch {
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
setError("Incorrect password.");
|
|
169
|
+
} catch (err) {
|
|
170
|
+
// "Incorrect password." (or "That recovery code didn't work.") unless the secret was right but the
|
|
171
|
+
// encryption key won't open - see `unlockErrorMessage()`.
|
|
172
|
+
setError(unlockErrorMessage(err, unlockMode));
|
|
130
173
|
setStatus("unlock");
|
|
131
174
|
}
|
|
132
175
|
}
|
|
@@ -144,47 +187,101 @@ export default function KeyEnrollmentGate({ mailboxUid, mailboxAddress, mailboxK
|
|
|
144
187
|
setError(null);
|
|
145
188
|
setStatus("enrolling");
|
|
146
189
|
try {
|
|
190
|
+
// The vault was only checked on mount - another tab or device may have set encryption up since.
|
|
191
|
+
// Provisioning now would publish a second master key, orphaning whichever setup lost the race, so
|
|
192
|
+
// re-check right before generating anything. restapi's enrollKey() also refuses (409) wraps for a
|
|
193
|
+
// vault that already has them, for a race inside this window.
|
|
147
194
|
// Only reachable via "setup_password", which the effect above only ever sets once mailboxUid
|
|
148
195
|
// was defined (and mailboxAddress necessarily came with it - see KeyEnrollmentGateProps).
|
|
196
|
+
const fresh = await getKeyVault(mailboxUid!);
|
|
197
|
+
if (fresh.wrappedKeys.length > 0 || fresh.masterKeyWraps.length > 0) {
|
|
198
|
+
setStatus("already_set_up");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
149
201
|
const { recoveryCodes: codes } = await provisionEncryptionKey(mailboxUid!, mailboxAddress!, password);
|
|
150
202
|
setRecoveryCodes(codes);
|
|
151
203
|
setStatus("show_recovery_codes");
|
|
152
204
|
} catch (err) {
|
|
205
|
+
// Only a 409 that is really "the vault already has wraps" - an unrelated lost optimistic-lock race is shown
|
|
206
|
+
// as an ordinary error.
|
|
207
|
+
if (err instanceof VaultAlreadyInitializedError) {
|
|
208
|
+
setStatus("already_set_up");
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
153
211
|
setError(err instanceof ApiRequestError ? err.message : "Could not set up encryption for this mailbox.");
|
|
154
212
|
setStatus("setup_password");
|
|
155
213
|
}
|
|
156
214
|
}
|
|
157
215
|
|
|
216
|
+
async function handleCopyCodes() {
|
|
217
|
+
try {
|
|
218
|
+
await navigator.clipboard.writeText(recoveryCodes.join("\n"));
|
|
219
|
+
setCodesCopied(true);
|
|
220
|
+
setTimeout(() => setCodesCopied(false), 2000);
|
|
221
|
+
} catch {
|
|
222
|
+
// Clipboard access can be denied by the browser - the codes are still selectable/copyable by
|
|
223
|
+
// hand from the list below.
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
158
227
|
if (status === "checking") {
|
|
159
228
|
return null;
|
|
160
229
|
}
|
|
161
230
|
|
|
162
|
-
if (status === "unlock" || status === "unlocking") {
|
|
231
|
+
if ((status === "unlock" || status === "unlocking") && blocking) {
|
|
163
232
|
const unlocking = status === "unlocking";
|
|
164
233
|
return (
|
|
165
234
|
<div className="min-h-screen flex items-center justify-center p-8 bg-surface-alt">
|
|
166
235
|
<div className="w-full max-w-md bg-surface border border-border rounded-md p-8">
|
|
167
236
|
<h1 className="text-lg font-bold mb-2">Unlock your mailbox</h1>
|
|
168
237
|
<p className="text-sm text-text-muted mb-5">
|
|
169
|
-
|
|
238
|
+
{unlockMode === "password"
|
|
239
|
+
? "Enter your encryption password to unlock signing and reading protected mail this session."
|
|
240
|
+
: "Enter one of your recovery codes to unlock signing and reading protected mail this session. Each code works once."}
|
|
170
241
|
</p>
|
|
171
242
|
{error && <Alert>{error}</Alert>}
|
|
172
243
|
<form onSubmit={handleUnlock}>
|
|
173
|
-
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
244
|
+
{unlockMode === "password" ? (
|
|
245
|
+
<FormField label="Encryption password" htmlFor="key-unlock-password">
|
|
246
|
+
<input
|
|
247
|
+
id="key-unlock-password"
|
|
248
|
+
type="password"
|
|
249
|
+
className="w-full text-sm border border-border rounded-sm py-1.5 px-2 bg-surface"
|
|
250
|
+
value={password}
|
|
251
|
+
onChange={(e) => setPassword(e.target.value)}
|
|
252
|
+
disabled={unlocking}
|
|
253
|
+
autoComplete="current-password"
|
|
254
|
+
/>
|
|
255
|
+
</FormField>
|
|
256
|
+
) : (
|
|
257
|
+
<FormField label="Recovery code" htmlFor="key-unlock-recovery-code">
|
|
258
|
+
<input
|
|
259
|
+
id="key-unlock-recovery-code"
|
|
260
|
+
type="text"
|
|
261
|
+
className="w-full text-sm font-mono border border-border rounded-sm py-1.5 px-2 bg-surface"
|
|
262
|
+
value={recoveryCode}
|
|
263
|
+
onChange={(e) => setRecoveryCode(e.target.value)}
|
|
264
|
+
disabled={unlocking}
|
|
265
|
+
autoComplete="off"
|
|
266
|
+
autoCapitalize="characters"
|
|
267
|
+
spellCheck={false}
|
|
268
|
+
/>
|
|
269
|
+
</FormField>
|
|
270
|
+
)}
|
|
184
271
|
<Button type="submit" loading={unlocking} disabled={unlocking}>
|
|
185
272
|
Unlock
|
|
186
273
|
</Button>
|
|
187
274
|
</form>
|
|
275
|
+
<div className="mt-3">
|
|
276
|
+
<UnlockModeToggle
|
|
277
|
+
mode={unlockMode}
|
|
278
|
+
disabled={unlocking}
|
|
279
|
+
onChange={(next) => {
|
|
280
|
+
setUnlockMode(next);
|
|
281
|
+
setError(null);
|
|
282
|
+
}}
|
|
283
|
+
/>
|
|
284
|
+
</div>
|
|
188
285
|
</div>
|
|
189
286
|
</div>
|
|
190
287
|
);
|
|
@@ -233,6 +330,24 @@ export default function KeyEnrollmentGate({ mailboxUid, mailboxAddress, mailboxK
|
|
|
233
330
|
);
|
|
234
331
|
}
|
|
235
332
|
|
|
333
|
+
if (status === "already_set_up") {
|
|
334
|
+
return (
|
|
335
|
+
<div className="min-h-screen flex items-center justify-center p-8 bg-surface-alt">
|
|
336
|
+
<div className="w-full max-w-md bg-surface border border-border rounded-md p-8">
|
|
337
|
+
<h1 className="text-lg font-bold mb-2">Encryption is already set up</h1>
|
|
338
|
+
<p className="text-sm text-text-muted mb-5">
|
|
339
|
+
This mailbox’s encryption was set up in another tab or on another device while this
|
|
340
|
+
page was open, so nothing was changed here. Reload the page and unlock with the password
|
|
341
|
+
chosen there.
|
|
342
|
+
</p>
|
|
343
|
+
<Button type="button" onClick={() => window.location.reload()}>
|
|
344
|
+
Reload
|
|
345
|
+
</Button>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
236
351
|
if (status === "show_recovery_codes") {
|
|
237
352
|
return (
|
|
238
353
|
<div className="min-h-screen flex items-center justify-center p-8 bg-surface-alt">
|
|
@@ -242,13 +357,16 @@ export default function KeyEnrollmentGate({ mailboxUid, mailboxAddress, mailboxK
|
|
|
242
357
|
If you lose your password, these codes are the only way to recover your encrypted mail.
|
|
243
358
|
Each code can be used once. Store them somewhere safe — they will not be shown again.
|
|
244
359
|
</p>
|
|
245
|
-
<ul className="grid grid-cols-2 gap-2 mb-
|
|
360
|
+
<ul className="grid grid-cols-2 gap-2 mb-3 font-mono text-sm">
|
|
246
361
|
{recoveryCodes.map((code) => (
|
|
247
362
|
<li key={code} className="bg-surface-alt rounded-sm py-1.5 px-2 text-center">
|
|
248
363
|
{code}
|
|
249
364
|
</li>
|
|
250
365
|
))}
|
|
251
366
|
</ul>
|
|
367
|
+
<Button type="button" variant="secondary" className="!w-auto mb-5" onClick={handleCopyCodes}>
|
|
368
|
+
{codesCopied ? "Copied" : "Copy codes to clipboard"}
|
|
369
|
+
</Button>
|
|
252
370
|
<label className="flex items-center gap-2 text-sm mb-4">
|
|
253
371
|
<input type="checkbox" checked={codesSaved} onChange={(e) => setCodesSaved(e.target.checked)} />
|
|
254
372
|
I have saved these recovery codes in a safe place.
|
|
@@ -261,5 +379,11 @@ export default function KeyEnrollmentGate({ mailboxUid, mailboxAddress, mailboxK
|
|
|
261
379
|
);
|
|
262
380
|
}
|
|
263
381
|
|
|
264
|
-
return
|
|
382
|
+
return (
|
|
383
|
+
<>
|
|
384
|
+
{children}
|
|
385
|
+
{unopenableKeys && <UnopenableKeysNotice fingerprints={unopenableKeys} onDismiss={() => setUnopenableKeys(null)} />}
|
|
386
|
+
{followUp && <RecoveryFollowUpModal followUp={followUp} onDone={() => setFollowUp(null)} />}
|
|
387
|
+
</>
|
|
388
|
+
);
|
|
265
389
|
}
|
|
@@ -8,7 +8,7 @@ import { MailboxAutoProvisionAliasOption, autoProvisionMailbox } from "@rapidmx/
|
|
|
8
8
|
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
9
9
|
import Button from "@rapidmx/react-shared/components/buttons/Button.js";
|
|
10
10
|
|
|
11
|
-
type Status = "checking" | "needs_selection" | "creating" | "unavailable";
|
|
11
|
+
type Status = "checking" | "needs_selection" | "creating" | "unavailable" | "retryable";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Rendered by each app's shell (Mail/Calendar/Contacts/Tasks) *instead of* the normal `AppShell`
|
|
@@ -27,7 +27,11 @@ export default function MailboxProvisioning() {
|
|
|
27
27
|
const [selected, setSelected] = useState("");
|
|
28
28
|
const [error, setError] = useState<string | null>(null);
|
|
29
29
|
|
|
30
|
+
// Bumped by "Retry" to re-run the check below.
|
|
31
|
+
const [attempt, setAttempt] = useState(0);
|
|
32
|
+
|
|
30
33
|
useEffect(() => {
|
|
34
|
+
setStatus("checking");
|
|
31
35
|
autoProvisionMailbox()
|
|
32
36
|
.then((result) => {
|
|
33
37
|
if (result.status === "needs_selection") {
|
|
@@ -44,8 +48,10 @@ export default function MailboxProvisioning() {
|
|
|
44
48
|
window.location.reload();
|
|
45
49
|
}
|
|
46
50
|
})
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
// A 503 means the server couldn't read its own provisioning policy right now - not that there's no
|
|
52
|
+
// mailbox to be had - so it gets a retry instead of the permanent "ask an administrator" message.
|
|
53
|
+
.catch((err) => setStatus(err instanceof ApiRequestError && err.status === 503 ? "retryable" : "unavailable"));
|
|
54
|
+
}, [attempt]);
|
|
49
55
|
|
|
50
56
|
async function handleConfirm() {
|
|
51
57
|
// `selected` only ever takes a value from `options` itself (the initial default, or the
|
|
@@ -90,6 +96,16 @@ export default function MailboxProvisioning() {
|
|
|
90
96
|
</Button>
|
|
91
97
|
</div>
|
|
92
98
|
);
|
|
99
|
+
} else if (status === "retryable") {
|
|
100
|
+
content = (
|
|
101
|
+
<>
|
|
102
|
+
<h1 className="text-lg font-bold uppercase tracking-wide">Couldn’t check right now</h1>
|
|
103
|
+
<p className="text-sm text-text-muted">We couldn’t check whether a mailbox can be set up for you. Please try again.</p>
|
|
104
|
+
<Button type="button" onClick={() => setAttempt((n) => n + 1)} className="!w-auto self-center">
|
|
105
|
+
Retry
|
|
106
|
+
</Button>
|
|
107
|
+
</>
|
|
108
|
+
);
|
|
93
109
|
} else {
|
|
94
110
|
content = (
|
|
95
111
|
<>
|