(
context: &Context,
esk: &SymKeyEncryptedSessionKey,
)
| 91 | } |
| 92 | |
| 93 | async fn decrypt_session_key_symmetrically( |
| 94 | context: &Context, |
| 95 | esk: &SymKeyEncryptedSessionKey, |
| 96 | ) -> Result<(PlainSessionKey, Option<String>)> { |
| 97 | let self_fp = self_fingerprint(context).await?; |
| 98 | let query_only = true; |
| 99 | context |
| 100 | .sql |
| 101 | .call(query_only, |conn| { |
| 102 | // First, try decrypting using AUTH tokens from scanned QR codes, stored in the bobstate, |
| 103 | // because usually there will only be 1 or 2 of it, so, it should be fast |
| 104 | let res: Option<(PlainSessionKey, String)> = try_decrypt_with_bobstate(esk, conn)?; |
| 105 | if let Some((plain_session_key, fingerprint)) = res { |
| 106 | return Ok((plain_session_key, Some(fingerprint))); |
| 107 | } |
| 108 | |
| 109 | // Then, try decrypting using broadcast secrets |
| 110 | let res: Option<(PlainSessionKey, Option<String>)> = |
| 111 | try_decrypt_with_broadcast_secret(esk, conn)?; |
| 112 | if let Some((plain_session_key, fingerprint)) = res { |
| 113 | return Ok((plain_session_key, fingerprint)); |
| 114 | } |
| 115 | |
| 116 | // Finally, try decrypting using own AUTH tokens |
| 117 | // There can be a lot of AUTH tokens, |
| 118 | // because a new one is generated every time a QR code is shown |
| 119 | let res: Option<PlainSessionKey> = try_decrypt_with_auth_token(esk, conn, self_fp)?; |
| 120 | if let Some(plain_session_key) = res { |
| 121 | return Ok((plain_session_key, None)); |
| 122 | } |
| 123 | |
| 124 | bail!("Could not find symmetric secret for session key") |
| 125 | }) |
| 126 | .await |
| 127 | } |
| 128 | |
| 129 | fn try_decrypt_with_bobstate( |
| 130 | esk: &SymKeyEncryptedSessionKey, |
no test coverage detected