crypto: Don't panic if we don't have the keys to generate a QR code

master
Damir Jelić 2021-07-01 10:27:45 +02:00
parent 9052843acb
commit db0843a47a
1 changed files with 77 additions and 37 deletions

View File

@ -796,8 +796,6 @@ impl RequestState<Ready> {
&self, &self,
we_started: bool, we_started: bool,
) -> Result<Option<QrVerification>, CryptoStoreError> { ) -> Result<Option<QrVerification>, CryptoStoreError> {
// TODO return an error explaining why we can't generate a QR code?
// If we didn't state that we support showing QR codes or if the other // If we didn't state that we support showing QR codes or if the other
// side doesn't support scanning QR codes bail early. // side doesn't support scanning QR codes bail early.
if !self.state.our_methods.contains(&VerificationMethod::QrCodeShowV1) if !self.state.our_methods.contains(&VerificationMethod::QrCodeShowV1)
@ -830,44 +828,86 @@ impl RequestState<Ready> {
let verification = if let Some(identity) = &identites.identity_being_verified { let verification = if let Some(identity) = &identites.identity_being_verified {
match &identity { match &identity {
UserIdentities::Own(i) => { UserIdentities::Own(i) => {
if let Some(master_key) = i.master_key().get_first_key() {
if identites.can_sign_devices().await { if identites.can_sign_devices().await {
if let Some(device_key) =
identites.other_device().get_key(DeviceKeyAlgorithm::Ed25519)
{
Some(QrVerification::new_self( Some(QrVerification::new_self(
self.store.clone(), self.store.clone(),
self.flow_id.as_ref().to_owned(), self.flow_id.as_ref().to_owned(),
i.master_key().get_first_key().unwrap().to_owned(), master_key.to_owned(),
identites device_key.to_owned(),
.other_device()
.get_key(DeviceKeyAlgorithm::Ed25519)
.unwrap()
.to_owned(),
identites, identites,
we_started, we_started,
)) ))
} else {
warn!(
user_id = self.other_user_id.as_str(),
device_id = self.state.other_device_id.as_str(),
"Can't create a QR code, the other device \
doesn't have a valid device key"
);
None
}
} else { } else {
Some(QrVerification::new_self_no_master( Some(QrVerification::new_self_no_master(
self.account.clone(), self.account.clone(),
self.store.clone(), self.store.clone(),
self.flow_id.as_ref().to_owned(), self.flow_id.as_ref().to_owned(),
i.master_key().get_first_key().unwrap().to_owned(), master_key.to_owned(),
identites, identites,
we_started, we_started,
)) ))
} }
} else {
warn!(
user_id = self.other_user_id.as_str(),
device_id = self.state.other_device_id.as_str(),
"Can't create a QR code, our cross signing identity \
doesn't contain a valid master key"
);
None
} }
UserIdentities::Other(i) => Some(QrVerification::new_cross( }
self.store.clone(), UserIdentities::Other(i) => {
self.flow_id.as_ref().to_owned(), if let Some(other_master) = i.master_key().get_first_key() {
self.private_cross_signing_identity // TODO we can get the master key from the public
// identity if we don't have the private one and we
// trust the public one.
if let Some(own_master) = self
.private_cross_signing_identity
.master_public_key() .master_public_key()
.await .await
.unwrap() .and_then(|m| m.get_first_key().map(|m| m.to_owned()))
.get_first_key() {
.unwrap() Some(QrVerification::new_cross(
.to_owned(), self.store.clone(),
i.master_key().get_first_key().unwrap().to_owned(), self.flow_id.as_ref().to_owned(),
own_master,
other_master.to_owned(),
identites, identites,
we_started, we_started,
)), ))
} else {
warn!(
user_id = self.other_user_id.as_str(),
device_id = self.state.other_device_id.as_str(),
"Can't create a QR code, we don't trust our own \
master key"
);
None
}
} else {
warn!(
user_id = self.other_user_id.as_str(),
device_id = self.state.other_device_id.as_str(),
"Can't create a QR code, the user's identity \
doesn't have a valid master key"
);
None
}
}
} }
} else { } else {
warn!( warn!(