Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Show fwlink on HTTPS certificate errors (#83) #94

Merged
merged 11 commits into from
May 3, 2017

Conversation

cesarblum
Copy link
Contributor

#83

internal class CertificateConfigurationException : Exception
{
public CertificateConfigurationException(string message)
: base(message + ". For information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.")
Copy link

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...."?

Copy link
Contributor

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?

Copy link
Contributor

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...

Copy link
Contributor

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.

Copy link

@muratg muratg left a 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.)

:shipit: 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.")
Copy link
Contributor

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.")
Copy link
Contributor

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");
Copy link
Contributor

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}");
Copy link
Contributor

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}");
Copy link
Contributor

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}");
Copy link
Contributor

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}'");
Copy link
Contributor

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.")
Copy link
Contributor

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.

Copy link
Contributor

@Eilon Eilon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@danroth27
Copy link
Member

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.

Copy link
Member

@danroth27 danroth27 left a 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.");
Copy link
Contributor Author

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?

Copy link
Member

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
Copy link
Contributor Author

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?

Copy link
Member

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'.");
Copy link
Contributor Author

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);
Copy link
Contributor Author

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?

@cesarblum cesarblum changed the title Show fwlink on certificate errors (#83) Show fwlink on HTTPS certificate errors (#83) May 3, 2017
Cesar Blum Silveira added 2 commits May 3, 2017 15:24
@cesarblum cesarblum merged commit 012d999 into rel/2.0.0-preview1 May 3, 2017
@cesarblum cesarblum deleted the cesarbs/83 branch May 3, 2017 22:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants