Skip to content

Commit d2b7826

Browse files
committed
Handle WGTokenInvalidException when fetching confirmations
1 parent 74f4f40 commit d2b7826

File tree

4 files changed

+82
-31
lines changed

4 files changed

+82
-31
lines changed

Steam Desktop Authenticator/ConfirmationForm.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,39 @@ private void listAccounts_SelectedValueChanged(object sender, EventArgs e)
4545

4646
}
4747

48-
private void loadConfirmations()
48+
private void loadConfirmations(bool retry = false)
4949
{
5050
listConfirmations.Items.Clear();
5151
listConfirmations.SelectedIndex = -1;
5252

53-
Confirmations = mCurrentAccount.FetchConfirmations();
53+
try
54+
{
55+
Confirmations = mCurrentAccount.FetchConfirmations();
56+
}
57+
catch (SteamGuardAccount.WGTokenInvalidException e)
58+
{
59+
if (retry)
60+
{
61+
this.Close();
62+
return;
63+
}
64+
//TODO: catch only the relevant exceptions
65+
if (mCurrentAccount.RefreshSession())
66+
{
67+
Manifest manifest = Manifest.GetManifest();
68+
69+
bool success;
70+
string passKey = manifest.PromptForPassKey(out success);
71+
72+
if (!success)
73+
MessageBox.Show("Unable to fetch confirmations without your passkey.");
74+
75+
manifest.SaveAccount(mCurrentAccount, manifest.Encrypted, passKey);
76+
77+
loadConfirmations(true);
78+
}
79+
}
80+
5481
if (Confirmations.Length > 0)
5582
{
5683
for (int i = 0; i < Confirmations.Length; i++)

Steam Desktop Authenticator/MainForm.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Steam Desktop Authenticator/MainForm.cs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public partial class MainForm : MetroFramework.Forms.MetroForm
2626
public MainForm()
2727
{
2828
InitializeComponent();
29+
2930
this.labelVersion.Text = String.Format("v{0}", Application.ProductVersion);
3031
this.mManifest = Manifest.GetManifest();
31-
loadAccountsList();
3232

3333
pbTimeout.Maximum = 30;
3434
pbTimeout.Minimum = 0;
@@ -64,36 +64,19 @@ private void loadAccountsList()
6464
listAccounts.Items.Clear();
6565
listAccounts.SelectedIndex = -1;
6666

67-
string passKey = null;
68-
if (mManifest.Encrypted)
67+
bool success;
68+
string passKey = mManifest.PromptForPassKey(out success);
69+
if (!success)
6970
{
70-
bool passKeyValid = false;
71-
while (!passKeyValid)
72-
{
73-
InputForm passKeyForm = new InputForm("Please enter your encryption passkey.", true);
74-
passKeyForm.ShowDialog();
75-
if (!passKeyForm.Canceled)
76-
{
77-
passKey = passKeyForm.txtBox.Text;
78-
passKeyValid = this.mManifest.VerifyPasskey(passKey);
79-
if (!passKeyValid)
80-
{
81-
MessageBox.Show("That passkey is invalid.");
82-
}
83-
}
84-
else
85-
{
86-
this.Close();
87-
return;
88-
}
89-
}
71+
this.Close();
72+
return;
73+
}
9074

75+
if (mManifest.Encrypted)
9176
btnManageEncryption.Text = "Manage Encryption";
92-
}
77+
9378
else
94-
{
9579
btnManageEncryption.Text = "Setup Encryption";
96-
}
9780

9881
btnManageEncryption.Enabled = mManifest.Entries.Count > 0;
9982

@@ -222,6 +205,10 @@ private void btnManageEncryption_Click(object sender, EventArgs e)
222205
}
223206
}
224207

208+
private void MainForm_Shown(object sender, EventArgs e)
209+
{
210+
loadAccountsList();
211+
}
225212

226213
// Logic for version checking
227214
private Version newVersion = null;

Steam Desktop Authenticator/Manifest.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,39 @@ private static Manifest _generateNewManifest(bool scanDir = false)
114114
return null;
115115
}
116116

117+
public string PromptForPassKey(out bool success)
118+
{
119+
success = false;
120+
if (!this.Encrypted)
121+
{
122+
success = true;
123+
return null;
124+
}
125+
126+
bool passKeyValid = false;
127+
string passKey = null;
128+
while (!passKeyValid)
129+
{
130+
InputForm passKeyForm = new InputForm("Please enter your encryption passkey.", true);
131+
passKeyForm.ShowDialog();
132+
if (!passKeyForm.Canceled)
133+
{
134+
passKey = passKeyForm.txtBox.Text;
135+
passKeyValid = this.VerifyPasskey(passKey);
136+
if (!passKeyValid)
137+
{
138+
MessageBox.Show("That passkey is invalid.");
139+
}
140+
}
141+
else
142+
{
143+
return null;
144+
}
145+
}
146+
success = passKeyValid;
147+
return passKey;
148+
}
149+
117150
public string PromptSetupPassKey(string initialPrompt = "Enter passkey, or hit cancel to remain unencrypted.")
118151
{
119152
InputForm newPassKeyForm = new InputForm(initialPrompt);
@@ -152,7 +185,7 @@ public string PromptSetupPassKey(string initialPrompt = "Enter passkey, or hit c
152185
return newPassKey;
153186
}
154187

155-
public SteamAuth.SteamGuardAccount[] GetAllAccounts(string passKey = null)
188+
public SteamAuth.SteamGuardAccount[] GetAllAccounts(string passKey = null, int limit = -1)
156189
{
157190
if (passKey == null && this.Encrypted) return new SteamGuardAccount[0];
158191
string maDir = Manifest.GetExecutableDir() + "/maFiles/";
@@ -171,6 +204,9 @@ public SteamAuth.SteamGuardAccount[] GetAllAccounts(string passKey = null)
171204
var account = JsonConvert.DeserializeObject<SteamAuth.SteamGuardAccount>(fileText);
172205
if (account == null) continue;
173206
accounts.Add(account);
207+
208+
if (limit != -1 && limit >= accounts.Count)
209+
break;
174210
}
175211

176212
return accounts.ToArray();
@@ -226,8 +262,8 @@ public bool VerifyPasskey(string passkey)
226262
{
227263
if (!this.Encrypted || this.Entries.Count == 0) return true;
228264

229-
var accounts = this.GetAllAccounts(passkey);
230-
return accounts != null && accounts.Length == this.Entries.Count;
265+
var accounts = this.GetAllAccounts(passkey, 1);
266+
return accounts != null && accounts.Length == 1;
231267
}
232268

233269
public bool RemoveAccount(SteamGuardAccount account)

0 commit comments

Comments
 (0)