Skip to content

Commit 315e003

Browse files
committed
Address feedback
1 parent 63f43f9 commit 315e003

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

src/Servers/Kestrel/Core/src/Internal/HttpsConnectionAdapter.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,18 @@ await sslStream.AuthenticateAsServerAsync(serverCert, certificateRequired,
195195
sslStream.Dispose();
196196
return _closedAdaptedConnection;
197197
}
198-
finally
198+
catch (NotSupportedException ex)
199199
{
200-
if (!sslStream.IsAuthenticated && (_serverCertificate != null ||
201-
CertificateManager.IsHttpsDevelopmentCertificate(_serverCertificate) ||
202-
!CertificateManager.CheckDeveloperCertificateKey(_serverCertificate)))
200+
if (_serverCertificate != null &&
201+
CertificateManager.IsHttpsDevelopmentCertificate(_serverCertificate) &&
202+
!CertificateManager.CheckDeveloperCertificateKey(_serverCertificate))
203203
{
204-
_logger?.LogError(3, CoreStrings.BadDeveloperCertificateState);
204+
_logger?.LogError(3, ex, CoreStrings.BadDeveloperCertificateState);
205205
}
206-
206+
throw;
207+
}
208+
finally
209+
{
207210
timeoutFeature.CancelTimeout();
208211
}
209212

src/Servers/Kestrel/shared/test/TestResources.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,10 @@ public static X509Certificate2 GetTestCertificate(string certName)
2222
{
2323
return new X509Certificate2(GetCertPath(certName), "testPassword");
2424
}
25+
26+
public static X509Certificate2 GetTestCertificate(string certName, string password)
27+
{
28+
return new X509Certificate2(GetCertPath(certName), password);
29+
}
2530
}
2631
}

src/Servers/Kestrel/test/FunctionalTests/HttpsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public async Task DevCertWithInvalidPrivateKeyProducesCustomWarning()
256256
.AddSingleton(LoggerFactory)
257257
.BuildServiceProvider();
258258

259-
var serverCertificate = new X509Certificate2(TestResources.GetTestCertificate().Export(X509ContentType.Cert));
259+
var serverCertificate = new X509Certificate2(TestResources.GetTestCertificate("aspnetdevcert.pfx", "aspnetdevcert").Export(X509ContentType.Cert));
260260
listenOptions.UseHttps(serverCertificate);
261261
using (var server = new TestServer(context => Task.CompletedTask,
262262
new TestServiceContext(LoggerFactory),

src/Tools/dotnet-dev-certs/src/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private static int EnsureHttpsCertificate(CommandOption exportPath, CommandOptio
196196

197197
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && manager.HasValidCertificateWithInnaccessibleKeyAcrossPartitions() || manager.GetHttpsCertificates().Count == 0)
198198
{
199-
reporter.Warn($"We didn't find a valid HTTPS certificate with a key accessible across security partitions. We will run the following command:" + Environment.NewLine +
199+
reporter.Warn($"A valid HTTPS certificate with a key accessible across security partitions was not found. The following command will run to fix it:" + Environment.NewLine +
200200
"'sudo security set-key-partition-list -D localhost -S unsigned:,teamid:UBF8T346G9'" + Environment.NewLine +
201201
"This command will make the certificate key accessible across security partitions and might prompt you for your password. For more information see: https://aka.ms/aspnetcore/2.1/troubleshootcertissues");
202202
}

0 commit comments

Comments
 (0)