Skip to content

Commit

Permalink
fix: accept QR codes with 'broken' JSON (#6528)
Browse files Browse the repository at this point in the history
this converts old QR codes to the new format, in an hacky, but simple
way, see #6518 for more details and for code snippet


then QR code change is esp. bad as ppl will have different versions for
some days at least, weakening overall UX, esp. of first-time-users that
may come to delta because of praised, seamless multidevice ... :)


i tested in deltachat/deltachat-ios#2595 that
this actually fixes the problem, and there is no deeper issue with
changed chashes or so - seemed not to be the case, at least, with this
hack, core accepts QR codes from the released 1.52-and-before series

this hack gives user time to update, it can be removed after some months
(we can also remove the old BACKUP qr code alltogether then)

we should still not wait too long with the PR as there are already
versions out with the "new/bad" QR code (and growing, as new iOS
installations will get the new format, one cannot revert a version, only
pause rollout)

---------

Co-authored-by: link2xt <[email protected]>
  • Loading branch information
r10s and link2xt authored Feb 10, 2025
1 parent a0ff0d7 commit 8bddd45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ pub enum Qr {
},
}

// hack around the changed JSON accidentally used by an iroh upgrade, see #6518 for more details and for code snippet.
// this hack is mainly needed to give ppl time to upgrade and can be removed after some months (added 2025-02)
fn fix_add_second_device_qr(qr: &str) -> String {
qr.replacen(r#","info":{"relay_url":"#, r#","relay_url":"#, 1)
.replacen(r#""]}}"#, r#""]}"#, 1)
}

fn starts_with_ignore_case(string: &str, pattern: &str) -> bool {
string.to_lowercase().starts_with(&pattern.to_lowercase())
}
Expand Down Expand Up @@ -290,7 +297,8 @@ pub async fn check_qr(context: &Context, qr: &str) -> Result<Qr> {
} else if qr.starts_with(SHADOWSOCKS_SCHEME) {
decode_shadowsocks_proxy(qr)?
} else if starts_with_ignore_case(qr, DCBACKUP2_SCHEME) {
decode_backup2(qr)?
let qr_fixed = fix_add_second_device_qr(qr);
decode_backup2(&qr_fixed)?
} else if qr.starts_with(MAILTO_SCHEME) {
decode_mailto(context, qr).await?
} else if qr.starts_with(SMTP_SCHEME) {
Expand Down
3 changes: 3 additions & 0 deletions src/qr/qr_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,5 +914,8 @@ async fn test_decode_backup() -> Result<()> {
let qr = check_qr(&ctx, r#"DCBACKUP2:TWSv6ZjDPa5eoxkocj7xMi8r&{"node_id":"9afc1ea5b4f543e5cdd7b7a21cd26aee7c0b1e1c2af26790896fbd8932a06e1e","relay_url":null,"direct_addresses":["192.168.1.10:12345"]}"#).await?;
assert!(matches!(qr, Qr::Backup2 { .. }));

let qr = check_qr(&ctx, r#"DCBACKUP2:AIvFjRFBt_aMiisSZ8P33JqY&{"node_id":"buzkyd4x76w66qtanjk5fm6ikeuo4quletajowsl3a3p7l6j23pa","info":{"relay_url":null,"direct_addresses":["192.168.1.5:12345"]}}"#).await?;
assert!(matches!(qr, Qr::Backup2 { .. }));

Ok(())
}

0 comments on commit 8bddd45

Please sign in to comment.