public MyAuthenticator()
 {
     AuthenticatorData = new GAPAuthenticatorDTO();
     OriginName        = string.Empty;
 }
Esempio n. 2
0
        public bool ReadXml(XmlReader reader, string password)
        {
            bool changed = false;

            //if (Guid.TryParse(reader.GetAttribute("id"), out Guid id) == true)
            //{
            //    Id = id;
            //}
            AuthenticatorData = new GAPAuthenticatorDTO();
            string authenticatorType = reader.GetAttribute("type");

            switch (authenticatorType)
            {
            case "WinAuth.SteamAuthenticator":
                AuthenticatorData.Value = new GAPAuthenticatorValueDTO.SteamAuthenticator();
                break;

            case "WinAuth.BattleNetAuthenticator":
                AuthenticatorData.Value = new GAPAuthenticatorValueDTO.BattleNetAuthenticator();
                break;

            case "WinAuth.GoogleAuthenticator":
                AuthenticatorData.Value = new GAPAuthenticatorValueDTO.GoogleAuthenticator();
                break;

            case "WinAuth.HOTPAuthenticator":
                AuthenticatorData.Value = new GAPAuthenticatorValueDTO.HOTPAuthenticator();
                break;

            case "WinAuth.MicrosoftAuthenticator":
                AuthenticatorData.Value = new GAPAuthenticatorValueDTO.MicrosoftAuthenticator();
                break;

            default:
                return(false);
            }

            //string encrypted = reader.GetAttribute("encrypted");
            //if (string.IsNullOrEmpty(encrypted) == false)
            //{
            //	// read the encrypted text from the node
            //	string data = reader.ReadElementContentAsString();
            //	// decrypt
            //	Authenticator.PasswordTypes passwordType;
            //	data = Authenticator.DecryptSequence(data, encrypted, password, out passwordType);

            //	using (MemoryStream ms = new MemoryStream(Authenticator.StringToByteArray(data)))
            //	{
            //		reader = XmlReader.Create(ms);
            //		ReadXml(reader, password);
            //	}
            //	this.PasswordType = passwordType;
            //	this.Password = password;

            //	return;
            //}

            reader.MoveToContent();

            if (reader.IsEmptyElement)
            {
                reader.Read();
                return(changed);
            }

            reader.Read();
            while (reader.EOF == false)
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "name":
                        Name       = reader.ReadElementContentAsString();
                        OriginName = Name;
                        break;

                    case "created":
                        long t = reader.ReadElementContentAsLong();
                        t     += Convert.ToInt64(new TimeSpan(new DateTime(1970, 1, 1).Ticks).TotalMilliseconds);
                        t     *= TimeSpan.TicksPerMillisecond;
                        Create = new DateTimeOffset(new DateTime(t).ToLocalTime());
                        break;

                    case "authenticatordata":
                        try
                        {
                            // we don't pass the password as they are locked till clicked
                            changed = AuthenticatorData.Value.ReadXml(reader) || changed;
                        }
                        catch (WinAuthEncryptedSecretDataException)
                        {
                            // no action needed
                        }
                        catch (WinAuthBadPasswordException)
                        {
                            // no action needed
                        }
                        break;

                    // v2
                    case "authenticator":
                        AuthenticatorData.Value = GAPAuthenticatorValueDTO.ReadXmlv2(reader, password);
                        break;

                    // v2
                    case "servertimediff":
                        AuthenticatorData.Value.ServerTimeDiff = reader.ReadElementContentAsLong();
                        break;


                    default:
                        reader.Skip();
                        break;
                    }
                }
                else
                {
                    reader.Read();
                    break;
                }
            }

            return(changed);
        }