Skip to content

Commit 69c8b9f

Browse files
zecakehpoljar
authored andcommitted
sdk: Add method to check if device is verified with cross-signing
Signed-off-by: Kévin Commaille <[email protected]>
1 parent 2c3664c commit 69c8b9f

File tree

1 file changed

+116
-0
lines changed
  • crates/matrix-sdk/src/encryption/identities

1 file changed

+116
-0
lines changed

crates/matrix-sdk/src/encryption/identities/devices.rs

+116
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,122 @@ impl Device {
386386
self.inner.is_verified()
387387
}
388388

389+
/// Is the device considered to be verified with cross-signing.
390+
///
391+
/// A device is considered to be verified if it's signed by the appropriate
392+
/// cross-signing key.
393+
///
394+
/// ## Cross-signing verification
395+
///
396+
/// Cross-signing verification uses signatures over devices and user
397+
/// identities to check if a device is considered to be verified. The
398+
/// signatures can be uploaded to the homeserver, this allows us to
399+
/// share the verification state with other devices. Devices only need to
400+
/// verify a user identity, if the user identity has verified and signed
401+
/// the device we can consider the device to be verified as well.
402+
///
403+
/// Devices are usually cross-signing verified using interactive
404+
/// verification, which can be started using the
405+
/// [`Device::request_verification()`] method.
406+
///
407+
/// A [`Device`] can also be manually signed using the [`Device::verify()`]
408+
/// method, this works only for devices belonging to our own user.
409+
///
410+
/// Do note that the device that is being manually signed will not trust our
411+
/// own user identity like it would if we interactively verify the device.
412+
/// Such a device can mark our own user as verified using the
413+
/// [`UserIdentity::verify()`] method.
414+
///
415+
/// ### Verification of devices belonging to our own user.
416+
///
417+
/// If the device belongs to our own user, the device will be considered to
418+
/// be verified if:
419+
///
420+
/// * The device has been signed by our self-signing key
421+
/// * Our own user identity is considered to be [verified]
422+
///
423+
/// In other words we need to find a valid signature chain from our user
424+
/// identity to the device:
425+
///
426+
///```text
427+
/// ┌─────────────────────────────────────┐ ┌─────────────┐
428+
/// │ Own User Identity │ │ Device │
429+
/// ├──────────────────┬──────────────────┤───►├─────────────┤
430+
/// │ Master Key │ Self-signing Key │ │ Device Keys │
431+
/// └──────────────────┴──────────────────┘ └─────────────┘
432+
/// ```
433+
///
434+
/// ### Verification of devices belonging to other users.
435+
///
436+
/// If the device belongs to some other user it will be considered to be
437+
/// verified if:
438+
///
439+
/// * The device has been signed by the user's self-signing key
440+
/// * The user's master-signing key has been signed by our own user-signing
441+
/// key, i.e. our own identity trusts the other users identity.
442+
/// * Our own user identity is considered to be [verified]
443+
///
444+
/// ```text
445+
/// ┌─────────────────────────────────────┐
446+
/// │ Own User Identity │
447+
/// ├──────────────────┬──────────────────┤─────┐
448+
/// │ Master Key │ User-signing Key │ │
449+
/// └──────────────────┴──────────────────┘ │
450+
/// ┌───────────────────────────────────────────────────┘
451+
/// │
452+
/// │ ┌─────────────────────────────────────┐ ┌─────────────┐
453+
/// │ │ User Identity │ │ Device │
454+
/// └──────►├──────────────────┬──────────────────┤───►│─────────────│
455+
/// │ Master Key │ Self-signing Key │ │ Device Keys │
456+
/// └──────────────────┴──────────────────┘ └─────────────┘
457+
/// ```
458+
///
459+
/// # Examples
460+
///
461+
/// Let's check if a device is verified:
462+
///
463+
/// ```no_run
464+
/// # use matrix_sdk::{
465+
/// # Client,
466+
/// # ruma::{
467+
/// # device_id, user_id,
468+
/// # events::key::verification::VerificationMethod,
469+
/// # }
470+
/// # };
471+
/// # use url::Url;
472+
/// # use futures::executor::block_on;
473+
/// # block_on(async {
474+
/// # let alice = user_id!("@alice:example.org");
475+
/// # let homeserver = Url::parse("http://example.com")?;
476+
/// # let client = Client::new(homeserver).await?;
477+
/// let device =
478+
/// client.encryption().get_device(alice, device_id!("DEVICEID")).await?;
479+
///
480+
/// if let Some(device) = device {
481+
/// if device.is_verified_with_cross_signing() {
482+
/// println!(
483+
/// "Device {} of user {} is verified with cross-signing",
484+
/// device.device_id(),
485+
/// device.user_id()
486+
/// );
487+
/// } else {
488+
/// println!(
489+
/// "Device {} of user {} is not verified with cross-signing",
490+
/// device.device_id(),
491+
/// device.user_id()
492+
/// );
493+
/// }
494+
/// }
495+
/// # anyhow::Ok(()) });
496+
/// ```
497+
///
498+
/// [`UserIdentity::verify()`]:
499+
/// crate::encryption::identities::UserIdentity::verify
500+
/// [verified]: crate::encryption::identities::UserIdentity::is_verified
501+
pub fn is_verified_with_cross_signing(&self) -> bool {
502+
self.inner.is_cross_signing_trusted()
503+
}
504+
389505
/// Set the local trust state of the device to the given state.
390506
///
391507
/// This won't affect any cross signing verification state, this only sets

0 commit comments

Comments
 (0)