Merge Kestrel.Https into Kestrel.Core. Fix sample.

This commit is contained in:
Chris Ross (ASP.NET) 2017-12-18 12:47:43 -08:00
parent 9f02935074
commit d505d20ba7
17 changed files with 103 additions and 254 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp2.0;net461</TargetFrameworks>
<IsPackable>false</IsPackable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
</PropertyGroup>

Binary file not shown.

View File

@ -465,4 +465,19 @@
<data name="UnableToConfigureHttpsBindings" xml:space="preserve">
<value>Unable to configure default https bindings because no IDefaultHttpsProvider service was provided.</value>
</data>
<data name="AuthenticationFailed" xml:space="preserve">
<value>Failed to authenticate HTTPS connection.</value>
</data>
<data name="AuthenticationTimedOut" xml:space="preserve">
<value>Authentication of the HTTPS connection timed out.</value>
</data>
<data name="InvalidServerCertificateEku" xml:space="preserve">
<value>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>
</data>
<data name="PositiveTimeSpanRequired1" xml:space="preserve">
<value>Value must be a positive TimeSpan.</value>
</data>
<data name="ServiceCertificateRequired" xml:space="preserve">
<value>The server certificate parameter is required.</value>
</data>
</root>

View File

@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https
{
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;
}

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
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 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
}
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 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https.Internal
if (hasEkuExtension)
{
throw new InvalidOperationException(HttpsStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint));
throw new InvalidOperationException(CoreStrings.FormatInvalidServerCertificateEku(certificate.Thumbprint));
}
}

View File

@ -1634,6 +1634,76 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
internal static string FormatUnableToConfigureHttpsBindings()
=> GetString("UnableToConfigureHttpsBindings");
/// <summary>
/// Failed to authenticate HTTPS connection.
/// </summary>
internal static string AuthenticationFailed
{
get => GetString("AuthenticationFailed");
}
/// <summary>
/// Failed to authenticate HTTPS connection.
/// </summary>
internal static string FormatAuthenticationFailed()
=> GetString("AuthenticationFailed");
/// <summary>
/// Authentication of the HTTPS connection timed out.
/// </summary>
internal static string AuthenticationTimedOut
{
get => GetString("AuthenticationTimedOut");
}
/// <summary>
/// Authentication of the HTTPS connection timed out.
/// </summary>
internal static string FormatAuthenticationTimedOut()
=> GetString("AuthenticationTimedOut");
/// <summary>
/// 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).
/// </summary>
internal static string InvalidServerCertificateEku
{
get => GetString("InvalidServerCertificateEku");
}
/// <summary>
/// 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).
/// </summary>
internal static string FormatInvalidServerCertificateEku(object thumbprint)
=> string.Format(CultureInfo.CurrentCulture, GetString("InvalidServerCertificateEku", "thumbprint"), thumbprint);
/// <summary>
/// Value must be a positive TimeSpan.
/// </summary>
internal static string PositiveTimeSpanRequired1
{
get => GetString("PositiveTimeSpanRequired1");
}
/// <summary>
/// Value must be a positive TimeSpan.
/// </summary>
internal static string FormatPositiveTimeSpanRequired1()
=> GetString("PositiveTimeSpanRequired1");
/// <summary>
/// The server certificate parameter is required.
/// </summary>
internal static string ServiceCertificateRequired
{
get => GetString("ServiceCertificateRequired");
}
/// <summary>
/// The server certificate parameter is required.
/// </summary>
internal static string FormatServiceCertificateRequired()
=> GetString("ServiceCertificateRequired");
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);

View File

@ -1,135 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AuthenticationFailed" xml:space="preserve">
<value>Failed to authenticate HTTPS connection.</value>
</data>
<data name="AuthenticationTimedOut" xml:space="preserve">
<value>Authentication of the HTTPS connection timed out.</value>
</data>
<data name="InvalidServerCertificateEku" xml:space="preserve">
<value>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>
</data>
<data name="PositiveTimeSpanRequired" xml:space="preserve">
<value>Value must be a positive TimeSpan.</value>
</data>
<data name="ServiceCertificateRequired" xml:space="preserve">
<value>The server certificate parameter is required.</value>
</data>
</root>

View File

@ -18,10 +18,4 @@
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="$(MicrosoftAspNetCoreHttpAbstractionsPackageVersion)" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="HttpsStrings.resx">
<Generator></Generator>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -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))]

View File

@ -1,100 +0,0 @@
// <auto-generated />
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);
/// <summary>
/// Failed to authenticate HTTPS connection.
/// </summary>
internal static string AuthenticationFailed
{
get => GetString("AuthenticationFailed");
}
/// <summary>
/// Failed to authenticate HTTPS connection.
/// </summary>
internal static string FormatAuthenticationFailed()
=> GetString("AuthenticationFailed");
/// <summary>
/// Authentication of the HTTPS connection timed out.
/// </summary>
internal static string AuthenticationTimedOut
{
get => GetString("AuthenticationTimedOut");
}
/// <summary>
/// Authentication of the HTTPS connection timed out.
/// </summary>
internal static string FormatAuthenticationTimedOut()
=> GetString("AuthenticationTimedOut");
/// <summary>
/// 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).
/// </summary>
internal static string InvalidServerCertificateEku
{
get => GetString("InvalidServerCertificateEku");
}
/// <summary>
/// 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).
/// </summary>
internal static string FormatInvalidServerCertificateEku(object thumbprint)
=> string.Format(CultureInfo.CurrentCulture, GetString("InvalidServerCertificateEku", "thumbprint"), thumbprint);
/// <summary>
/// Value must be a positive TimeSpan.
/// </summary>
internal static string PositiveTimeSpanRequired
{
get => GetString("PositiveTimeSpanRequired");
}
/// <summary>
/// Value must be a positive TimeSpan.
/// </summary>
internal static string FormatPositiveTimeSpanRequired()
=> GetString("PositiveTimeSpanRequired");
/// <summary>
/// The server certificate parameter is required.
/// </summary>
internal static string ServiceCertificateRequired
{
get => GetString("ServiceCertificateRequired");
}
/// <summary>
/// The server certificate parameter is required.
/// </summary>
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;
}
}
}

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel
= new ResourceManager("Microsoft.AspNetCore.Server.Kestrel.KestrelStrings", typeof(KestrelStrings).GetTypeInfo().Assembly);
/// <summary>
/// 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
/// </summary>
internal static string HttpsUrlProvidedButNoDevelopmentCertificateFound
{
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel
}
/// <summary>
/// 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
/// </summary>
internal static string FormatHttpsUrlProvidedButNoDevelopmentCertificateFound()
=> GetString("HttpsUrlProvidedButNoDevelopmentCertificateFound");

View File

@ -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 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
var exception = Assert.Throws<ArgumentOutOfRangeException>(() => new HttpsConnectionAdapterOptions { HandshakeTimeout = value });
Assert.Equal("value", exception.ParamName);
Assert.StartsWith(HttpsStrings.PositiveTimeSpanRequired, exception.Message);
Assert.StartsWith(CoreStrings.PositiveTimeSpanRequired, exception.Message);
}
public static TheoryData<TimeSpan> TimeoutValidData => new TheoryData<TimeSpan>

View File

@ -427,7 +427,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
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)