From eb51a7a2a7113120ec8add2bb2e224bee318dd6d Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sun, 9 Jul 2023 10:16:02 -0400 Subject: [PATCH] improve robustness of account migrations (#284) - add an extreme test case for migrations - improve robustness of manifest migrations fixes #283 --- src/accountmanager/legacy.rs | 10 +-- src/accountmanager/migrate.rs | 4 + .../compat/difficult-migration/1234.maFile | 1 + .../compat/difficult-migration/generate.sh | 6 ++ .../compat/difficult-migration/manifest.json | 83 +++++++++++++++++++ .../missing-OAuthToken.maFile | 21 +++++ .../missing-SessionID.maFile | 21 +++++ .../missing-SteamID.maFile | 21 +++++ .../missing-SteamLogin.maFile | 21 +++++ .../missing-SteamLoginSecure.maFile | 21 +++++ .../missing-WebCookie.maFile | 21 +++++ .../null-OAuthToken.maFile | 22 +++++ .../difficult-migration/null-SessionID.maFile | 22 +++++ .../difficult-migration/null-SteamID.maFile | 22 +++++ .../null-SteamLogin.maFile | 22 +++++ .../null-SteamLoginSecure.maFile | 22 +++++ .../difficult-migration/null-WebCookie.maFile | 22 +++++ 17 files changed, 357 insertions(+), 5 deletions(-) create mode 100644 src/fixtures/maFiles/compat/difficult-migration/1234.maFile create mode 100755 src/fixtures/maFiles/compat/difficult-migration/generate.sh create mode 100644 src/fixtures/maFiles/compat/difficult-migration/manifest.json create mode 100644 src/fixtures/maFiles/compat/difficult-migration/missing-OAuthToken.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/missing-SessionID.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/missing-SteamID.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/missing-SteamLogin.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/missing-SteamLoginSecure.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/missing-WebCookie.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/null-OAuthToken.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/null-SessionID.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/null-SteamID.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/null-SteamLogin.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/null-SteamLoginSecure.maFile create mode 100644 src/fixtures/maFiles/compat/difficult-migration/null-WebCookie.maFile diff --git a/src/accountmanager/legacy.rs b/src/accountmanager/legacy.rs index 4bdf75b..298781b 100644 --- a/src/accountmanager/legacy.rs +++ b/src/accountmanager/legacy.rs @@ -143,17 +143,17 @@ pub struct SdaAccount { #[deprecated(note = "this is not used anymore, the closest equivalent is `Tokens`")] pub struct Session { #[serde(default, rename = "SessionID")] - pub session_id: String, + pub session_id: Option, #[serde(default, rename = "SteamLogin")] - pub steam_login: String, + pub steam_login: Option, #[serde(default, rename = "SteamLoginSecure")] - pub steam_login_secure: String, + pub steam_login_secure: Option, #[serde(default, rename = "WebCookie")] pub web_cookie: Option, #[serde(default, rename = "OAuthToken")] pub token: Option, #[serde(rename = "SteamID")] - pub steam_id: u64, + pub steam_id: Option, } impl CloneableSecret for Session {} @@ -164,7 +164,7 @@ impl From for SteamGuardAccount { let steam_id = value .session .as_ref() - .map(|s| s.expose_secret().steam_id) + .and_then(|s| s.expose_secret().steam_id) .unwrap_or(0); Self { account_name: value.account_name, diff --git a/src/accountmanager/migrate.rs b/src/accountmanager/migrate.rs index 71c92e0..55cddec 100644 --- a/src/accountmanager/migrate.rs +++ b/src/accountmanager/migrate.rs @@ -304,6 +304,10 @@ mod tests { manifest: "src/fixtures/maFiles/compat/null-oauthtoken/manifest.json", passkey: None, }, + Test { + manifest: "src/fixtures/maFiles/compat/difficult-migration/manifest.json", + passkey: None, + }, ]; for case in cases { eprintln!("testing: {:?}", case); diff --git a/src/fixtures/maFiles/compat/difficult-migration/1234.maFile b/src/fixtures/maFiles/compat/difficult-migration/1234.maFile new file mode 100644 index 0000000..344ac66 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/1234.maFile @@ -0,0 +1 @@ +{"shared_secret":"zvIayp3JPvtvX/QGHqsqKBk/44s=","serial_number":"kljasfhds","revocation_code":"R12345","uri":"otpauth://totp/Steam:example?secret=ASDF&issuer=Steam","server_time":1602522478,"account_name":"example","token_gid":"jkkjlhkhjgf","identity_secret":"kjsdlwowiqe=","secret_1":"sklduhfgsdlkjhf=","status":1,"device_id":"android:99d2ad0e-4bad-4247-b111-26393aae0be3","fully_enrolled":true,"Session":{"SessionID":"a;lskdjf","SteamLogin":"983498437543","SteamLoginSecure":"dlkjdsl;j%7C%32984730298","WebCookie":";lkjsed;klfjas98093","OAuthToken":"asdk;lf;dsjlkfd","SteamID":1234}} \ No newline at end of file diff --git a/src/fixtures/maFiles/compat/difficult-migration/generate.sh b/src/fixtures/maFiles/compat/difficult-migration/generate.sh new file mode 100755 index 0000000..d884067 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/generate.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cat "1234.maFile" | jq -r '.Session | keys | .[]' | while read key; do + cat "1234.maFile" | jq ".Session[\"$key\"] = null" > "null-$key.maFile" + cat "1234.maFile" | jq ". | del(.Session.$key)" > "missing-$key.maFile" +done diff --git a/src/fixtures/maFiles/compat/difficult-migration/manifest.json b/src/fixtures/maFiles/compat/difficult-migration/manifest.json new file mode 100644 index 0000000..22ef30a --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/manifest.json @@ -0,0 +1,83 @@ +{ + "encrypted": false, + "first_run": true, + "entries": [ + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "missing-OAuthToken.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "missing-SessionID.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "missing-SteamID.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "missing-SteamLogin.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "missing-SteamLoginSecure.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "missing-WebCookie.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "null-OAuthToken.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "null-SessionID.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "null-SteamID.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "null-SteamLogin.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "null-SteamLoginSecure.maFile", + "steamid": 1234 + }, + { + "encryption_iv": null, + "encryption_salt": null, + "filename": "null-WebCookie.maFile", + "steamid": 1234 + } + ], + "periodic_checking": false, + "periodic_checking_interval": 5, + "periodic_checking_checkall": false, + "auto_confirm_market_transactions": false, + "auto_confirm_trades": false +} \ No newline at end of file diff --git a/src/fixtures/maFiles/compat/difficult-migration/missing-OAuthToken.maFile b/src/fixtures/maFiles/compat/difficult-migration/missing-OAuthToken.maFile new file mode 100644 index 0000000..8989c20 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/missing-OAuthToken.maFile @@ -0,0 +1,21 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/missing-SessionID.maFile b/src/fixtures/maFiles/compat/difficult-migration/missing-SessionID.maFile new file mode 100644 index 0000000..57be5f1 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/missing-SessionID.maFile @@ -0,0 +1,21 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/missing-SteamID.maFile b/src/fixtures/maFiles/compat/difficult-migration/missing-SteamID.maFile new file mode 100644 index 0000000..ce027b3 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/missing-SteamID.maFile @@ -0,0 +1,21 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd" + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/missing-SteamLogin.maFile b/src/fixtures/maFiles/compat/difficult-migration/missing-SteamLogin.maFile new file mode 100644 index 0000000..0b2a390 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/missing-SteamLogin.maFile @@ -0,0 +1,21 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/missing-SteamLoginSecure.maFile b/src/fixtures/maFiles/compat/difficult-migration/missing-SteamLoginSecure.maFile new file mode 100644 index 0000000..627312c --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/missing-SteamLoginSecure.maFile @@ -0,0 +1,21 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/missing-WebCookie.maFile b/src/fixtures/maFiles/compat/difficult-migration/missing-WebCookie.maFile new file mode 100644 index 0000000..c65ac90 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/missing-WebCookie.maFile @@ -0,0 +1,21 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/null-OAuthToken.maFile b/src/fixtures/maFiles/compat/difficult-migration/null-OAuthToken.maFile new file mode 100644 index 0000000..66649d0 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/null-OAuthToken.maFile @@ -0,0 +1,22 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": null, + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/null-SessionID.maFile b/src/fixtures/maFiles/compat/difficult-migration/null-SessionID.maFile new file mode 100644 index 0000000..8045ac9 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/null-SessionID.maFile @@ -0,0 +1,22 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": null, + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/null-SteamID.maFile b/src/fixtures/maFiles/compat/difficult-migration/null-SteamID.maFile new file mode 100644 index 0000000..9efd01c --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/null-SteamID.maFile @@ -0,0 +1,22 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": null + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/null-SteamLogin.maFile b/src/fixtures/maFiles/compat/difficult-migration/null-SteamLogin.maFile new file mode 100644 index 0000000..02be766 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/null-SteamLogin.maFile @@ -0,0 +1,22 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": null, + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/null-SteamLoginSecure.maFile b/src/fixtures/maFiles/compat/difficult-migration/null-SteamLoginSecure.maFile new file mode 100644 index 0000000..574d588 --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/null-SteamLoginSecure.maFile @@ -0,0 +1,22 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "SteamLoginSecure": null, + "WebCookie": ";lkjsed;klfjas98093", + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +} diff --git a/src/fixtures/maFiles/compat/difficult-migration/null-WebCookie.maFile b/src/fixtures/maFiles/compat/difficult-migration/null-WebCookie.maFile new file mode 100644 index 0000000..f530e0b --- /dev/null +++ b/src/fixtures/maFiles/compat/difficult-migration/null-WebCookie.maFile @@ -0,0 +1,22 @@ +{ + "shared_secret": "zvIayp3JPvtvX/QGHqsqKBk/44s=", + "serial_number": "kljasfhds", + "revocation_code": "R12345", + "uri": "otpauth://totp/Steam:example?secret=ASDF&issuer=Steam", + "server_time": 1602522478, + "account_name": "example", + "token_gid": "jkkjlhkhjgf", + "identity_secret": "kjsdlwowiqe=", + "secret_1": "sklduhfgsdlkjhf=", + "status": 1, + "device_id": "android:99d2ad0e-4bad-4247-b111-26393aae0be3", + "fully_enrolled": true, + "Session": { + "SessionID": "a;lskdjf", + "SteamLogin": "983498437543", + "SteamLoginSecure": "dlkjdsl;j%7C%32984730298", + "WebCookie": null, + "OAuthToken": "asdk;lf;dsjlkfd", + "SteamID": 1234 + } +}