@@ -53,7 +53,7 @@ use tokio::sync::Mutex;
53
53
use tracing:: {
54
54
debug, error,
55
55
field:: { debug, display} ,
56
- info, instrument, warn, Span ,
56
+ info, instrument, trace , warn, Span ,
57
57
} ;
58
58
use vodozemac:: {
59
59
megolm:: { DecryptionError , SessionOrdering } ,
@@ -1786,51 +1786,60 @@ impl OlmMachine {
1786
1786
}
1787
1787
}
1788
1788
1789
- /// Check that the sender of a Megolm session satisfies the trust
1789
+ /// Check that a Megolm event satisfies the sender trust
1790
1790
/// requirement from the decryption settings.
1791
+ ///
1792
+ /// If the requirement is not satisfied, returns
1793
+ /// [`MegolmError::SenderIdentityNotTrusted`].
1791
1794
fn check_sender_trust_requirement (
1792
1795
& self ,
1793
1796
session : & InboundGroupSession ,
1794
1797
encryption_info : & EncryptionInfo ,
1795
1798
trust_requirement : & TrustRequirement ,
1796
1799
) -> MegolmResult < ( ) > {
1797
1800
/// Get the error from the encryption information.
1798
- fn encryption_info_to_error ( encryption_info : & EncryptionInfo ) -> MegolmResult < ( ) > {
1799
- // When this is called, the verification state *must* be unverified,
1800
- // otherwise the sender_data would have been SenderVerified
1801
- let VerificationState :: Unverified ( verification_level) =
1802
- & encryption_info. verification_state
1803
- else {
1804
- unreachable ! ( "inconsistent verification state" ) ;
1805
- } ;
1801
+ fn verification_level_to_error ( verification_level : & VerificationLevel ) -> MegolmResult < ( ) > {
1806
1802
Err ( MegolmError :: SenderIdentityNotTrusted ( verification_level. clone ( ) ) )
1807
1803
}
1808
1804
1805
+ trace ! (
1806
+ verification_state = ?encryption_info. verification_state,
1807
+ ?trust_requirement, "check_sender_trust_requirement" ,
1808
+ ) ;
1809
+
1810
+ // VerificationState::Verified is acceptable for all TrustRequirement levels, so
1811
+ // let's get that out of the way
1812
+ let verification_level = match & encryption_info. verification_state {
1813
+ VerificationState :: Verified => return Ok ( ( ) ) ,
1814
+ VerificationState :: Unverified ( verification_level) => verification_level,
1815
+ } ;
1816
+
1809
1817
match trust_requirement {
1810
1818
TrustRequirement :: Untrusted => Ok ( ( ) ) ,
1811
1819
1812
- TrustRequirement :: CrossSignedOrLegacy => match & session. sender_data {
1813
- // Reject if the sender was previously verified, but changed
1814
- // their identity and is not verified any more.
1815
- SenderData :: VerificationViolation ( ..) => Err (
1816
- MegolmError :: SenderIdentityNotTrusted ( VerificationLevel :: VerificationViolation ) ,
1817
- ) ,
1818
- SenderData :: SenderUnverified ( ..) => Ok ( ( ) ) ,
1819
- SenderData :: SenderVerified ( ..) => Ok ( ( ) ) ,
1820
- SenderData :: DeviceInfo { legacy_session : true , .. } => Ok ( ( ) ) ,
1821
- SenderData :: UnknownDevice { legacy_session : true , .. } => Ok ( ( ) ) ,
1822
- _ => encryption_info_to_error ( encryption_info) ,
1823
- } ,
1820
+ TrustRequirement :: CrossSignedOrLegacy => {
1821
+ // `VerificationLevel::UnsignedDevice` and `VerificationLevel::None` correspond
1822
+ // to `SenderData::DeviceInfo` and `SenderData::UnknownDevice`
1823
+ // respectively, and those cases may be acceptable if the reason
1824
+ // for the lack of data is that the sessions were established
1825
+ // before we started collecting SenderData.
1826
+ let legacy_session = match & session. sender_data {
1827
+ SenderData :: DeviceInfo { legacy_session, .. } => legacy_session,
1828
+ SenderData :: UnknownDevice { legacy_session, .. } => legacy_session,
1829
+ _ => & false ,
1830
+ } ;
1831
+
1832
+ match ( verification_level, legacy_session) {
1833
+ ( VerificationLevel :: UnverifiedIdentity , _) => Ok ( ( ) ) ,
1834
+ ( VerificationLevel :: UnsignedDevice , true ) => Ok ( ( ) ) ,
1835
+ ( VerificationLevel :: None ( _) , true ) => Ok ( ( ) ) ,
1836
+ _ => verification_level_to_error ( verification_level) ,
1837
+ }
1838
+ }
1824
1839
1825
- TrustRequirement :: CrossSigned => match & session. sender_data {
1826
- // Reject if the sender was previously verified, but changed
1827
- // their identity and is not verified any more.
1828
- SenderData :: VerificationViolation ( ..) => Err (
1829
- MegolmError :: SenderIdentityNotTrusted ( VerificationLevel :: VerificationViolation ) ,
1830
- ) ,
1831
- SenderData :: SenderUnverified ( ..) => Ok ( ( ) ) ,
1832
- SenderData :: SenderVerified ( ..) => Ok ( ( ) ) ,
1833
- _ => encryption_info_to_error ( encryption_info) ,
1840
+ TrustRequirement :: CrossSigned => match verification_level {
1841
+ VerificationLevel :: UnverifiedIdentity => Ok ( ( ) ) ,
1842
+ _ => verification_level_to_error ( verification_level) ,
1834
1843
} ,
1835
1844
}
1836
1845
}
0 commit comments