Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit ad8f3da

Browse files
committed
ASP.NET Core HTTPS development certificate support
* Added support for generating the HTTPS development certificate on the CLI first run experience. * On first run, an HTTPS certificate will be set up on the current user local store. * The environment variable DOTNET_GENERATE_ASPNET_CERTIFICATE can be used to turn the feature off.
1 parent 661f004 commit ad8f3da

24 files changed

+395
-3
lines changed

build/DependencyVersions.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
<CLI_NETStandardLibraryNETFrameworkVersion>2.0.1-servicing-25908-02</CLI_NETStandardLibraryNETFrameworkVersion>
6060
<SharedHostVersion>$(MicrosoftNETCoreAppPackageVersion)</SharedHostVersion>
6161
<HostFxrVersion>$(MicrosoftNETCoreAppPackageVersion)</HostFxrVersion>
62-
62+
<!-- This is the version for ASP.NET packages that the CLI depends on to build, like the
63+
component for generating HTTPS certificates on first run. -->
64+
<CLI_ASPNET_Version>2.1.0-preview1-27617</CLI_ASPNET_Version>
6365
<AspNetCoreTemplatePackageVersion>2.0.3</AspNetCoreTemplatePackageVersion>
6466
<AspNetCoreRuntimePackageBrandName>aspnetcore-store</AspNetCoreRuntimePackageBrandName>
6567
<AspNetCoreRuntimePackageFolderName>dev-26623</AspNetCoreRuntimePackageFolderName>

build/NugetConfigFile.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<add key="BlobFeed" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
2222
<add key="templating" value="https://dotnet.myget.org/F/templating/api/v3/index.json" />
2323
<add key="aspnet" value="https://dotnet.myget.org/F/aspnetcore-release/api/v3/index.json" />
24+
<!-- Remove all other 2.0.0 aspnet entries when we start taking new ASP.NET packages -->
25+
<add key="aspnet-next" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
2426
<add key="websdkfeed" value="https://dotnet.myget.org/F/dotnet-web/api/v3/index.json" />
2527
<add key="cli-deps" value="https://dotnet.myget.org/F/cli-deps/api/v3/index.json" />
2628
<add key="roslyn" value="https://dotnet.myget.org/f/roslyn/api/v3/index.json" />
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Text;
8+
using Microsoft.DotNet.Cli.Utils;
9+
using Microsoft.Extensions.EnvironmentAbstractions;
10+
11+
namespace Microsoft.DotNet.Configurer
12+
{
13+
public class AspNetCertificateSentinel : IAspNetCertificateSentinel
14+
{
15+
public static readonly string SENTINEL = $"{Product.Version}.aspNetCertificateSentinel";
16+
17+
private readonly IFile _file;
18+
private readonly IDirectory _directory;
19+
20+
private string _dotnetUserProfileFolderPath;
21+
22+
private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL);
23+
24+
public AspNetCertificateSentinel(CliFolderPathCalculator cliFallbackFolderPathCalculator) :
25+
this(
26+
CliFolderPathCalculator.DotnetUserProfileFolderPath,
27+
FileSystemWrapper.Default.File,
28+
FileSystemWrapper.Default.Directory)
29+
{
30+
}
31+
32+
internal AspNetCertificateSentinel(string dotnetUserProfileFolderPath, IFile file, IDirectory directory)
33+
{
34+
_file = file;
35+
_directory = directory;
36+
_dotnetUserProfileFolderPath = dotnetUserProfileFolderPath;
37+
}
38+
39+
public bool Exists()
40+
{
41+
return _file.Exists(SentinelPath);
42+
}
43+
44+
public void CreateIfNotExists()
45+
{
46+
if (!Exists())
47+
{
48+
if (!_directory.Exists(_dotnetUserProfileFolderPath))
49+
{
50+
_directory.CreateDirectory(_dotnetUserProfileFolderPath);
51+
}
52+
53+
_file.CreateEmptyFile(SentinelPath);
54+
}
55+
}
56+
57+
public void Dispose()
58+
{
59+
}
60+
}
61+
}

src/Microsoft.DotNet.Configurer/DotnetFirstTimeUseConfigurer.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ public class DotnetFirstTimeUseConfigurer
1616
private INuGetCachePrimer _nugetCachePrimer;
1717
private INuGetCacheSentinel _nugetCacheSentinel;
1818
private IFirstTimeUseNoticeSentinel _firstTimeUseNoticeSentinel;
19+
private IAspNetCertificateSentinel _aspNetCertificateSentinel;
20+
private IAspNetCoreCertificateGenerator _aspNetCoreCertificateGenerator;
1921
private string _cliFallbackFolderPath;
2022
private readonly IEnvironmentPath _pathAdder;
2123

