Skip to content

Commit

Permalink
2024.04.05
Browse files Browse the repository at this point in the history
  • Loading branch information
drweb86 committed Apr 5, 2024
1 parent 46a46be commit 1229931
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 19 deletions.
7 changes: 6 additions & 1 deletion help/Version History (Changelog).md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 2024.04.02
# 2024.04.05

## New Features
- During recovery or version deletion, real progress is shown
Expand All @@ -8,6 +8,11 @@
Main idea behind change is to avoid already mounted error. And use it recovery.
- Restoration speed was increased in 2 times for Windows.

## Bug Fixes
- FTPS MITM attacks. Be aware that if you had previously setupped FTPS with self-signed certificate, you need to do the following steps:
a. Open task with FTPS in Edit mode,
b. Click Save.

# 2024.03.28

## Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion sources/BUtil.Core/BUtil.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ItemGroup>
<PackageReference Include="FluentFTP" Version="49.0.2" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.FileSystemGlobbing">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class FtpsStorageSettingsV2 : IStorageSettingsV2
public string? Folder { get; set; }
public string User { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public string TrustedCertificate { get; set; } = null!;

}
18 changes: 18 additions & 0 deletions sources/BUtil.Core/Localization/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions sources/BUtil.Core/Localization/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,10 @@ See detailed description in the following link.</value>
<data name="User_Field_Validation" xml:space="preserve">
<value>User is not specified.</value>
</data>
<data name="File_Deleting" xml:space="preserve">
<value>Deleting "{0}"</value>
</data>
<data name="File_Moving" xml:space="preserve">
<value>Moving "{0}" to "{1}"</value>
</data>
</root>
6 changes: 6 additions & 0 deletions sources/BUtil.Core/Localization/Resources.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -659,4 +659,10 @@ bin.
<data name="User_Field_Validation" xml:space="preserve">
<value>Пользователь не указан.</value>
</data>
<data name="File_Deleting" xml:space="preserve">
<value>Удаление "{0}"</value>
</data>
<data name="File_Moving" xml:space="preserve">
<value>Перемещение "{0}" в "{1}"</value>
</data>
</root>
30 changes: 29 additions & 1 deletion sources/BUtil.Core/Storages/FtpsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.IO;
using System.Linq;
using System.Net.Security;
using System.Security;
using System.Text.RegularExpressions;

