예제 #1
0
		/// <summary>
		/// Import a v2 authenticator from an existing file name
		/// </summary>
		/// <param name="authenticatorFile">name of v2 xml file</param>
		private void importAuthenticatorFromV2(string authenticatorFile)
		{
			bool retry = false;
			string password = null;
			bool needPassword = false;
			bool invalidPassword = false;
			do
			{
				try
				{
					WinAuthConfig config = WinAuthHelper.LoadConfig(this, authenticatorFile, password);
					if (config.Count == 0)
					{
						return;
					}

					// get the actual authenticator and ensure it is synced
					WinAuthAuthenticator importedAuthenticator = config[0];
					importedAuthenticator.Sync();

					// make sure there isn't a name clash
					int rename = 0;
					string importedName = importedAuthenticator.Name;
					while (this.Config.Where(a => a.Name == importedName).Count() != 0)
					{
						importedName = importedAuthenticator.Name + " (" + (++rename) + ")";
					}
					importedAuthenticator.Name = importedName;

					// save off any new authenticators as a backup
					WinAuthHelper.SaveToRegistry(this.Config, importedAuthenticator);

					// first time we prompt for protection and set out main settings from imported config
					if (this.Config.Count == 0)
					{
						this.Config.StartWithWindows = config.StartWithWindows;
						this.Config.UseTrayIcon = config.UseTrayIcon;
						this.Config.AlwaysOnTop = config.AlwaysOnTop;

						ChangePasswordForm form = new ChangePasswordForm();
						form.PasswordType = Authenticator.PasswordTypes.Explicit;
						if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
						{
							this.Config.Yubi = form.Yubikey;
							this.Config.PasswordType = form.PasswordType;
							if ((this.Config.PasswordType & Authenticator.PasswordTypes.Explicit) != 0 && string.IsNullOrEmpty(form.Password) == false)
							{
								this.Config.Password = form.Password;
							}
						}
					}

					// add to main list
					this.Config.Add(importedAuthenticator);
					SaveConfig(true);
					loadAuthenticatorList(importedAuthenticator);

					// reset UI
					setAutoSize();
					introLabel.Visible = (this.Config.Count == 0);

					// reset hotkeys
					HookHotkeys();

					needPassword = false;
					retry = false;
				}
				catch (EncrpytedSecretDataException)
				{
					needPassword = true;
					invalidPassword = false;
				}
				catch (BadYubiKeyException)
				{
					needPassword = true;
					invalidPassword = false;
				}
				catch (BadPasswordException)
				{
					needPassword = true;
					invalidPassword = true;
				}
				catch (Exception ex)
				{
					if (ErrorDialog(this, strings.UnknownError + ": " + ex.Message, ex, MessageBoxButtons.RetryCancel) == System.Windows.Forms.DialogResult.Cancel)
					{
						return;
					}
					needPassword = false;
					invalidPassword = false;
					retry = true;
				}

				if (needPassword == true)
				{
					GetPasswordForm form = new GetPasswordForm();
					form.InvalidPassword = invalidPassword;
					var result = form.ShowDialog(this);
					if (result == DialogResult.Cancel)
					{
						return;
					}
					password = form.Password;
					retry = true;
				}
			} while (retry == true);
		}
예제 #2
0
		/// <summary>
		/// Click the Change Password item of the Options menu
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void changePasswordOptionsMenuItem_Click(object sender, EventArgs e)
		{
			// confirm current password
			if ((this.Config.PasswordType & Authenticator.PasswordTypes.Explicit) != 0)
			{
				bool invalidPassword = false;
				while (true)
				{
					GetPasswordForm checkform = new GetPasswordForm();
					checkform.InvalidPassword = invalidPassword;
					var result = checkform.ShowDialog(this);
					if (result == DialogResult.Cancel)
					{
						return;
					}
					if (this.Config.IsPassword(checkform.Password) == true)
					{
						break;
					}
					invalidPassword = true;
				}
			}

			ChangePasswordForm form = new ChangePasswordForm();
			form.PasswordType = this.Config.PasswordType;
			if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
			{
				bool retry;
				var retrypasswordtype = this.Config.PasswordType;
				do
				{
					retry = false;

					this.Config.PasswordType = form.PasswordType;
					if ((this.Config.PasswordType & (Authenticator.PasswordTypes.YubiKeySlot1 | Authenticator.PasswordTypes.YubiKeySlot2)) != 0 && form.Yubikey != null)
					{
						this.Config.Yubi = form.Yubikey;
					}
					if ((this.Config.PasswordType & Authenticator.PasswordTypes.Explicit) != 0 && string.IsNullOrEmpty(form.Password) == false)
					{
						this.Config.Password = form.Password;
					}

					try
					{
						SaveConfig(true);
					}
					catch (InvalidEncryptionException)
					{
						var result = WinAuthForm.ConfirmDialog(this, "Decryption test failed. Retry?", MessageBoxButtons.YesNo);
						if (result == DialogResult.Yes)
						{
							retry = true;
							continue;
						}
						this.Config.PasswordType = retrypasswordtype;
					}
					catch (ChallengeResponseException)
					{
						var result = WinAuthForm.ConfirmDialog(this, "YubiKey Challenge/Response failed. Retry?", MessageBoxButtons.YesNo);
						if (result == DialogResult.Yes)
						{
							retry = true;
							continue;
						}
						this.Config.PasswordType = retrypasswordtype;
					}
				} while (retry);
			}
		}
