Internal
Global override for whether the client should ever send encrypted messages to unverified devices. This provides the default for rooms which do not specify a value.
If true, all unverified devices will be blacklisted by default
Whether sendMessage in a room with unknown and unverified devices should throw an error and not send the message. This has 'Global' for symmetry with setGlobalBlacklistUnverifiedDevices but there is currently no room-level equivalent for this setting.
Bootstrap cross-signing by creating keys if needed.
If everything is already set up, then no changes are made, so this is safe to run to ensure cross-signing is ready for use.
This function:
options object
Bootstrap the secret storage by creating a new secret storage key, add it in the secret storage and store the cross signing keys in the secret storage.
createSecretStorageKey
.
Only if setupNewSecretStorage
is set or if there is no AES key in the secret storagecryptoCallbacks.cacheSecretStorageKey
if provided.Options object.
Force a re-check of the key backup and enable/disable it as appropriate.
Fetches the current backup information from the server. If there is a backup, and it is trusted, starts backing up to it; otherwise, disables backups.
null
if there is no backup on the server. Otherwise, data on the backup as returned by the server,
and trust information (as returned by isKeyBackupTrusted).
Check the cross signing trust of the current user
Optional
opts: CheckOwnCrossSigningTrustOptsOptions object.
Get the verification level for a given user
user to be checked
Superceded by CryptoApi#getUserVerificationStatus.
Create a recovery key (ie, a key suitable for use with server-side secret storage).
The key can either be based on a user-supplied passphrase, or just created randomly.
Optional
password: stringOptional passphrase string to use to derive the key, which can later be entered by the user as an alternative to entering the recovery key itself. If omitted, a key is generated randomly.
Object including recovery key and server upload parameters. The private key should be disposed of after displaying to the use.
Cross-sign one of our own devices.
This will create a signature for the device using our self-signing key, and publish that signature. Cross-signing a device indicates, to our other devices and to other users, that we have verified that it really belongs to us.
Requires that cross-signing has been set up on this device (normally by calling bootstrapCrossSigning).
Note: Do not call this unless you have verified, somehow, that the device is genuine!
ID of the device to be signed.
Decrypt a received event
a promise which resolves once we have finished decrypting. Rejects with an error if there is a problem decrypting the event.
Encrypt an event according to the configuration of the room.
event to be sent
destination room.
Promise which resolves when the event has been encrypted, or null if nothing was needed
Encrypts a given payload object via Olm to-device messages to a given set of devices.
the type of the event to send.
an array of devices to encrypt the payload for.
the payload to encrypt.
the batch of encrypted payloads which can then be sent via matrix.MatrixClient#queueToDevice.
Get a list containing all of the room keys
This should be encrypted before returning it to the user.
a promise which resolves to a list of session export objects
Optional
exportExport secrets bundle for transmitting to another device as part of OIDC QR login
Finds a DM verification request that is already in progress for the given room id
the room to use for verification
the VerificationRequest that is in progress, if any
Finds a DM verification request that is already in progress for the given room and user.
the room to use for verification.
Optional
userId: stringsearch for a verification request for the given user.
the VerificationRequest that is in progress, if any.
Discard any existing megolm session for the given room.
This will ensure that a new session is created on the next call to prepareToEncrypt, or the next time a message is sent.
This should not normally be necessary: it should only be used as a debugging tool if there has been a problem with encryption.
the room to discard sessions for
Get a backup decryptor capable of decrypting megolm session data encrypted with the given backup information.
The backup information
The private decryption key.
Get the ID of one of the user's cross-signing keys, if both private and matching public parts of that key are available (ie. cached in the local crypto store).
The public part may not be available if a /keys/query
request has not yet been
performed, or if the device that created the keys failed to publish them.
If either part of the keypair is not available, this will return null
.
Optional
type: CrossSigningKeyThe type of key to get the ID of. One of CrossSigningKey.Master
, CrossSigningKey.SelfSigning
,
or CrossSigningKey.UserSigning
. Defaults to CrossSigningKey.Master
.
If cross-signing has been initialised on this device, the ID of the given key. Otherwise, null
Get the status of our cross-signing keys.
The current status of cross-signing keys: whether we have public and private keys cached locally, and whether the private keys are in secret storage.
May throw matrix.ClientStoppedError if the MatrixClient
is stopped before or during the call.
Get the verification status of a given device.
The ID of the user whose device is to be checked.
The ID of the device to check
null
if the device is unknown, or has not published any encryption keys (implying it does not support
encryption); otherwise the verification status of the device.
Get information about the encryption of the given event.
the event to get information for
null
if the event is not encrypted, or has not (yet) been successfully decrypted. Otherwise, an
object with information about the encryption of the event.
Get information about the encryption of an event
event to be checked
Return the details of the latest backup on the server, when we last checked.
This normally returns a cached value, but if we haven't yet made a request to the server, it will fire one off. It will always return the details of the active backup if key backup is enabled.
Return null if there is no backup.
the key backup information
Get the public part of the device keys for the current device.
The public device keys.
Fetch the backup decryption key we have saved in our store.
This can be used for gossiping the key to other devices.
the key, if any, or null
Get the cross signing information for a given user.
The cross-signing API is currently UNSTABLE and may change without notice.
the user ID to get the cross-signing info for.
the cross signing information for the user.
Get the device information for the given list of users.
For any users whose device lists are cached (due to sharing an encrypted room with the user), the cached device data is returned.
If there are uncached users, and the downloadUncached
parameter is set to true
,
a /keys/query
request is made to the server to retrieve these devices.
The users to fetch.
Optional
downloadUncached: booleanIf true, download the device list for users whose device list we are not currently tracking. Defaults to false, in which case such users will not appear at all in the result map.
A map {@link DeviceMap}
.
Get the verification status of a given user.
The ID of the user to check.
Returns to-device verification requests that are already in progress for the given user id.
the ID of the user to query
the VerificationRequests that are in progress
Import a list of room keys restored from backup
a list of session export objects
the version of the backup these keys came from.
Optional
opts: ImportRoomKeysOptsoptions object
a promise which resolves once the keys have been imported
Import a list of room keys previously exported by exportRoomKeys
a list of session export objects
Optional
opts: ImportRoomKeysOptsoptions object
a promise which resolves once the keys have been imported
Import a JSON string encoding a list of room keys previously exported by exportRoomKeysAsJson
a JSON string encoding a list of session export objects, each of which is an IMegolmSessionData
Optional
opts: ImportRoomKeysOptsoptions object
a promise which resolves once the keys have been imported
Optional
importImport secrets bundle transmitted from another device.
The secrets bundle received from the other device
Optional
backup?: { Checks whether cross signing:
If this function returns false, bootstrapCrossSigning() can be used to fix things such that it returns true. That is to say, after bootstrapCrossSigning() completes successfully, this function should return true.
True if cross-signing is ready to be used on this device
May throw matrix.ClientStoppedError if the MatrixClient
is stopped before or during the call.
Check if we believe the given room to be encrypted.
This method returns true if the room has been configured with encryption. The setting is persistent, so that even if the encryption event is removed from the room state, it still returns true. This helps to guard against a downgrade attack wherein a server admin attempts to remove encryption.
true
if the room with the supplied ID is encrypted. false
if the room is not encrypted, or is unknown to
us.
Determine if a key backup can be trusted.
key backup info dict from matrix.MatrixClient.getKeyBackupVersion.
Checks whether secret storage:
If this function returns false, bootstrapSecretStorage() can be used to fix things such that it returns true. That is to say, after bootstrapSecretStorage() completes successfully, this function should return true.
True if secret storage is ready to be used on this device
Attempt to fetch the backup decryption key from secret storage.
If the key is found in secret storage, checks it against the latest backup on the server; if they match, stores the key in the crypto store by calling storeSessionBackupPrivateKey, which enables automatic restore of individual keys when an Unable-to-decrypt error is encountered.
If we are unable to fetch the key from secret storage, there is no backup on the server, or the key does not match, throws an exception.
Called by the /sync loop whenever an m.room.encryption event is received.
This is called before RoomStateEvents are emitted for any of the events in the /sync response (even if the other events technically happened first). This works around a problem if the client uses a RoomStateEvent (typically a membership event) as a trigger to send a message in a new room (or one where encryption has been newly enabled): that would otherwise leave the crypto layer confused because it expects crypto to be set up, but it has not yet been.
in which the event was received
encryption event to be processed
Called by the /sync loop after each /sync response is processed.
Used to complete batch processing, or to initiate background processes
information about the completed sync.
"Pin" the current identity of the given user, accepting it as genuine.
This is useful if the user has changed identity since we first saw them (leading to UserVerificationStatus.needsUserApproval), and we are now accepting their new identity.
Throws an error if called on our own user ID, or on a user ID that we don't have an identity for.
Perform any background tasks that can be done before a message is ready to send, in order to speed up sending of the message.
the room the event is in
Called by the /sync loop whenever there are incoming to-device messages.
The implementation may preprocess the received messages (eg, decrypt them) and return an updated list of messages for dispatch to the rest of the system.
Note that, unlike ClientEvent.ToDeviceEvent events, this is called on the raw to-device messages, rather than the results of any decryption attempts.
the received to-device messages
A list of preprocessed to-device messages.
Handle the notification from /sync that device lists have been changed.
device_lists field from /sync
Called by the /sync loop when one time key counts and unused fallback key details are received.
Optional
oneTimeKeysCounts: Record<string, number>the received one time key counts
Optional
unusedFallbackKeys: string[]the received unused fallback keys
Request an interactive verification with the given device.
This is normally used on one of our own devices, when the current device is already cross-signed, and we want to validate another device.
If a verification for this user/device is already in flight, returns it. Otherwise, initiates a new one.
To control the methods offered, set matrix.ICreateClientOpts.verificationMethods when creating the
MatrixClient
.
ID of the owner of the device to verify
ID of the device to verify
a VerificationRequest when the request has been sent to the other party.
Send a verification request to our other devices.
This is normally used when the current device is new, and we want to ask another of our devices to cross-sign.
If an all-devices verification is already in flight, returns it. Otherwise, initiates a new one.
To control the methods offered, set matrix.ICreateClientOpts.verificationMethods when creating the
MatrixClient
.
a VerificationRequest when the request has been sent to the other party.
Request a key verification from another user, using a DM.
the user to request verification with.
the room to use for verification.
resolves to a VerificationRequest when the request has been sent to the other party.
Creates a new key backup version.
If there are existing backups they will be replaced.
The decryption key will be saved in Secret Storage (the matrix.SecretStorage.SecretStorageCallbacks.getSecretStorageKey Crypto callback will be called) and the backup engine will be started.
Download and restore the full key backup from the homeserver.
Before calling this method, a decryption key, and the backup version to restore, must have been saved in the crypto store. This happens in one of the following ways:
Warning: the full key backup may be quite large, so this operation may take several hours to complete. Use of KeyBackupRestoreOpts.progressCallback is recommended.
Optional
opts: KeyBackupRestoreOptsRestores a key backup using a passphrase. The decoded key (derived from the passphrase) is stored locally by calling CryptoApi#storeSessionBackupPrivateKey.
The passphrase to use to restore the key backup.
Optional
opts: KeyBackupRestoreOptsThe DeviceIsolationMode mode to use.
Mark the given device as locally verified.
Marking a device as locally verified has much the same effect as completing the verification dance, or receiving a cross-signing signature for it.
owner of the device
unique identifier for the device.
Optional
verified: booleanwhether to mark the device as verified. Defaults to 'true'.
Set whether to trust other user's signatures of their devices.
If false, devices will only be considered 'verified' if we have verified that device individually (effectively disabling cross-signing).
true
by default.
the new value
Start using device dehydration.
createNewKey
is set to true, always creates a new key.This function must not be called unless isDehydrationSupported
returns
true
, and must not be called until after cross-signing and secret
storage have been set up.
Optional
createNewKey: booleanwhether to force creation of a new dehydration key. This can be used, for example, if Secret Storage is being reset. Defaults to false.
Store the backup decryption key.
This should be called if the client has received the key from another device via secret sharing (gossiping). It is the responsability of the caller to check that the decryption key is valid for the current backup version.
the backup decryption key
Store the backup decryption key.
This should be called if the client has received the key from another device via secret sharing (gossiping). It is the responsability of the caller to check that the decryption key is valid for the given backup version.
the backup decryption key
the backup version corresponding to this decryption key
Check if the given user has published cross-signing keys.
/keys/query
request is made to update locally the cross signing keys./keys/query
request is made to the server to retrieve the cross signing keys.Optional
userId: stringthe user ID to check. Defaults to the local user.
Optional
downloadUncached: booleanIf true, download the device list for users whose device list we are not
currently tracking. Defaults to false, in which case false
will be returned for such users.
true if the cross signing keys are available.
Common interface for the crypto implementations