-
Notifications
You must be signed in to change notification settings - Fork 109
Show fwlink on HTTPS certificate errors (#83) #94
Conversation
internal class CertificateConfigurationException : Exception | ||
{ | ||
public CertificateConfigurationException(string message) | ||
: base(message + ". For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not $"{message}. For infor...."
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it adding a period to the previous message at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O I C. All the previous exception messages should be complete sentences (wherever possible) and end with periods... Though some of them I can see why they don't...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I suggested fixes for all the exception messages below. Then remove the leading period on this one here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good (apart from string formatting nit below.)
after @danroth27 confirms the fwlink to be correct.
internal class CertificateConfigurationException : Exception | ||
{ | ||
public CertificateConfigurationException(string message) | ||
: base(message + ". For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it adding a period to the previous message at all?
internal class CertificateConfigurationException : Exception | ||
{ | ||
public CertificateConfigurationException(string message) | ||
: base(message + ". For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O I C. All the previous exception messages should be complete sentences (wherever possible) and end with periods... Though some of them I can see why they don't...
@@ -99,7 +99,7 @@ private X509Certificate2 LoadSingle(string certificateName) | |||
|
|||
if (!certificateConfiguration.Exists()) | |||
{ | |||
throw new InvalidOperationException($"No certificate named {certificateName} found in configuration"); | |||
throw new CertificateConfigurationException($"No certificate named {certificateName} found in configuration for the current environment"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence needs to end with a period.
@@ -119,7 +119,7 @@ private X509Certificate2 LoadSingle(IConfigurationSection certificateConfigurati | |||
certificateSource = new CertificateStoreSource(_certificateStoreLoader); | |||
break; | |||
default: | |||
throw new InvalidOperationException($"Invalid certificate source kind: {sourceKind}"); | |||
throw new CertificateConfigurationException($"Invalid certificate source kind: {sourceKind}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to be a sentence: Invalid certificate source kind '{sourceKind}'.
@@ -163,7 +163,7 @@ public override X509Certificate2 Load() | |||
|
|||
if (error != null) | |||
{ | |||
throw error; | |||
throw new CertificateConfigurationException($"Unable to load certificate from file '{Path}': {error.Message}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unable to load certificate from file '{Path}'. Error details: '{error.Message}'.
@@ -203,7 +203,7 @@ public override X509Certificate2 Load() | |||
{ | |||
if (!Enum.TryParse(StoreLocation, ignoreCase: true, result: out StoreLocation storeLocation)) | |||
{ | |||
throw new InvalidOperationException($"Invalid store location: {StoreLocation}"); | |||
throw new CertificateConfigurationException($"Invalid certificate store location: {StoreLocation}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The certificate store location '{StoreLocation}' is invalid.
@@ -63,7 +63,7 @@ private void BindConfiguration(KestrelServerOptions options) | |||
|
|||
if (certificate == null) | |||
{ | |||
throw new InvalidOperationException($"Unable to load certificate for endpoint '{endPoint.Key}'"); | |||
throw new CertificateConfigurationException($"Unable to load certificate for endpoint '{endPoint.Key}'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End with period.
internal class CertificateConfigurationException : Exception | ||
{ | ||
public CertificateConfigurationException(string message) | ||
: base(message + ". For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I suggested fixes for all the exception messages below. Then remove the leading period on this one here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
The CertificateLoader will be used for other scenarios than loading the HTTPS certificate. We're using it to load signing certificates as well. So I don't think the information about how to enable HTTPS is being added in the right context. I.e. you don't need instructions about setting up HTTPS if the configuration for your signing certificate is invalid. I think the HTTPS information needs to be added when setting up HTTPS with Kestrel. Also, we should log a warning if the CertificateLoader try to find a certificate with a particular subject name in a store but doesn't find any. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only add the message with information on setting up HTTPS in the context of setting up HTTPS. We need to be able to use the CertificateLoader for things other than the HTTPS certificate.
@@ -99,7 +125,7 @@ private X509Certificate2 LoadSingle(string certificateName) | |||
|
|||
if (!certificateConfiguration.Exists()) | |||
{ | |||
throw new InvalidOperationException($"No certificate named {certificateName} found in configuration"); | |||
throw new KeyNotFoundException($"No certificate named '{certificateName}' found in configuration for the current environment."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tratcher Is it ok to throw this exception type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
namespace Microsoft.AspNetCore | ||
{ | ||
internal class CertificateConfigurationException : Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tratcher Is it ok to keep this internal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
Assert.Equal(0, loadedCertificates.Count()); | ||
Assert.Single(logger.LogMessages, logMessage => | ||
logMessage.LogLevel == LogLevel.Warning && | ||
logMessage.Message == "Unable to find a matching certificate for subject 'localhost' in store 'My' in 'CurrentUser'."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Eilon Is the language alright? Should log messages also end with a period?
@@ -27,7 +31,7 @@ public void Configure(KestrelServerOptions options) | |||
|
|||
private void BindConfiguration(KestrelServerOptions options) | |||
{ | |||
var certificateLoader = new CertificateLoader(_configurationRoot.GetSection("Certificates")); | |||
var certificateLoader = new CertificateLoader(_configurationRoot.GetSection("Certificates"), _loggerFactory); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danroth27 I think we should put CertificateLoader
in DI.
@davidfowl What do you think?
#83