Exemplo 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;
        }
Exemplo n.º 2
0
 static KdbxString()
 {
     Empty            = new KdbxString();
     Empty._rng       = null;
     Empty.Protected  = false;
     Empty.Key        = null;
     Empty.ClearValue = null;
 }
Exemplo n.º 3
0
 public KdbxGroup(IKeePassGroup parent) : this()
 {
     Parent              = parent;
     Title               = new KdbxString("Name", String.Empty, null);
     Notes               = new KdbxString("Notes", String.Empty, null);
     Uuid                = new KeePassUuid();
     IconID              = KdbxGroup.DefaultIconId;
     Times               = new KdbxTimes();
     IsExpanded          = true;
     LastTopVisibleEntry = KeePassUuid.Empty;
 }
Exemplo n.º 4
0
        public KdbxGroup(XElement xml, IKeePassGroup parent, IRandomNumberGenerator rng, KdbxMetadata metadata, KdbxSerializationParameters parameters)
            : base(xml, parameters)
        {
            InitializeCollections();

            Parent = parent;

            Title = new KdbxString("Name", GetString("Name"), null);
            Notes = new KdbxString("Notes", GetString("Notes"), null);

            IsExpanded = GetBool("IsExpanded");
            DefaultAutoTypeSequence = GetString("DefaultAutoTypeSequence");
            EnableAutoType          = GetNullableBool("EnableAutoType");
            EnableSearching         = GetNullableBool("EnableSearching");
            LastTopVisibleEntry     = GetUuid("LastTopVisibleEntry", false) ?? KeePassUuid.Empty;

            // The order in which we deserialize entries and groups matters.
            // They must be constructed in the order that they appear in the XML,
            // or the RNG will enter undefined territory.
            ForgetNodes(KdbxEntry.RootName);
            ForgetNodes(KdbxGroup.RootName);

            // First, we need to select each XElement that represents either a group or an entry.
            // From these, we construct KdbxEntries and KdbxGroups.
            // Then we sort them, groups first, and add them to the child collection.
            IEnumerable <IKeePassNode> nodes = xml.Elements()
                                               .Where(element => element.Name == KdbxEntry.RootName || element.Name == KdbxGroup.RootName)
                                               .Select(
                matchedElement =>
            {
                if (matchedElement.Name == KdbxEntry.RootName)
                {
                    return(new KdbxEntry(matchedElement, this, rng, metadata, parameters)
                           as IKeePassNode);
                }
                else
                {
                    return(new KdbxGroup(matchedElement, this, rng, metadata, parameters)
                           as IKeePassNode);
                }
            }
                )
                                               .OrderBy(
                node => node is IKeePassGroup,
                Comparer <bool> .Create((b1, b2) => b1.CompareTo(b2))
                );

            foreach (IKeePassNode node in nodes)
            {
                this._children.Add(node);
            }
        }
Exemplo n.º 5
0
        public override bool Equals(object obj)
        {
            KdbxString other = obj as KdbxString;

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

            return(Protected == other.Protected &&
                   ClearValue == other.ClearValue &&
                   Key == other.Key);
        }
Exemplo n.º 6
0
        public IProtectedString Clone()
        {
            KdbxString clone = new KdbxString();

            if (this._rng != null)
            {
                clone._rng = this._rng.Clone();
            }
            else
            {
                clone._rng = null;
            }
            clone.Protected  = Protected;
            clone.Key        = Key;
            clone.ClearValue = ClearValue;
            return(clone);
        }
Exemplo n.º 7
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;
        }