@open-e2ee/signal-protocol-sdk 0.4.0 → 1.0.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/CHANGELOG.md +63 -5
- package/README.md +10 -7
- package/SECURITY.md +2 -2
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/device/README.md +7 -5
- package/dist/client/client.d.ts +3 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +58 -25
- package/dist/client/client.js.map +1 -1
- package/dist/client/config.d.ts +46 -7
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js +2 -2
- package/dist/client/config.js.map +1 -1
- package/dist/client/group-outbox.d.ts +38 -0
- package/dist/client/group-outbox.d.ts.map +1 -0
- package/dist/client/group-outbox.js +221 -0
- package/dist/client/group-outbox.js.map +1 -0
- package/dist/client/group-sealed-sender.d.ts +28 -0
- package/dist/client/group-sealed-sender.d.ts.map +1 -0
- package/dist/client/group-sealed-sender.js +74 -0
- package/dist/client/group-sealed-sender.js.map +1 -0
- package/dist/client/hosted-push.d.ts +77 -0
- package/dist/client/hosted-push.d.ts.map +1 -0
- package/dist/client/hosted-push.js +90 -0
- package/dist/client/hosted-push.js.map +1 -0
- package/dist/client/hosted.d.ts +207 -0
- package/dist/client/hosted.d.ts.map +1 -0
- package/dist/client/hosted.js +505 -0
- package/dist/client/hosted.js.map +1 -0
- package/dist/client/index.d.ts +4 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/relay-subscription.d.ts.map +1 -1
- package/dist/client/relay-subscription.js +34 -7
- package/dist/client/relay-subscription.js.map +1 -1
- package/dist/client/{sealed-sender-ops.d.ts → sealed-sender.d.ts} +39 -22
- package/dist/client/sealed-sender.d.ts.map +1 -0
- package/dist/client/sealed-sender.js +296 -0
- package/dist/client/sealed-sender.js.map +1 -0
- package/dist/client/signal-service-cipher.d.ts +23 -26
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +465 -706
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/client/types.d.ts +18 -3
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js +6 -0
- package/dist/client/types.js.map +1 -1
- package/dist/device/index.d.ts +2 -2
- package/dist/device/index.d.ts.map +1 -1
- package/dist/device/index.js +1 -1
- package/dist/device/index.js.map +1 -1
- package/dist/device/transfer.d.ts +7 -43
- package/dist/device/transfer.d.ts.map +1 -1
- package/dist/device/transfer.js +31 -150
- package/dist/device/transfer.js.map +1 -1
- package/dist/device/types.d.ts +6 -47
- package/dist/device/types.d.ts.map +1 -1
- package/dist/device/types.js +1 -1
- package/dist/device/types.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/encoding/proto/pq-ratchet-serialize.js +1 -1
- package/dist/internal/encoding/proto/pq-ratchet-serialize.js.map +1 -1
- package/dist/internal/encoding/proto/primitives.js +1 -1
- package/dist/internal/encoding/proto/primitives.js.map +1 -1
- package/dist/internal/groups/manager.d.ts +3 -3
- package/dist/internal/groups/manager.d.ts.map +1 -1
- package/dist/internal/groups/manager.js +5 -4
- package/dist/internal/groups/manager.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/certificate.d.ts +10 -4
- package/dist/internal/protocol/sealed-sender/certificate.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/certificate.js +64 -7
- package/dist/internal/protocol/sealed-sender/certificate.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/decryption.d.ts +34 -47
- package/dist/internal/protocol/sealed-sender/decryption.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/decryption.js +95 -182
- package/dist/internal/protocol/sealed-sender/decryption.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/encryption.d.ts +49 -64
- package/dist/internal/protocol/sealed-sender/encryption.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/encryption.js +120 -123
- package/dist/internal/protocol/sealed-sender/encryption.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/index.d.ts +5 -7
- package/dist/internal/protocol/sealed-sender/index.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/index.js +4 -12
- package/dist/internal/protocol/sealed-sender/index.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/{v2-helpers.d.ts → multi-recipient-crypto.d.ts} +1 -1
- package/dist/internal/protocol/sealed-sender/multi-recipient-crypto.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/{v2-helpers.js → multi-recipient-crypto.js} +1 -1
- package/dist/internal/protocol/sealed-sender/multi-recipient-crypto.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/{v2-binary.d.ts → multi-recipient-message.d.ts} +3 -2
- package/dist/internal/protocol/sealed-sender/multi-recipient-message.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/{v2-binary.js → multi-recipient-message.js} +16 -8
- package/dist/internal/protocol/sealed-sender/multi-recipient-message.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts +3 -0
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.js +25 -2
- package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/trust-root.d.ts +11 -1
- package/dist/internal/protocol/sealed-sender/trust-root.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/trust-root.js +13 -1
- package/dist/internal/protocol/sealed-sender/trust-root.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/types.d.ts +20 -135
- package/dist/internal/protocol/sealed-sender/types.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/types.js +15 -6
- package/dist/internal/protocol/sealed-sender/types.js.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts +22 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.js +39 -4
- package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
- package/dist/internal/protocol/spqr/braid-serialize.js +1 -1
- package/dist/internal/protocol/spqr/braid-serialize.js.map +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js +4 -4
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js.map +1 -1
- package/dist/internal/protocol/zk/groups/index.d.ts +1 -1
- package/dist/internal/protocol/zk/groups/index.d.ts.map +1 -1
- package/dist/internal/protocol/zk/groups/index.js +1 -1
- package/dist/internal/protocol/zk/groups/index.js.map +1 -1
- package/dist/internal/protocol/zk/groups/profile-key-credential.d.ts +37 -12
- package/dist/internal/protocol/zk/groups/profile-key-credential.d.ts.map +1 -1
- package/dist/internal/protocol/zk/groups/profile-key-credential.js +104 -31
- package/dist/internal/protocol/zk/groups/profile-key-credential.js.map +1 -1
- package/dist/local/store/expo/adapter.d.ts +1 -0
- package/dist/local/store/expo/adapter.d.ts.map +1 -1
- package/dist/local/store/expo/adapter.js +3 -0
- package/dist/local/store/expo/adapter.js.map +1 -1
- package/dist/local/store/expo/key-storage.d.ts +1 -0
- package/dist/local/store/expo/key-storage.d.ts.map +1 -1
- package/dist/local/store/expo/key-storage.js +4 -0
- package/dist/local/store/expo/key-storage.js.map +1 -1
- package/dist/local/store/memory/adapter.d.ts +1 -0
- package/dist/local/store/memory/adapter.d.ts.map +1 -1
- package/dist/local/store/memory/adapter.js +4 -0
- package/dist/local/store/memory/adapter.js.map +1 -1
- package/dist/local/store/node/adapter.d.ts +1 -0
- package/dist/local/store/node/adapter.d.ts.map +1 -1
- package/dist/local/store/node/adapter.js +3 -0
- package/dist/local/store/node/adapter.js.map +1 -1
- package/dist/local/store/node/database.d.ts +1 -0
- package/dist/local/store/node/database.d.ts.map +1 -1
- package/dist/local/store/node/database.js +5 -0
- package/dist/local/store/node/database.js.map +1 -1
- package/dist/local/store/react-native/adapter.d.ts +1 -0
- package/dist/local/store/react-native/adapter.d.ts.map +1 -1
- package/dist/local/store/react-native/adapter.js +4 -0
- package/dist/local/store/react-native/adapter.js.map +1 -1
- package/dist/local/store/react-native/reference-backend.js +1 -1
- package/dist/local/store/react-native/reference-backend.js.map +1 -1
- package/dist/local/store/reliability.d.ts +63 -0
- package/dist/local/store/reliability.d.ts.map +1 -0
- package/dist/local/store/reliability.js +219 -0
- package/dist/local/store/reliability.js.map +1 -0
- package/dist/local/store/web/adapter.d.ts +1 -0
- package/dist/local/store/web/adapter.d.ts.map +1 -1
- package/dist/local/store/web/adapter.js +5 -0
- package/dist/local/store/web/adapter.js.map +1 -1
- package/dist/remote/relay/convex/backend.d.ts +4 -14
- package/dist/remote/relay/convex/backend.d.ts.map +1 -1
- package/dist/remote/relay/convex/backend.js +11 -20
- package/dist/remote/relay/convex/backend.js.map +1 -1
- package/dist/remote/relay/convex/component/_generated/component.d.ts +7 -14
- package/dist/remote/relay/convex/component/_generated/component.d.ts.map +1 -1
- package/dist/remote/relay/convex/component/certificates.d.ts.map +1 -1
- package/dist/remote/relay/convex/component/certificates.js +14 -5
- package/dist/remote/relay/convex/component/certificates.js.map +1 -1
- package/dist/remote/relay/convex/component/messages.d.ts +0 -13
- package/dist/remote/relay/convex/component/messages.d.ts.map +1 -1
- package/dist/remote/relay/convex/component/messages.js +13 -47
- package/dist/remote/relay/convex/component/messages.js.map +1 -1
- package/dist/remote/relay/convex/component/schema.d.ts +3 -1
- package/dist/remote/relay/convex/component/schema.js +1 -0
- package/dist/remote/relay/convex/component/schema.js.map +1 -1
- package/dist/remote/relay/convex/component/zkAuth.d.ts +7 -1
- package/dist/remote/relay/convex/component/zkAuth.d.ts.map +1 -1
- package/dist/remote/relay/convex/component/zkAuth.js +29 -14
- package/dist/remote/relay/convex/component/zkAuth.js.map +1 -1
- package/dist/remote/relay/convex/relay.d.ts +2 -5
- package/dist/remote/relay/convex/relay.d.ts.map +1 -1
- package/dist/remote/relay/convex/relay.js +17 -47
- package/dist/remote/relay/convex/relay.js.map +1 -1
- package/dist/remote/relay/memory/adapter.d.ts +4 -10
- package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
- package/dist/remote/relay/memory/adapter.js +31 -34
- package/dist/remote/relay/memory/adapter.js.map +1 -1
- package/dist/remote/relay/types.d.ts +6 -19
- package/dist/remote/relay/types.d.ts.map +1 -1
- package/dist/types/api.d.ts +2 -0
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/errors.d.ts +3 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +4 -2
- package/dist/types/errors.js.map +1 -1
- package/dist/types/protocol-config.d.ts +1 -1
- package/dist/username/link.d.ts.map +1 -1
- package/dist/username/link.js +1 -1
- package/dist/username/link.js.map +1 -1
- package/docs/ASSURANCE.md +5 -5
- package/docs/DEVIATIONS.md +32 -61
- package/docs/GETTING_STARTED.md +7 -0
- package/docs/SECURITY.md +6 -0
- package/package.json +1 -1
- package/remote/relay/convex/component/README.md +20 -14
- package/scripts/oe-groups.mjs +5 -1
- package/dist/client/sealed-sender-ops.d.ts.map +0 -1
- package/dist/client/sealed-sender-ops.js +0 -203
- package/dist/client/sealed-sender-ops.js.map +0 -1
- package/dist/internal/protocol/sealed-sender/decryption-v2.d.ts +0 -46
- package/dist/internal/protocol/sealed-sender/decryption-v2.d.ts.map +0 -1
- package/dist/internal/protocol/sealed-sender/decryption-v2.js +0 -198
- package/dist/internal/protocol/sealed-sender/decryption-v2.js.map +0 -1
- package/dist/internal/protocol/sealed-sender/encryption-v2.d.ts +0 -56
- package/dist/internal/protocol/sealed-sender/encryption-v2.d.ts.map +0 -1
- package/dist/internal/protocol/sealed-sender/encryption-v2.js +0 -163
- package/dist/internal/protocol/sealed-sender/encryption-v2.js.map +0 -1
- package/dist/internal/protocol/sealed-sender/v2-binary.d.ts.map +0 -1
- package/dist/internal/protocol/sealed-sender/v2-binary.js.map +0 -1
- package/dist/internal/protocol/sealed-sender/v2-helpers.d.ts.map +0 -1
- package/dist/internal/protocol/sealed-sender/v2-helpers.js.map +0 -1
|
@@ -152,7 +152,6 @@ export const {
|
|
|
152
152
|
getPendingMessages,
|
|
153
153
|
markDelivered,
|
|
154
154
|
getActiveDevices,
|
|
155
|
-
sendUnidentified,
|
|
156
155
|
sendMultiRecipientUnidentified,
|
|
157
156
|
sendRetryRequest,
|
|
158
157
|
getPendingRetryRequests,
|
|
@@ -232,8 +231,8 @@ issuance also resolves identity. Group wrappers pass client arguments through
|
|
|
232
231
|
untouched because group reads and writes authenticate membership solely through
|
|
233
232
|
the supplied zero-knowledge presentation.
|
|
234
233
|
|
|
235
|
-
`
|
|
236
|
-
|
|
234
|
+
`sendMultiRecipientUnidentified` is the deliberate exception: this
|
|
235
|
+
sealed-sender path does **not** call `identify`. It authorizes
|
|
237
236
|
the bearer request with the target's unidentified-access key or verified group
|
|
238
237
|
send material, which keeps delivery available without an authenticated
|
|
239
238
|
application session. Rejections carry structured `ConvexError` data. The relay
|
|
@@ -330,8 +329,8 @@ Add `--prod` for the default production deployment or
|
|
|
330
329
|
- generates a cryptographically random 32-byte seed only when the secret is
|
|
331
330
|
absent
|
|
332
331
|
- writes the seed to the selected Convex deployment through stdin
|
|
333
|
-
- prints
|
|
334
|
-
|
|
332
|
+
- prints the serialized group trust root, the Ed25519 sender-certificate root,
|
|
333
|
+
and the sender-certificate relay scope as labeled base64 values
|
|
335
334
|
|
|
336
335
|
Pin both in the client build. See
|
|
337
336
|
[Sender certificate trust root](#sender-certificate-trust-root) for where each
|
|
@@ -350,18 +349,21 @@ from the group signing key by distinct KDF labels
|
|
|
350
349
|
(`open-e2ee:sealed-sender:root:v1` / `:server:v1`). Clients verify inbound
|
|
351
350
|
sealed-sender certificates against the matching Ed25519 **root** public key.
|
|
352
351
|
|
|
353
|
-
`oe-groups trust-root` prints both roots,
|
|
352
|
+
`oe-groups trust-root` prints both roots, labeled:
|
|
354
353
|
|
|
355
354
|
```
|
|
356
355
|
group trust root: <base64>
|
|
357
356
|
sealed sender trust root: <base64>
|
|
357
|
+
sealed sender relay scope: <base64>
|
|
358
358
|
```
|
|
359
359
|
|
|
360
360
|
The two roots go in different places and are not interchangeable. The group
|
|
361
361
|
trust root goes into the group configuration, and the sealed-sender root into
|
|
362
|
-
`sealedSender.trustRoots` in the client build.
|
|
363
|
-
|
|
364
|
-
|
|
362
|
+
`sealedSender.trustRoots` in the client build. Put the matching relay scope into
|
|
363
|
+
`sealedSender.relayScopeId`, and configure the operator-owned issuer revocation
|
|
364
|
+
list in `sealedSender.revokedIssuerKeyIds`. Pin these values at build time.
|
|
365
|
+
Never fetch them from a relay at runtime, because a relay that chooses its own
|
|
366
|
+
validation policy can mint certificates for any sender.
|
|
365
367
|
|
|
366
368
|
The component derives both from the same deployment secret, so rotating
|
|
367
369
|
`OE_GROUPS_SERVER_SECRET` rotates both and strands clients pinned to either
|
|
@@ -451,8 +453,12 @@ The component cannot do it while its identity has no device field.
|
|
|
451
453
|
|
|
452
454
|
## Profile-key issuance threat model
|
|
453
455
|
|
|
454
|
-
`issueProfileKeyCredentialMutation` receives
|
|
455
|
-
group server
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
456
|
+
`issueProfileKeyCredentialMutation` receives a 160-byte blinded request bound
|
|
457
|
+
to the authenticated ACI. The group server sees the ACI and redemption window,
|
|
458
|
+
but it does not receive the raw 32-byte profile key or the client's ephemeral
|
|
459
|
+
blinding secret. The client unblinds and verifies the response before it uses
|
|
460
|
+
the credential in a group presentation.
|
|
461
|
+
|
|
462
|
+
`setUnidentifiedAccessKeyMutation` is a separate delivery-authorization seam.
|
|
463
|
+
It receives only the 16-byte access key that the client derives from its
|
|
464
|
+
profile key. Credential issuance does not derive or register that access key.
|
package/scripts/oe-groups.mjs
CHANGED
|
@@ -94,7 +94,7 @@ async function printTrustRoot(args) {
|
|
|
94
94
|
const [
|
|
95
95
|
{ generateServerSecretParams, getServerPublicParams },
|
|
96
96
|
{ encodeGroupTrustRoot },
|
|
97
|
-
{ deriveSealedSenderRootPublicKey },
|
|
97
|
+
{ deriveSealedSenderRootPublicKey, deriveSealedSenderScopeId },
|
|
98
98
|
] = await Promise.all([
|
|
99
99
|
// pathToFileURL: dynamic import of a bare absolute path fails on
|
|
100
100
|
// Windows, where the ESM loader requires a file:// URL.
|
|
@@ -136,6 +136,7 @@ async function printTrustRoot(args) {
|
|
|
136
136
|
const sealedSenderRoot = await deriveSealedSenderRootPublicKey(
|
|
137
137
|
secretParams.signingKeyPair.signingKey
|
|
138
138
|
);
|
|
139
|
+
const sealedSenderScope = await deriveSealedSenderScopeId(sealedSenderRoot);
|
|
139
140
|
|
|
140
141
|
// Two independently pinned roots, printed with labels because they go to
|
|
141
142
|
// different places in the client build and are not interchangeable.
|
|
@@ -145,6 +146,9 @@ async function printTrustRoot(args) {
|
|
|
145
146
|
process.stdout.write(
|
|
146
147
|
`sealed sender trust root: ${Buffer.from(sealedSenderRoot).toString('base64')}\n`
|
|
147
148
|
);
|
|
149
|
+
process.stdout.write(
|
|
150
|
+
`sealed sender relay scope: ${Buffer.from(sealedSenderScope).toString('base64')}\n`
|
|
151
|
+
);
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
const [command, ...args] = process.argv.slice(2);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sealed-sender-ops.d.ts","sourceRoot":"","sources":["../../client/sealed-sender-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAA+B,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,EACL,uBAAuB,EAGxB,MAAM,0CAA0C,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,CAAC;AACV,wBAAsB,WAAW,CAC/B,gBAAgB,EAAE,MAAM,EACxB,uBAAuB,EAAE,MAAM,EAC/B,qBAAqB,EAAE,UAAU,EACjC,uBAAuB,EAAE,UAAU,EACnC,OAAO,EAAE,kBAAkB,EAC3B,eAAe,CAAC,EAAE,OAAO,EACzB,WAAW,CAAC,EAAE,uBAAuB,GACpC,OAAO,CAAC,MAAM,CAAC,CAkCjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,aAAa,CACjC,sBAAsB,EAAE,MAAM,EAC9B,wBAAwB,EAAE,UAAU,EACpC,aAAa,EAAE,MAAM,EACrB,iBAAiB,EAAE,MAAM,EACzB,MAAM,EAAE,kBAAkB,EAC1B,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC;IACT,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,EAAE,uBAAuB,CAAC;CACtC,CAAC,CAgED;AA8ED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,gBAAgB,EAAE,QAAQ,EAC1B,QAAQ,EAAE;IACR,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,EAAE,uBAAuB,CAAC;CACtC,GACA,QAAQ,CAQV;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,uBAAuB,GACnC,QAAQ,CAAC,aAAa,CAAC,CAUzB"}
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sealed Sender Operations
|
|
3
|
-
*
|
|
4
|
-
* Provides seal/unseal wrapping for the message send/receive pipeline.
|
|
5
|
-
* Called by SignalProtocolServiceCipher when sealed sender is enabled.
|
|
6
|
-
*
|
|
7
|
-
* @see https://signal.org/blog/sealed-sender/
|
|
8
|
-
*/
|
|
9
|
-
import { resolveSignalProtocolLogger } from '../logger.js';
|
|
10
|
-
import { SealedSenderContentType, SEALED_SENDER_V2_SERVICE_ID_VERSION, SEALED_SENDER_V2_UUID_VERSION, } from '../internal/protocol/sealed-sender/types.js';
|
|
11
|
-
export async function sealMessage(ciphertextBase64, senderCertificateBase64, senderIdentityPrivate, recipientIdentityPublic, _config, _providedLogger, contentType) {
|
|
12
|
-
const { seal, deserializeSenderCertificate, encodeUnidentifiedSenderMessage } = await import('../internal/protocol/sealed-sender/index.js');
|
|
13
|
-
const { base64ToBytes, bytesToBase64 } = await import('../internal/crypto/index.js');
|
|
14
|
-
// Deserialize the sender certificate
|
|
15
|
-
const certBytes = base64ToBytes(senderCertificateBase64);
|
|
16
|
-
const senderCertificate = deserializeSenderCertificate(certBytes);
|
|
17
|
-
// Convert ciphertext to bytes for seal()
|
|
18
|
-
const signalProtocolMessage = base64ToBytes(ciphertextBase64);
|
|
19
|
-
// Seal the message
|
|
20
|
-
const sealed = await seal({
|
|
21
|
-
senderCertificate,
|
|
22
|
-
senderIdentityPrivate,
|
|
23
|
-
recipientIdentityPublic,
|
|
24
|
-
signalProtocolMessage,
|
|
25
|
-
contentType,
|
|
26
|
-
});
|
|
27
|
-
// Serialize: version byte + protobuf-encoded message (Sealed Sender wire format)
|
|
28
|
-
const protoBytes = encodeUnidentifiedSenderMessage({
|
|
29
|
-
ephemeralPublic: base64ToBytes(sealed.ephemeralPublic),
|
|
30
|
-
encryptedStatic: base64ToBytes(sealed.encryptedStatic),
|
|
31
|
-
encryptedMessage: base64ToBytes(sealed.encryptedMessage),
|
|
32
|
-
});
|
|
33
|
-
// Prepend version byte
|
|
34
|
-
const sealedBytes = new Uint8Array(1 + protoBytes.length);
|
|
35
|
-
sealedBytes[0] = sealed.version;
|
|
36
|
-
sealedBytes.set(protoBytes, 1);
|
|
37
|
-
return bytesToBase64(sealedBytes);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Unseal a sealed sender message to reveal the sender and inner ciphertext.
|
|
41
|
-
*
|
|
42
|
-
* Called when an incoming envelope has messageType === 'unidentified_sender'.
|
|
43
|
-
* Validates the certificate chain, reveals sender identity, and returns
|
|
44
|
-
* the inner Signal Protocol ciphertext for normal decryption.
|
|
45
|
-
*
|
|
46
|
-
* @param sealedCiphertextBase64 - Base64-encoded sealed sender message
|
|
47
|
-
* @param recipientIdentityPrivate - Recipient's X25519 identity private key
|
|
48
|
-
* @param recipientUuid - Recipient's user ID (for self-send detection)
|
|
49
|
-
* @param recipientDeviceId - Recipient's device ID
|
|
50
|
-
* @param config - Sealed sender config with trust roots
|
|
51
|
-
* @returns Unsealed envelope info with sender identity and inner ciphertext
|
|
52
|
-
*/
|
|
53
|
-
export async function unsealMessage(sealedCiphertextBase64, recipientIdentityPrivate, recipientUuid, recipientDeviceId, config, providedLogger) {
|
|
54
|
-
const logger = resolveSignalProtocolLogger(providedLogger);
|
|
55
|
-
const { base64ToBytes, bytesToBase64 } = await import('../internal/crypto/index.js');
|
|
56
|
-
// Decode sealed bytes and check version byte for V1 vs V2 dispatch
|
|
57
|
-
const sealedBytes = base64ToBytes(sealedCiphertextBase64);
|
|
58
|
-
const versionByte = sealedBytes[0];
|
|
59
|
-
// V2 detection: 0x22 = UUID version (ReceivedMessage), 0x23 = ServiceId version
|
|
60
|
-
if (versionByte === SEALED_SENDER_V2_UUID_VERSION ||
|
|
61
|
-
versionByte === SEALED_SENDER_V2_SERVICE_ID_VERSION) {
|
|
62
|
-
return unsealV2Message(sealedBytes, recipientIdentityPrivate, recipientUuid, recipientDeviceId, config, logger);
|
|
63
|
-
}
|
|
64
|
-
// V1 path (0x11). Existing code
|
|
65
|
-
const { unseal, decodeUnidentifiedSenderMessage } = await import('../internal/protocol/sealed-sender/index.js');
|
|
66
|
-
const version = versionByte;
|
|
67
|
-
const sealedProto = decodeUnidentifiedSenderMessage(sealedBytes.subarray(1));
|
|
68
|
-
// Build the UnidentifiedSenderMessage structure
|
|
69
|
-
const sealedMessage = {
|
|
70
|
-
version,
|
|
71
|
-
ephemeralPublic: bytesToBase64(sealedProto.ephemeralPublic),
|
|
72
|
-
encryptedStatic: bytesToBase64(sealedProto.encryptedStatic),
|
|
73
|
-
encryptedMessage: bytesToBase64(sealedProto.encryptedMessage),
|
|
74
|
-
};
|
|
75
|
-
// Build trust roots as base64 strings
|
|
76
|
-
const trustRoots = config.trustRoots.map((root) => bytesToBase64(root));
|
|
77
|
-
// Unseal the message
|
|
78
|
-
const content = await unseal({
|
|
79
|
-
sealedMessage,
|
|
80
|
-
recipientIdentityPrivate,
|
|
81
|
-
trustRoots,
|
|
82
|
-
recipientUuid,
|
|
83
|
-
recipientDeviceId,
|
|
84
|
-
});
|
|
85
|
-
logger.debug('Sealed sender message unsealed', {
|
|
86
|
-
category: 'E2EE',
|
|
87
|
-
data: {
|
|
88
|
-
senderUuid: content.senderCertificate.senderUuid,
|
|
89
|
-
senderDeviceId: content.senderCertificate.senderDeviceId,
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
return {
|
|
93
|
-
senderUserId: content.senderCertificate.senderUuid,
|
|
94
|
-
senderDeviceId: content.senderCertificate.senderDeviceId,
|
|
95
|
-
innerCiphertextBase64: content.signalProtocolMessage,
|
|
96
|
-
contentType: content.contentType,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Unseal a V2 multi-recipient sealed sender message (per-device view).
|
|
101
|
-
*
|
|
102
|
-
* The server constructs a per-device view: [0x22][C_i(32)][AT_i(16)][e_pub(32)][ciphertext]
|
|
103
|
-
* We deserialize this, build a SealedSenderV2Message, and call unsealV2().
|
|
104
|
-
*/
|
|
105
|
-
async function unsealV2Message(sealedBytes, recipientIdentityPrivate, recipientUuid, recipientDeviceId, config, logger) {
|
|
106
|
-
const { deserializeReceivedMessage } = await import('../internal/protocol/sealed-sender/v2-binary.js');
|
|
107
|
-
const { unsealV2 } = await import('../internal/protocol/sealed-sender/decryption-v2.js');
|
|
108
|
-
const { bytesToBase64 } = await import('../internal/crypto/index.js');
|
|
109
|
-
const { x25519 } = await import('@noble/curves/ed25519.js');
|
|
110
|
-
// 1. Deserialize per-device ReceivedMessage
|
|
111
|
-
const deserialized = deserializeReceivedMessage(sealedBytes);
|
|
112
|
-
// 2. Derive recipient public key from private
|
|
113
|
-
const recipientIdentityPublic = x25519.getPublicKey(recipientIdentityPrivate);
|
|
114
|
-
// 3. Build SealedSenderV2Message with single recipient entry
|
|
115
|
-
const message = {
|
|
116
|
-
version: SEALED_SENDER_V2_UUID_VERSION,
|
|
117
|
-
ephemeralPublic: bytesToBase64(deserialized.ephemeralPublic),
|
|
118
|
-
recipients: [
|
|
119
|
-
{
|
|
120
|
-
serviceId: recipientUuid,
|
|
121
|
-
deviceId: recipientDeviceId,
|
|
122
|
-
registrationId: 0, // Not needed for unseal. Only used in send path
|
|
123
|
-
encryptedMessageKey: bytesToBase64(deserialized.encryptedMessageKey),
|
|
124
|
-
authenticationTag: bytesToBase64(deserialized.authenticationTag),
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
messageCiphertext: bytesToBase64(deserialized.messageCiphertext),
|
|
128
|
-
};
|
|
129
|
-
// 4. Build trust roots as Base64 strings
|
|
130
|
-
const trustRoots = config.trustRoots.map((root) => bytesToBase64(root));
|
|
131
|
-
// 5. Call unsealV2
|
|
132
|
-
const content = await unsealV2({
|
|
133
|
-
sealedMessage: message,
|
|
134
|
-
recipientIdentityPrivate,
|
|
135
|
-
recipientIdentityPublic,
|
|
136
|
-
recipientServiceId: recipientUuid,
|
|
137
|
-
recipientDeviceId,
|
|
138
|
-
trustRoots,
|
|
139
|
-
});
|
|
140
|
-
logger.debug('V2 sealed sender message unsealed', {
|
|
141
|
-
category: 'E2EE',
|
|
142
|
-
data: {
|
|
143
|
-
senderUuid: content.senderCertificate.senderUuid,
|
|
144
|
-
senderDeviceId: content.senderCertificate.senderDeviceId,
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
senderUserId: content.senderCertificate.senderUuid,
|
|
149
|
-
senderDeviceId: content.senderCertificate.senderDeviceId,
|
|
150
|
-
innerCiphertextBase64: content.signalProtocolMessage,
|
|
151
|
-
contentType: content.contentType,
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Reconstruct an Envelope from an unsealed message.
|
|
156
|
-
*
|
|
157
|
-
* Takes the original sealed sender envelope (with empty sender fields)
|
|
158
|
-
* and fills in the sender identity revealed by unsealing.
|
|
159
|
-
*
|
|
160
|
-
* @param originalEnvelope - The incoming envelope with messageType 'unidentified_sender'
|
|
161
|
-
* @param unsealed - The unsealed sender info and inner ciphertext
|
|
162
|
-
* @returns A new envelope with real sender info and the inner ciphertext
|
|
163
|
-
*/
|
|
164
|
-
export function reconstructEnvelope(originalEnvelope, unsealed) {
|
|
165
|
-
return {
|
|
166
|
-
...originalEnvelope,
|
|
167
|
-
senderUserId: unsealed.senderUserId,
|
|
168
|
-
senderDeviceId: unsealed.senderDeviceId,
|
|
169
|
-
ciphertext: unsealed.innerCiphertextBase64,
|
|
170
|
-
messageType: envelopeTypeForContent(unsealed.contentType),
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Map a sealed envelope's content type onto the envelope type the decrypt
|
|
175
|
-
* path routes on.
|
|
176
|
-
*
|
|
177
|
-
* Exported because both receive paths need it. `SignalProtocolServiceCipher`
|
|
178
|
-
* via `reconstructEnvelope`, and `SignalProtocolClient.processIncomingEnvelope`
|
|
179
|
-
* directly. Two copies of this mapping would drift.
|
|
180
|
-
*
|
|
181
|
-
* `SENDERKEY_MESSAGE` is the only case that matters here. It is what keeps
|
|
182
|
-
* group routing working now that no group identifier travels on an envelope,
|
|
183
|
-
* sealed or otherwise. Both `PREKEY_MESSAGE` and `MESSAGE` decrypt as pairwise
|
|
184
|
-
* ratchet messages, and the ratchet distinguishes them from the payload
|
|
185
|
-
* itself.
|
|
186
|
-
*
|
|
187
|
-
* The default is unreachable: `isSealedSenderContentType` rejects every other
|
|
188
|
-
* value at the parse, so nothing arrives here that this function cannot map.
|
|
189
|
-
* It exists so that adding an enum member without a route fails loudly rather
|
|
190
|
-
* than silently decrypting as something it is not.
|
|
191
|
-
*/
|
|
192
|
-
export function envelopeTypeForContent(contentType) {
|
|
193
|
-
switch (contentType) {
|
|
194
|
-
case SealedSenderContentType.SENDERKEY_MESSAGE:
|
|
195
|
-
return 'sender_key';
|
|
196
|
-
case SealedSenderContentType.PREKEY_MESSAGE:
|
|
197
|
-
case SealedSenderContentType.MESSAGE:
|
|
198
|
-
return 'ciphertext';
|
|
199
|
-
default:
|
|
200
|
-
throw new Error('Unsupported sealed sender content type');
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
//# sourceMappingURL=sealed-sender-ops.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sealed-sender-ops.js","sourceRoot":"","sources":["../../client/sealed-sender-ops.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,2BAA2B,EAAgB,MAAM,WAAW,CAAC;AAEtE,OAAO,EACL,uBAAuB,EACvB,mCAAmC,EACnC,6BAA6B,GAC9B,MAAM,0CAA0C,CAAC;AAmBlD,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,gBAAwB,EACxB,uBAA+B,EAC/B,qBAAiC,EACjC,uBAAmC,EACnC,OAA2B,EAC3B,eAAyB,EACzB,WAAqC;IAErC,MAAM,EAAE,IAAI,EAAE,4BAA4B,EAAE,+BAA+B,EAAE,GAC3E,MAAM,MAAM,CAAC,oCAAoC,CAAC,CAAC;IACrD,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAE5E,qCAAqC;IACrC,MAAM,SAAS,GAAG,aAAa,CAAC,uBAAiC,CAAC,CAAC;IACnE,MAAM,iBAAiB,GAAG,4BAA4B,CAAC,SAAS,CAAC,CAAC;IAElE,yCAAyC;IACzC,MAAM,qBAAqB,GAAG,aAAa,CAAC,gBAA0B,CAAC,CAA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ed Sender V2 Multi-Recipient Decryption
|
|
3
|
-
*
|
|
4
|
-
* Implements V2 multi-recipient sealed-sender decryption.
|
|
5
|
-
*
|
|
6
|
-
* Algorithm:
|
|
7
|
-
* 1. Parse version, find my recipient entry by serviceId
|
|
8
|
-
* 2. M = apply_agreement_xor(recipient_identity, ephemeral_pub, encrypted_key)
|
|
9
|
-
* 3. Verify E_pub matches X25519(derive_private_from_M(M)) - authenticates XOR decryption
|
|
10
|
-
* 4. K = HKDF(M, LABEL_K)
|
|
11
|
-
* 5. usmc = AES-GCM-SIV.Decrypt(K, nonce=zeros, ciphertext) - authenticated decryption
|
|
12
|
-
* 6. Parse certificate from usmc to get sender identity
|
|
13
|
-
* 7. Verify auth_tag using identity-to-identity ECDH (binds sender to message)
|
|
14
|
-
* 8. Validate sender certificate, return content
|
|
15
|
-
*
|
|
16
|
-
* IMPORTANT: Auth tag is verified AFTER decryption because it requires sender identity
|
|
17
|
-
* from the certificate. This is safe because:
|
|
18
|
-
* - AES-GCM-SIV provides authenticated encryption
|
|
19
|
-
* - Ephemeral key consistency check authenticates the XOR decryption
|
|
20
|
-
* - Auth tag binds the sender's identity to the message
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
import type { UnsealV2Options, UnidentifiedSenderMessageContent } from './types.js';
|
|
24
|
-
/** Generic error message for all unseal failures */
|
|
25
|
-
export {};
|
|
26
|
-
/**
|
|
27
|
-
* Unseal a V2 multi-recipient Sealed Sender message.
|
|
28
|
-
*
|
|
29
|
-
* @param options V2 unsealing options
|
|
30
|
-
* @returns Decrypted content with validated sender certificate
|
|
31
|
-
* @throws Error (generic) if any validation fails
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const content = await unsealV2({
|
|
36
|
-
* sealedMessage: receivedMessage,
|
|
37
|
-
* recipientIdentityPrivate: myPrivateKey,
|
|
38
|
-
* recipientIdentityPublic: myPublicKey,
|
|
39
|
-
* recipientServiceId: 'my-user-id',
|
|
40
|
-
* recipientDeviceId: 1,
|
|
41
|
-
* trustRoots: [trustRootPublicKey],
|
|
42
|
-
* });
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare function unsealV2(options: UnsealV2Options): Promise<UnidentifiedSenderMessageContent>;
|
|
46
|
-
//# sourceMappingURL=decryption-v2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decryption-v2.d.ts","sourceRoot":"","sources":["../../../../internal/protocol/sealed-sender/decryption-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAgC,EAAqB,MAAM,SAAS,CAAC;AA2BpG,oDAAoD;AACpD,OAAO,EAAE,CAAC;AA6EV;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,gCAAgC,CAAC,CAuI3C"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sealed Sender V2 Multi-Recipient Decryption
|
|
3
|
-
*
|
|
4
|
-
* Implements V2 multi-recipient sealed-sender decryption.
|
|
5
|
-
*
|
|
6
|
-
* Algorithm:
|
|
7
|
-
* 1. Parse version, find my recipient entry by serviceId
|
|
8
|
-
* 2. M = apply_agreement_xor(recipient_identity, ephemeral_pub, encrypted_key)
|
|
9
|
-
* 3. Verify E_pub matches X25519(derive_private_from_M(M)) - authenticates XOR decryption
|
|
10
|
-
* 4. K = HKDF(M, LABEL_K)
|
|
11
|
-
* 5. usmc = AES-GCM-SIV.Decrypt(K, nonce=zeros, ciphertext) - authenticated decryption
|
|
12
|
-
* 6. Parse certificate from usmc to get sender identity
|
|
13
|
-
* 7. Verify auth_tag using identity-to-identity ECDH (binds sender to message)
|
|
14
|
-
* 8. Validate sender certificate, return content
|
|
15
|
-
*
|
|
16
|
-
* IMPORTANT: Auth tag is verified AFTER decryption because it requires sender identity
|
|
17
|
-
* from the certificate. This is safe because:
|
|
18
|
-
* - AES-GCM-SIV provides authenticated encryption
|
|
19
|
-
* - Ephemeral key consistency check authenticates the XOR decryption
|
|
20
|
-
* - Auth tag binds the sender's identity to the message
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
import { SEALED_SENDER_V2_UUID_VERSION, SEALED_SENDER_V2_SERVICE_ID_VERSION, isSealedSenderContentType, } from './types.js';
|
|
24
|
-
import { deserializeSenderCertificate, validateSenderCertificate } from './certificate.js';
|
|
25
|
-
import { deriveEphemeralPrivateFromM, deriveCipherKeyFromM, applyAgreementXor, computeAuthenticationTag, verifyAuthenticationTag, } from './v2-helpers.js';
|
|
26
|
-
import { bytesToBase64, base64ToBytes, constantTimeEqual, secureZeroBytes, aesGcmSivDecryptZeroNonce, } from '../../crypto/index.js';
|
|
27
|
-
import { decodeVarint } from '../../encoding/proto/primitives.js';
|
|
28
|
-
import { x25519 } from '@noble/curves/ed25519.js';
|
|
29
|
-
const GENERIC_ERROR = 'Sealed sender verification failed';
|
|
30
|
-
/** contentType(1) + certLen varint(1) + msgLen varint(1) + contentHint(1). */
|
|
31
|
-
const MIN_ENVELOPE_BYTES = 4;
|
|
32
|
-
/**
|
|
33
|
-
* Parse decrypted envelope to extract certificate and message.
|
|
34
|
-
*/
|
|
35
|
-
function parseEnvelope(envelope) {
|
|
36
|
-
// Smallest well-formed envelope: type, two zero-length varints, hint.
|
|
37
|
-
if (envelope.length < MIN_ENVELOPE_BYTES) {
|
|
38
|
-
throw new Error(GENERIC_ERROR);
|
|
39
|
-
}
|
|
40
|
-
// Read content type (1 byte)
|
|
41
|
-
const contentType = envelope[0];
|
|
42
|
-
if (!isSealedSenderContentType(contentType)) {
|
|
43
|
-
throw new Error(GENERIC_ERROR);
|
|
44
|
-
}
|
|
45
|
-
let offset = 1;
|
|
46
|
-
// Read certificate length
|
|
47
|
-
const { value: certLen, bytesRead: certLenBytes } = decodeVarint(envelope, offset);
|
|
48
|
-
if (certLenBytes === 0) {
|
|
49
|
-
throw new Error(GENERIC_ERROR);
|
|
50
|
-
}
|
|
51
|
-
offset += certLenBytes;
|
|
52
|
-
if (offset + certLen > envelope.length) {
|
|
53
|
-
throw new Error(GENERIC_ERROR);
|
|
54
|
-
}
|
|
55
|
-
// Read certificate bytes
|
|
56
|
-
const certBytes = envelope.slice(offset, offset + certLen);
|
|
57
|
-
offset += certLen;
|
|
58
|
-
// Read message length
|
|
59
|
-
const { value: msgLen, bytesRead: msgLenBytes } = decodeVarint(envelope, offset);
|
|
60
|
-
if (msgLenBytes === 0) {
|
|
61
|
-
throw new Error(GENERIC_ERROR);
|
|
62
|
-
}
|
|
63
|
-
offset += msgLenBytes;
|
|
64
|
-
if (offset + msgLen > envelope.length) {
|
|
65
|
-
throw new Error(GENERIC_ERROR);
|
|
66
|
-
}
|
|
67
|
-
// Read message bytes
|
|
68
|
-
const message = envelope.slice(offset, offset + msgLen);
|
|
69
|
-
offset += msgLen;
|
|
70
|
-
// Read content hint. The serializer always writes it, and nothing follows
|
|
71
|
-
// it any more, so it is required rather than optional.
|
|
72
|
-
if (offset >= envelope.length) {
|
|
73
|
-
throw new Error(GENERIC_ERROR);
|
|
74
|
-
}
|
|
75
|
-
const contentHint = envelope[offset];
|
|
76
|
-
offset += 1;
|
|
77
|
-
// The envelope is exactly its fields. Trailing bytes would make the format
|
|
78
|
-
// non-canonical. Two distinct envelopes parsing to the same content.
|
|
79
|
-
if (offset !== envelope.length) {
|
|
80
|
-
throw new Error(GENERIC_ERROR);
|
|
81
|
-
}
|
|
82
|
-
// Deserialize certificate
|
|
83
|
-
const certificate = deserializeSenderCertificate(certBytes);
|
|
84
|
-
return { certificate, message, contentType, contentHint };
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Unseal a V2 multi-recipient Sealed Sender message.
|
|
88
|
-
*
|
|
89
|
-
* @param options V2 unsealing options
|
|
90
|
-
* @returns Decrypted content with validated sender certificate
|
|
91
|
-
* @throws Error (generic) if any validation fails
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* const content = await unsealV2({
|
|
96
|
-
* sealedMessage: receivedMessage,
|
|
97
|
-
* recipientIdentityPrivate: myPrivateKey,
|
|
98
|
-
* recipientIdentityPublic: myPublicKey,
|
|
99
|
-
* recipientServiceId: 'my-user-id',
|
|
100
|
-
* recipientDeviceId: 1,
|
|
101
|
-
* trustRoots: [trustRootPublicKey],
|
|
102
|
-
* });
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export async function unsealV2(options) {
|
|
106
|
-
const { sealedMessage, recipientIdentityPrivate, recipientIdentityPublic, recipientServiceId, recipientDeviceId, trustRoots, currentTime, } = options;
|
|
107
|
-
// Track sensitive material for secure zeroing
|
|
108
|
-
const toZero = [];
|
|
109
|
-
// ========================================================================
|
|
110
|
-
// Step 1: Validate version and find my recipient entry
|
|
111
|
-
// ========================================================================
|
|
112
|
-
const version = sealedMessage.version;
|
|
113
|
-
if (version !== SEALED_SENDER_V2_UUID_VERSION &&
|
|
114
|
-
version !== SEALED_SENDER_V2_SERVICE_ID_VERSION) {
|
|
115
|
-
throw new Error(GENERIC_ERROR);
|
|
116
|
-
}
|
|
117
|
-
// Find my recipient entry
|
|
118
|
-
const myRecipient = sealedMessage.recipients.find((r) => r.serviceId === recipientServiceId && r.deviceId === recipientDeviceId);
|
|
119
|
-
if (!myRecipient) {
|
|
120
|
-
throw new Error(GENERIC_ERROR);
|
|
121
|
-
}
|
|
122
|
-
try {
|
|
123
|
-
const ephemeralPublic = base64ToBytes(sealedMessage.ephemeralPublic);
|
|
124
|
-
const encryptedMessageKey = base64ToBytes(myRecipient.encryptedMessageKey);
|
|
125
|
-
const receivedAuthTag = base64ToBytes(myRecipient.authenticationTag);
|
|
126
|
-
const messageCiphertext = base64ToBytes(sealedMessage.messageCiphertext);
|
|
127
|
-
if (ephemeralPublic.length !== 32) {
|
|
128
|
-
throw new Error(GENERIC_ERROR);
|
|
129
|
-
}
|
|
130
|
-
// ========================================================================
|
|
131
|
-
// Step 2: Decrypt M using XOR (ephemeral-to-identity ECDH)
|
|
132
|
-
// ========================================================================
|
|
133
|
-
const M = await applyAgreementXor(recipientIdentityPrivate, ephemeralPublic, ephemeralPublic, // For receiving: both ECDH target and IKM are the ephemeral key
|
|
134
|
-
'receiving', encryptedMessageKey);
|
|
135
|
-
toZero.push(M);
|
|
136
|
-
// ========================================================================
|
|
137
|
-
// Step 3: Verify ephemeral public key consistency
|
|
138
|
-
// This authenticates the XOR decryption - if M was wrong, derived key will not match
|
|
139
|
-
// ========================================================================
|
|
140
|
-
const derivedEphemeralPrivate = await deriveEphemeralPrivateFromM(M);
|
|
141
|
-
toZero.push(derivedEphemeralPrivate);
|
|
142
|
-
const derivedEphemeralPublic = x25519.getPublicKey(derivedEphemeralPrivate);
|
|
143
|
-
if (!constantTimeEqual(ephemeralPublic, derivedEphemeralPublic)) {
|
|
144
|
-
throw new Error(GENERIC_ERROR);
|
|
145
|
-
}
|
|
146
|
-
// ========================================================================
|
|
147
|
-
// Step 4: Derive cipher key K from M
|
|
148
|
-
// ========================================================================
|
|
149
|
-
const cipherKey = await deriveCipherKeyFromM(M);
|
|
150
|
-
toZero.push(cipherKey);
|
|
151
|
-
// ========================================================================
|
|
152
|
-
// Step 5: Decrypt message with AES-GCM-SIV (provides authenticated decryption)
|
|
153
|
-
// ========================================================================
|
|
154
|
-
let envelope;
|
|
155
|
-
try {
|
|
156
|
-
envelope = aesGcmSivDecryptZeroNonce(cipherKey, messageCiphertext);
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
throw new Error(GENERIC_ERROR);
|
|
160
|
-
}
|
|
161
|
-
// ========================================================================
|
|
162
|
-
// Step 6: Parse envelope to get sender certificate
|
|
163
|
-
// ========================================================================
|
|
164
|
-
const { certificate, message, contentType, contentHint } = parseEnvelope(envelope);
|
|
165
|
-
// ========================================================================
|
|
166
|
-
// Step 7: Verify authentication tag (identity-to-identity ECDH).
|
|
167
|
-
// Now that we have the sender's identity from the certificate, verify the
|
|
168
|
-
// auth tag. This binds the sender's identity to the message.
|
|
169
|
-
// ========================================================================
|
|
170
|
-
const senderIdentityPublic = base64ToBytes(certificate.senderIdentityKey);
|
|
171
|
-
const expectedAuthTag = await computeAuthenticationTag(recipientIdentityPrivate, recipientIdentityPublic, senderIdentityPublic, ephemeralPublic, encryptedMessageKey, 'receiving');
|
|
172
|
-
if (!verifyAuthenticationTag(expectedAuthTag, receivedAuthTag)) {
|
|
173
|
-
throw new Error(GENERIC_ERROR);
|
|
174
|
-
}
|
|
175
|
-
// ========================================================================
|
|
176
|
-
// Step 8: Validate sender certificate
|
|
177
|
-
// ========================================================================
|
|
178
|
-
await validateSenderCertificate(certificate, trustRoots, currentTime);
|
|
179
|
-
// Self-send detection
|
|
180
|
-
if (certificate.senderUuid === recipientServiceId &&
|
|
181
|
-
certificate.senderDeviceId === recipientDeviceId) {
|
|
182
|
-
throw new Error(GENERIC_ERROR);
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
senderCertificate: certificate,
|
|
186
|
-
signalProtocolMessage: bytesToBase64(message),
|
|
187
|
-
contentHint,
|
|
188
|
-
contentType,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
finally {
|
|
192
|
-
// Security: Zero all sensitive key material
|
|
193
|
-
for (const arr of toZero) {
|
|
194
|
-
secureZeroBytes(arr);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
//# sourceMappingURL=decryption-v2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"decryption-v2.js","sourceRoot":"","sources":["../../../../internal/protocol/sealed-sender/decryption-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EACL,6BAA6B,EAC7B,mCAAmC,EAEnC,yBAAyB,GAC1B,MAAM,SAAS,CAAC;AAEjB,OA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,CAAC;QAE1E,MAAM,eAAe,GAAG,MAAM,wBAAwB,CACpD,wBAAwB,EACxB,uBAAuB,EACvB,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,WAAW,CACZ,CAAC;QAEF,IAAI,CAAC,uBAAuB,CAAC,eAAe,EAAE,eAAe,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;QAED,2EAA2E;QAC3E,sCAAsC;QACtC,2EAA2E;QAC3E,MAAM,yBAAyB,CAAC,WAAW,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QAEtE,sBAAsB;QACtB,IACE,WAAW,CAAC,UAAU,KAAK,kBAAkB;YAC7C,WAAW,CAAC,cAAc,KAAK,iBAAiB,EAChD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QACjC,CAAC;QAED,OAAO;YACL,iBAAiB,EAAE,WAAW;YAC9B,qBAAqB,EAAE,aAAa,CAAC,OAAO,CAAW;YACvD,WAAW;YACX,WAAW;SACZ,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,4CAA4C;QAC5C,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,eAAe,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sealed Sender V2 Multi-Recipient Encryption
|
|
3
|
-
*
|
|
4
|
-
* Implements V2 multi-recipient sealed sender based on
|
|
5
|
-
* Barbosa & Farshim's randomness reuse technique (IMA 2007).
|
|
6
|
-
*
|
|
7
|
-
* Key efficiency gain: A single ephemeral key and message ciphertext
|
|
8
|
-
* is shared across all recipients, with per-recipient key encapsulation.
|
|
9
|
-
*
|
|
10
|
-
* Algorithm:
|
|
11
|
-
* 1. Generate random M (32 bytes)
|
|
12
|
-
* 2. Derive ephemeral keypair E from M via HKDF(LABEL_R)
|
|
13
|
-
* 3. Derive symmetric key K from M via HKDF(LABEL_K)
|
|
14
|
-
* 4. Encrypt USMC with AES-GCM-SIV(K, nonce=zeros, plaintext=usmc)
|
|
15
|
-
* 5. For each recipient i:
|
|
16
|
-
* a. ikm = X25519(E_private, recipient_pub[i]) || E_pub || recipient_pub[i]
|
|
17
|
-
* b. xor_key = HKDF(ikm, info=LABEL_DH)
|
|
18
|
-
* c. encrypted_key[i] = M XOR xor_key
|
|
19
|
-
* d. auth_ikm = X25519(sender_identity, recipient_pub[i]) || E_pub || encrypted_key[i] || sender_id_pub || recipient_pub[i]
|
|
20
|
-
* e. auth_tag[i] = HKDF(auth_ikm, info=LABEL_DH_S) (16 bytes)
|
|
21
|
-
* 6. Return { version, E_pub, recipients[], ciphertext }
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
import type { SealMultiRecipientOptions, SealedSenderV2Message } from './types.js';
|
|
25
|
-
/** Generic error message for all seal failures */
|
|
26
|
-
export {};
|
|
27
|
-
/**
|
|
28
|
-
* Seal a Signal Protocol message for multiple recipients using V2 format.
|
|
29
|
-
*
|
|
30
|
-
* Uses randomness reuse (Barbosa & Farshim 2007) for efficiency:
|
|
31
|
-
* - Single ephemeral key shared across all recipients
|
|
32
|
-
* - Single message ciphertext shared across all recipients
|
|
33
|
-
* - Per-recipient key encapsulation via XOR with HKDF-derived key
|
|
34
|
-
* - Per-recipient auth tag using identity-to-identity ECDH
|
|
35
|
-
*
|
|
36
|
-
* @param options Multi-recipient sealing options
|
|
37
|
-
* @returns V2 sealed sender message
|
|
38
|
-
* @throws Error (generic) if any validation fails
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const sealed = await sealMultiRecipient({
|
|
43
|
-
* senderCertificate: cert,
|
|
44
|
-
* senderIdentityPrivate: myPrivateKey,
|
|
45
|
-
* senderIdentityPublic: myPublicKey,
|
|
46
|
-
* recipients: [
|
|
47
|
-
* { serviceId: 'user1', deviceId: 1, registrationId: 12345, identityPublic: user1Pub },
|
|
48
|
-
* { serviceId: 'user2', deviceId: 1, registrationId: 23456, identityPublic: user2Pub },
|
|
49
|
-
* ],
|
|
50
|
-
* signalProtocolMessage: encryptedMessage,
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export declare function sealMultiRecipient(options: SealMultiRecipientOptions): Promise<SealedSenderV2Message>;
|
|
55
|
-
export { deriveEphemeralFromM, deriveCipherKeyFromM, applyAgreementXor, computeAuthenticationTag, } from './v2-helpers.js';
|
|
56
|
-
//# sourceMappingURL=encryption-v2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"encryption-v2.d.ts","sourceRoot":"","sources":["../../../../internal/protocol/sealed-sender/encryption-v2.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EACV,yBAAyB,EACzB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAuBjB,kDAAkD;AAClD,OAAO,EAAE,CAAC;AAkCV;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,qBAAqB,CAAC,CA0HhC;AAGD,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,cAAc,CAAC"}
|