Skip to content

Commit ab1f16a

Browse files
committed
Merge branch 'release/3.1.2'
2 parents f0922b5 + 3a1b1fb commit ab1f16a

29 files changed

Lines changed: 365 additions & 207 deletions

FubarDev.FtpServer.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1616
PackageLibrary.props = PackageLibrary.props
1717
README.md = README.md
1818
stylecop.json = stylecop.json
19+
DotNetSdkMono.props = DotNetSdkMono.props
1920
EndProjectSection
2021
EndProject
2122
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FubarDev.FtpServer.FileSystem.DotNet", "src\FubarDev.FtpServer.FileSystem.DotNet\FubarDev.FtpServer.FileSystem.DotNet.csproj", "{9A83C6F5-378B-48B3-B32A-151DB90B390C}"

samples/TestFtpServer/ServiceCollectionExtensions.cs

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
// </copyright>
44

55
using System;
6-
using System.Collections.Generic;
76
using System.IO;
8-
using System.Linq;
9-
using System.Security.Cryptography.X509Certificates;
107
using System.Text;
118
using System.Threading;
12-
using System.Threading.Tasks;
139

1410
using FubarDev.FtpServer;
1511
using FubarDev.FtpServer.AccountManagement.Directories.RootPerUser;
1612
using FubarDev.FtpServer.AccountManagement.Directories.SingleRootWithoutHome;
17-
using FubarDev.FtpServer.Authentication;
1813
using FubarDev.FtpServer.CommandExtensions;
1914
using FubarDev.FtpServer.Commands;
2015
using FubarDev.FtpServer.FileSystem;
@@ -226,33 +221,6 @@ public static IServiceCollection AddFtpServices(
226221
break;
227222
}
228223

229-
if (options.Ftps.Implicit)
230-
{
231-
var implicitFtpsCertificate = options.GetCertificate();
232-
if (implicitFtpsCertificate != null)
233-
{
234-
services
235-
.AddSingleton(new ImplicitFtpsControlConnectionStreamAdapterOptions(implicitFtpsCertificate))
236-
.AddSingleton<IFtpControlStreamAdapter, ImplicitFtpsControlConnectionStreamAdapter>();
237-
238-
// Ensure that PROT and PBSZ commands are working.
239-
services.Decorate<IFtpServer>(
240-
(ftpServer, _) =>
241-
{
242-
ftpServer.ConfigureConnection += (s, e) =>
243-
{
244-
var serviceProvider = e.Connection.ConnectionServices;
245-
var stateMachine = serviceProvider.GetRequiredService<IFtpLoginStateMachine>();
246-
var authTlsMechanism = serviceProvider.GetRequiredService<IEnumerable<IAuthenticationMechanism>>()
247-
.Single(x => x.CanHandle("TLS"));
248-
stateMachine.Activate(authTlsMechanism);
249-
};
250-
251-
return ftpServer;
252-
});
253-
}
254-
}
255-
256224
#if NETCOREAPP
257225
services.Decorate<IFtpServer>(
258226
(ftpServer, serviceProvider) =>
@@ -302,6 +270,15 @@ private static IFtpServerBuilder ConfigureServer(this IFtpServerBuilder builder,
302270
.EnableConnectionCheck();
303271
}
304272

273+
if (options.Ftps.Implicit)
274+
{
275+
var implicitFtpsCertificate = options.GetCertificate();
276+
if (implicitFtpsCertificate != null)
277+
{
278+
builder = builder.UseImplicitTls(implicitFtpsCertificate);
279+
}
280+
}
281+
305282
return builder;
306283
}
307284

@@ -329,41 +306,11 @@ private static UserCredential GetUserCredential(
329306
return credential;
330307
}
331308

332-
private class ImplicitFtpsControlConnectionStreamAdapterOptions
333-
{
334-
public ImplicitFtpsControlConnectionStreamAdapterOptions(X509Certificate2 certificate)
335-
{
336-
Certificate = certificate;
337-
}
338-
339-
public X509Certificate2 Certificate { get; }
340-
}
341-
342309
private static TimeSpan? ToTimeSpan(int? seconds)
343310
{
344311
return seconds == null
345312
? (TimeSpan?)null
346313
: TimeSpan.FromSeconds(seconds.Value);
347314
}
348-
349-
private class ImplicitFtpsControlConnectionStreamAdapter : IFtpControlStreamAdapter
350-
{
351-
private readonly ImplicitFtpsControlConnectionStreamAdapterOptions _options;
352-
private readonly ISslStreamWrapperFactory _sslStreamWrapperFactory;
353-
354-
public ImplicitFtpsControlConnectionStreamAdapter(
355-
ImplicitFtpsControlConnectionStreamAdapterOptions options,
356-
ISslStreamWrapperFactory sslStreamWrapperFactory)
357-
{
358-
_options = options;
359-
_sslStreamWrapperFactory = sslStreamWrapperFactory;
360-
}
361-
362-
/// <inheritdoc />
363-
public Task<Stream> WrapAsync(Stream stream, CancellationToken cancellationToken)
364-
{
365-
return _sslStreamWrapperFactory.WrapStreamAsync(stream, false, _options.Certificate, cancellationToken);
366-
}
367-
}
368315
}
369316
}