2224
public DotnetFirstTimeUseConfigurer(
2325
INuGetCachePrimer nugetCachePrimer,
2426
INuGetCacheSentinel nugetCacheSentinel,
2527
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
28+
IAspNetCertificateSentinel aspNetCertificateSentinel,
29+
IAspNetCoreCertificateGenerator aspNetCoreCertificateGenerator,
2630
IEnvironmentProvider environmentProvider,
2731
IReporter reporter,
2832
string cliFallbackFolderPath,
@@ -31,6 +35,8 @@ public DotnetFirstTimeUseConfigurer(
3135
_nugetCachePrimer = nugetCachePrimer;
3236
_nugetCacheSentinel = nugetCacheSentinel;
3337
_firstTimeUseNoticeSentinel = firstTimeUseNoticeSentinel;
38+
_aspNetCertificateSentinel = aspNetCertificateSentinel;
39+
_aspNetCoreCertificateGenerator = aspNetCoreCertificateGenerator;
3440
_environmentProvider = environmentProvider;
3541
_reporter = reporter;
3642
_cliFallbackFolderPath = cliFallbackFolderPath;
@@ -59,6 +65,31 @@ public void Configure()
5965
_nugetCachePrimer.PrimeCache();
6066
}
6167
}
68+
69+
if(ShouldGenerateAspNetCertificate())
70+
{
71+
GenerateAspNetCertificate();
72+
}
73+
}
74+
75+
private void GenerateAspNetCertificate()
76+
{
77+
_aspNetCoreCertificateGenerator.GenerateAspNetCoreDevelopmentCertificate();
78+
79+
_reporter.WriteLine();
80+
_reporter.WriteLine(LocalizableStrings.AspNetCertificateInstalled);
81+
82+
_aspNetCertificateSentinel.CreateIfNotExists();
83+
}
84+
85+
private bool ShouldGenerateAspNetCertificate()
86+
{
87+
var generateAspNetCertificate =
88+
_environmentProvider.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true);
89+
90+
return ShouldRunFirstRunExperience() &&
91+
generateAspNetCertificate &&
92+
!_aspNetCertificateSentinel.Exists();
6293
}
6394

6495
private void AddPackageExecutablePath()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.DotNet.Configurer
5+
{
6+
public interface IAspNetCertificateSentinel
7+
{
8+
bool Exists();
9+
10+
void CreateIfNotExists();
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.DotNet.Configurer
5+
{
6+
public interface IAspNetCoreCertificateGenerator
7+
{
8+
void GenerateAspNetCoreDevelopmentCertificate();
9+
}
10+
}

src/Microsoft.DotNet.Configurer/LocalizableStrings.resx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ A command is running to populate your local package cache to improve restore spe
137137
<data name="FailedToPrimeCacheError" xml:space="preserve">
138138
<value>Failed to prime the NuGet cache. {0} failed with: {1}</value>
139139
</data>
140-
<data name="UnauthorizedAccessMessage" xml:space="preserve">
140+
<data name="UnauthorizedAccessMessage" xml:space="preserve">
141141
<value>Permission denied to modify the '{0}' folder.
142142

143143
Here are some options to fix this error:
@@ -147,4 +147,9 @@ Here are some options to fix this error:
147147
3. Copy the .NET Core SDK to a non-protected location and use it from there.
148148
</value>
149149
</data>
150-
</root>
150+
<data name="AspNetCertificateInstalled" xml:space="preserve">
151+
<value>ASP.NET Core
152+
------------
153+
Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805</value>
154+
</data>
155+
</root>

src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.cs.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ Tuto chybu můžete opravit pomocí některé z těchto možností:
5757
</target>
5858
<note />
5959
</trans-unit>
60+
<trans-unit id="AspNetCertificateInstalled">
61+
<source>ASP.NET Core
62+
------------
63+
Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805</source>
64+
<target state="new">ASP.NET Core
65+
------------
66+
Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805</target>
67+
<note />
68+
</trans-unit>
6069
</body>
6170
</file>
6271
</xliff>

src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.de.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ Im Folgenden finden Sie einige Optionen, um diesen Fehler zu beheben:
5757
</target>
5858
<note />
5959
</trans-unit>
60+
<trans-unit id="AspNetCertificateInstalled">
61+
<source>ASP.NET Core
62+
------------
63+
Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805</source>
64+
<target state="new">ASP.NET Core
65+
------------
66+
Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805</target>
67+
<note />
68+
</trans-unit>
6069
</body>
6170
</file>
6271
</xliff>

src/Microsoft.DotNet.Configurer/xlf/LocalizableStrings.es.xlf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ Estas son algunas opciones para corregir este error:
5757
</target>
5858
<note />
5959
</trans-unit>
60+
<trans-unit id="AspNetCertificateInstalled">
61+
<source>ASP.NET Core
62+
------------
63+
Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805</source>
64+
<target state="new">ASP.NET Core
65+
------------
66+
Installed ASP.NET Core HTTPS development certificate. For more information go to https://go.microsoft.com/fwlink/?linkid=84805</target>
67+
<note />
68+
</trans-unit>
6069
</body>
6170
</file>
6271
</xliff>

0 commit comments

Comments
 (0)