/// <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, "您需要创建身份验证器并将其附加到您的帐户"); 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); }
/// <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); }