diff --git a/build/dependencies.props b/build/dependencies.props index 3467fe7ed..511e04d92 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -7,34 +7,34 @@ 0.10.11 2.1.0-preview1-15626 1.10.0 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 - 2.1.0-preview1-27807 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 + 2.1.0-preview1-27845 2.0.0 - 2.1.0-preview1-26008-01 - 2.1.0-preview1-27807 + 2.1.0-preview1-26016-05 + 2.1.0-preview1-27845 15.3.0 4.7.49 10.0.1 - 4.5.0-preview1-26006-06 - 0.1.0-e171206-2 - 0.1.0-e171206-2 - 4.5.0-preview1-26006-06 - 4.5.0-preview1-26006-06 - 4.5.0-preview1-26006-06 - 4.5.0-preview1-26006-06 - 0.1.0-e171206-2 + 4.5.0-preview1-26016-05 + 0.1.0-e171215-1 + 0.1.0-e171215-1 + 4.5.0-preview1-26016-05 + 4.5.0-preview1-26016-05 + 4.5.0-preview1-26016-05 + 4.5.0-preview1-26016-05 + 0.1.0-e171215-1 4.5.0-preview2-25707-02 0.8.0 2.3.1 diff --git a/samples/SampleApp/SampleApp.csproj b/samples/SampleApp/SampleApp.csproj index 222560812..a7ba9be9d 100644 --- a/samples/SampleApp/SampleApp.csproj +++ b/samples/SampleApp/SampleApp.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0;net461 + netcoreapp2.1;netcoreapp2.0;net461 false true diff --git a/samples/SampleApp/testCert.pfx b/samples/SampleApp/testCert.pfx new file mode 100644 index 000000000..7118908c2 Binary files /dev/null and b/samples/SampleApp/testCert.pfx differ diff --git a/src/Kestrel.Https/ClientCertificateMode.cs b/src/Kestrel.Core/ClientCertificateMode.cs similarity index 100% rename from src/Kestrel.Https/ClientCertificateMode.cs rename to src/Kestrel.Core/ClientCertificateMode.cs diff --git a/src/Kestrel.Core/CoreStrings.resx b/src/Kestrel.Core/CoreStrings.resx index 158bc6cc5..49ee7e20b 100644 --- a/src/Kestrel.Core/CoreStrings.resx +++ b/src/Kestrel.Core/CoreStrings.resx @@ -465,4 +465,19 @@ Unable to configure default https bindings because no IDefaultHttpsProvider service was provided. + + Failed to authenticate HTTPS connection. + + + Authentication of the HTTPS connection timed out. + + + Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + + + Value must be a positive TimeSpan. + + + The server certificate parameter is required. + \ No newline at end of file diff --git a/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs similarity index 98% rename from src/Kestrel.Https/HttpsConnectionAdapterOptions.cs rename to src/Kestrel.Core/HttpsConnectionAdapterOptions.cs index 14238658d..6ada70170 100644 --- a/src/Kestrel.Https/HttpsConnectionAdapterOptions.cs +++ b/src/Kestrel.Core/HttpsConnectionAdapterOptions.cs @@ -73,7 +73,7 @@ public TimeSpan HandshakeTimeout { if (value <= TimeSpan.Zero && value != Timeout.InfiniteTimeSpan) { - throw new ArgumentOutOfRangeException(nameof(value), HttpsStrings.PositiveTimeSpanRequired); + throw new ArgumentOutOfRangeException(nameof(value), CoreStrings.PositiveTimeSpanRequired); } _handshakeTimeout = value != Timeout.InfiniteTimeSpan ? value : TimeSpan.MaxValue; } diff --git a/src/Kestrel.Https/Internal/ClosedStream.cs b/src/Kestrel.Core/Internal/ClosedStream.cs similarity index 100% rename from src/Kestrel.Https/Internal/ClosedStream.cs rename to src/Kestrel.Core/Internal/ClosedStream.cs diff --git a/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs similarity index 96% rename from src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs rename to src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs index 853f81966..68043a076 100644 --- a/src/Kestrel.Https/Internal/HttpsConnectionAdapter.cs +++ b/src/Kestrel.Core/Internal/HttpsConnectionAdapter.cs @@ -43,7 +43,7 @@ public HttpsConnectionAdapter(HttpsConnectionAdapterOptions options, ILoggerFact if (options.ServerCertificate == null) { - throw new ArgumentException(HttpsStrings.ServiceCertificateRequired, nameof(options)); + throw new ArgumentException(CoreStrings.ServiceCertificateRequired, nameof(options)); } // capture the certificate now so it can be switched after validation @@ -148,13 +148,13 @@ await sslStream.AuthenticateAsServerAsync(_serverCertificate, certificateRequire } catch (OperationCanceledException) { - _logger?.LogInformation(2, HttpsStrings.AuthenticationTimedOut); + _logger?.LogInformation(2, CoreStrings.AuthenticationTimedOut); sslStream.Dispose(); return _closedAdaptedConnection; } catch (IOException ex) { - _logger?.LogInformation(1, ex, HttpsStrings.AuthenticationFailed); + _logger?.LogInformation(1, ex, CoreStrings.AuthenticationFailed); sslStream.Dispose(); return _closedAdaptedConnection; } @@ -218,7 +218,7 @@ private static void EnsureCertificateIsAllowedForServerAuth(X509Certificate2 cer if (hasEkuExtension) { - throw new InvalidOperationException(HttpsStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint)); + throw new InvalidOperationException(CoreStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint)); } } diff --git a/src/Kestrel.Https/Internal/TlsConnectionFeature.cs b/src/Kestrel.Core/Internal/TlsConnectionFeature.cs similarity index 100% rename from src/Kestrel.Https/Internal/TlsConnectionFeature.cs rename to src/Kestrel.Core/Internal/TlsConnectionFeature.cs diff --git a/src/Kestrel.Https/ListenOptionsHttpsExtensions.cs b/src/Kestrel.Core/ListenOptionsHttpsExtensions.cs similarity index 100% rename from src/Kestrel.Https/ListenOptionsHttpsExtensions.cs rename to src/Kestrel.Core/ListenOptionsHttpsExtensions.cs diff --git a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs index 9321f1a2c..4e1d8cf2c 100644 --- a/src/Kestrel.Core/Properties/CoreStrings.Designer.cs +++ b/src/Kestrel.Core/Properties/CoreStrings.Designer.cs @@ -1634,6 +1634,76 @@ internal static string UnableToConfigureHttpsBindings internal static string FormatUnableToConfigureHttpsBindings() => GetString("UnableToConfigureHttpsBindings"); + /// + /// Failed to authenticate HTTPS connection. + /// + internal static string AuthenticationFailed + { + get => GetString("AuthenticationFailed"); + } + + /// + /// Failed to authenticate HTTPS connection. + /// + internal static string FormatAuthenticationFailed() + => GetString("AuthenticationFailed"); + + /// + /// Authentication of the HTTPS connection timed out. + /// + internal static string AuthenticationTimedOut + { + get => GetString("AuthenticationTimedOut"); + } + + /// + /// Authentication of the HTTPS connection timed out. + /// + internal static string FormatAuthenticationTimedOut() + => GetString("AuthenticationTimedOut"); + + /// + /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// + internal static string InvalidServerCertificateEku + { + get => GetString("InvalidServerCertificateEku"); + } + + /// + /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). + /// + internal static string FormatInvalidServerCertificateEku(object thumbprint) + => string.Format(CultureInfo.CurrentCulture, GetString("InvalidServerCertificateEku", "thumbprint"), thumbprint); + + /// + /// Value must be a positive TimeSpan. + /// + internal static string PositiveTimeSpanRequired1 + { + get => GetString("PositiveTimeSpanRequired1"); + } + + /// + /// Value must be a positive TimeSpan. + /// + internal static string FormatPositiveTimeSpanRequired1() + => GetString("PositiveTimeSpanRequired1"); + + /// + /// The server certificate parameter is required. + /// + internal static string ServiceCertificateRequired + { + get => GetString("ServiceCertificateRequired"); + } + + /// + /// The server certificate parameter is required. + /// + internal static string FormatServiceCertificateRequired() + => GetString("ServiceCertificateRequired"); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Kestrel.Https/HttpsStrings.resx b/src/Kestrel.Https/HttpsStrings.resx deleted file mode 100644 index 689b5c477..000000000 --- a/src/Kestrel.Https/HttpsStrings.resx +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Failed to authenticate HTTPS connection. - - - Authentication of the HTTPS connection timed out. - - - Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). - - - Value must be a positive TimeSpan. - - - The server certificate parameter is required. - - \ No newline at end of file diff --git a/src/Kestrel.Https/Kestrel.Https.csproj b/src/Kestrel.Https/Kestrel.Https.csproj index d9620b513..8b3226529 100644 --- a/src/Kestrel.Https/Kestrel.Https.csproj +++ b/src/Kestrel.Https/Kestrel.Https.csproj @@ -18,10 +18,4 @@ - - - - - - diff --git a/src/Kestrel.Https/Properties/AssemblyInfo.cs b/src/Kestrel.Https/Properties/AssemblyInfo.cs index 65c2045e2..c99dd8d3e 100644 --- a/src/Kestrel.Https/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Https/Properties/AssemblyInfo.cs @@ -2,7 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Runtime.CompilerServices; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Https; +using Microsoft.AspNetCore.Server.Kestrel.Https.Internal; -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] -[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] - +[assembly: TypeForwardedTo(typeof(ClientCertificateMode))] +[assembly: TypeForwardedTo(typeof(HttpsConnectionAdapter))] +[assembly: TypeForwardedTo(typeof(HttpsConnectionAdapterOptions))] +[assembly: TypeForwardedTo(typeof(ListenOptionsHttpsExtensions))] \ No newline at end of file diff --git a/src/Kestrel.Https/Properties/HttpsStrings.Designer.cs b/src/Kestrel.Https/Properties/HttpsStrings.Designer.cs deleted file mode 100644 index 417309ee9..000000000 --- a/src/Kestrel.Https/Properties/HttpsStrings.Designer.cs +++ /dev/null @@ -1,100 +0,0 @@ -// -namespace Microsoft.AspNetCore.Server.Kestrel.Https -{ - using System.Globalization; - using System.Reflection; - using System.Resources; - - internal static class HttpsStrings - { - private static readonly ResourceManager _resourceManager - = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.Https.HttpsStrings", typeof(HttpsStrings).GetTypeInfo().Assembly); - - /// - /// Failed to authenticate HTTPS connection. - /// - internal static string AuthenticationFailed - { - get => GetString("AuthenticationFailed"); - } - - /// - /// Failed to authenticate HTTPS connection. - /// - internal static string FormatAuthenticationFailed() - => GetString("AuthenticationFailed"); - - /// - /// Authentication of the HTTPS connection timed out. - /// - internal static string AuthenticationTimedOut - { - get => GetString("AuthenticationTimedOut"); - } - - /// - /// Authentication of the HTTPS connection timed out. - /// - internal static string FormatAuthenticationTimedOut() - => GetString("AuthenticationTimedOut"); - - /// - /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). - /// - internal static string InvalidServerCertificateEku - { - get => GetString("InvalidServerCertificateEku"); - } - - /// - /// Certificate {thumbprint} cannot be used as an SSL server certificate. It has an Extended Key Usage extension but the usages do not include Server Authentication (OID 1.3.6.1.5.5.7.3.1). - /// - internal static string FormatInvalidServerCertificateEku(object thumbprint) - => string.Format(CultureInfo.CurrentCulture, GetString("InvalidServerCertificateEku", "thumbprint"), thumbprint); - - /// - /// Value must be a positive TimeSpan. - /// - internal static string PositiveTimeSpanRequired - { - get => GetString("PositiveTimeSpanRequired"); - } - - /// - /// Value must be a positive TimeSpan. - /// - internal static string FormatPositiveTimeSpanRequired() - => GetString("PositiveTimeSpanRequired"); - - /// - /// The server certificate parameter is required. - /// - internal static string ServiceCertificateRequired - { - get => GetString("ServiceCertificateRequired"); - } - - /// - /// The server certificate parameter is required. - /// - internal static string FormatServiceCertificateRequired() - => GetString("ServiceCertificateRequired"); - - private static string GetString(string name, params string[] formatterNames) - { - var value = _resourceManager.GetString(name); - - System.Diagnostics.Debug.Assert(value != null); - - if (formatterNames != null) - { - for (var i = 0; i < formatterNames.Length; i++) - { - value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); - } - } - - return value; - } - } -} diff --git a/src/Kestrel/Properties/KestrelStrings.Designer.cs b/src/Kestrel/Properties/KestrelStrings.Designer.cs index ede41f12c..0246bf453 100644 --- a/src/Kestrel/Properties/KestrelStrings.Designer.cs +++ b/src/Kestrel/Properties/KestrelStrings.Designer.cs @@ -11,7 +11,7 @@ private static readonly ResourceManager _resourceManager = new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.KestrelStrings", typeof(KestrelStrings).GetTypeInfo().Assembly); /// - /// An 'https' URL was provided, but a development certificate could not be found. + /// Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 /// internal static string HttpsUrlProvidedButNoDevelopmentCertificateFound { @@ -19,7 +19,7 @@ internal static string HttpsUrlProvidedButNoDevelopmentCertificateFound } /// - /// An 'https' URL was provided, but a development certificate could not be found. + /// Unable to configure HTTPS endpoint. Try running 'dotnet developercertificates https -t' to setup a developer certificate for use with localhost. For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054 /// internal static string FormatHttpsUrlProvidedButNoDevelopmentCertificateFound() => GetString("HttpsUrlProvidedButNoDevelopmentCertificateFound"); diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs index b62641609..7d32d4be9 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterOptionsTest.cs @@ -3,6 +3,7 @@ using System; using System.Threading; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.AspNetCore.Server.Kestrel.Https; using Xunit; @@ -36,7 +37,7 @@ public void HandshakeTimeoutInvalid(TimeSpan value) var exception = Assert.Throws(() => new HttpsConnectionAdapterOptions { HandshakeTimeout = value }); Assert.Equal("value", exception.ParamName); - Assert.StartsWith(HttpsStrings.PositiveTimeSpanRequired, exception.Message); + Assert.StartsWith(CoreStrings.PositiveTimeSpanRequired, exception.Message); } public static TheoryData TimeoutValidData => new TheoryData diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index ebf608176..c08d02fb3 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -427,7 +427,7 @@ public void ThrowsForCertificatesMissingServerEku(string testCertName) ServerCertificate = cert, })); - Assert.Equal(HttpsStrings.FormatInvalidServerCertificateEku(cert.Thumbprint), ex.Message); + Assert.Equal(CoreStrings.FormatInvalidServerCertificateEku(cert.Thumbprint), ex.Message); } private static async Task App(HttpContext httpContext)