(
esk: &SymKeyEncryptedSessionKey,
conn: &mut rusqlite::Connection,
self_fingerprint: &str,
)
| 200 | } |
| 201 | |
| 202 | fn try_decrypt_with_auth_token( |
| 203 | esk: &SymKeyEncryptedSessionKey, |
| 204 | conn: &mut rusqlite::Connection, |
| 205 | self_fingerprint: &str, |
| 206 | ) -> Result<Option<PlainSessionKey>> { |
| 207 | // ORDER BY id DESC to query the most-recently saved tokens are returned first. |
| 208 | // This improves performance when Bob scans a QR code that was just created. |
| 209 | let mut stmt = conn.prepare("SELECT token FROM tokens WHERE namespc=? ORDER BY id DESC")?; |
| 210 | let mut rows = stmt.query((Namespace::Auth,))?; |
| 211 | while let Some(row) = rows.next()? { |
| 212 | let token: String = row.get(0)?; |
| 213 | let shared_secret = format!("securejoin/{self_fingerprint}/{token}"); |
| 214 | if let Ok(psk) = decrypt_session_key_with_password(esk, &Password::from(shared_secret)) { |
| 215 | return Ok(Some(psk)); |
| 216 | } |
| 217 | } |
| 218 | Ok(None) |
| 219 | } |
| 220 | |
| 221 | /// Returns Ok(()) if we want to try symmetrically decrypting the message, |
| 222 | /// and Err with a reason if symmetric decryption should not be tried. |
no test coverage detected