Ejemplo n.º 1
0
        public bool ReadXml(XmlReader reader, string password)
        {
            bool changed = false;

              Guid id;
            #if NETFX_4
            if (Guid.TryParse(reader.GetAttribute("id"), out id) == true)
              {
            Id = id;
              }
            #endif
            #if NETFX_3
            try
            {
                id = new Guid(reader.GetAttribute("id"));
                Id = id;
            }
            catch (Exception) { }
            #endif

            string authenticatorType = reader.GetAttribute("type");
              if (string.IsNullOrEmpty(authenticatorType) == false)
              {
            Type type = typeof(Authenticator).Assembly.GetType(authenticatorType, false, true);
            this.AuthenticatorData = Activator.CreateInstance(type) as Authenticator;
              }

            //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();
              break;

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

            case "autorefresh":
              _autoRefresh = reader.ReadElementContentAsBoolean();
              break;

            case "allowcopy":
              _allowCopy= reader.ReadElementContentAsBoolean();
              break;

            case "copyoncode":
              _copyOnCode = reader.ReadElementContentAsBoolean();
              break;

            case "hideserial":
              _hideSerial = reader.ReadElementContentAsBoolean();
              break;

            case "skin":
              _skin = reader.ReadElementContentAsString();
              break;

                        case "hotkey":
                            _hotkey = new WinAuth.HotKey();
                            _hotkey.ReadXml(reader);
                            break;

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

                        // v2
                        case "authenticator":
                            this.AuthenticatorData = Authenticator.ReadXmlv2(reader, password);
                            break;
                        // v2
                        case "autologin":
              var hks = new HoyKeySequence();
              hks.ReadXml(reader, password);
              break;
                        // v2
                        case "servertimediff":
                            this.AuthenticatorData.ServerTimeDiff = reader.ReadElementContentAsLong();
                            break;

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

            return changed;
        }
Ejemplo n.º 2
0
        public bool ReadXml(XmlReader reader, string password)
        {
            bool changed = false;

            Guid id;

#if NETFX_4
            if (Guid.TryParse(reader.GetAttribute("id"), out id) == true)
            {
                Id = id;
            }
#endif
#if NETFX_3
            try
            {
                id = new Guid(reader.GetAttribute("id"));
                Id = id;
            }
            catch (Exception) { }
#endif

            string authenticatorType = reader.GetAttribute("type");
            if (string.IsNullOrEmpty(authenticatorType) == false)
            {
                Type type = typeof(Authenticator).Assembly.GetType(authenticatorType, false, true);
                this.AuthenticatorData = Activator.CreateInstance(type) as Authenticator;
            }

            //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();
                        break;

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

                    case "autorefresh":
                        _autoRefresh = reader.ReadElementContentAsBoolean();
                        break;

                    case "allowcopy":
                        _allowCopy = reader.ReadElementContentAsBoolean();
                        break;

                    case "copyoncode":
                        _copyOnCode = reader.ReadElementContentAsBoolean();
                        break;

                    case "hideserial":
                        _hideSerial = reader.ReadElementContentAsBoolean();
                        break;

                    case "skin":
                        _skin = reader.ReadElementContentAsString();
                        break;

                    case "hotkey":
                        _hotkey = new WinAuth.HotKey();
                        _hotkey.ReadXml(reader);
                        break;

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

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

                    // v2
                    case "autologin":
                        var hks = new HoyKeySequence();
                        hks.ReadXml(reader, password);
                        break;

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


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

            return(changed);
        }