Пример #1
0
        private PasswordEntry GetLithnetCurrentPassword(IComputer computer, DateTime?newExpiry)
        {
            var item = this.lithnetProvider.GetCurrentPassword(computer, newExpiry);

            if (item == null)
            {
                return(null);
            }

            PasswordEntry current = new PasswordEntry()
            {
                Created    = item.Created,
                Password   = this.encryptionProvider.Decrypt(item.EncryptedData, (thumbprint) => this.certificateProvider.FindDecryptionCertificate(thumbprint)),
                ExpiryDate = newExpiry ?? this.lithnetProvider.GetExpiry(computer)
            };

            return(current);
        }
Пример #2
0
        private IList <PasswordEntry> GetPasswordHistoryEntries(IComputer computer)
        {
            List <PasswordEntry> list = new List <PasswordEntry>();

            foreach (var item in this.lithnetProvider.GetPasswordHistory(computer))
            {
                PasswordEntry p = new PasswordEntry()
                {
                    Created    = item.Created,
                    ExpiryDate = item.Retired
                };

                string tp = null;

                try
                {
                    p.Password = this.encryptionProvider.Decrypt(item.EncryptedData,
                                                                 (thumbprint) =>
                    {
                        tp = thumbprint;
                        return(this.certificateProvider.FindDecryptionCertificate(thumbprint));
                    });
                }
                catch (Exception ex)
                {
                    this.logger.LogError(EventIDs.LapsPasswordHistoryError, ex, $"Could not decrypt a password history item. Certificate thumbprint {tp}, Created: {p.Created}, Expired: {p.ExpiryDate}");
                    p.DecryptionFailed = true;
                }

                list.Add(p);
            }

            if (list.Count == 0)
            {
                throw new NoPasswordException();
            }

            return(list);
        }