cyrpto: Fill out the method to get the MacEventContent.
parent
c35f73473e
commit
9214f01185
|
@ -12,17 +12,19 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use crate::Device;
|
use crate::Device;
|
||||||
|
|
||||||
use olm_rs::sas::OlmSas;
|
use olm_rs::sas::OlmSas;
|
||||||
|
|
||||||
|
use matrix_sdk_common::api::r0::keys::{AlgorithmAndDeviceId, KeyAlgorithm};
|
||||||
use matrix_sdk_common::events::{
|
use matrix_sdk_common::events::{
|
||||||
key::verification::{
|
key::verification::{
|
||||||
accept::AcceptEventContent,
|
accept::AcceptEventContent,
|
||||||
key::KeyEventContent,
|
key::KeyEventContent,
|
||||||
mac::MacEvent,
|
mac::{MacEvent, MacEventContent},
|
||||||
start::{MSasV1Content, MSasV1ContentOptions, StartEventContent},
|
start::{MSasV1Content, MSasV1ContentOptions, StartEventContent},
|
||||||
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
|
HashAlgorithm, KeyAgreementProtocol, MessageAuthenticationCode, ShortAuthenticationString,
|
||||||
VerificationMethod,
|
VerificationMethod,
|
||||||
|
@ -390,9 +392,52 @@ struct Confirmed {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sas<Confirmed> {
|
impl Sas<Confirmed> {
|
||||||
fn confirm(self) -> Sas<Done> {
|
fn into_done(self, event: &MacEvent) -> Sas<Done> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_mac_info(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"MATRIX_KEY_VERIFICATION_MAC{first_user}{first_device}\
|
||||||
|
{second_user}{second_device}{transaction_id}",
|
||||||
|
first_user = self.ids.own_user_id,
|
||||||
|
first_device = self.ids.own_device_id,
|
||||||
|
second_user = self.ids.other_device.user_id(),
|
||||||
|
second_device = self.ids.other_device.device_id(),
|
||||||
|
transaction_id = self.verification_flow_id,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_mac_event_content(&self) -> MacEventContent {
|
||||||
|
let mut mac: BTreeMap<String, String> = BTreeMap::new();
|
||||||
|
|
||||||
|
let info = self.get_mac_info();
|
||||||
|
|
||||||
|
let key_id = AlgorithmAndDeviceId(KeyAlgorithm::Ed25519, self.ids.own_device_id.clone());
|
||||||
|
|
||||||
|
// TODO the MAC needs to include our own ed25519 key.
|
||||||
|
mac.insert(
|
||||||
|
key_id.to_string(),
|
||||||
|
self.inner
|
||||||
|
.calculate_mac("TODO", &format!("{}{}", info, key_id))
|
||||||
|
.expect("Can't calculate SAS MAC"),
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO Add the cross signing master key here if we trust/have it.
|
||||||
|
|
||||||
|
let mut keys = mac.keys().cloned().collect::<Vec<String>>();
|
||||||
|
keys.sort();
|
||||||
|
let keys = self
|
||||||
|
.inner
|
||||||
|
.calculate_mac(&keys.join(","), &format!("{}KEYIDS", &info))
|
||||||
|
.expect("Can't calculate SAS MAC");
|
||||||
|
|
||||||
|
MacEventContent {
|
||||||
|
transaction_id: self.verification_flow_id.clone(),
|
||||||
|
keys,
|
||||||
|
mac,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MacReceived {
|
struct MacReceived {
|
||||||
|
@ -401,7 +446,7 @@ struct MacReceived {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sas<MacReceived> {
|
impl Sas<MacReceived> {
|
||||||
fn into_done(self, event: &MacEvent) -> Sas<Done> {
|
fn confirm(self) -> Sas<Done> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue