sealedSenderDecryptToUsmcWithCallbacks function
Unseal a sealed sender message down to its USMC without decrypting the message inside it.
Use it when you need the content hint or group id of a message you cannot decrypt — that is exactly the case a resend request is for.
Security
Three gates run before the envelope is returned — the same three, in the
same order, that sealedSenderDecryptWithCallbacks puts in front of its
plaintext:
- the sender certificate is validated against
trust_root; - a certificate naming
local_name/local_device_idis refused as a self-send, so your own message reflected back at you cannot be unsealed and attributed to you; and - the identity the certificate carries is checked against
get_identityfor that sender, so a changed identity key is rejected with the sameuntrusted identityerror the decrypt path raises.
Gate 1 alone is not enough. It proves a server vouched for the certificate,
not that the certificate names the peer you have been talking to: a peer
that re-registers gets a valid certificate carrying a new identity key,
which is precisely a safety-number change. Without gate 3 this function
would hand that back silently while SealedSenderCipher.decrypt refuses it,
and a caller acting on senderCertificate() or groupId() — deciding who
to send a resend request to, and for which group — would never see the
change.
One difference from the decrypt path is worth knowing, because it is not a
weakening: gate 3 compares the certificate's identity key, while the
decrypt path lets libsignal compare the key bound into the session (or
carried by the inner PreKeySignalMessage). Upstream never checks that
those two agree. Comparing the certificate's key is the right test for a
function that hands the certificate back, and it is the stricter of the two
— a certificate carrying a key you have not stored is refused here even when
the session it wraps would still decrypt.
Gate 1 is a deliberate divergence from upstream's factoring. libsignal
splits the two: sealed_sender_decrypt_to_usmc performs no validation and
sealed_sender_decrypt layers it on. This binding merges them, so there is
no unchecked variant. The cost is real — a message whose certificate has
expired (clock skew, or long-queued delivery) can no longer be unsealed to
read its content hint at all — but SealedSenderCipher.decrypt already
behaves that way, and an unchecked reader is too sharp an edge to expose:
libsignal's own
sealed_sender_decrypt_to_usmc only binds the certificate to whoever sealed
the blob, and sealing requires nothing but the recipient's public identity
key. Without the trust-root check anyone could mint a certificate naming any
sender and any group, and a caller reading senderCertificate() or
groupId() off the result would attribute the message — and aim its resend
request — wherever the attacker chose.
Implementation
Future<Uint8List> sealedSenderDecryptToUsmcWithCallbacks({
required List<int> ciphertext,
required List<int> trustRoot,
required BigInt timestamp,
required String localName,
required int localDeviceId,
required FutureOr<Uint8List> Function() getIdentityKeyPair,
required FutureOr<int> Function() getLocalRegistrationId,
required FutureOr<Uint8List?> Function(String, int) getIdentity,
}) => RustLib.instance.api
.crateApiSealedSenderSealedSenderDecryptToUsmcWithCallbacks(
ciphertext: ciphertext,
trustRoot: trustRoot,
timestamp: timestamp,
localName: localName,
localDeviceId: localDeviceId,
getIdentityKeyPair: getIdentityKeyPair,
getLocalRegistrationId: getLocalRegistrationId,
getIdentity: getIdentity,
);