samples/TestFtpServer/appsettings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
"Microsoft": "Information",
88
"FubarDev.FtpServer.CommandHandlers.ListCommandHandler": "Verbose",
99
"FubarDev.FtpServer.CommandHandlers.MlstCommandHandler": "Verbose"
10-
},
10+
}
1111
},
1212
"WriteTo": [
13-
{ "Name": "Console" }
13+
{
14+
"Name": "Console",
15+
"OutputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] {ConnectionId} {Message:lj}{NewLine}{Exception}"
16+
}
1417
],
1518
"Enrich": ["FromLogContext"]
1619
},
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// <copyright file="IFtpConnectionConfigurator.cs" company="Fubar Development Junker">
2+
// Copyright (c) Fubar Development Junker. All rights reserved.
3+
// </copyright>
4+
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace FubarDev.FtpServer
9+
{
10+
/// <summary>
11+
/// Interface for services that need to reconfigure the connection.
12+
/// </summary>
13+
public interface IFtpConnectionConfigurator
14+
{
15+
/// <summary>
16+
/// Changes the connections configuration.
17+
/// </summary>
18+
/// <param name="connection">The FTP connection.</param>
19+
/// <param name="cancellationToken">The cancellation token.</param>
20+
/// <returns>The task.</returns>
21+
Task Configure(IFtpConnection connection, CancellationToken cancellationToken);
22+
}
23+
}

src/FubarDev.FtpServer.Abstractions/IFtpServer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public interface IFtpServer : IPausableFtpService
1414
/// <summary>
1515
/// This event is raised when the connection is ready to be configured.
1616
/// </summary>
17-
event EventHandler<ConnectionEventArgs> ConfigureConnection;
17+
[Obsolete("Register a service of type IFtpConnectionConfigurator instead.")]
18+
event EventHandler<ConnectionEventArgs>? ConfigureConnection;
1819

1920
/// <summary>
2021
/// This event is raised when the listener was started.
2122
/// </summary>
22-
event EventHandler<ListenerStartedEventArgs> ListenerStarted;
23+
event EventHandler<ListenerStartedEventArgs>? ListenerStarted;
2324

2425
/// <summary>
2526
/// Gets the public IP address (required for <c>PASV</c> and <c>EPSV</c>).

src/FubarDev.FtpServer/AuthTlsOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AuthTlsOptions
1414
/// <summary>
1515
/// Gets or sets the server certificate.
1616
/// </summary>
17-
public X509Certificate2? ServerCertificate { get; set; }
17+
public X509Certificate? ServerCertificate { get; set; }
1818

1919
/// <summary>
2020
/// Gets or sets a value indicating whether implicit FTPS is used.

src/FubarDev.FtpServer/ConnectionHandlers/IFtpConnectionAdapter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Copyright (c) Fubar Development Junker. All rights reserved.
33
// </copyright>
44

5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
58
namespace FubarDev.FtpServer.ConnectionHandlers
69
{
710
/// <summary>

src/FubarDev.FtpServer/ConnectionHandlers/IFtpSecureConnectionAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ public interface IFtpSecureConnectionAdapter : IFtpConnectionAdapter
2727
/// <param name="certificate">The server certificate (with private key).</param>
2828
/// <param name="cancellationToken">The cancellation token.</param>
2929
/// <returns>The task.</returns>
30-
Task EnableSslStreamAsync(X509Certificate2 certificate, CancellationToken cancellationToken);
30+
Task EnableSslStreamAsync(X509Certificate certificate, CancellationToken cancellationToken);
3131
}
3232
}

src/FubarDev.FtpServer/ConnectionHandlers/PassThroughConnectionAdapter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace FubarDev.FtpServer.ConnectionHandlers
1818
/// </summary>
1919
internal class PassThroughConnectionAdapter : IFtpConnectionAdapter
2020
{
21-
private readonly IFtpService _transmitService;
21+
private readonly IPausableFtpService _transmitService;
2222
private readonly IPausableFtpService _receiverService;
2323

2424
/// <summary>
@@ -38,12 +38,12 @@ public PassThroughConnectionAdapter(
3838
socketPipe.Input,
3939
connectionPipe.Output,
4040
connectionClosed,
41-
loggerFactory?.CreateLogger(typeof(PassThroughConnectionAdapter).FullName + ":Receiver"));
41+
loggerFactory?.CreateLogger(typeof(PassThroughConnectionAdapter).FullName + ".Receiver"));
4242
_transmitService = new NonClosingNetworkPassThrough(
4343
connectionPipe.Input,
4444
socketPipe.Output,
4545
connectionClosed,
46-
loggerFactory?.CreateLogger(typeof(PassThroughConnectionAdapter).FullName + ":Transmitter"));
46+
loggerFactory?.CreateLogger(typeof(PassThroughConnectionAdapter).FullName + ".Transmitter"));
4747
}
4848

4949
/// <inheritdoc />

src/FubarDev.FtpServer/ConnectionHandlers/SecureConnectionAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ await StartAsync(cancellationToken)
7474
}
7575

7676
/// <inheritdoc />
77-
public async Task EnableSslStreamAsync(X509Certificate2 certificate, CancellationToken cancellationToken)
77+
public async Task EnableSslStreamAsync(X509Certificate certificate, CancellationToken cancellationToken)
7878
{
7979
await StopAsync(cancellationToken)
8080
.ConfigureAwait(false);

0 commit comments

Comments
 (0)