Class CryptoService
End-to-end encryption of the client: owns the OlmMachine, decrypts syncs and encrypts outgoing events.
Inheritance
CryptoService
Assembly: Uniform.Matrix.Client.dll
public sealed class CryptoService : IDisposable
Constructors
|
Edit this page
View Source
Declaration
public CryptoService(EfCryptoStore store, AccountPaths paths, ILogger<CryptoService> logger)
Parameters
Properties
|
Edit this page
View Source
Declaration
public bool Available { get; }
Property Value
|
Edit this page
View Source
This device's ID, when available.
Declaration
public string? DeviceId { get; }
Property Value
|
Edit this page
View Source
This device's identity keys, when available.
Declaration
public IdentityKeys? IdentityKeys { get; }
Property Value
|
Edit this page
View Source
Send a room event, encrypted in encrypted rooms: the room, event type and content; set by the outbox, which in-room verification answers through.
Declaration
public Func<string, string, JsonObject, CancellationToken, Task>? RoomEventSender { get; set; }
Property Value
|
Edit this page
View Source
Why encryption is not available, or null.
Declaration
public string? UnavailableReason { get; }
Property Value
|
Edit this page
View Source
Verifications in progress.
Declaration
public IReadOnlyList<Verification> Verifications { get; }
Property Value
|
Edit this page
View Source
Declaration
public Task WhenStarted { get; }
Property Value
Methods
|
Edit this page
View Source
Accept an incoming verification request.
Declaration
public Task AcceptVerificationAsync(Verification verification, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Cancel a verification; m.mismatched_sas when the emoji differ.
Declaration
public Task CancelVerificationAsync(Verification verification, string code = "m.user", CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Confirm that the emoji match.
Declaration
public Task ConfirmVerificationAsync(Verification verification, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Decrypt one event; return it unchanged when not encrypted or not decryptable.
Declaration
public Task<ClientEvent> DecryptAsync(string roomId, ClientEvent clientEvent, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Process the encryption parts of sync and return it with Megolm timeline events decrypted where keys are known.
Declaration
public Task<SyncResponse> DecryptSyncAsync(SyncResponse sync, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Wipe key material in memory.
Declaration
|
Edit this page
View Source
EncryptAsync(string, string, JsonElement, IReadOnlyCollection<string>, EncryptionContent?, CancellationToken)
Encrypt an event for an encrypted room; throw InvalidOperationException when encryption is unavailable, so nothing is sent in the clear.
Declaration
public Task<EncryptedContent> EncryptAsync(string roomId, string eventType, JsonElement content, IReadOnlyCollection<string> memberIds, EncryptionContent? settings, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Format an Ed25519 key in groups of four, as clients show fingerprints for comparison.
Declaration
public static string FormatFingerprint(string key)
Parameters
| Type |
Name |
Description |
| string |
key |
|
Returns
|
Edit this page
View Source
Return the trust of a known device, or null when the device is unknown or encryption is off.
Declaration
public DeviceTrust? GetDeviceTrust(string userId, string deviceId)
Parameters
Returns
|
Edit this page
View Source
Declaration
public IReadOnlyList<DeviceInfo> GetDevices(string userId)
Parameters
| Type |
Name |
Description |
| string |
userId |
|
Returns
|
Edit this page
View Source
Report cross-signing, backup and secret storage state of the account.
Declaration
public Task<SecurityStatus> GetSecurityStatusAsync(CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Return the user's devices signed by their current self-signing key, which can vouch for others of the account, whether or not this device trusts the identity; none when encryption is off.
Declaration
public IReadOnlyList<DeviceInfo> GetSignedDevices(string userId)
Parameters
| Type |
Name |
Description |
| string |
userId |
|
Returns
|
Edit this page
View Source
Return whether this device has verified userId: their cross-signing identity is trusted, or, without one, every device of theirs known here is verified; false when encryption is off.
Declaration
public bool IsUserVerified(string userId)
Parameters
| Type |
Name |
Description |
| string |
userId |
|
Returns
|
Edit this page
View Source
Declaration
public Task<RecoveryResult> RecoverAsync(string recoveryKey, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Start verifying a device of userId, or all of them.
Declaration
public Task<Verification> RequestVerificationAsync(string userId, string? deviceId, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
RequestVerificationInRoomAsync(string, string, Func<JsonObject, CancellationToken, Task<string>>, CancellationToken)
Ask another user to verify in a room, their direct chat, with a request message that sendRequest sends and returns the event ID of.
Declaration
public Task<Verification> RequestVerificationInRoomAsync(string roomId, string userId, Func<JsonObject, CancellationToken, Task<string>> sendRequest, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
SendEncryptedToDevicesAsync(string, JsonObject, IReadOnlyCollection<(string UserId, string DeviceId)>, CancellationToken)
Send a to-device event to each of devices, encrypted over Olm; return how many it went to, none without encryption.
Declaration
public Task<int> SendEncryptedToDevicesAsync(string type, JsonObject content, IReadOnlyCollection<(string UserId, string DeviceId)> devices, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Declaration
public Task<string> SetUpRecoveryAsync(string? password, CancellationToken cancellationToken = default)
Parameters
Returns
|
Edit this page
View Source
Load or create the device's encryption account and upload its keys; log and continues without encryption on failure.
Declaration
public Task StartAsync(MatrixClient client, CancellationToken cancellationToken)
Parameters
Returns
|
Edit this page
View Source
Return room keys received since the last call, to decrypt stored events that were waiting for them.
Declaration
public IReadOnlyList<(string RoomId, string SessionId)> TakeReceivedKeys()
Returns
|
Edit this page
View Source
Fetch the devices of userId, so their trust is known.
Declaration
public Task TrackUserAsync(string userId, CancellationToken cancellationToken = default)
Parameters
Returns
Events
|
Edit this page
View Source
Raised for each to-device event that came encrypted over Olm, decrypted, e.g. MatrixRTC's media keys; on the sync loop, so a handler should be quick.
Declaration
public event Action<DecryptedToDeviceEvent>? ToDeviceReceived
Event Type
|
Edit this page
View Source
Raised when a verification starts, changes or ends; raised off the UI thread.
Declaration
public event Action<Verification>? VerificationChanged
Event Type
|
Edit this page
View Source
Raised when a verification message is dropped, with its sender, device and why, see VerificationIgnored.
Declaration
public event Action<string, string?, string>? VerificationIgnored
Event Type
Implements