crypto: Add a GroupSessionKey type.
parent
9d52037b40
commit
d04c7e0190
|
@ -21,7 +21,7 @@ use std::sync::Arc;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::error::{OlmError, Result, SignatureError, VerificationResult};
|
use super::error::{OlmError, Result, SignatureError, VerificationResult};
|
||||||
use super::olm::{Account, InboundGroupSession, OutboundGroupSession, Session};
|
use super::olm::{Account, GroupSessionKey, InboundGroupSession, OutboundGroupSession, Session};
|
||||||
use super::store::memorystore::MemoryStore;
|
use super::store::memorystore::MemoryStore;
|
||||||
#[cfg(feature = "sqlite-cryptostore")]
|
#[cfg(feature = "sqlite-cryptostore")]
|
||||||
use super::store::sqlite::SqliteStore;
|
use super::store::sqlite::SqliteStore;
|
||||||
|
@ -776,11 +776,13 @@ impl OlmMachine {
|
||||||
.get("ed25519")
|
.get("ed25519")
|
||||||
.ok_or(OlmError::MissingSigningKey)?;
|
.ok_or(OlmError::MissingSigningKey)?;
|
||||||
|
|
||||||
|
let session_key = GroupSessionKey(event.content.session_key.to_owned());
|
||||||
|
|
||||||
let session = InboundGroupSession::new(
|
let session = InboundGroupSession::new(
|
||||||
sender_key,
|
sender_key,
|
||||||
signing_key,
|
signing_key,
|
||||||
&event.content.room_id,
|
&event.content.room_id,
|
||||||
&event.content.session_key,
|
session_key,
|
||||||
)?;
|
)?;
|
||||||
self.store.save_inbound_group_session(session).await?;
|
self.store.save_inbound_group_session(session).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -807,7 +809,7 @@ impl OlmMachine {
|
||||||
sender_key,
|
sender_key,
|
||||||
signing_key,
|
signing_key,
|
||||||
&room_id,
|
&room_id,
|
||||||
&session.session_key().await,
|
session.session_key().await,
|
||||||
)?;
|
)?;
|
||||||
self.store
|
self.store
|
||||||
.save_inbound_group_session(inbound_session)
|
.save_inbound_group_session(inbound_session)
|
||||||
|
|
|
@ -17,6 +17,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use serde::Serialize;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use olm_rs::account::{IdentityKeys, OlmAccount, OneTimeKeys};
|
use olm_rs::account::{IdentityKeys, OlmAccount, OneTimeKeys};
|
||||||
|
@ -309,6 +310,11 @@ impl PartialEq for Session {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The private session key of a group session.
|
||||||
|
/// Can be used to create a new inbound group session.
|
||||||
|
#[derive(Clone, Serialize)]
|
||||||
|
pub struct GroupSessionKey(pub String);
|
||||||
|
|
||||||
/// Inbound group session.
|
/// Inbound group session.
|
||||||
///
|
///
|
||||||
/// Inbound group sessions are used to exchange room messages between a group of
|
/// Inbound group sessions are used to exchange room messages between a group of
|
||||||
|
@ -342,10 +348,10 @@ impl InboundGroupSession {
|
||||||
sender_key: &str,
|
sender_key: &str,
|
||||||
signing_key: &str,
|
signing_key: &str,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
session_key: &str,
|
session_key: GroupSessionKey,
|
||||||
) -> Result<Self, OlmGroupSessionError> {
|
) -> Result<Self, OlmGroupSessionError> {
|
||||||
Ok(InboundGroupSession {
|
Ok(InboundGroupSession {
|
||||||
inner: OlmInboundGroupSession::new(session_key)?,
|
inner: OlmInboundGroupSession::new(&session_key.0)?,
|
||||||
sender_key: sender_key.to_owned(),
|
sender_key: sender_key.to_owned(),
|
||||||
signing_key: signing_key.to_owned(),
|
signing_key: signing_key.to_owned(),
|
||||||
room_id: room_id.clone(),
|
room_id: room_id.clone(),
|
||||||
|
@ -504,9 +510,9 @@ impl OutboundGroupSession {
|
||||||
/// Get the session key of this session.
|
/// Get the session key of this session.
|
||||||
///
|
///
|
||||||
/// A session key can be used to to create an `InboundGroupSession`.
|
/// A session key can be used to to create an `InboundGroupSession`.
|
||||||
pub async fn session_key(&self) -> String {
|
pub async fn session_key(&self) -> GroupSessionKey {
|
||||||
let session = self.inner.lock().await;
|
let session = self.inner.lock().await;
|
||||||
session.session_key()
|
GroupSessionKey(session.session_key())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the unique identifier for this session.
|
/// Returns the unique identifier for this session.
|
||||||
|
|
Loading…
Reference in New Issue