Ejemplo n.º 1
0
        public KdbxEntry(IKeePassGroup parent, IRandomNumberGenerator rng, KdbxMetadata metadata)
            : this(false)
        {
            DebugHelper.Assert(parent != null);
            DebugHelper.Assert(rng != null);
            if (rng == null)
            {
                throw new ArgumentNullException("rng");
            }

            DebugHelper.Assert(metadata != null);
            if (metadata == null)
            {
                throw new ArgumentNullException("metadata");
            }

            Parent  = parent ?? throw new ArgumentNullException("parent");
            Uuid    = new KeePassUuid();
            IconID  = KdbxEntry.DefaultIconId;
            Times   = new KdbxTimes();
            History = new KdbxHistory(metadata);

            KdbxMemoryProtection memProtection = metadata.MemoryProtection;
            Title = new KdbxString("Title", string.Empty, rng, memProtection.ProtectTitle);
            string initialUsername = metadata.DefaultUserName ?? string.Empty;
            UserName       = new KdbxString("UserName", initialUsername, rng, memProtection.ProtectUserName);
            Password       = new KdbxString("Password", string.Empty, rng, memProtection.ProtectPassword);
            Url            = new KdbxString("URL", string.Empty, rng, memProtection.ProtectUrl);
            Notes          = new KdbxString("Notes", string.Empty, rng, memProtection.ProtectNotes);
            Tags           = string.Empty;
            OverrideUrl    = string.Empty;
            this._metadata = metadata;
        }
Ejemplo n.º 2
0
        public override bool Equals(object obj)
        {
            KdbxMemoryProtection other = obj as KdbxMemoryProtection;

            if (other == null)
            {
                return(false);
            }

            return(ProtectTitle == other.ProtectTitle &&
                   ProtectUserName == other.ProtectUserName &&
                   ProtectPassword == other.ProtectPassword &&
                   ProtectUrl == other.ProtectUrl &&
                   ProtectNotes == other.ProtectNotes);
        }
