/// <summary> /// Perform a verification of the restore code in the background by checking it with the servers /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VerifyRestoreCode(object sender, DoWorkEventArgs e) { var auth = e.Argument as BattleNetAuthenticator; // check if this authenticator is too old to be restored try { var testrestore = new BattleNetAuthenticator(); testrestore.Restore(auth.Serial, auth.RestoreCode); auth.RestoreCodeVerified = true; e.Result = null; } catch (InvalidRestoreCodeException) { e.Result = "This authenticator was created before the restore capability existed and so the restore code will not work.\n\n" + "You will need to remove this authenticator from your Battle.net account and create a new one."; } catch (InvalidRestoreResponseException) { // ignore the validation if servers are down } catch (Exception ex2) { e.Result = "Oops. An error (" + ex2.Message + ") occured whilst validating your restore code." + "Please log a ticket at https://github.com/winauth/winauth/issues so we can fix this."; } }
/// <summary> /// Verify and create the authenticator if needed /// </summary> /// <returns>true is successful</returns> private bool verifyAuthenticator() { this.Authenticator.Name = nameField.Text; if (this.tabControl1.SelectedIndex == 0) { if (this.Authenticator.AuthenticatorData == null) { WinAuthForm.ErrorDialog(this.Owner, "您需要创建身份验证器并将其附加到您的帐户"); return(false); } } else if (this.tabControl1.SelectedIndex == 1) { string serial = this.restoreSerialNumberField.Text.Trim(); string restore = this.restoreRestoreCodeField.Text.Trim(); if (serial.Length == 0 || restore.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "请输入序列号和恢复代码"); return(false); } try { BattleNetAuthenticator authenticator = new BattleNetAuthenticator(); authenticator.Restore(serial, restore); this.Authenticator.AuthenticatorData = authenticator; } catch (InvalidRestoreResponseException irre) { WinAuthForm.ErrorDialog(this.Owner, "无法恢复验证器: " + irre.Message, irre); return(false); } } else if (this.tabControl1.SelectedIndex == 2) { string privatekey = this.importPrivateKeyField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "请输入私钥"); return(false); } // just get the hex chars privatekey = Regex.Replace(privatekey, @"0x", "", RegexOptions.IgnoreCase); privatekey = Regex.Replace(privatekey, @"[^0-9abcdef]", "", RegexOptions.IgnoreCase); if (privatekey.Length == 0 || privatekey.Length < 40) { WinAuthForm.ErrorDialog(this.Owner, "私钥必须是至少40个十六进制字符的序列, e.g. 7B0BFA82... or 0x7B, 0x0B, 0xFA, 0x82, ..."); return(false); } try { BattleNetAuthenticator authenticator = new BattleNetAuthenticator(); if (privatekey.Length == 40) // 20 bytes which is key only { authenticator.SecretKey = WinAuth.Authenticator.StringToByteArray(privatekey); authenticator.Serial = "US-Imported"; } else { authenticator.SecretData = privatekey; if (string.IsNullOrEmpty(authenticator.Serial) == true) { authenticator.Serial = "US-Imported"; } } authenticator.Sync(); this.Authenticator.AuthenticatorData = authenticator; } catch (Exception irre) { WinAuthForm.ErrorDialog(this.Owner, "无法导入身份验证器。私钥可能无效。", irre); return(false); } } return(true); }
private bool HandleBattleNetToken() { var serial = _wowManager.Settings.AuthenticatorSerial; var restoreCode = _wowManager.Settings.AuthenticatorRestoreCode; if (string.IsNullOrEmpty(serial) || string.IsNullOrEmpty(restoreCode)) return false; if (string.IsNullOrEmpty(_wowManager.Settings.AuthenticatorSerial)) return false; var frame = UIObject.GetUIObjectByName<Frame>(_wowManager, "TokenEnterDialogBackgroundEdit"); if (frame == null || !frame.IsVisible || !frame.IsShown) return false; var editBox = UIObject.GetUIObjectByName<EditBox>(_wowManager, "AccountLoginTokenEdit"); var auth = new BattleNetAuthenticator(); try { auth.Restore(serial, restoreCode); } catch (Exception ex) { _wowManager.Profile.Err("Could not get auth token: {0}", ex.Message); return false; } if (!string.IsNullOrEmpty(editBox.Text)) { Utility.SendBackgroundKey(_wowManager.GameProcess.MainWindowHandle, (char)Keys.End, false); Utility.SendBackgroundString(_wowManager.GameProcess.MainWindowHandle, new string('\b', "AccountLoginTokenEdit".Length * 2), false); _wowManager.Profile.Log("Pressing 'end' + delete keys to remove contents from {0}", "AccountLoginTokenEdit"); } Utility.SendBackgroundString(_wowManager.GameProcess.MainWindowHandle, auth.CurrentCode); Utility.SendBackgroundKey(_wowManager.GameProcess.MainWindowHandle, (char)Keys.Enter, false); _wowManager.Profile.Log("Accepting Battle net token."); return true; }
/// <summary> /// Perform a verification of the restore code in the background by checking it with the servers /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void VerifyRestoreCode(object sender, DoWorkEventArgs e) { BattleNetAuthenticator auth = e.Argument as BattleNetAuthenticator; // check if this authenticator is too old to be restored try { BattleNetAuthenticator testrestore = new BattleNetAuthenticator(); testrestore.Restore(auth.Serial, auth.RestoreCode); auth.RestoreCodeVerified = true; e.Result = null; } catch (InvalidRestoreCodeException) { e.Result = "This authenticator was created before the restore capability existed and so the restore code will not work.\n\n" + "You will need to remove this authenticator from your Battle.net account and create a new one."; } catch (InvalidRestoreResponseException) { // ignore the validation if servers are down } catch (Exception ex2) { e.Result = "Oops. An error (" + ex2.Message + ") occured whilst validating your restore code." + "Please log a ticket at https://github.com/winauth/winauth/issues so we can fix this."; } }
/// <summary> /// Verify and create the authenticator if needed /// </summary> /// <returns>true is successful</returns> private bool verifyAuthenticator() { this.Authenticator.Name = nameField.Text; if (this.tabControl1.SelectedIndex == 0) { if (this.Authenticator.AuthenticatorData == null) { WinAuthForm.ErrorDialog(this.Owner, "You need to create an authenticator and attach it to your account"); return false; } } else if (this.tabControl1.SelectedIndex == 1) { string serial = this.restoreSerialNumberField.Text.Trim(); string restore = this.restoreRestoreCodeField.Text.Trim(); if (serial.Length == 0 || restore.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Serial number and Restore code"); return false; } try { BattleNetAuthenticator authenticator = new BattleNetAuthenticator(); authenticator.Restore(serial, restore); this.Authenticator.AuthenticatorData = authenticator; } catch (InvalidRestoreResponseException irre) { WinAuthForm.ErrorDialog(this.Owner, "Unable to restore the authenticator: " + irre.Message, irre); return false; } } else if (this.tabControl1.SelectedIndex == 2) { string privatekey = this.importPrivateKeyField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Private key"); return false; } // just get the hex chars privatekey = Regex.Replace(privatekey, @"0x", "", RegexOptions.IgnoreCase); privatekey = Regex.Replace(privatekey, @"[^0-9abcdef]", "", RegexOptions.IgnoreCase); if (privatekey.Length == 0 || privatekey.Length < 40) { WinAuthForm.ErrorDialog(this.Owner, "The private key must be a sequence of at least 40 hexadecimal characters, e.g. 7B0BFA82... or 0x7B, 0x0B, 0xFA, 0x82, ..."); return false; } try { BattleNetAuthenticator authenticator = new BattleNetAuthenticator(); if (privatekey.Length == 40) // 20 bytes which is key only { authenticator.SecretKey = WinAuth.Authenticator.StringToByteArray(privatekey); authenticator.Serial = "US-Imported"; } else { authenticator.SecretData = privatekey; if (string.IsNullOrEmpty(authenticator.Serial) == true) { authenticator.Serial = "US-Imported"; } } authenticator.Sync(); this.Authenticator.AuthenticatorData = authenticator; } catch (Exception irre) { WinAuthForm.ErrorDialog(this.Owner, "Unable to import the authenticator. The private key is probably invalid.", irre); return false; } } return true; }
/// <summary> /// Verify and create the authenticator if needed /// </summary> /// <returns>true is successful</returns> private bool verifyAuthenticator() { this.Authenticator.Name = nameField.Text; if (this.tabControl1.SelectedIndex == 0) { if (this.Authenticator.AuthenticatorData == null) { WinAuthForm.ErrorDialog(this.Owner, "You need to create an authenticator and attach it to your account"); return(false); } } else if (this.tabControl1.SelectedIndex == 1) { string serial = this.restoreSerialNumberField.Text.Trim(); string restore = this.restoreRestoreCodeField.Text.Trim(); if (serial.Length == 0 || restore.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Serial number and Restore code"); return(false); } try { BattleNetAuthenticator authenticator = new BattleNetAuthenticator(); authenticator.Restore(serial, restore); this.Authenticator.AuthenticatorData = authenticator; } catch (InvalidRestoreResponseException irre) { WinAuthForm.ErrorDialog(this.Owner, "Unable to restore the authenticator: " + irre.Message, irre); return(false); } } else if (this.tabControl1.SelectedIndex == 2) { string privatekey = this.importPrivateKeyField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Private key"); return(false); } // just get the hex chars privatekey = Regex.Replace(privatekey, @"0x", "", RegexOptions.IgnoreCase); privatekey = Regex.Replace(privatekey, @"[^0-9abcdef]", "", RegexOptions.IgnoreCase); if (privatekey.Length == 0 || privatekey.Length < 40) { WinAuthForm.ErrorDialog(this.Owner, "The private key must be a sequence of at least 40 hexadecimal characters, e.g. 7B0BFA82... or 0x7B, 0x0B, 0xFA, 0x82, ..."); return(false); } try { BattleNetAuthenticator authenticator = new BattleNetAuthenticator(); if (privatekey.Length == 40) // 20 bytes which is key only { authenticator.SecretKey = WinAuth.Authenticator.StringToByteArray(privatekey); authenticator.Serial = "US-Imported"; } else { authenticator.SecretData = privatekey; if (string.IsNullOrEmpty(authenticator.Serial) == true) { authenticator.Serial = "US-Imported"; } } authenticator.Sync(); this.Authenticator.AuthenticatorData = authenticator; } catch (Exception irre) { WinAuthForm.ErrorDialog(this.Owner, "Unable to import the authenticator. The private key is probably invalid.", irre); return(false); } } return(true); }