mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Cryptography service now handles random byte generation
Protected strings are now protected in memory
This commit is contained in:
@@ -19,19 +19,28 @@ namespace ModernKeePass.Actions
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TextProperty =
|
||||
DependencyProperty.Register("Text", typeof(string), typeof(ClipboardAction), new PropertyMetadata(string.Empty));
|
||||
DependencyProperty.Register(nameof(Text), typeof(string), typeof(ClipboardAction), new PropertyMetadata(string.Empty));
|
||||
public bool IsProtected
|
||||
{
|
||||
get { return (bool)GetValue(IsProtectedProperty); }
|
||||
set { SetValue(IsProtectedProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsProtectedProperty =
|
||||
DependencyProperty.Register(nameof(IsProtected), typeof(bool), typeof(ClipboardAction), new PropertyMetadata(false));
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Text)) return null;
|
||||
|
||||
var settings = App.Services.GetRequiredService<ISettingsProxy>();
|
||||
var cryptography = App.Services.GetRequiredService<ICryptographyClient>();
|
||||
|
||||
_dispatcher = new DispatcherTimer {Interval = TimeSpan.FromSeconds(settings.GetSetting(Constants.Settings.ClipboardTimeout, 10))};
|
||||
_dispatcher.Tick += Dispatcher_Tick;
|
||||
|
||||
var dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy };
|
||||
dataPackage.SetText(Text);
|
||||
dataPackage.SetText(IsProtected ? cryptography.UnProtect(Text).GetAwaiter().GetResult() : Text);
|
||||
Clipboard.SetContent(dataPackage);
|
||||
_dispatcher.Start();
|
||||
|
||||
|
@@ -1,12 +1,14 @@
|
||||
using System.Linq;
|
||||
using GalaSoft.MvvmLight;
|
||||
using Messages;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Domain.Enums;
|
||||
|
||||
namespace ModernKeePass.ViewModels.ListItems
|
||||
{
|
||||
public class EntryFieldVm: ViewModelBase
|
||||
{
|
||||
private readonly ICryptographyClient _cryptography;
|
||||
private string _name;
|
||||
private string _value;
|
||||
private bool _isProtected;
|
||||
@@ -24,7 +26,10 @@ namespace ModernKeePass.ViewModels.ListItems
|
||||
|
||||
public string Value
|
||||
{
|
||||
get { return _value; }
|
||||
get
|
||||
{
|
||||
return IsProtected? _cryptography.UnProtect(_value).GetAwaiter().GetResult() : _value;
|
||||
}
|
||||
set
|
||||
{
|
||||
MessengerInstance.Send(new EntryFieldValueChangedMessage { FieldName = Name, FieldValue = value, IsProtected = IsProtected });
|
||||
@@ -41,7 +46,12 @@ namespace ModernKeePass.ViewModels.ListItems
|
||||
}
|
||||
}
|
||||
|
||||
public EntryFieldVm(string fieldName, string fieldValue, bool isProtected)
|
||||
public EntryFieldVm(ICryptographyClient cryptography)
|
||||
{
|
||||
_cryptography = cryptography;
|
||||
}
|
||||
|
||||
public void Initialize(string fieldName, string fieldValue, bool isProtected)
|
||||
{
|
||||
_name = fieldName;
|
||||
_value = fieldValue;
|
||||
|
@@ -51,7 +51,7 @@ namespace ModernKeePass.ViewModels.Settings
|
||||
_mediator = mediator;
|
||||
_database = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult();
|
||||
var rootGroup = _mediator.Send(new GetGroupQuery { Id = _database.RootGroupId }).GetAwaiter().GetResult();
|
||||
Groups = new ObservableCollection<IEntityVm>(rootGroup.SubGroups);
|
||||
Groups = new ObservableCollection<IEntityVm>(rootGroup.Groups);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user