Expand All @@ -14,8 +15,9 @@ class FtpsStorage : StorageBase<FtpsStorageSettingsV2>
{
private readonly string? _normalizedFolder;
private readonly FtpClient _client;
private readonly bool _autodetectConnectionSettings;

internal FtpsStorage(ILog log, FtpsStorageSettingsV2 settings)
internal FtpsStorage(ILog log, FtpsStorageSettingsV2 settings, bool autodetectConnectionSettings)
: base(log, settings)
{
if (string.IsNullOrWhiteSpace(Settings.Host))
Expand All @@ -30,9 +32,11 @@ internal FtpsStorage(ILog log, FtpsStorageSettingsV2 settings)
_normalizedFolder = NormalizeNullablePath(Settings.Folder);

_client = Mount();
_autodetectConnectionSettings = autodetectConnectionSettings;
}

private readonly object _uploadLock = new();

public override IStorageUploadResult Upload(string sourceFile, string relativeFileName)
{
lock (_uploadLock) // because we're limited by upload speed by Server and Internet
Expand Down Expand Up @@ -84,10 +88,34 @@ private FtpClient Mount()
var client = new FtpClient(Settings.Host, Settings.User, Settings.Password, Settings.Port);
client.Config.EncryptionMode = GetFtpEncryptionMode();
client.Config.ValidateAnyCertificate = true;
client.ValidateCertificate += OnClientValidateCertificate;
client.Connect();
return client;
}

private void OnClientValidateCertificate(FluentFTP.Client.BaseClient.BaseFtpClient control, FtpSslValidationEventArgs e)
{
if (e.PolicyErrors == SslPolicyErrors.None)
{
e.Accept = true;
return;
}

if (_autodetectConnectionSettings)
{
Settings.TrustedCertificate = e.Certificate.GetRawCertDataString();
}

if (e.Certificate.GetRawCertDataString() == Settings.TrustedCertificate)
{
e.Accept = true;
return;
}

Log.WriteLine(LoggingEvent.Error, $"Received certificate from FTPS server violates policy {e.PolicyErrors}. Connection will not be accepted. You're facing Man-in-the-middle attack.");
Log.WriteLine(LoggingEvent.Error, $"If you trust this certificate, open in BUtil this task in Edit mode and click Save. Application will record this certificate as trusted.");
}

private FtpEncryptionMode GetFtpEncryptionMode()
{
return Settings.Encryption switch
Expand Down
6 changes: 3 additions & 3 deletions sources/BUtil.Core/Storages/StorageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ namespace BUtil.Core.Storages;

public class StorageFactory
{
public static IStorage Create(ILog log, IStorageSettingsV2 storageSettings)
public static IStorage Create(ILog log, IStorageSettingsV2 storageSettings, bool autodetectConnectionSettings)
{
if (storageSettings is FolderStorageSettingsV2)
return new FailoverStorageWrapper(log, new FolderStorage(log, (FolderStorageSettingsV2)storageSettings));
else if (storageSettings is SambaStorageSettingsV2)
return new FailoverStorageWrapper(log, PlatformSpecificExperience.Instance.GetSmbStorage(log, (SambaStorageSettingsV2)storageSettings));
else if (storageSettings is FtpsStorageSettingsV2)
return new FailoverStorageWrapper(log, new FtpsStorage(log, (FtpsStorageSettingsV2)storageSettings));
return new FailoverStorageWrapper(log, new FtpsStorage(log, (FtpsStorageSettingsV2)storageSettings, autodetectConnectionSettings));
else if (storageSettings is MtpStorageSettings)
{
var mtpStorage = PlatformSpecificExperience.Instance.GetMtpStorage(log, (MtpStorageSettings)storageSettings);
Expand All @@ -34,7 +34,7 @@ public static IStorage Create(ILog log, IStorageSettingsV2 storageSettings)

try
{
using var storage = Create(log, storageSettings);
using var storage = Create(log, storageSettings, true);
return storage.Test();
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions sources/BUtil.Core/TasksTree/ImportMedia/ImportFilesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public override void Execute()

var importMediaFileService = new ImportMediaFileService();
var importMediaState = options.SkipAlreadyImportedFiles ? importMediaFileService.Load(_task.Name) ?? new ImportMediaState() : new ImportMediaState();
var fromStorage = StorageFactory.Create(this.Log, options.From);
var toStorage = StorageFactory.Create(this.Log, new FolderStorageSettingsV2 { DestinationFolder = options.DestinationFolder });
var fromStorage = StorageFactory.Create(this.Log, options.From, false);
var toStorage = StorageFactory.Create(this.Log, new FolderStorageSettingsV2 { DestinationFolder = options.DestinationFolder }, false);
var transformFileName = options.TransformFileName;

var fromStorageFiles = fromStorage.GetFiles(null, SearchOption.AllDirectories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class StorageSpecificServicesIoc : IDisposable
private readonly Lazy<IncrementalBackupFileService> _incrementalBackupFileService;
public IncrementalBackupFileService IncrementalBackupFileService { get { return _incrementalBackupFileService.Value; } }

public StorageSpecificServicesIoc(ILog log, IStorageSettingsV2 storageSettings, IHashService hashService)
public StorageSpecificServicesIoc(ILog log, IStorageSettingsV2 storageSettings, IHashService hashService, bool autodetectConnectionSettings = false)
{
Log = log;
StorageSettings = storageSettings;
_storage = new Lazy<IStorage>(() => StorageFactory.Create(log, storageSettings));
_storage = new Lazy<IStorage>(() => StorageFactory.Create(log, storageSettings, autodetectConnectionSettings));
_incrementalBackupStateService = new Lazy<IncrementalBackupStateService>(() => new IncrementalBackupStateService(this, hashService));
_incrementalBackupFileService = new Lazy<IncrementalBackupFileService>(() => new IncrementalBackupFileService(hashService, this));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BUtil.Core.Events;
using BUtil.Core.Localization;
using BUtil.Core.TasksTree.Core;
using BUtil.Core.TasksTree.IncrementalModel;
using System;
Expand All @@ -14,7 +15,7 @@ public DeleteStorageFileTask(
StorageSpecificServicesIoc services,
TaskEvents events,
string relativeFileName) :
base(services.Log, events, $"Delete storage file \"{relativeFileName}\"")
base(services.Log, events, string.Format(Resources.File_Deleting, relativeFileName))
{
_services = services;
_relativeFileName = relativeFileName;
Expand Down
3 changes: 2 additions & 1 deletion sources/BUtil.Core/TasksTree/Storage/MoveStorageFileTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BUtil.Core.Events;
using BUtil.Core.Localization;
using BUtil.Core.TasksTree.Core;
using BUtil.Core.TasksTree.IncrementalModel;
using System;
Expand All @@ -16,7 +17,7 @@ public MoveStorageFileTask(
TaskEvents events,
string fromRelativeFileName,
string toRelativeFileName) :
base(services.Log, events, $"Move storage file \"{fromRelativeFileName}\" to \"{toRelativeFileName}\"")
base(services.Log, events, string.Format(Resources.File_Moving, fromRelativeFileName, toRelativeFileName))
{
_services = services;
_fromRelativeFileName = fromRelativeFileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public WriteStorageFilesToSourceFileTask(ILog log, TaskEvents events,
: base(log, events, Resources.Task_Restore)
{
_commonServicesIoc = new CommonServicesIoc();
_storageSpecificServicesIoc = new StorageSpecificServicesIoc(log, storageSettings, _commonServicesIoc.HashService);
_storageSpecificServicesIoc = new StorageSpecificServicesIoc(log, storageSettings, _commonServicesIoc.HashService, true);

Children = storageFiles
.Select(x => new WriteStorageFileToSourceFileTask(_storageSpecificServicesIoc, events, sourceItem, x, destinationFolder))
Expand Down
6 changes: 3 additions & 3 deletions sources/BUtil.Tests/BUtil.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions sources/butil-ui.Desktop/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"profiles": {
"butil-ui.Desktop": {
"commandName": "Project",
"commandLineArgs": "RestoreTask \"Task=👍👍👍check bug with same content, different last write time\""
"commandName": "Project"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<WrapPanel Orientation="Horizontal" Margin="24 8 24 8" Background="{Binding HeaderBackground}" HorizontalAlignment="Stretch" IsEnabled="{Binding !ParentViewModel.TaskExecuterViewModel.TaskNotCompleted}">
<TextBlock Margin="8 0 8 0" Text="{Binding Field_Version}" VerticalAlignment="Center" />
<ComboBox Margin="0 4 4 4" HorizontalAlignment="Stretch" VerticalAlignment="Center" SelectedValue="{Binding SelectedVersion}" ItemsSource="{Binding Versions}" DisplayMemberBinding="{Binding Title}" />
<Button Padding="8" VerticalAlignment="Center" Content="{Binding BackupVersion_Button_Delete}" HorizontalContentAlignment="Center" Margin="8 0 8 0" Command="{Binding DeleteBackupVersionCommand}" IsEnabled="{Binding IsDeleteBackupVersionEnabled}" IsVisible="{Binding ParentViewModel.TaskExecuterViewModel, Converter={x:Static ObjectConverters.IsNull}}" />
<Button Padding="8" VerticalAlignment="Center" Content="{Binding BackupVersion_Button_Delete}" HorizontalContentAlignment="Center" Margin="8 0 8 0" Command="{Binding DeleteBackupVersionCommand}" IsEnabled="{Binding IsDeleteBackupVersionEnabled}" />
<TextBlock TextWrapping="Wrap" Text="{Binding StorageSize}" Margin="8 0 0 0" VerticalAlignment="Center" />
</WrapPanel>

Expand Down

0 comments on commit 1229931

Please sign in to comment.