예제 #3
0
		/// <summary>
		/// Import authenticators from a file
		/// 
		/// *.xml = WinAuth v2
		/// *.txt = plain text with KeyUriFormat per line (https://code.google.com/p/google-authenticator/wiki/KeyUriFormat)
		/// *.zip = encrypted zip, containing import file
		/// *.pgp = PGP encrypted, containing import file
		/// 
		/// </summary>
		/// <param name="authenticatorFile">name import file</param>
		private void importAuthenticator(string authenticatorFile)
		{
			// call legacy import for v2 xml files
			if (string.Compare(Path.GetExtension(authenticatorFile), ".xml", true) == 0)
			{
				importAuthenticatorFromV2(authenticatorFile);
				return;
			}

			List<WinAuthAuthenticator> authenticators = null;
			bool retry;
			do
			{
				retry = false;
				try
				{
					authenticators = WinAuthHelper.ImportAuthenticators(this, authenticatorFile);
				}
				catch (ImportException ex)
				{
					if (ErrorDialog(this, ex.Message, ex.InnerException, MessageBoxButtons.RetryCancel) == System.Windows.Forms.DialogResult.Cancel)
					{
						return;
					}
					retry = true;
				}
			} while (retry);
			if (authenticators == null)
			{
				return;
			}

			// save all the new authenticators
			foreach (var authenticator in authenticators)
			{
				//sync
				authenticator.Sync();

				// make sure there isn't a name clash
				int rename = 0;
				string importedName = authenticator.Name;
				while (this.Config.Where(a => a.Name == importedName).Count() != 0)
				{
					importedName = authenticator.Name + " (" + (++rename) + ")";
				}
				authenticator.Name = importedName;

				// save off any new authenticators as a backup
				WinAuthHelper.SaveToRegistry(this.Config, authenticator);

				// first time we prompt for protection and set out main settings from imported config
				if (this.Config.Count == 0)
				{
					ChangePasswordForm form = new ChangePasswordForm();
					form.PasswordType = Authenticator.PasswordTypes.Explicit;
					if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
					{
						this.Config.Yubi = form.Yubikey;
						this.Config.PasswordType = form.PasswordType;
						if ((this.Config.PasswordType & Authenticator.PasswordTypes.Explicit) != 0 && string.IsNullOrEmpty(form.Password) == false)
						{
							this.Config.Password = form.Password;
						}
					}
				}

				// add to main list
				this.Config.Add(authenticator);
			}

			SaveConfig(true);
			loadAuthenticatorList();

			// reset UI
			setAutoSize();
			introLabel.Visible = (this.Config.Count == 0);

			// reset hotkeys
			HookHotkeys();
		}
