@aeolus-fleet/core 0.33.0 → 0.34.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/README.md +24 -0
- package/dist/adapters/cli/fleet-api.d.ts +33 -0
- package/dist/adapters/cli/fleet-api.js +64 -0
- package/dist/adapters/cli/fleet-api.js.map +1 -0
- package/dist/adapters/cli/fleet-recover-keys.d.ts +22 -0
- package/dist/adapters/cli/fleet-recover-keys.js +81 -0
- package/dist/adapters/cli/fleet-recover-keys.js.map +1 -0
- package/dist/adapters/cli/run.js +1 -1
- package/dist/adapters/cli/run.js.map +1 -1
- package/dist/adapters/crypto/age-recovery-identity.d.ts +9 -0
- package/dist/adapters/crypto/age-recovery-identity.js +45 -0
- package/dist/adapters/crypto/age-recovery-identity.js.map +1 -0
- package/dist/adapters/crypto/age-recovery-keys.d.ts +2 -0
- package/dist/adapters/crypto/age-recovery-keys.js +36 -0
- package/dist/adapters/crypto/age-recovery-keys.js.map +1 -0
- package/dist/adapters/crypto/payload-sealer.d.ts +2 -0
- package/dist/adapters/crypto/payload-sealer.js +48 -0
- package/dist/adapters/crypto/payload-sealer.js.map +1 -0
- package/dist/adapters/kms/aws-kms-key-vault.d.ts +13 -0
- package/dist/adapters/kms/aws-kms-key-vault.js +98 -0
- package/dist/adapters/kms/aws-kms-key-vault.js.map +1 -0
- package/dist/adapters/kms/company-key-vault.d.ts +9 -0
- package/dist/adapters/kms/company-key-vault.js +14 -0
- package/dist/adapters/kms/company-key-vault.js.map +1 -0
- package/dist/adapters/kms/no-key-vault.d.ts +7 -0
- package/dist/adapters/kms/no-key-vault.js +11 -0
- package/dist/adapters/kms/no-key-vault.js.map +1 -0
- package/dist/adapters/prisma/feature-flags.d.ts +7 -0
- package/dist/adapters/prisma/feature-flags.js +29 -0
- package/dist/adapters/prisma/feature-flags.js.map +1 -0
- package/dist/adapters/prisma/generated/browser.d.ts +16 -1
- package/dist/adapters/prisma/generated/client.d.ts +16 -1
- package/dist/adapters/prisma/generated/commonInputTypes.d.ts +187 -97
- package/dist/adapters/prisma/generated/enums.d.ts +5 -0
- package/dist/adapters/prisma/generated/enums.js +4 -0
- package/dist/adapters/prisma/generated/enums.js.map +1 -1
- package/dist/adapters/prisma/generated/internal/class.d.ts +22 -0
- package/dist/adapters/prisma/generated/internal/class.js +4 -4
- package/dist/adapters/prisma/generated/internal/class.js.map +1 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespace.d.ts +203 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespace.js +36 -2
- package/dist/adapters/prisma/generated/internal/prismaNamespace.js.map +1 -1
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.d.ts +36 -0
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js +36 -2
- package/dist/adapters/prisma/generated/internal/prismaNamespaceBrowser.js.map +1 -1
- package/dist/adapters/prisma/generated/models/DataKey.d.ts +1503 -0
- package/dist/adapters/prisma/generated/models/DataKey.js +2 -0
- package/dist/adapters/prisma/generated/models/DataKey.js.map +1 -0
- package/dist/adapters/prisma/generated/models/Fleet.d.ts +2475 -2
- package/dist/adapters/prisma/generated/models/FleetFeatureFlag.d.ts +1117 -0
- package/dist/adapters/prisma/generated/models/FleetFeatureFlag.js +2 -0
- package/dist/adapters/prisma/generated/models/FleetFeatureFlag.js.map +1 -0
- package/dist/adapters/prisma/generated/models/Lease.d.ts +0 -7
- package/dist/adapters/prisma/generated/models/Message.d.ts +728 -62
- package/dist/adapters/prisma/generated/models/MessageDay.d.ts +1 -5
- package/dist/adapters/prisma/generated/models/Schedule.d.ts +657 -50
- package/dist/adapters/prisma/generated/models/Ship.d.ts +0 -3
- package/dist/adapters/prisma/generated/models.d.ts +2 -0
- package/dist/adapters/prisma/history-pruner.js +3 -2
- package/dist/adapters/prisma/history-pruner.js.map +1 -1
- package/dist/adapters/prisma/history.d.ts +2 -2
- package/dist/adapters/prisma/history.js +5 -7
- package/dist/adapters/prisma/history.js.map +1 -1
- package/dist/adapters/prisma/installation.js +14 -3
- package/dist/adapters/prisma/installation.js.map +1 -1
- package/dist/adapters/prisma/messaging.js +5 -3
- package/dist/adapters/prisma/messaging.js.map +1 -1
- package/dist/adapters/prisma/registry.js +2 -0
- package/dist/adapters/prisma/registry.js.map +1 -1
- package/dist/adapters/prisma/rows.d.ts +11 -0
- package/dist/adapters/prisma/rows.js +25 -2
- package/dist/adapters/prisma/rows.js.map +1 -1
- package/dist/adapters/prisma/schedules.d.ts +3 -0
- package/dist/adapters/prisma/schedules.js +5 -4
- package/dist/adapters/prisma/schedules.js.map +1 -1
- package/dist/adapters/prisma/sealings.d.ts +4 -0
- package/dist/adapters/prisma/sealings.js +211 -0
- package/dist/adapters/prisma/sealings.js.map +1 -0
- package/dist/adapters/prisma/unit-of-work.d.ts +4 -2
- package/dist/adapters/prisma/unit-of-work.js +4 -0
- package/dist/adapters/prisma/unit-of-work.js.map +1 -1
- package/dist/adapters/trpc/console.d.ts +13 -1
- package/dist/adapters/trpc/console.js +6 -3
- package/dist/adapters/trpc/console.js.map +1 -1
- package/dist/adapters/trpc/context.d.ts +16 -0
- package/dist/adapters/trpc/fleet.d.ts +150 -3
- package/dist/adapters/trpc/fleet.js +113 -11
- package/dist/adapters/trpc/fleet.js.map +1 -1
- package/dist/adapters/trpc/installation.d.ts +138 -2
- package/dist/adapters/trpc/installation.js +19 -3
- package/dist/adapters/trpc/installation.js.map +1 -1
- package/dist/adapters/trpc/listed-payload.d.ts +9 -0
- package/dist/adapters/trpc/listed-payload.js +8 -0
- package/dist/adapters/trpc/listed-payload.js.map +1 -0
- package/dist/adapters/trpc/router.d.ts +290 -3
- package/dist/adapters/trpc/ship-contract.js +1 -0
- package/dist/adapters/trpc/ship-contract.js.map +1 -1
- package/dist/adapters/trpc/ship.d.ts +11 -0
- package/dist/adapters/trpc/ship.js +3 -2
- package/dist/adapters/trpc/ship.js.map +1 -1
- package/dist/adapters/trpc/starting-prompt-text.js +2 -1
- package/dist/adapters/trpc/starting-prompt-text.js.map +1 -1
- package/dist/adapters/trpc/system.d.ts +10 -0
- package/dist/adapters/trpc/trpc.d.ts +15 -3
- package/dist/adapters/trpc/trpc.js +31 -6
- package/dist/adapters/trpc/trpc.js.map +1 -1
- package/dist/app.d.ts +3 -0
- package/dist/app.js +11 -1
- package/dist/app.js.map +1 -1
- package/dist/bin/aeolus-core.js +8 -1
- package/dist/bin/aeolus-core.js.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.js +8 -2
- package/dist/config.js.map +1 -1
- package/dist/domain/messaging/add-to-meeting.d.ts +6 -2
- package/dist/domain/messaging/add-to-meeting.js +7 -4
- package/dist/domain/messaging/add-to-meeting.js.map +1 -1
- package/dist/domain/messaging/change-company-key.d.ts +46 -0
- package/dist/domain/messaging/change-company-key.js +74 -0
- package/dist/domain/messaging/change-company-key.js.map +1 -0
- package/dist/domain/messaging/change-meeting.d.ts +6 -2
- package/dist/domain/messaging/change-meeting.js +6 -4
- package/dist/domain/messaging/change-meeting.js.map +1 -1
- package/dist/domain/messaging/change-mic.d.ts +6 -1
- package/dist/domain/messaging/change-mic.js +6 -3
- package/dist/domain/messaging/change-mic.js.map +1 -1
- package/dist/domain/messaging/change-recovery-key.d.ts +45 -0
- package/dist/domain/messaging/change-recovery-key.js +68 -0
- package/dist/domain/messaging/change-recovery-key.js.map +1 -0
- package/dist/domain/messaging/company-key-check.d.ts +20 -0
- package/dist/domain/messaging/company-key-check.js +31 -0
- package/dist/domain/messaging/company-key-check.js.map +1 -0
- package/dist/domain/messaging/data-keys.d.ts +165 -0
- package/dist/domain/messaging/data-keys.js +275 -0
- package/dist/domain/messaging/data-keys.js.map +1 -0
- package/dist/domain/messaging/fleet-sealing.d.ts +75 -0
- package/dist/domain/messaging/fleet-sealing.js +21 -0
- package/dist/domain/messaging/fleet-sealing.js.map +1 -0
- package/dist/domain/messaging/key-unavailable.d.ts +5 -0
- package/dist/domain/messaging/key-unavailable.js +14 -0
- package/dist/domain/messaging/key-unavailable.js.map +1 -0
- package/dist/domain/messaging/key-vault.d.ts +61 -0
- package/dist/domain/messaging/key-vault.js +2 -0
- package/dist/domain/messaging/key-vault.js.map +1 -0
- package/dist/domain/messaging/meeting-notice.d.ts +15 -13
- package/dist/domain/messaging/meeting-notice.js +12 -3
- package/dist/domain/messaging/meeting-notice.js.map +1 -1
- package/dist/domain/messaging/message.d.ts +17 -4
- package/dist/domain/messaging/message.js +19 -5
- package/dist/domain/messaging/message.js.map +1 -1
- package/dist/domain/messaging/open-meeting.d.ts +8 -2
- package/dist/domain/messaging/open-meeting.js +6 -1
- package/dist/domain/messaging/open-meeting.js.map +1 -1
- package/dist/domain/messaging/payload-sealer.d.ts +39 -0
- package/dist/domain/messaging/payload-sealer.js +2 -0
- package/dist/domain/messaging/payload-sealer.js.map +1 -0
- package/dist/domain/messaging/ping-ship.d.ts +4 -1
- package/dist/domain/messaging/ping-ship.js +6 -4
- package/dist/domain/messaging/ping-ship.js.map +1 -1
- package/dist/domain/messaging/ports.d.ts +98 -1
- package/dist/domain/messaging/public.d.ts +4 -1
- package/dist/domain/messaging/public.js +2 -0
- package/dist/domain/messaging/public.js.map +1 -1
- package/dist/domain/messaging/push-receive-deliveries.d.ts +4 -0
- package/dist/domain/messaging/push-receive-deliveries.js +8 -2
- package/dist/domain/messaging/push-receive-deliveries.js.map +1 -1
- package/dist/domain/messaging/read-delivery.d.ts +6 -2
- package/dist/domain/messaging/read-delivery.js +7 -4
- package/dist/domain/messaging/read-delivery.js.map +1 -1
- package/dist/domain/messaging/read-meeting.d.ts +9 -3
- package/dist/domain/messaging/read-meeting.js +11 -4
- package/dist/domain/messaging/read-meeting.js.map +1 -1
- package/dist/domain/messaging/read-recovery-set.d.ts +34 -0
- package/dist/domain/messaging/read-recovery-set.js +43 -0
- package/dist/domain/messaging/read-recovery-set.js.map +1 -0
- package/dist/domain/messaging/read-sealing.d.ts +30 -0
- package/dist/domain/messaging/read-sealing.js +28 -0
- package/dist/domain/messaging/read-sealing.js.map +1 -0
- package/dist/domain/messaging/receive-deliveries.d.ts +18 -6
- package/dist/domain/messaging/receive-deliveries.js +18 -6
- package/dist/domain/messaging/receive-deliveries.js.map +1 -1
- package/dist/domain/messaging/receive-reply.d.ts +2 -0
- package/dist/domain/messaging/receive-reply.js +2 -1
- package/dist/domain/messaging/receive-reply.js.map +1 -1
- package/dist/domain/messaging/recover-keys.d.ts +56 -0
- package/dist/domain/messaging/recover-keys.js +83 -0
- package/dist/domain/messaging/recover-keys.js.map +1 -0
- package/dist/domain/messaging/recovery-key.d.ts +25 -0
- package/dist/domain/messaging/recovery-key.js +14 -0
- package/dist/domain/messaging/recovery-key.js.map +1 -0
- package/dist/domain/messaging/reply-to-message.d.ts +2 -0
- package/dist/domain/messaging/reply-to-message.js +4 -3
- package/dist/domain/messaging/reply-to-message.js.map +1 -1
- package/dist/domain/messaging/resend-delivery.d.ts +9 -2
- package/dist/domain/messaging/resend-delivery.js +26 -6
- package/dist/domain/messaging/resend-delivery.js.map +1 -1
- package/dist/domain/messaging/retired-participant.d.ts +5 -2
- package/dist/domain/messaging/retired-participant.js +2 -1
- package/dist/domain/messaging/retired-participant.js.map +1 -1
- package/dist/domain/messaging/rotate-data-keys.d.ts +33 -0
- package/dist/domain/messaging/rotate-data-keys.js +52 -0
- package/dist/domain/messaging/rotate-data-keys.js.map +1 -0
- package/dist/domain/messaging/schedule-message.d.ts +10 -2
- package/dist/domain/messaging/schedule-message.js +43 -15
- package/dist/domain/messaging/schedule-message.js.map +1 -1
- package/dist/domain/messaging/schedule.d.ts +18 -1
- package/dist/domain/messaging/schedule.js +15 -0
- package/dist/domain/messaging/schedule.js.map +1 -1
- package/dist/domain/messaging/seal-stored-payloads.d.ts +45 -0
- package/dist/domain/messaging/seal-stored-payloads.js +122 -0
- package/dist/domain/messaging/seal-stored-payloads.js.map +1 -0
- package/dist/domain/messaging/sealed-payload.d.ts +9 -0
- package/dist/domain/messaging/sealed-payload.js +15 -0
- package/dist/domain/messaging/sealed-payload.js.map +1 -0
- package/dist/domain/messaging/send-due-schedules.d.ts +6 -0
- package/dist/domain/messaging/send-due-schedules.js +63 -16
- package/dist/domain/messaging/send-due-schedules.js.map +1 -1
- package/dist/domain/messaging/send-message.d.ts +20 -6
- package/dist/domain/messaging/send-message.js +51 -18
- package/dist/domain/messaging/send-message.js.map +1 -1
- package/dist/domain/messaging/send-request.d.ts +4 -2
- package/dist/domain/messaging/send-request.js +3 -2
- package/dist/domain/messaging/send-request.js.map +1 -1
- package/dist/domain/messaging/turn-on-sealing.d.ts +61 -0
- package/dist/domain/messaging/turn-on-sealing.js +76 -0
- package/dist/domain/messaging/turn-on-sealing.js.map +1 -0
- package/dist/domain/registry/create-fleet.d.ts +7 -3
- package/dist/domain/registry/create-fleet.js +9 -2
- package/dist/domain/registry/create-fleet.js.map +1 -1
- package/dist/domain/registry/feature-flag.d.ts +66 -0
- package/dist/domain/registry/feature-flag.js +56 -0
- package/dist/domain/registry/feature-flag.js.map +1 -0
- package/dist/domain/registry/get-ship.d.ts +2 -0
- package/dist/domain/registry/get-ship.js +1 -0
- package/dist/domain/registry/get-ship.js.map +1 -1
- package/dist/domain/registry/installation-fleet.d.ts +3 -1
- package/dist/domain/registry/installation-fleet.js +3 -1
- package/dist/domain/registry/installation-fleet.js.map +1 -1
- package/dist/domain/registry/lease.d.ts +1 -1
- package/dist/domain/registry/lease.js +1 -1
- package/dist/domain/registry/ports.d.ts +15 -1
- package/dist/domain/registry/public.d.ts +2 -0
- package/dist/domain/registry/public.js +1 -0
- package/dist/domain/registry/public.js.map +1 -1
- package/dist/domain/registry/read-feature-flags.d.ts +16 -0
- package/dist/domain/registry/read-feature-flags.js +11 -0
- package/dist/domain/registry/read-feature-flags.js.map +1 -0
- package/dist/domain/registry/retire-ship.d.ts +6 -2
- package/dist/domain/registry/retire-ship.js +7 -4
- package/dist/domain/registry/retire-ship.js.map +1 -1
- package/dist/domain/registry/set-feature-flag.d.ts +34 -0
- package/dist/domain/registry/set-feature-flag.js +37 -0
- package/dist/domain/registry/set-feature-flag.js.map +1 -0
- package/dist/domain/shared/errors.d.ts +1 -1
- package/dist/domain/shared/errors.js.map +1 -1
- package/dist/domain/shared/history.d.ts +22 -21
- package/dist/domain/shared/plain-history.d.ts +45 -0
- package/dist/domain/shared/plain-history.js +35 -0
- package/dist/domain/shared/plain-history.js.map +1 -0
- package/dist/domain/shared/read-health.d.ts +14 -3
- package/dist/domain/shared/read-health.js +8 -4
- package/dist/domain/shared/read-health.js.map +1 -1
- package/dist/domain/shared/read-inbox-message.d.ts +7 -2
- package/dist/domain/shared/read-inbox-message.js +5 -1
- package/dist/domain/shared/read-inbox-message.js.map +1 -1
- package/dist/domain/shared/read-inbox-withdrawals.d.ts +9 -3
- package/dist/domain/shared/read-inbox-withdrawals.js +7 -3
- package/dist/domain/shared/read-inbox-withdrawals.js.map +1 -1
- package/dist/domain/shared/read-inbox.d.ts +14 -4
- package/dist/domain/shared/read-inbox.js +7 -3
- package/dist/domain/shared/read-inbox.js.map +1 -1
- package/dist/domain/shared/read-message.d.ts +11 -2
- package/dist/domain/shared/read-message.js +6 -2
- package/dist/domain/shared/read-message.js.map +1 -1
- package/dist/domain/shared/read-needs-attention.d.ts +6 -2
- package/dist/domain/shared/read-needs-attention.js +7 -5
- package/dist/domain/shared/read-needs-attention.js.map +1 -1
- package/dist/domain/shared/read-ship-messages.d.ts +10 -1
- package/dist/domain/shared/read-ship-messages.js +9 -3
- package/dist/domain/shared/read-ship-messages.js.map +1 -1
- package/dist/start.js +2 -0
- package/dist/start.js.map +1 -1
- package/dist/testing/container-images.d.ts +13 -6
- package/dist/testing/container-images.js +14 -7
- package/dist/testing/container-images.js.map +1 -1
- package/dist/wiring.d.ts +26 -0
- package/dist/wiring.js +57 -20
- package/dist/wiring.js.map +1 -1
- package/package.json +4 -2
- package/src/adapters/prisma/migrations/20261029120000_data_keys/migration.sql +23 -0
- package/src/adapters/prisma/migrations/20261029180000_sealed_messages/migration.sql +42 -0
- package/src/adapters/prisma/migrations/20261029200000_sealed_schedules/migration.sql +20 -0
- package/src/adapters/prisma/migrations/20261030090000_key_availability/migration.sql +18 -0
- package/src/adapters/prisma/migrations/20261030120000_keys_scope/migration.sql +64 -0
- package/src/adapters/prisma/migrations/20261031090000_recovery_key/migration.sql +11 -0
- package/src/adapters/prisma/migrations/20261101090000_sealing_progress/migration.sql +16 -0
- package/src/adapters/prisma/migrations/20261102090000_feature_flags/migration.sql +17 -0
- package/src/adapters/prisma/schema.prisma +104 -23
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sealing and unsealing payloads inside a use case (decision 0068, B8, B9).
|
|
3
|
+
* No key vault call runs inside a unit of work: the work seals and unseals
|
|
4
|
+
* with the data keys it holds, and when it meets one it does not hold it
|
|
5
|
+
* answers which it needs, so its unit of work rolls back, storing and
|
|
6
|
+
* claiming nothing. The keys are then unwrapped outside it and the work runs
|
|
7
|
+
* again with them; a key the vault does not give refuses KEY_UNAVAILABLE.
|
|
8
|
+
*/
|
|
9
|
+
import { type DataKeyId, type FleetId, type IdGenerator } from '@aeolus-fleet/common';
|
|
10
|
+
import type { Clock } from '../shared/clock.js';
|
|
11
|
+
import { type DomainError } from '../shared/errors.js';
|
|
12
|
+
import { type EventLog } from '../shared/events.js';
|
|
13
|
+
import type { UnitOfWork } from '../shared/unit-of-work.js';
|
|
14
|
+
import { type Result } from '../shared/result.js';
|
|
15
|
+
import type { CompanyKeyReference, KeyUnavailable, KeyVault, WrappedDataKey } from './key-vault.js';
|
|
16
|
+
import type { DataKey, PayloadSealer, SealedRow } from './payload-sealer.js';
|
|
17
|
+
import type { Message } from './message.js';
|
|
18
|
+
import type { FleetSealingRepository } from './ports.js';
|
|
19
|
+
import type { RecoveryKey, RecoveryKeys } from './recovery-key.js';
|
|
20
|
+
import { type StoredPayload } from './sealed-payload.js';
|
|
21
|
+
/** The work met data keys it does not hold: its unit of work rolls back, and it runs again with them. */
|
|
22
|
+
export interface DataKeysNeeded {
|
|
23
|
+
readonly kind: 'dataKeysNeeded';
|
|
24
|
+
readonly dataKeyIds: readonly DataKeyId[];
|
|
25
|
+
}
|
|
26
|
+
/** What a unit of work seals and unseals with: the sealer, and the fleet's data keys unwrapped before it began. */
|
|
27
|
+
export interface HeldDataKeys {
|
|
28
|
+
readonly sealer: PayloadSealer;
|
|
29
|
+
readonly keys: ReadonlyMap<DataKeyId, DataKey>;
|
|
30
|
+
/** For a list: the data keys the vault did not give, whose payloads it marks unreadable (B9). */
|
|
31
|
+
readonly unreachable?: ReadonlySet<DataKeyId>;
|
|
32
|
+
}
|
|
33
|
+
/** A payload a list cannot unseal: its data key is not reachable, or it does not open for its row (B9). */
|
|
34
|
+
export interface UnreadablePayload {
|
|
35
|
+
readonly kind: 'unreadable';
|
|
36
|
+
}
|
|
37
|
+
export declare const UNREADABLE_PAYLOAD: UnreadablePayload;
|
|
38
|
+
/** A payload as a list answers it: plain, or marked unreadable while the rest are listed (B9). */
|
|
39
|
+
export type ListedPayload = string | UnreadablePayload;
|
|
40
|
+
/** A new data key for a fleet, kept only wrapped: the company key and the recovery key that wrap it, its wraps and its check value. */
|
|
41
|
+
export interface NewDataKey {
|
|
42
|
+
readonly companyKey: CompanyKeyReference;
|
|
43
|
+
readonly wrappedByCompanyKey: WrappedDataKey;
|
|
44
|
+
readonly recoveryKey: RecoveryKey | null;
|
|
45
|
+
readonly wrappedByRecoveryKey: WrappedDataKey | null;
|
|
46
|
+
readonly checkValue: Uint8Array<ArrayBuffer>;
|
|
47
|
+
}
|
|
48
|
+
/** Unwraps a fleet's data keys through its company key, outside every unit of work. */
|
|
49
|
+
export interface FleetDataKeys {
|
|
50
|
+
unwrap(fleetId: FleetId, dataKeyIds: readonly DataKeyId[]): Promise<Result<DataKey[], KeyUnavailable>>;
|
|
51
|
+
}
|
|
52
|
+
/** Makes a fleet's new data key through its company key, outside every unit of work, for the data key rotation (B13a). */
|
|
53
|
+
export interface FleetDataKeyMaker {
|
|
54
|
+
make(fleetId: FleetId): Promise<Result<NewDataKey, KeyUnavailable>>;
|
|
55
|
+
}
|
|
56
|
+
/** What a use case seals and unseals payloads with. */
|
|
57
|
+
export interface PayloadSealing {
|
|
58
|
+
readonly sealer: PayloadSealer;
|
|
59
|
+
readonly dataKeys: FleetDataKeys;
|
|
60
|
+
}
|
|
61
|
+
export declare function isDataKeysNeeded(error: unknown): error is DataKeysNeeded;
|
|
62
|
+
/** How long a server keeps a data key it unwrapped in memory (N2): a cut grant or a disabled key bites within it. */
|
|
63
|
+
export declare const DATA_KEY_CACHE_MS: number;
|
|
64
|
+
/** What a change of the company key's availability is written through. */
|
|
65
|
+
export interface KeyAvailabilityTx {
|
|
66
|
+
sealings: Pick<FleetSealingRepository, 'changeKeyAvailability'>;
|
|
67
|
+
events: EventLog;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The fleet's data keys from their wraps, each checked against its check
|
|
71
|
+
* value, so a vault that answered another key is refused as a wrap that
|
|
72
|
+
* does not open. Each key unwrapped is kept in this server's memory for 5
|
|
73
|
+
* minutes from its unwrap (B11), never longer, never on disk, so the key
|
|
74
|
+
* vault is asked once per key and period, and a company that cuts its grant
|
|
75
|
+
* stops every seal and unseal within 5 minutes. Each answer of the key vault
|
|
76
|
+
* that changes the company key's availability writes it with its event in one
|
|
77
|
+
* unit of work: FleetKeyUnavailable with the vault's reason on the first
|
|
78
|
+
* refusal after a success, FleetKeyAvailable on the first success after; a
|
|
79
|
+
* wrap that does not open is the key answering, and changes nothing. A new
|
|
80
|
+
* data key for the rotation is made under the company key the fleet names
|
|
81
|
+
* then, its answer written the same way, and wrapped to the recovery key the
|
|
82
|
+
* fleet names then, when it has one.
|
|
83
|
+
*/
|
|
84
|
+
export declare function createFleetDataKeys(deps: {
|
|
85
|
+
sealings: Pick<FleetSealingRepository, 'find' | 'wrappedDataKeys'>;
|
|
86
|
+
vault: KeyVault;
|
|
87
|
+
sealer: PayloadSealer;
|
|
88
|
+
recoveryKeys: RecoveryKeys;
|
|
89
|
+
clock: Clock;
|
|
90
|
+
uow: UnitOfWork<KeyAvailabilityTx>;
|
|
91
|
+
ids: IdGenerator;
|
|
92
|
+
}): FleetDataKeys & FleetDataKeyMaker;
|
|
93
|
+
/**
|
|
94
|
+
* Runs the work, holding no key at first, and again with the keys it met,
|
|
95
|
+
* unwrapped outside its unit of work. A fleet that is not sealed never meets
|
|
96
|
+
* one, so its work runs once and the key vault is never called. A key the
|
|
97
|
+
* vault does not give refuses KEY_UNAVAILABLE.
|
|
98
|
+
*/
|
|
99
|
+
export declare function withDataKeys<T, E>(of: {
|
|
100
|
+
sealing: PayloadSealing;
|
|
101
|
+
fleetId: FleetId;
|
|
102
|
+
}, work: (held: HeldDataKeys) => Promise<Result<T, E | DataKeysNeeded>>): Promise<Result<T, E | DomainError<'KEY_UNAVAILABLE'>>>;
|
|
103
|
+
/**
|
|
104
|
+
* As {@link withDataKeys}, for a read that lists several payloads (B9): a key
|
|
105
|
+
* the vault does not give is held as unreachable, and the work runs again, so
|
|
106
|
+
* it marks the payloads under it unreadable with {@link listedUnsealed} and
|
|
107
|
+
* lists the rest.
|
|
108
|
+
*/
|
|
109
|
+
export declare function withDataKeysForList<T, E>(of: {
|
|
110
|
+
sealing: PayloadSealing;
|
|
111
|
+
fleetId: FleetId;
|
|
112
|
+
}, work: (held: HeldDataKeys) => Promise<Result<T, E | DataKeysNeeded>>): Promise<Result<T, E | DomainError<'KEY_UNAVAILABLE'>>>;
|
|
113
|
+
/**
|
|
114
|
+
* The data keys a read that lists several payloads holds (B9): each key its
|
|
115
|
+
* stored payloads were sealed under, unwrapped on its own, outside any unit of
|
|
116
|
+
* work; a key the vault does not give is held as unreachable, never refused.
|
|
117
|
+
*/
|
|
118
|
+
export declare function heldForList(of: {
|
|
119
|
+
sealing: PayloadSealing;
|
|
120
|
+
fleetId: FleetId;
|
|
121
|
+
}, payloads: readonly StoredPayload[]): Promise<HeldDataKeys>;
|
|
122
|
+
/**
|
|
123
|
+
* The payload as a list answers it (B9): plain, or unreadable when its data
|
|
124
|
+
* key is unreachable or it does not open for its row; a key neither held nor
|
|
125
|
+
* unreachable is still needed.
|
|
126
|
+
*/
|
|
127
|
+
export declare function listedUnsealed(held: HeldDataKeys, stored: {
|
|
128
|
+
row: SealedRow;
|
|
129
|
+
payload: StoredPayload;
|
|
130
|
+
}): Result<ListedPayload, DataKeysNeeded>;
|
|
131
|
+
/** The payload sealed under the fleet's current data key, or plain in a fleet that has none. */
|
|
132
|
+
export declare function sealedFor(held: HeldDataKeys, sealing: {
|
|
133
|
+
currentDataKeyId: DataKeyId | undefined;
|
|
134
|
+
row: SealedRow;
|
|
135
|
+
payload: string;
|
|
136
|
+
}): Result<StoredPayload, DataKeysNeeded>;
|
|
137
|
+
/** The plain payload of a stored one; a sealed payload that does not open for its row refuses KEY_UNAVAILABLE. */
|
|
138
|
+
export declare function unsealed(held: HeldDataKeys, stored: {
|
|
139
|
+
row: SealedRow;
|
|
140
|
+
payload: StoredPayload;
|
|
141
|
+
}): Result<string, DataKeysNeeded | DomainError<'KEY_UNAVAILABLE'>>;
|
|
142
|
+
/** The message as the fleet stores it: sealed in a sealed fleet, under its current data key, with the request hash that leaves the payload out. */
|
|
143
|
+
export declare function sealedMessage(deps: {
|
|
144
|
+
tx: {
|
|
145
|
+
sealings: Pick<FleetSealingRepository, 'currentDataKeyId'>;
|
|
146
|
+
};
|
|
147
|
+
held: HeldDataKeys;
|
|
148
|
+
}, accepted: {
|
|
149
|
+
message: Message;
|
|
150
|
+
sealedRequestHash: string;
|
|
151
|
+
}): Promise<Result<Message, DataKeysNeeded>>;
|
|
152
|
+
/**
|
|
153
|
+
* The data keys a read that claims nothing holds (decision 0068, B9): every
|
|
154
|
+
* key its stored payloads were sealed under, each unwrapped once, outside
|
|
155
|
+
* any unit of work. A key the vault does not give refuses KEY_UNAVAILABLE.
|
|
156
|
+
*/
|
|
157
|
+
export declare function heldForRead(of: {
|
|
158
|
+
sealing: PayloadSealing;
|
|
159
|
+
fleetId: FleetId;
|
|
160
|
+
}, payloads: readonly StoredPayload[]): Promise<Result<HeldDataKeys, DomainError<'KEY_UNAVAILABLE'>>>;
|
|
161
|
+
/** The plain payload of a stored one, with the keys {@link heldForRead} unwrapped; one that does not open refuses KEY_UNAVAILABLE. */
|
|
162
|
+
export declare function plainForRead(held: HeldDataKeys, stored: {
|
|
163
|
+
row: SealedRow;
|
|
164
|
+
payload: StoredPayload;
|
|
165
|
+
}): Result<string, DomainError<'KEY_UNAVAILABLE'>>;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sealing and unsealing payloads inside a use case (decision 0068, B8, B9).
|
|
3
|
+
* No key vault call runs inside a unit of work: the work seals and unseals
|
|
4
|
+
* with the data keys it holds, and when it meets one it does not hold it
|
|
5
|
+
* answers which it needs, so its unit of work rolls back, storing and
|
|
6
|
+
* claiming nothing. The keys are then unwrapped outside it and the work runs
|
|
7
|
+
* again with them; a key the vault does not give refuses KEY_UNAVAILABLE.
|
|
8
|
+
*/
|
|
9
|
+
import { payloadBytes } from '@aeolus-fleet/common';
|
|
10
|
+
import { refuse } from '../shared/errors.js';
|
|
11
|
+
import { recordEvent, SYSTEM } from '../shared/events.js';
|
|
12
|
+
import { err, ok } from '../shared/result.js';
|
|
13
|
+
import { keyUnavailable } from './key-unavailable.js';
|
|
14
|
+
import { isSealedPayload } from './sealed-payload.js';
|
|
15
|
+
export const UNREADABLE_PAYLOAD = { kind: 'unreadable' };
|
|
16
|
+
/** How often the work runs again for keys it met: each run holds every key the runs before it met. */
|
|
17
|
+
const MAX_RUNS = 3;
|
|
18
|
+
export function isDataKeysNeeded(error) {
|
|
19
|
+
return typeof error === 'object' && error !== null && 'kind' in error && error.kind === 'dataKeysNeeded';
|
|
20
|
+
}
|
|
21
|
+
/** How long a server keeps a data key it unwrapped in memory (N2): a cut grant or a disabled key bites within it. */
|
|
22
|
+
export const DATA_KEY_CACHE_MS = 5 * 60 * 1000;
|
|
23
|
+
/**
|
|
24
|
+
* The fleet's data keys from their wraps, each checked against its check
|
|
25
|
+
* value, so a vault that answered another key is refused as a wrap that
|
|
26
|
+
* does not open. Each key unwrapped is kept in this server's memory for 5
|
|
27
|
+
* minutes from its unwrap (B11), never longer, never on disk, so the key
|
|
28
|
+
* vault is asked once per key and period, and a company that cuts its grant
|
|
29
|
+
* stops every seal and unseal within 5 minutes. Each answer of the key vault
|
|
30
|
+
* that changes the company key's availability writes it with its event in one
|
|
31
|
+
* unit of work: FleetKeyUnavailable with the vault's reason on the first
|
|
32
|
+
* refusal after a success, FleetKeyAvailable on the first success after; a
|
|
33
|
+
* wrap that does not open is the key answering, and changes nothing. A new
|
|
34
|
+
* data key for the rotation is made under the company key the fleet names
|
|
35
|
+
* then, its answer written the same way, and wrapped to the recovery key the
|
|
36
|
+
* fleet names then, when it has one.
|
|
37
|
+
*/
|
|
38
|
+
export function createFleetDataKeys(deps) {
|
|
39
|
+
// Keyed by fleet and data key, so a fleet is answered only the keys it holds.
|
|
40
|
+
const cache = new Map();
|
|
41
|
+
const heldNow = (now) => {
|
|
42
|
+
for (const [id, cached] of cache) {
|
|
43
|
+
if (now - cached.unwrappedAt >= DATA_KEY_CACHE_MS) {
|
|
44
|
+
cache.delete(id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const changeAvailability = async (fleetId, availability) => {
|
|
49
|
+
await deps.uow.run(async (tx) => {
|
|
50
|
+
if (await tx.sealings.changeKeyAvailability(fleetId, availability)) {
|
|
51
|
+
await recordEvent({ events: tx.events, ids: deps.ids }, availability.isAvailable
|
|
52
|
+
? { fleetId, type: 'FleetKeyAvailable', occurredAt: availability.since, actor: SYSTEM }
|
|
53
|
+
: { fleetId, type: 'FleetKeyUnavailable', occurredAt: availability.since, actor: SYSTEM, details: { reason: availability.reason } });
|
|
54
|
+
}
|
|
55
|
+
return ok(undefined);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
/** The key vault's answer, its change of the company key's availability written. */
|
|
59
|
+
const answered = async (fleetId, answer) => {
|
|
60
|
+
const { at, outcome } = answer;
|
|
61
|
+
if (outcome.isOk) {
|
|
62
|
+
await changeAvailability(fleetId, { isAvailable: true, since: at });
|
|
63
|
+
}
|
|
64
|
+
else if (outcome.error.reason !== 'invalidWrap') {
|
|
65
|
+
await changeAvailability(fleetId, { isAvailable: false, reason: outcome.error.reason, since: at });
|
|
66
|
+
}
|
|
67
|
+
return outcome;
|
|
68
|
+
};
|
|
69
|
+
const unwrapped = async (fleetId, dataKeyIds) => {
|
|
70
|
+
const now = deps.clock.now();
|
|
71
|
+
const wrapped = await deps.sealings.wrappedDataKeys(fleetId, dataKeyIds);
|
|
72
|
+
if (wrapped?.dataKeys.length !== dataKeyIds.length) {
|
|
73
|
+
return err({ kind: 'keyUnavailable', reason: 'notFound' });
|
|
74
|
+
}
|
|
75
|
+
for (const dataKey of wrapped.dataKeys) {
|
|
76
|
+
const material = await answered(fleetId, { at: now, outcome: await deps.vault.unwrap({ fleetId, companyKey: wrapped.companyKey }, dataKey.wrappedByCompanyKey) });
|
|
77
|
+
if (!material.isOk) {
|
|
78
|
+
return material;
|
|
79
|
+
}
|
|
80
|
+
if (!Buffer.from(deps.sealer.checkValue(material.value)).equals(dataKey.checkValue)) {
|
|
81
|
+
return err({ kind: 'keyUnavailable', reason: 'invalidWrap' });
|
|
82
|
+
}
|
|
83
|
+
cache.set(`${fleetId}/${dataKey.id}`, { dataKey: { id: dataKey.id, material: material.value }, unwrappedAt: now.getTime() });
|
|
84
|
+
}
|
|
85
|
+
return ok(undefined);
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
unwrap: async (fleetId, dataKeyIds) => {
|
|
89
|
+
heldNow(deps.clock.now().getTime());
|
|
90
|
+
const missing = dataKeyIds.filter((id) => !cache.has(`${fleetId}/${id}`));
|
|
91
|
+
if (missing.length > 0) {
|
|
92
|
+
const outcome = await unwrapped(fleetId, missing);
|
|
93
|
+
if (!outcome.isOk) {
|
|
94
|
+
return outcome;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return ok(dataKeyIds.flatMap((id) => {
|
|
98
|
+
const cached = cache.get(`${fleetId}/${id}`);
|
|
99
|
+
return cached === undefined ? [] : [cached.dataKey];
|
|
100
|
+
}));
|
|
101
|
+
},
|
|
102
|
+
make: async (fleetId) => {
|
|
103
|
+
const sealing = await deps.sealings.find(fleetId);
|
|
104
|
+
if (sealing === undefined) {
|
|
105
|
+
return err({ kind: 'keyUnavailable', reason: 'notFound' });
|
|
106
|
+
}
|
|
107
|
+
const { companyKey, recoveryKey } = sealing;
|
|
108
|
+
const made = await answered(fleetId, { at: deps.clock.now(), outcome: await deps.vault.makeDataKey({ fleetId, companyKey }) });
|
|
109
|
+
if (!made.isOk) {
|
|
110
|
+
return made;
|
|
111
|
+
}
|
|
112
|
+
const { material, wrapped } = made.value;
|
|
113
|
+
const wrappedByRecoveryKey = recoveryKey === null ? null : await deps.recoveryKeys.wrap(recoveryKey, material);
|
|
114
|
+
return ok({ companyKey, wrappedByCompanyKey: wrapped, recoveryKey, wrappedByRecoveryKey, checkValue: deps.sealer.checkValue(material) });
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Runs the work, holding no key at first, and again with the keys it met,
|
|
120
|
+
* unwrapped outside its unit of work. A fleet that is not sealed never meets
|
|
121
|
+
* one, so its work runs once and the key vault is never called. A key the
|
|
122
|
+
* vault does not give refuses KEY_UNAVAILABLE.
|
|
123
|
+
*/
|
|
124
|
+
export function withDataKeys(of, work) {
|
|
125
|
+
return runWithDataKeys(of, { work, onUnreachable: 'refuse' });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* As {@link withDataKeys}, for a read that lists several payloads (B9): a key
|
|
129
|
+
* the vault does not give is held as unreachable, and the work runs again, so
|
|
130
|
+
* it marks the payloads under it unreadable with {@link listedUnsealed} and
|
|
131
|
+
* lists the rest.
|
|
132
|
+
*/
|
|
133
|
+
export function withDataKeysForList(of, work) {
|
|
134
|
+
return runWithDataKeys(of, { work, onUnreachable: 'markUnreadable' });
|
|
135
|
+
}
|
|
136
|
+
async function runWithDataKeys(of, run) {
|
|
137
|
+
const { sealing, fleetId } = of;
|
|
138
|
+
const keys = new Map();
|
|
139
|
+
const unreachable = new Set();
|
|
140
|
+
for (let attempt = 1;; attempt += 1) {
|
|
141
|
+
const outcome = await run.work({ sealer: sealing.sealer, keys, unreachable });
|
|
142
|
+
if (outcome.isOk) {
|
|
143
|
+
return outcome;
|
|
144
|
+
}
|
|
145
|
+
const { error } = outcome;
|
|
146
|
+
if (!isDataKeysNeeded(error)) {
|
|
147
|
+
return err(error);
|
|
148
|
+
}
|
|
149
|
+
if (attempt === MAX_RUNS) {
|
|
150
|
+
return refuse('KEY_UNAVAILABLE', "The fleet's data keys changed while this call ran: call again");
|
|
151
|
+
}
|
|
152
|
+
const missing = error.dataKeyIds.filter((id) => !keys.has(id) && !unreachable.has(id));
|
|
153
|
+
if (run.onUnreachable === 'markUnreadable') {
|
|
154
|
+
await heldEach({ sealing, fleetId }, { dataKeyIds: missing, keys, unreachable });
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const unwrapped = await sealing.dataKeys.unwrap(fleetId, missing);
|
|
158
|
+
if (!unwrapped.isOk) {
|
|
159
|
+
return keyUnavailable(unwrapped.error);
|
|
160
|
+
}
|
|
161
|
+
for (const dataKey of unwrapped.value) {
|
|
162
|
+
keys.set(dataKey.id, dataKey);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** Unwraps each data key on its own, holding those the vault gives and noting those it does not. */
|
|
167
|
+
async function heldEach(of, into) {
|
|
168
|
+
for (const id of into.dataKeyIds) {
|
|
169
|
+
const unwrapped = await of.sealing.dataKeys.unwrap(of.fleetId, [id]);
|
|
170
|
+
if (!unwrapped.isOk) {
|
|
171
|
+
into.unreachable.add(id);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
for (const dataKey of unwrapped.value) {
|
|
175
|
+
into.keys.set(dataKey.id, dataKey);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The data keys a read that lists several payloads holds (B9): each key its
|
|
181
|
+
* stored payloads were sealed under, unwrapped on its own, outside any unit of
|
|
182
|
+
* work; a key the vault does not give is held as unreachable, never refused.
|
|
183
|
+
*/
|
|
184
|
+
export async function heldForList(of, payloads) {
|
|
185
|
+
const keys = new Map();
|
|
186
|
+
const unreachable = new Set();
|
|
187
|
+
const dataKeyIds = [...new Set(payloads.flatMap((payload) => (isSealedPayload(payload) ? [payload.sealed.dataKeyId] : [])))];
|
|
188
|
+
await heldEach(of, { dataKeyIds, keys, unreachable });
|
|
189
|
+
return { sealer: of.sealing.sealer, keys, unreachable };
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The payload as a list answers it (B9): plain, or unreadable when its data
|
|
193
|
+
* key is unreachable or it does not open for its row; a key neither held nor
|
|
194
|
+
* unreachable is still needed.
|
|
195
|
+
*/
|
|
196
|
+
export function listedUnsealed(held, stored) {
|
|
197
|
+
const { payload } = stored;
|
|
198
|
+
if (isSealedPayload(payload) && held.unreachable?.has(payload.sealed.dataKeyId) === true) {
|
|
199
|
+
return ok(UNREADABLE_PAYLOAD);
|
|
200
|
+
}
|
|
201
|
+
const plain = unsealed(held, stored);
|
|
202
|
+
if (plain.isOk) {
|
|
203
|
+
return plain;
|
|
204
|
+
}
|
|
205
|
+
return isDataKeysNeeded(plain.error) ? err(plain.error) : ok(UNREADABLE_PAYLOAD);
|
|
206
|
+
}
|
|
207
|
+
/** The payload sealed under the fleet's current data key, or plain in a fleet that has none. */
|
|
208
|
+
export function sealedFor(held, sealing) {
|
|
209
|
+
const { currentDataKeyId, row, payload } = sealing;
|
|
210
|
+
if (currentDataKeyId === undefined) {
|
|
211
|
+
return ok(payload);
|
|
212
|
+
}
|
|
213
|
+
const key = held.keys.get(currentDataKeyId);
|
|
214
|
+
if (key === undefined) {
|
|
215
|
+
return err({ kind: 'dataKeysNeeded', dataKeyIds: [currentDataKeyId] });
|
|
216
|
+
}
|
|
217
|
+
return ok({ sealed: held.sealer.seal({ key, row }, payload), plainBytes: payloadBytes(payload) });
|
|
218
|
+
}
|
|
219
|
+
/** The plain payload of a stored one; a sealed payload that does not open for its row refuses KEY_UNAVAILABLE. */
|
|
220
|
+
export function unsealed(held, stored) {
|
|
221
|
+
const { row, payload } = stored;
|
|
222
|
+
if (!isSealedPayload(payload)) {
|
|
223
|
+
return ok(payload);
|
|
224
|
+
}
|
|
225
|
+
const key = held.keys.get(payload.sealed.dataKeyId);
|
|
226
|
+
if (key === undefined) {
|
|
227
|
+
return err({ kind: 'dataKeysNeeded', dataKeyIds: [payload.sealed.dataKeyId] });
|
|
228
|
+
}
|
|
229
|
+
const opened = held.sealer.unseal({ key, row }, payload.sealed);
|
|
230
|
+
return opened.isOk ? opened : refuse('KEY_UNAVAILABLE', `The sealed payload of ${row.rowId} does not open under its data key`);
|
|
231
|
+
}
|
|
232
|
+
/** The message as the fleet stores it: sealed in a sealed fleet, under its current data key, with the request hash that leaves the payload out. */
|
|
233
|
+
export async function sealedMessage(deps, accepted) {
|
|
234
|
+
const { message, sealedRequestHash } = accepted;
|
|
235
|
+
if (typeof message.payload !== 'string') {
|
|
236
|
+
return ok(message);
|
|
237
|
+
}
|
|
238
|
+
const currentDataKeyId = await deps.tx.sealings.currentDataKeyId(message.fleetId);
|
|
239
|
+
const payload = sealedFor(deps.held, { currentDataKeyId, row: { fleetId: message.fleetId, rowId: message.id }, payload: message.payload });
|
|
240
|
+
if (!payload.isOk) {
|
|
241
|
+
return payload;
|
|
242
|
+
}
|
|
243
|
+
return ok(typeof payload.value === 'string' ? message : { ...message, payload: payload.value, requestHash: sealedRequestHash });
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The data keys a read that claims nothing holds (decision 0068, B9): every
|
|
247
|
+
* key its stored payloads were sealed under, each unwrapped once, outside
|
|
248
|
+
* any unit of work. A key the vault does not give refuses KEY_UNAVAILABLE.
|
|
249
|
+
*/
|
|
250
|
+
export async function heldForRead(of, payloads) {
|
|
251
|
+
const { sealing, fleetId } = of;
|
|
252
|
+
const dataKeyIds = [...new Set(payloads.flatMap((payload) => (isSealedPayload(payload) ? [payload.sealed.dataKeyId] : [])))];
|
|
253
|
+
const keys = new Map();
|
|
254
|
+
if (dataKeyIds.length > 0) {
|
|
255
|
+
const unwrapped = await sealing.dataKeys.unwrap(fleetId, dataKeyIds);
|
|
256
|
+
if (!unwrapped.isOk) {
|
|
257
|
+
return keyUnavailable(unwrapped.error);
|
|
258
|
+
}
|
|
259
|
+
for (const dataKey of unwrapped.value) {
|
|
260
|
+
keys.set(dataKey.id, dataKey);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return ok({ sealer: sealing.sealer, keys });
|
|
264
|
+
}
|
|
265
|
+
/** The plain payload of a stored one, with the keys {@link heldForRead} unwrapped; one that does not open refuses KEY_UNAVAILABLE. */
|
|
266
|
+
export function plainForRead(held, stored) {
|
|
267
|
+
const plain = unsealed(held, stored);
|
|
268
|
+
if (plain.isOk) {
|
|
269
|
+
return plain;
|
|
270
|
+
}
|
|
271
|
+
const { error } = plain;
|
|
272
|
+
// heldForRead unwrapped every key these payloads name: one not held is never met.
|
|
273
|
+
return isDataKeysNeeded(error) ? refuse('KEY_UNAVAILABLE', `The data key of ${stored.row.rowId} is not held`) : err(error);
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=data-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-keys.js","sourceRoot":"","sources":["../../../src/domain/messaging/data-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAkD,MAAM,sBAAsB,CAAC;AAGpG,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAC/D,OAAO,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SAAS,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;YACpB,OAAO,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC;QACD,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;YACtC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,sIAAsI;AACtI,MAAM,UAAU,YAAY,CAAC,IAAkB,EAAE,MAAkD;IACjG,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACrC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACxB,kFAAkF;IAClF,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,iBAAiB,EAAE,mBAAmB,MAAM,CAAC,GAAG,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC7H,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sealed fleet (decision 0068): it stores no payload readable. Its sealing
|
|
3
|
+
* names the company key that wraps its data keys; each data key is kept only
|
|
4
|
+
* wrapped, with a check value that proves an unwrap gave the right key.
|
|
5
|
+
*/
|
|
6
|
+
import type { DataKeyId, FleetId } from '@aeolus-fleet/common';
|
|
7
|
+
import type { CompanyKeyReference, KeyUnavailableReason, WrappedDataKey } from './key-vault.js';
|
|
8
|
+
import type { RecoveryKey } from './recovery-key.js';
|
|
9
|
+
/** Sealing while payloads stored plain before wait for the sealing pass; sealed once none is left. */
|
|
10
|
+
export type SealingState = 'sealing' | 'sealed';
|
|
11
|
+
/** Why the company key vault refused the company key: a wrap that does not open is no change of its availability. */
|
|
12
|
+
export type CompanyKeyUnavailableReason = Exclude<KeyUnavailableReason, 'invalidWrap'>;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the company key answered this fleet's last unwrap, and since when
|
|
15
|
+
* (B11): available from turning on, unavailable with the key vault's reason
|
|
16
|
+
* from the first refusal after a success, available again from the first
|
|
17
|
+
* success after.
|
|
18
|
+
*/
|
|
19
|
+
export type KeyAvailability = {
|
|
20
|
+
isAvailable: true;
|
|
21
|
+
since: Date;
|
|
22
|
+
} | {
|
|
23
|
+
isAvailable: false;
|
|
24
|
+
reason: CompanyKeyUnavailableReason;
|
|
25
|
+
since: Date;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* How far the sealing pass is (B5): the payloads the fleet stored plain when
|
|
29
|
+
* it turned sealing on, and how many the pass sealed since.
|
|
30
|
+
*/
|
|
31
|
+
export interface SealingProgress {
|
|
32
|
+
toSeal: number;
|
|
33
|
+
sealed: number;
|
|
34
|
+
}
|
|
35
|
+
export interface FleetSealing {
|
|
36
|
+
fleetId: FleetId;
|
|
37
|
+
state: SealingState;
|
|
38
|
+
/** When the fleet turned sealing on, or, once sealed, when the sealing pass left no payload plain. */
|
|
39
|
+
since: Date;
|
|
40
|
+
progress: SealingProgress;
|
|
41
|
+
companyKey: CompanyKeyReference;
|
|
42
|
+
/** The offline key each data key is wrapped to as well, by its public half; none when the company set none. */
|
|
43
|
+
recoveryKey: RecoveryKey | null;
|
|
44
|
+
keyAvailability: KeyAvailability;
|
|
45
|
+
}
|
|
46
|
+
/** A data key as the fleet keeps it (B6): never unwrapped in storage. */
|
|
47
|
+
export interface StoredDataKey {
|
|
48
|
+
id: DataKeyId;
|
|
49
|
+
fleetId: FleetId;
|
|
50
|
+
wrappedByCompanyKey: WrappedDataKey;
|
|
51
|
+
/** The same key wrapped to the fleet's recovery key; none while the fleet has none. */
|
|
52
|
+
wrappedByRecoveryKey: WrappedDataKey | null;
|
|
53
|
+
checkValue: Uint8Array<ArrayBuffer>;
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
/** One current per fleet: the key that seals; old ones only unseal. */
|
|
56
|
+
isCurrent: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** A data key as the fleet's sealing read shows it: its id, when it was made and whether it seals now. */
|
|
59
|
+
export type DataKeyAge = Pick<StoredDataKey, 'id' | 'createdAt' | 'isCurrent'>;
|
|
60
|
+
/** How old the current data key grows before the 30 second pass makes a new one current (B13a). */
|
|
61
|
+
export declare const DATA_KEY_ROTATION_MS: number;
|
|
62
|
+
/** The time a current data key made at or before is due a new one (B13a). */
|
|
63
|
+
export declare function dataKeyRotationCutoff(now: Date): Date;
|
|
64
|
+
/** Whether the fleet's current data key is 30 days old or older, so a new one is due (B13a); a fleet with none is not. */
|
|
65
|
+
export declare function isDueANewDataKey(dataKeys: readonly DataKeyAge[], now: Date): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* The sealing pass's progress as the sealing page shows it: how many of how
|
|
68
|
+
* many payloads are sealed. A send that read the fleet before the switch
|
|
69
|
+
* stores plain after the count, and the pass seals it too, so the total
|
|
70
|
+
* never reads below what is sealed.
|
|
71
|
+
*/
|
|
72
|
+
export declare function shownProgress(progress: SealingProgress): {
|
|
73
|
+
sealed: number;
|
|
74
|
+
total: number;
|
|
75
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** How old the current data key grows before the 30 second pass makes a new one current (B13a). */
|
|
2
|
+
export const DATA_KEY_ROTATION_MS = 30 * 24 * 60 * 60 * 1000;
|
|
3
|
+
/** The time a current data key made at or before is due a new one (B13a). */
|
|
4
|
+
export function dataKeyRotationCutoff(now) {
|
|
5
|
+
return new Date(now.getTime() - DATA_KEY_ROTATION_MS);
|
|
6
|
+
}
|
|
7
|
+
/** Whether the fleet's current data key is 30 days old or older, so a new one is due (B13a); a fleet with none is not. */
|
|
8
|
+
export function isDueANewDataKey(dataKeys, now) {
|
|
9
|
+
const current = dataKeys.find((dataKey) => dataKey.isCurrent);
|
|
10
|
+
return current !== undefined && current.createdAt.getTime() <= dataKeyRotationCutoff(now).getTime();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The sealing pass's progress as the sealing page shows it: how many of how
|
|
14
|
+
* many payloads are sealed. A send that read the fleet before the switch
|
|
15
|
+
* stores plain after the count, and the pass seals it too, so the total
|
|
16
|
+
* never reads below what is sealed.
|
|
17
|
+
*/
|
|
18
|
+
export function shownProgress(progress) {
|
|
19
|
+
return { sealed: progress.sealed, total: Math.max(progress.toSeal, progress.sealed) };
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=fleet-sealing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fleet-sealing.js","sourceRoot":"","sources":["../../../src/domain/messaging/fleet-sealing.ts"],"names":[],"mappings":"AA6DA,mGAAmG;AACnG,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7D,6EAA6E;AAC7E,MAAM,UAAU,qBAAqB,CAAC,GAAS;IAC7C,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,oBAAoB,CAAC,CAAC;AACxD,CAAC;AAED,0HAA0H;AAC1H,MAAM,UAAU,gBAAgB,CAAC,QAA+B,EAAE,GAAS;IACzE,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9D,OAAO,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,qBAAqB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;AACtG,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,QAAyB;IACrD,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;AACxF,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type DomainError } from '../shared/errors.js';
|
|
2
|
+
import type { Err } from '../shared/result.js';
|
|
3
|
+
import type { KeyUnavailable } from './key-vault.js';
|
|
4
|
+
/** KEY_UNAVAILABLE with the key vault's reason (decision 0068): nothing was stored or claimed. */
|
|
5
|
+
export declare function keyUnavailable(unavailable: KeyUnavailable): Err<DomainError<'KEY_UNAVAILABLE'>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { refuse } from '../shared/errors.js';
|
|
2
|
+
/** The key vault's reason, as the refusal says it. */
|
|
3
|
+
const REASONS = {
|
|
4
|
+
accessDenied: 'access denied',
|
|
5
|
+
disabled: 'disabled',
|
|
6
|
+
notFound: 'not found',
|
|
7
|
+
unreachable: 'unreachable',
|
|
8
|
+
invalidWrap: 'a data key that does not open under it',
|
|
9
|
+
};
|
|
10
|
+
/** KEY_UNAVAILABLE with the key vault's reason (decision 0068): nothing was stored or claimed. */
|
|
11
|
+
export function keyUnavailable(unavailable) {
|
|
12
|
+
return refuse('KEY_UNAVAILABLE', `The fleet's company key is not reachable: ${REASONS[unavailable.reason]}`);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=key-unavailable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-unavailable.js","sourceRoot":"","sources":["../../../src/domain/messaging/key-unavailable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,qBAAqB,CAAC;AAI/D,sDAAsD;AACtD,MAAM,OAAO,GAAyC;IACpD,YAAY,EAAE,eAAe;IAC7B,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,WAAW;IACrB,WAAW,EAAE,aAAa;IAC1B,WAAW,EAAE,wCAAwC;CACtD,CAAC;AAEF,kGAAkG;AAClG,MAAM,UAAU,cAAc,CAAC,WAA2B;IACxD,OAAO,MAAM,CAAC,iBAAiB,EAAE,6CAA6C,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC/G,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outbound port: the company's key vault, which keeps a sealed fleet's
|
|
3
|
+
* company key (decision 0068). Core never sees the company key; it asks the
|
|
4
|
+
* vault to make, wrap, unwrap and rewrap data keys under it. Every call names
|
|
5
|
+
* the fleet, and the vault binds each wrap to it (the encryption context
|
|
6
|
+
* `aeolus:fleet = <fleet id>`), so a wrap made for one fleet never opens for
|
|
7
|
+
* another. Called outside every transaction.
|
|
8
|
+
*/
|
|
9
|
+
import type { FleetId } from '@aeolus-fleet/common';
|
|
10
|
+
import type { Result } from '../shared/result.js';
|
|
11
|
+
/** A company key as the company's key vault names it: an AWS KMS key ARN first. */
|
|
12
|
+
export type CompanyKeyReference = string;
|
|
13
|
+
/** Why the key vault could not answer: the KMS's reason, as `KEY_UNAVAILABLE` carries it. */
|
|
14
|
+
export type KeyUnavailableReason =
|
|
15
|
+
/** The installation may not use the company key: no grant, or a policy that refuses it. */
|
|
16
|
+
'accessDenied'
|
|
17
|
+
/** The company key is disabled or waits for deletion. */
|
|
18
|
+
| 'disabled'
|
|
19
|
+
/** No such company key. */
|
|
20
|
+
| 'notFound'
|
|
21
|
+
/** The key vault did not answer in time, or not at all. */
|
|
22
|
+
| 'unreachable'
|
|
23
|
+
/** The wrap does not open under this company key for this fleet: made for another fleet, another key, or damaged. */
|
|
24
|
+
| 'invalidWrap';
|
|
25
|
+
export interface KeyUnavailable {
|
|
26
|
+
readonly kind: 'keyUnavailable';
|
|
27
|
+
readonly reason: KeyUnavailableReason;
|
|
28
|
+
}
|
|
29
|
+
/** A data key's bytes, unwrapped: held in memory only, never stored, logged or sent. */
|
|
30
|
+
export type DataKeyMaterial = Uint8Array<ArrayBuffer>;
|
|
31
|
+
/** A data key wrapped by a company key: what the vault answered, opaque to core. */
|
|
32
|
+
export type WrappedDataKey = Uint8Array<ArrayBuffer>;
|
|
33
|
+
/** A new data key: its bytes, and the same bytes wrapped by the company key. */
|
|
34
|
+
export interface MadeDataKey {
|
|
35
|
+
readonly material: DataKeyMaterial;
|
|
36
|
+
readonly wrapped: WrappedDataKey;
|
|
37
|
+
}
|
|
38
|
+
/** Which company key, for which fleet. */
|
|
39
|
+
export interface CompanyKeyUse {
|
|
40
|
+
readonly fleetId: FleetId;
|
|
41
|
+
readonly companyKey: CompanyKeyReference;
|
|
42
|
+
}
|
|
43
|
+
export interface KeyVault {
|
|
44
|
+
/** A new 256-bit data key under the company key, for this fleet. */
|
|
45
|
+
makeDataKey(use: CompanyKeyUse): Promise<Result<MadeDataKey, KeyUnavailable>>;
|
|
46
|
+
/** The data key a wrap holds, when it was made under the company key for this fleet. */
|
|
47
|
+
unwrap(use: CompanyKeyUse, wrapped: WrappedDataKey): Promise<Result<DataKeyMaterial, KeyUnavailable>>;
|
|
48
|
+
/** The given data key wrapped by the company key, for this fleet. */
|
|
49
|
+
wrap(use: CompanyKeyUse, material: DataKeyMaterial): Promise<Result<WrappedDataKey, KeyUnavailable>>;
|
|
50
|
+
/**
|
|
51
|
+
* A wrap moved from one company key to another inside the vault, for this
|
|
52
|
+
* fleet, so the data key never leaves it.
|
|
53
|
+
*/
|
|
54
|
+
rewrap(change: CompanyKeyChange, wrapped: WrappedDataKey): Promise<Result<WrappedDataKey, KeyUnavailable>>;
|
|
55
|
+
}
|
|
56
|
+
/** Moving a fleet's data keys from one company key to another. */
|
|
57
|
+
export interface CompanyKeyChange {
|
|
58
|
+
readonly fleetId: FleetId;
|
|
59
|
+
readonly from: CompanyKeyReference;
|
|
60
|
+
readonly to: CompanyKeyReference;
|
|
61
|
+
}
|