Ejemplo n.º 3
0
 public KdbxMetadata(string databaseName)
 {
     Generator                  = PKGenerator;
     HeaderHash                 = null;
     DatabaseName               = databaseName;
     DatabaseDescription        = null;
     DefaultUserName            = null;
     MaintenanceHistoryDays     = 365;
     RecycleBinEnabled          = false;
     RecycleBinUuid             = new KeePassUuid(Guid.Empty);
     RecycleBinChanged          = DateTime.Now;
     EntryTemplatesGroup        = new KeePassUuid(Guid.Empty);
     EntryTemplatesGroupChanged = DateTime.Now;
     HistoryMaxItems            = 10;
     HistoryMaxSize             = -1;
     DbColor              = null;
     MasterKeyChanged     = DateTime.Now;
     MasterKeyChangeRec   = -1;
     MasterKeyChangeForce = -1;
     MemoryProtection     = new KdbxMemoryProtection();
     CustomIcons          = null;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Parses out a metadata element from XML.
        /// </summary>
        /// <param name="xml">XML to deserialize.</param>
        /// <param name="headerBinaries">Binaries that have been pre-parsed from a header.</param>
        /// <param name="parameters">Parameters controlling serialization.</param>
        public KdbxMetadata(XElement xml, IEnumerable <ProtectedBinary> headerBinaries, KdbxSerializationParameters parameters)
            : base(xml)
        {
            if (headerBinaries == null)
            {
                throw new ArgumentNullException(nameof(headerBinaries));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            Generator                  = GetString("Generator");
            HeaderHash                 = GetString("HeaderHash");
            DatabaseName               = GetString("DatabaseName");
            DatabaseNameChanged        = GetDate("DatabaseNameChanged", parameters);
            DatabaseDescription        = GetString("DatabaseDescription");
            DatabaseDescriptionChanged = GetDate("DatabaseDescriptionChanged", parameters);
            DefaultUserName            = GetString("DefaultUserName");
            DefaultUserNameChanged     = GetDate("DefaultUserNameChanged", parameters);
            MaintenanceHistoryDays     = GetInt("MaintenanceHistoryDays");
            DbColor              = GetNullableColor("Color");
            MasterKeyChanged     = GetDate("MasterKeyChanged", parameters, false);
            MasterKeyChangeRec   = GetInt("MasterKeyChangeRec", -1);
            MasterKeyChangeForce = GetInt("MasterKeyChangeForce", -1);
            MemoryProtection     = new KdbxMemoryProtection(GetNode(KdbxMemoryProtection.RootName));

            XElement iconsElement = GetNode(KdbxCustomIcons.RootName);

            if (iconsElement != null)
            {
                CustomIcons = new KdbxCustomIcons(iconsElement);
            }
            else
            {
                CustomIcons = null;
            }

            RecycleBinEnabled          = GetBool("RecycleBinEnabled");
            RecycleBinUuid             = GetUuid("RecycleBinUUID");
            RecycleBinChanged          = GetDate("RecycleBinChanged", parameters);
            EntryTemplatesGroup        = GetUuid("EntryTemplatesGroup");
            EntryTemplatesGroupChanged = GetDate("EntryTemplatesGroupChanged", parameters);
            HistoryMaxItems            = GetInt("HistoryMaxItems", -1);
            HistoryMaxSize             = GetInt("HistoryMaxSize", -1);
            LastSelectedGroup          = GetUuid("LastSelectedGroup");
            LastTopVisibleGroup        = GetUuid("LastTopVisibleGroup");

            XElement binariesElement = GetNode(KdbxBinaries.RootName);

            if (parameters.BinariesInXml)
            {
                if (binariesElement != null)
                {
                    Binaries = new KdbxBinaries(binariesElement, parameters);
                }
                else
                {
                    Binaries = new KdbxBinaries();
                }
            }
            else
            {
                // Populate with values from binary inner header
                Binaries = new KdbxBinaries(headerBinaries);
            }

            XElement customDataElement = GetNode(KdbxCustomData.RootName);

            if (customDataElement != null)
            {
                CustomData = new KdbxCustomData(customDataElement);
            }
            else
            {
                CustomData = null;
            }
        }
Ejemplo n.º 5
0
        public KdbxEntry(XElement xml, IKeePassGroup parent, IRandomNumberGenerator rng, KdbxMetadata metadata, KdbxSerializationParameters parameters)
            : base(xml, parameters)
        {
            Parent = parent;

            ForegroundColor = GetNullableColor("ForegroundColor");
            BackgroundColor = GetNullableColor("BackgroundColor");
            OverrideUrl     = GetString("OverrideURL") ?? string.Empty;
            Tags            = GetString("Tags") ?? string.Empty;

            Fields = new ObservableCollection <IProtectedString>();
            IEnumerable <KdbxString> strings = GetNodes(KdbxString.RootName)
                                               .Select(x => new KdbxString(x, rng));

            foreach (KdbxString s in strings)
            {
                switch (s.Key)
                {
                case "Notes":
                    Notes = s;
                    break;

                case "Password":
                    Password = s;
                    break;

                case "Title":
                    Title = s;
                    break;

                case "URL":
                    Url = s;
                    break;

                case "UserName":
                    UserName = s;
                    break;

                default:
                    Fields.Add(s);
                    break;
                }
            }

            KdbxMemoryProtection memProtection = metadata.MemoryProtection;

            if (Password == null)
            {
                Password = new KdbxString("Password", string.Empty, rng, memProtection.ProtectPassword);
            }
            if (Title == null)
            {
                Title = new KdbxString("Title", string.Empty, rng, memProtection.ProtectTitle);
            }
            if (Url == null)
            {
                Url = new KdbxString("URL", string.Empty, rng, memProtection.ProtectUrl);
            }
            if (UserName == null)
            {
                UserName = new KdbxString("UserName", string.Empty, rng, memProtection.ProtectUserName);
            }
            if (Notes == null)
            {
                Notes = new KdbxString("Notes", string.Empty, rng, memProtection.ProtectNotes);
            }

            IEnumerable <KdbxBinAttachment> binNodes = GetNodes(KdbxBinAttachment.RootName).Select(x => new KdbxBinAttachment(x, metadata, parameters));

            Binaries = new ObservableCollection <IKeePassBinAttachment>(binNodes);

            XElement autoTypeNode = GetNode(KdbxAutoType.RootName);

            if (autoTypeNode != null)
            {
                AutoType = new KdbxAutoType(autoTypeNode);
            }

            XElement historyElement = GetNode(KdbxHistory.RootName);

            if (historyElement != null)
            {
                History = new KdbxHistory(historyElement, rng, metadata, parameters);
            }
            else
            {
                History = new KdbxHistory(metadata);
            }

            this._metadata = metadata;
        }