예제 #4
0
		/// <summary>
		/// Click on a choice of new authenticator
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void addAuthenticatorMenu_Click(object sender, EventArgs e)
		{
			ToolStripItem menuitem = (ToolStripItem)sender;
			RegisteredAuthenticator registeredauth = menuitem.Tag as RegisteredAuthenticator;
			if (registeredauth != null)
			{
				// add the new authenticator
				WinAuthAuthenticator winauthauthenticator = new WinAuthAuthenticator();
				bool added = false;

				if (registeredauth.AuthenticatorType == RegisteredAuthenticator.AuthenticatorTypes.BattleNet)
				{
					int existing = 0;
					string name;
					do
					{
						name = "Battle.net" + (existing != 0 ? " (" + existing + ")" : string.Empty);
						existing++;
					} while (authenticatorList.Items.Cast<AuthenticatorListitem>().Where(a => a.Authenticator.Name == name).Count() != 0);

					winauthauthenticator.Name = name;
					winauthauthenticator.AutoRefresh = false;

					// create the Battle.net authenticator
					AddBattleNetAuthenticator form = new AddBattleNetAuthenticator();
					form.Authenticator = winauthauthenticator;
					added = (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK);
				}
				else if (registeredauth.AuthenticatorType == RegisteredAuthenticator.AuthenticatorTypes.Trion)
				{
					// create the Trion authenticator
					int existing = 0;
					string name;
					do
					{
						name = "Trion" + (existing != 0 ? " (" + existing + ")" : string.Empty);
						existing++;
					} while (authenticatorList.Items.Cast<AuthenticatorListitem>().Where(a => a.Authenticator.Name == name).Count() != 0);

					winauthauthenticator.Name = name;
					winauthauthenticator.AutoRefresh = false;

					AddTrionAuthenticator form = new AddTrionAuthenticator();
					form.Authenticator = winauthauthenticator;
					added = (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK);
				}
				else if (registeredauth.AuthenticatorType == RegisteredAuthenticator.AuthenticatorTypes.Steam)
				{
					// create the authenticator
					int existing = 0;
					string name;
					do
					{
						name = "Steam" + (existing != 0 ? " (" + existing + ")" : string.Empty);
						existing++;
					} while (authenticatorList.Items.Cast<AuthenticatorListitem>().Where(a => a.Authenticator.Name == name).Count() != 0);

					winauthauthenticator.Name = name;
					winauthauthenticator.AutoRefresh = false;

					AddSteamAuthenticator form = new AddSteamAuthenticator();
					form.Authenticator = winauthauthenticator;
					added = (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK);
				}
				else if (registeredauth.AuthenticatorType == RegisteredAuthenticator.AuthenticatorTypes.Google)
				{
					// create the Google authenticator
					// add the new authenticator
					int existing = 0;
					string name;
					do
					{
						name = "Google" + (existing != 0 ? " (" + existing + ")" : string.Empty);
						existing++;
					} while (authenticatorList.Items.Cast<AuthenticatorListitem>().Where(a => a.Authenticator.Name == name).Count() != 0);
					winauthauthenticator.Name = name;
					winauthauthenticator.AutoRefresh = false;

					AddGoogleAuthenticator form = new AddGoogleAuthenticator();
					form.Authenticator = winauthauthenticator;
					added = (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK);
				}
				else if (registeredauth.AuthenticatorType == RegisteredAuthenticator.AuthenticatorTypes.GuildWars)
				{
					// create the GW2 authenticator
					int existing = 0;
					string name;
					do
					{
						name = "GuildWars" + (existing != 0 ? " (" + existing + ")" : string.Empty);
						existing++;
					} while (authenticatorList.Items.Cast<AuthenticatorListitem>().Where(a => a.Authenticator.Name == name).Count() != 0);
					winauthauthenticator.Name = name;
					winauthauthenticator.AutoRefresh = false;

					AddGuildWarsAuthenticator form = new AddGuildWarsAuthenticator();
					form.Authenticator = winauthauthenticator;
					added = (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK);
				}
				else if (registeredauth.AuthenticatorType == RegisteredAuthenticator.AuthenticatorTypes.Microsoft)
				{
					// create the Microsoft authenticator
					int existing = 0;
					string name;
					do
					{
						name = "Microsoft" + (existing != 0 ? " (" + existing + ")" : string.Empty);
						existing++;
					} while (authenticatorList.Items.Cast<AuthenticatorListitem>().Where(a => a.Authenticator.Name == name).Count() != 0);
					winauthauthenticator.Name = name;
					winauthauthenticator.AutoRefresh = false;

					AddMicrosoftAuthenticator form = new AddMicrosoftAuthenticator();
					form.Authenticator = winauthauthenticator;
					added = (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK);
				}
				else if (registeredauth.AuthenticatorType == RegisteredAuthenticator.AuthenticatorTypes.RFC6238_TIME)
				{
					// create the Google authenticator
					// add the new authenticator
					int existing = 0;
					string name;
					do
					{
						name = "Authenticator" + (existing != 0 ? " (" + existing + ")" : string.Empty);
						existing++;
					} while (authenticatorList.Items.Cast<AuthenticatorListitem>().Where(a => a.Authenticator.Name == name).Count() != 0);
					winauthauthenticator.Name = name;
					winauthauthenticator.AutoRefresh = false;
					winauthauthenticator.Skin = "WinAuthIcon.png";

					AddAuthenticator form = new AddAuthenticator();
					form.Authenticator = winauthauthenticator;
					added = (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK);
				}
				else
				{
					throw new NotImplementedException(strings.AuthenticatorNotImplemented + ": " + registeredauth.AuthenticatorType.ToString());
				}

				if (added == true)
				{
					// save off any new authenticators as a backup
					WinAuthHelper.SaveToRegistry(this.Config, winauthauthenticator);

					// first time we prompt for protection
					if (this.Config.Count == 0)
					{
						ChangePasswordForm form = new ChangePasswordForm();
						form.PasswordType = Authenticator.PasswordTypes.Explicit;
						if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
						{
							this.Config.Yubi = form.Yubikey;
							this.Config.PasswordType = form.PasswordType;
							if ((this.Config.PasswordType & Authenticator.PasswordTypes.Explicit) != 0 && string.IsNullOrEmpty(form.Password) == false)
							{
								this.Config.Password = form.Password;
							}
						}
					}

					this.Config.Add(winauthauthenticator);
					SaveConfig(true);
					loadAuthenticatorList(winauthauthenticator);

					// reset UI
					setAutoSize();
					introLabel.Visible = (this.Config.Count == 0);

					// reset hotkeeys
					HookHotkeys();
				}
			}
		}