diff --git a/ModernKeePass.Application/Application.csproj b/ModernKeePass.Application/Application.csproj index dcc8af3..1d6c67b 100644 --- a/ModernKeePass.Application/Application.csproj +++ b/ModernKeePass.Application/Application.csproj @@ -77,6 +77,7 @@ + diff --git a/ModernKeePass.Application/Common/Interfaces/ICryptographyClient.cs b/ModernKeePass.Application/Common/Interfaces/ICryptographyClient.cs index f7c19ff..b98040c 100644 --- a/ModernKeePass.Application/Common/Interfaces/ICryptographyClient.cs +++ b/ModernKeePass.Application/Common/Interfaces/ICryptographyClient.cs @@ -1,12 +1,10 @@ -using System.Collections.Generic; -using ModernKeePass.Domain.Entities; +using System.Threading.Tasks; namespace ModernKeePass.Application.Common.Interfaces { public interface ICryptographyClient { - IEnumerable Ciphers { get; } - IEnumerable KeyDerivations { get; } - IEnumerable CompressionAlgorithms { get; } + Task Protect(string value); + Task UnProtect(string value); } } \ No newline at end of file diff --git a/ModernKeePass.Application/Common/Interfaces/IDatabaseSettingsProxy.cs b/ModernKeePass.Application/Common/Interfaces/IDatabaseSettingsProxy.cs new file mode 100644 index 0000000..217aa79 --- /dev/null +++ b/ModernKeePass.Application/Common/Interfaces/IDatabaseSettingsProxy.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using ModernKeePass.Domain.Entities; + +namespace ModernKeePass.Application.Common.Interfaces +{ + public interface IDatabaseSettingsProxy + { + IEnumerable Ciphers { get; } + IEnumerable KeyDerivations { get; } + IEnumerable CompressionAlgorithms { get; } + } +} \ No newline at end of file diff --git a/ModernKeePass.Application/Group/Commands/DeleteGroup/DeleteGroupCommand.cs b/ModernKeePass.Application/Group/Commands/DeleteGroup/DeleteGroupCommand.cs index d157536..79d20ae 100644 --- a/ModernKeePass.Application/Group/Commands/DeleteGroup/DeleteGroupCommand.cs +++ b/ModernKeePass.Application/Group/Commands/DeleteGroup/DeleteGroupCommand.cs @@ -25,12 +25,13 @@ namespace ModernKeePass.Application.Group.Commands.DeleteGroup { if (!_database.IsOpen) throw new DatabaseClosedException(); + var isRecycleBin = message.GroupId.Equals(_database.RecycleBinId); if (_database.IsRecycleBinEnabled && (string.IsNullOrEmpty(_database.RecycleBinId) || _database.RecycleBinId.Equals(Constants.EmptyId))) { _database.CreateGroup(_database.RootGroupId, message.RecycleBinName, true); } - if (!_database.IsRecycleBinEnabled || message.ParentGroupId.Equals(_database.RecycleBinId)) + if (!_database.IsRecycleBinEnabled || message.ParentGroupId.Equals(_database.RecycleBinId) || isRecycleBin) { _database.DeleteEntity(message.GroupId); } @@ -40,6 +41,7 @@ namespace ModernKeePass.Application.Group.Commands.DeleteGroup } await _database.RemoveGroup(message.ParentGroupId, message.GroupId); + if (isRecycleBin) _database.RecycleBinId = Constants.EmptyId; } } } diff --git a/ModernKeePass.Application/Parameters/Queries/GetCiphers/GetCiphersQuery.cs b/ModernKeePass.Application/Parameters/Queries/GetCiphers/GetCiphersQuery.cs index e75ba33..d0a6106 100644 --- a/ModernKeePass.Application/Parameters/Queries/GetCiphers/GetCiphersQuery.cs +++ b/ModernKeePass.Application/Parameters/Queries/GetCiphers/GetCiphersQuery.cs @@ -10,16 +10,16 @@ namespace ModernKeePass.Application.Parameters.Queries.GetCiphers { public class GetCiphersQueryHandler: IRequestHandler> { - private readonly ICryptographyClient _cryptography; + private readonly IDatabaseSettingsProxy _databaseSettings; - public GetCiphersQueryHandler(ICryptographyClient cryptography) + public GetCiphersQueryHandler(IDatabaseSettingsProxy databaseSettings) { - _cryptography = cryptography; + _databaseSettings = databaseSettings; } public IEnumerable Handle(GetCiphersQuery message) { - return _cryptography.Ciphers.Select(c => new CipherVm + return _databaseSettings.Ciphers.Select(c => new CipherVm { Id = c.Id, Name = c.Name diff --git a/ModernKeePass.Application/Parameters/Queries/GetCompressions/GetCompressionsQuery.cs b/ModernKeePass.Application/Parameters/Queries/GetCompressions/GetCompressionsQuery.cs index 66c4271..caa9112 100644 --- a/ModernKeePass.Application/Parameters/Queries/GetCompressions/GetCompressionsQuery.cs +++ b/ModernKeePass.Application/Parameters/Queries/GetCompressions/GetCompressionsQuery.cs @@ -9,16 +9,16 @@ namespace ModernKeePass.Application.Parameters.Queries.GetCompressions { public class GetCompressionsQueryHandler : IRequestHandler> { - private readonly ICryptographyClient _cryptography; + private readonly IDatabaseSettingsProxy _databaseSettings; - public GetCompressionsQueryHandler(ICryptographyClient cryptography) + public GetCompressionsQueryHandler(IDatabaseSettingsProxy databaseSettings) { - _cryptography = cryptography; + _databaseSettings = databaseSettings; } public IEnumerable Handle(GetCompressionsQuery message) { - return _cryptography.CompressionAlgorithms.OrderBy(c => c); + return _databaseSettings.CompressionAlgorithms.OrderBy(c => c); } } } diff --git a/ModernKeePass.Application/Parameters/Queries/GetKeyDerivations/GetKeyDerivationsQuery.cs b/ModernKeePass.Application/Parameters/Queries/GetKeyDerivations/GetKeyDerivationsQuery.cs index 9cb07b0..8f57030 100644 --- a/ModernKeePass.Application/Parameters/Queries/GetKeyDerivations/GetKeyDerivationsQuery.cs +++ b/ModernKeePass.Application/Parameters/Queries/GetKeyDerivations/GetKeyDerivationsQuery.cs @@ -10,16 +10,16 @@ namespace ModernKeePass.Application.Parameters.Queries.GetKeyDerivations { public class GetKeyDerivationsQueryHandler : IRequestHandler> { - private readonly ICryptographyClient _cryptography; + private readonly IDatabaseSettingsProxy _databaseSettings; - public GetKeyDerivationsQueryHandler(ICryptographyClient cryptography) + public GetKeyDerivationsQueryHandler(IDatabaseSettingsProxy databaseSettings) { - _cryptography = cryptography; + _databaseSettings = databaseSettings; } public IEnumerable Handle(GetKeyDerivationsQuery message) { - return _cryptography.KeyDerivations.Select(c => new KeyDerivationVm + return _databaseSettings.KeyDerivations.Select(c => new KeyDerivationVm { Id = c.Id, Name = c.Name diff --git a/ModernKeePass.Infrastructure/DependencyInjection.cs b/ModernKeePass.Infrastructure/DependencyInjection.cs index 49f0d0d..59e99ab 100644 --- a/ModernKeePass.Infrastructure/DependencyInjection.cs +++ b/ModernKeePass.Infrastructure/DependencyInjection.cs @@ -18,7 +18,7 @@ namespace ModernKeePass.Infrastructure public static IServiceCollection AddInfrastructureKeePass(this IServiceCollection services) { services.AddSingleton(typeof(IDatabaseProxy), typeof(KeePassDatabaseClient)); - services.AddTransient(typeof(ICryptographyClient), typeof(KeePassCryptographyClient)); + services.AddTransient(typeof(IDatabaseSettingsProxy), typeof(KeePassDatabaseSettingsProxy)); services.AddTransient(typeof(ICredentialsProxy), typeof(KeePassCredentialsClient)); return services; } @@ -29,6 +29,7 @@ namespace ModernKeePass.Infrastructure services.AddTransient(typeof(ISettingsProxy), typeof(UwpSettingsClient)); services.AddTransient(typeof(IRecentProxy), typeof(UwpRecentFilesClient)); services.AddTransient(typeof(IResourceProxy), typeof(UwpResourceClient)); + services.AddTransient(typeof(ICryptographyClient), typeof(UwpCryptographyClient)); services.AddTransient(typeof(INotificationService), typeof(ToastNotificationService)); return services; } diff --git a/ModernKeePass.Infrastructure/Infrastructure.csproj b/ModernKeePass.Infrastructure/Infrastructure.csproj index 7e4acc0..5690c25 100644 --- a/ModernKeePass.Infrastructure/Infrastructure.csproj +++ b/ModernKeePass.Infrastructure/Infrastructure.csproj @@ -82,12 +82,13 @@ - + + diff --git a/ModernKeePass.Infrastructure/KeePass/KeePassCryptographyClient.cs b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseSettingsProxy.cs similarity index 94% rename from ModernKeePass.Infrastructure/KeePass/KeePassCryptographyClient.cs rename to ModernKeePass.Infrastructure/KeePass/KeePassDatabaseSettingsProxy.cs index 9dfb3b0..aac8318 100644 --- a/ModernKeePass.Infrastructure/KeePass/KeePassCryptographyClient.cs +++ b/ModernKeePass.Infrastructure/KeePass/KeePassDatabaseSettingsProxy.cs @@ -9,7 +9,7 @@ using ModernKeePassLib.Cryptography.KeyDerivation; namespace ModernKeePass.Infrastructure.KeePass { - public class KeePassCryptographyClient: ICryptographyClient + public class KeePassDatabaseSettingsProxy: IDatabaseSettingsProxy { public IEnumerable Ciphers { diff --git a/ModernKeePass.Infrastructure/UWP/UwpCryptographyClient.cs b/ModernKeePass.Infrastructure/UWP/UwpCryptographyClient.cs new file mode 100644 index 0000000..362407d --- /dev/null +++ b/ModernKeePass.Infrastructure/UWP/UwpCryptographyClient.cs @@ -0,0 +1,47 @@ +using System; +using System.Threading.Tasks; +using Windows.Security.Cryptography; +using Windows.Security.Cryptography.DataProtection; +using ModernKeePass.Application.Common.Interfaces; + +namespace ModernKeePass.Infrastructure.UWP +{ + public class UwpCryptographyClient: ICryptographyClient + { + public async Task Protect(string value) + { + // Create a DataProtectionProvider object for the specified descriptor. + var provider = new DataProtectionProvider(); + + // Encode the plaintext input message to a buffer. + var buffMsg = CryptographicBuffer.ConvertStringToBinary(value, BinaryStringEncoding.Utf8); + + // Encrypt the message. + var buffProtected = await provider.ProtectAsync(buffMsg); + + // Encode buffer to Base64 + var stringProtected = CryptographicBuffer.EncodeToBase64String(buffProtected); + + // Return the encrypted string. + return stringProtected; + } + + public async Task UnProtect(string value) + { + // Create a DataProtectionProvider object. + var provider = new DataProtectionProvider(); + + // Decode from Base64 string + var buffProtected = CryptographicBuffer.DecodeFromBase64String(value); + + // Decrypt the protected message specified on input. + var buffUnprotected = await provider.UnprotectAsync(buffProtected); + + // Convert the unprotected message from an IBuffer object to a string. + var strClearText = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, buffUnprotected); + + // Return the plaintext string. + return strClearText; + } + } +} \ No newline at end of file diff --git a/ModernKeePass/Strings/fr-FR/CodeBehind.resw b/ModernKeePass/Strings/fr-FR/CodeBehind.resw index 10a05c7..64728c5 100644 --- a/ModernKeePass/Strings/fr-FR/CodeBehind.resw +++ b/ModernKeePass/Strings/fr-FR/CodeBehind.resw @@ -270,9 +270,6 @@ Clé - - Ajouter un champ - La base de données est trop grosse pour sauvegarder automatiquement lors de la suspension. Pensez à bien sauvegarder vos changements avant de fermer l'app ! diff --git a/ModernKeePass/Strings/fr-FR/Resources.resw b/ModernKeePass/Strings/fr-FR/Resources.resw index 53fbadf..dd6da85 100644 --- a/ModernKeePass/Strings/fr-FR/Resources.resw +++ b/ModernKeePass/Strings/fr-FR/Resources.resw @@ -561,4 +561,7 @@ Supprimer la valeur copiée dans le presse papier après combien de secondes ? + + Ajouter un champ + \ No newline at end of file diff --git a/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs b/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs index 5a22044..7f622dc 100644 --- a/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs +++ b/WinAppCommon/ViewModels/ViewModelLocatorCommon.cs @@ -55,6 +55,7 @@ namespace ModernKeePass.ViewModels SimpleIoc.Default.Register(() => App.Services.GetRequiredService()); SimpleIoc.Default.Register(() => App.Services.GetRequiredService()); SimpleIoc.Default.Register(() => App.Services.GetRequiredService()); + SimpleIoc.Default.Register(() => App.Services.GetRequiredService()); } SimpleIoc.Default.Register();