Skip to content

Commit 607fb4a

Browse files
Revert "Update Linux dev cert trust instructions" (#33263)
1 parent 351373b commit 607fb4a

File tree

4 files changed

+243
-23
lines changed

4 files changed

+243
-23
lines changed

aspnetcore/includes/trustCertVSC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
dotnet dev-certs https --trust
55
```
66

7-
The preceding command requires .NET 9.0 or higher on Linux. For Linux on .NET 8 and earlier, see your Linux distribution's documentation for trusting a certificate.
7+
The preceding command doesn't work on Linux. See your Linux distribution's documentation for trusting a certificate.
88

99
The preceding command displays the following dialog, provided the certificate was not previously trusted:
1010

aspnetcore/security/docker-compose-https.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p $CREDENTIAL_PL
9999
dotnet dev-certs https --trust
100100
```
101101

102-
On Linux, `dotnet dev-certs https --trust` requires .NET 9 and later. For Linux on .NET 8 and earlier, see your Linux distribution's documentation for trusting a certificate.
102+
`dotnet dev-certs https --trust` is only supported on macOS and Windows. You need to trust certificates on Linux in the way that is supported by your distribution. It is likely that you need to trust the certificate in your browser.
103103

104104
In the preceding commands, replace `$CREDENTIAL_PLACEHOLDER$` with a password.
105105

aspnetcore/security/docker-https.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p <CREDENTIAL_PL
8080
dotnet dev-certs https --trust
8181
```
8282

83-
On Linux, `dotnet dev-certs https --trust` requires .NET 9 and later. For Linux on .NET 8 and earlier, see your Linux distribution's documentation for trusting a certificate.
83+
`dotnet dev-certs https --trust` is only supported on macOS and Windows. You need to trust certs on Linux in the way that is supported by your distribution. It is likely that you need to trust the certificate in your browser.
84+
8485
In the preceding commands, replace `<CREDENTIAL_PLACEHOLDER>` with a password.
8586

8687
Run the container image with ASP.NET Core configured for HTTPS:

aspnetcore/security/enforcing-ssl.md

Lines changed: 239 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ dotnet new webapp --no-https
199199

200200
<a name="trust"></a>
201201

202-
## Trust the ASP.NET Core HTTPS development certificate
202+
## Trust the ASP.NET Core HTTPS development certificate on Windows and macOS
203+
204+
For the Firefox browser, see the next section.
203205

204206
The .NET Core SDK includes an HTTPS development certificate. The certificate is installed as part of the first-run experience. For example, `dotnet --info` produces a variation of the following output:
205207

@@ -227,42 +229,57 @@ dotnet dev-certs https --help
227229
> [!WARNING]
228230
> Do not create a development certificate in an environment that will be redistributed, such as a container image or virtual machine. Doing so can lead to spoofing and elevation of privilege. To help prevent this, set the `DOTNET_GENERATE_ASPNET_CERTIFICATE` environment variable to `false` prior to calling the .NET CLI for the first time. This will skip the automatic generation of the ASP.NET Core development certificate during the CLI's first-run experience.
229231
230-
## How to set up a developer certificate for Docker
232+
<a name="trust-ff"></a>
231233

232-
See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/6199).
234+
### Trust the HTTPS certificate with Firefox to prevent SEC_ERROR_INADEQUATE_KEY_USAGE error
233235

234-
## Linux-specific considerations
236+
The Firefox browser uses its own certificate store, and therefore doesn't trust the [IIS Express](/iis/extensions/introduction-to-iis-express/iis-express-overview) or [Kestrel](xref:fundamentals/servers/kestrel) developer certificates.
235237

236-
Linux distros differ substantially in how they mark certificates as trusted. While `dotnet dev-certs` is expected to be broadly applicable it is only officially supported on Ubuntu and Fedora and specifically aims to ensure trust in Firefox and Chromium-based browsers (Edge, Chrome, and Chromium).
238+
There are two approaches to trusting the HTTPS certificate with Firefox, create a policy file or configure with the FireFox browser. Configuring with the browser creates the policy file, so the two approaches are equivalent.
237239

238-
### Dependencies
240+
#### Create a policy file to trust HTTPS certificate with Firefox
239241

240-
To establish OpenSSL trust, the `openssl` tool must be on the path.
242+
Create a policy file (`policies.json`) at:
241243

242-
To establish browser trust (e.g. in Edge or Firefox), the `certutil` tool must be on the path.
244+
* Windows: `%PROGRAMFILES%\Mozilla Firefox\distribution\`
245+
* MacOS: `Firefox.app/Contents/Resources/distribution`
246+
* Linux: See [Trust the certificate with Firefox on Linux](#trust-ff-linux) in this article.
243247

244-
### OpenSSL trust
248+
Add the following JSON to the Firefox policy file:
245249

246-
When the ASP.NET Core development certificate is trusted, it is exported to a folder in the current user's home directory. To have [OpenSSL](https://www.openssl.org/) (and clients that consume it) pick up this folder, you need to set the `SSL_CERT_DIR` environment variable. You can either do this in a single session by running a command like `export SSL_CERT_DIR=$HOME/.aspnet/dev-certs/trust:/usr/lib/ssl/certs` (the exact value will be in the output when `--verbose` is passed) or by adding it your (distro- and shell-specific) configuration file (e.g. `.profile`).
250+
```json
251+
{
252+
"policies": {
253+
"Certificates": {
254+
"ImportEnterpriseRoots": true
255+
}
256+
}
257+
}
258+
```
259+
260+
The preceding policy file makes Firefox trust certificates from the trusted certificates in the Windows certificate store. The next section provides an alternative approach to create the preceding policy file by using the Firefox browser.
247261

248-
This is required to make tools like `curl` trust the development certificate. (Or, alternatively, you can pass `-CAfile` or `-CApath` to each individual `curl` invocation.)
262+
<a name="trust-ff-ba"></a>
249263

250-
Note that this requires 1.1.1h or later or 3.0.0 or later, depending on which major version you're using.
264+
### Configure trust of HTTPS certificate using Firefox browser
251265

252-
If OpenSSL trust gets into a bad state (e.g. if `dotnet dev-certs https --clean` fails to remove it), it is frequently possible to set things right using the [`c_rehash`](https://docs.openssl.org/master/man1/openssl-rehash/) tool.
266+
Set `security.enterprise_roots.enabled` = `true` using the following instructions:
253267

254-
### Overrides
268+
1. Enter `about:config` in the FireFox browser.
269+
1. Select **Accept the Risk and Continue** if you accept the risk.
270+
1. Select **Show All**
271+
1. Set `security.enterprise_roots.enabled` = `true`
272+
1. Exit and restart Firefox
255273

256-
If you're using another browser with its own Network Security Services (NSS) store, you can use the `DOTNET_DEV_CERTS_NSSDB_PATHS` environment variable to specify a colon-delimited list of NSS directories (i.e. the directory containing `cert9.db`) to which to add the development certificate.
274+
For more information, see [Setting Up Certificate Authorities (CAs) in Firefox](https://support.mozilla.org/kb/setting-certificate-authorities-firefox) and the [mozilla/policy-templates/README file](https://github.com/mozilla/policy-templates/blob/master/README.md).
257275

258-
If you store the certificates you want OpenSSL to trust in a specific directory, you can use the `DOTNET_DEV_CERTS_OPENSSL_CERTIFICATE_DIRECTORY` environment variable to indicate where that is.
276+
## How to set up a developer certificate for Docker
259277

260-
> [!WARNING]
261-
> If you set either of these variables, it is important that they are set to the same values each time trust is updated. If they change, the tool won't know about certificates in the former locations (e.g. to clean them up)
278+
See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/6199).
262279

263-
### Using sudo
280+
## Trust HTTPS certificate on Linux
264281

265-
As on other platforms, development certificates are stored and trusted separately for each user. As a result, if you run `dotnet dev-certs` as a different user (e.g. by using `sudo`), it is _that_ user (e.g. `root`) that will trust the development certificate.
282+
Establishing trust is distribution and browser specific. The following sections provide instructions for some popular distributions and the Chromium browsers (Edge and Chrome) and for Firefox.
266283

267284
### Trust HTTPS certificate on Linux with linux-dev-certs
268285

@@ -277,6 +294,170 @@ dotnet linux-dev-certs install
277294

278295
For more information or to report issues, see the [linux-dev-certs GitHub repository](https://github.com/tmds/linux-dev-certs).
279296

297+
### Ubuntu trust the certificate for service-to-service communication
298+
299+
The following instructions don't work for some Ubuntu versions, such as 20.04. For more information, see GitHub issue [dotnet/AspNetCore.Docs #23686](https://github.com/dotnet/AspNetCore.Docs/issues/23686).
300+
301+
1. Install [OpenSSL](https://www.openssl.org/) 1.1.1h or later. See your distribution for instructions on how to update OpenSSL.
302+
1. Run the following commands:
303+
304+
```cli
305+
dotnet dev-certs https
306+
sudo -E dotnet dev-certs https -ep /usr/local/share/ca-certificates/aspnet/https.crt --format PEM
307+
sudo update-ca-certificates
308+
```
309+
310+
The preceding commands:
311+
312+
* Ensure the current user's developer certificate is created.
313+
* Exports the certificate with elevated permissions needed for the `ca-certificates` folder, using the current user's environment.
314+
* Removing the `-E` flag exports the root user certificate, generating it if necessary. Each newly generated certificate has a different thumbprint. When running as root, `sudo` and `-E` are not needed.
315+
316+
The path in the preceding command is specific for Ubuntu. For other distributions, select an appropriate path or use the path for the Certificate Authorities (CAs).
317+
318+
<a name="ssl-linux"></a>
319+
320+
### Trust HTTPS certificate on Linux using Edge or Chrome
321+
322+
# [Ubuntu](#tab/linux-ubuntu)
323+
324+
For chromium browsers on Linux:
325+
326+
* Install the `libnss3-tools` for your distribution.
327+
* Create or verify the `$HOME/.pki/nssdb` folder exists on the machine.
328+
* Export the certificate with the following command:
329+
330+
```cli
331+
dotnet dev-certs https
332+
sudo -E dotnet dev-certs https -ep /usr/local/share/ca-certificates/aspnet/https.crt --format PEM
333+
```
334+
335+
The path in the preceding command is specific for Ubuntu. For other distributions, select an appropriate path or use the path for the Certificate Authorities (CAs).
336+
337+
* Run the following commands:
338+
339+
```cli
340+
certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n localhost -i /usr/local/share/ca-certificates/aspnet/https.crt
341+
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n localhost -i /usr/local/share/ca-certificates/aspnet/https.crt
342+
```
343+
344+
* Exit and restart the browser.
345+
346+
<a name="trust-ff-linux"></a>
347+
348+
#### Trust the certificate with Firefox on Linux
349+
350+
* Export the certificate with the following command:
351+
352+
```vstscli
353+
dotnet dev-certs https
354+
sudo -E dotnet dev-certs https -ep /usr/local/share/ca-certificates/aspnet/https.crt --format PEM
355+
```
356+
357+
The path in the preceding command is specific for Ubuntu. For other distributions, select an appropriate path or use the path for the Certificate Authorities (CAs).
358+
359+
* Create a JSON file at `/usr/lib/firefox/distribution/policies.json` with the following command:
360+
361+
```sh
362+
cat <<EOF | sudo tee /usr/lib/firefox/distribution/policies.json
363+
{
364+
"policies": {
365+
"Certificates": {
366+
"Install": [
367+
"/usr/local/share/ca-certificates/aspnet/https.crt"
368+
]
369+
}
370+
}
371+
}
372+
EOF
373+
```
374+
Note: Ubuntu 21.10 Firefox comes as a snap package and the installation folder is `/snap/firefox/current/usr/lib/firefox`.
375+
376+
See [Configure trust of HTTPS certificate using Firefox browser](#trust-ff-ba) in this article for an alternative way to configure the policy file using the browser.
377+
378+
# [Red Hat Enterprise Linux](#tab/linux-rhel)
379+
380+
> [!WARNING]
381+
> The following instructions are intended for development purposes only. Do not use the certificates generated in these instructions for a production environment.
382+
383+
These instructions use Mozilla's *legacy* tool `certutil` at `https://firefox-source-docs.mozilla.org/security/nss/legacy/tools/nss_tools_certutil/index.html`. Instructions may be updated as modern utilities and practices are discovered.
384+
385+
> [!CAUTION]
386+
> Improper use of TLS certificates could lead to spoofing.
387+
388+
> [!TIP]
389+
> Instructions for valid production certificates can be found in the RHEL Documentation.
390+
> [RHEL8 TLS Certificates](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/securing_networks/index#creating-and-managing-tls-keys-and-certificates_securing-networks)
391+
> [RHEL9 TLS Certificates](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/securing_networks/index#creating-and-managing-tls-keys-and-certificates_securing-networks)
392+
> [RHEL9 Certificate System](https://access.redhat.com/documentation/en-us/red_hat_certificate_system/9)
393+
394+
### Install Dependencies
395+
396+
```sh
397+
dnf install nss-tools
398+
```
399+
400+
### Export The ASP.NET Core Development Certificate
401+
402+
> [!IMPORTANT]
403+
> Replace `${ProjectDirectory}` with your projects directory.
404+
> Replace `${CertificateName}` with a name you'll be able to identify in the future.
405+
406+
```sh
407+
cd ${ProjectDirectory}
408+
dotnet dev-certs https -ep ${ProjectDirectory}/${CertificateName}.crt --format PEM
409+
```
410+
411+
> [!CAUTION]
412+
> If using git, add your certificate to your `${ProjectDirectory}/.gitignore` or `${ProjectDirectory}/.git/info/exclude`.
413+
> View the [git documentation](https://git-scm.com/docs/gitignore) for information about these files.
414+
415+
> [!TIP]
416+
> You can move your exported certificate outside of your Git repository and replace the occurrences of `${ProjectDirectory}`, in the following instructions, with the new location.
417+
418+
### Import The ASP.NET Core Development Certificate
419+
420+
> [!IMPORTANT]
421+
> Replace `${UserProfile}` with the profile you intend to use.
422+
> Do not replace `$HOME`, it is the environment variable to your user directory.
423+
424+
#### Chromium-based Browsers
425+
426+
```sh
427+
certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
428+
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
429+
```
430+
431+
#### Mozilla Firefox
432+
433+
```sh
434+
certutil -d sql:$HOME/.mozilla/firefox/${UserProfile}/ -A -t "P,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
435+
certutil -d sql:$HOME/.mozilla/firefox/${UserProfile}/ -A -t "C,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
436+
```
437+
438+
#### Create An Alias To Test With Curl
439+
440+
> [!IMPORTANT]
441+
>
442+
> Don't delete the exported certificate if you plan to test with curl.
443+
> You'll need to create an alias referencing it in your `$SHELL`'s profile
444+
445+
```sh
446+
alias curl="curl --cacert ${ProjectDirectory}/${CertificateName}.crt"
447+
```
448+
449+
### Cleaning up the Development Certificates
450+
451+
```sh
452+
certutil -d sql:$HOME/.pki/nssdb -D -n ${CertificateName}
453+
certutil -d sql:$HOME/.mozilla/firefox/${UserProfile}/ -D -n ${CertificateName}
454+
rm ${ProjectDirectory}/${CertificateName}.crt
455+
dotnet dev-certs https --clean
456+
```
457+
458+
>[!NOTE]
459+
> Remove the curl alias you created earlier
460+
280461
# [SUSE Linux Enterprise Server](#tab/linux-sles)
281462

282463
See [this GitHub issue](https://github.com/dotnet/AspNetCore.Docs/issues/28292)
@@ -330,11 +511,13 @@ dotnet dev-certs https -ep ${ProjectDirectory}/${CertificateName}.crt --format P
330511
331512
```sh
332513
certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
514+
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
333515
```
334516
335517
#### Mozilla Firefox
336518
337519
```sh
520+
certutil -d sql:$HOME/.mozilla/firefox/${UserProfile}/ -A -t "P,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
338521
certutil -d sql:$HOME/.mozilla/firefox/${UserProfile}/ -A -t "C,," -n ${CertificateName} -i ${ProjectDirectory}/${CertificateName}.crt
339522
```
340523
@@ -364,6 +547,41 @@ dotnet dev-certs https --clean
364547

365548
---
366549

550+
<a name="wsl"></a>
551+
552+
### Trust the certificate with Fedora 34
553+
554+
See:
555+
556+
* [This GitHub comment](https://github.com/dotnet/aspnetcore/issues/32361#issuecomment-837111639)
557+
* [Fedora: Using Shared System Certificates](https://docs.fedoraproject.org/en-US/quick-docs/using-shared-system-certificates/)
558+
* [Set up a .NET development environment](https://fedoramagazine.org/set-up-a-net-development-environment/) on Fedora.
559+
560+
### Trust the certificate with other distros
561+
562+
See [this GitHub issue](https://github.com/dotnet/aspnetcore/issues/32842).
563+
564+
## Trust HTTPS certificate from Windows Subsystem for Linux
565+
566+
The following instructions don't work for some Linux distributions, such as Ubuntu 20.04. For more information, see GitHub issue [dotnet/AspNetCore.Docs #23686](https://github.com/dotnet/AspNetCore.Docs/issues/23686).
567+
568+
The [Windows Subsystem for Linux (WSL)](/windows/wsl/about) generates an HTTPS self-signed development certificate, which by default isn't trusted in Windows. The easiest way to have Windows trust the WSL certificate, is to configure WSL to use the same certificate as Windows:
569+
570+
* On ***Windows***, export the developer certificate to a file:
571+
572+
```
573+
dotnet dev-certs https -ep https.pfx -p $CREDENTIAL_PLACEHOLDER$ --trust
574+
```
575+
Where `$CREDENTIAL_PLACEHOLDER$` is a password.
576+
577+
* In a WSL window, import the exported certificate on the WSL instance:
578+
579+
```
580+
dotnet dev-certs https --clean --import <<path-to-pfx>> --password $CREDENTIAL_PLACEHOLDER$
581+
```
582+
583+
The preceding approach is a one time operation per certificate and per WSL distribution. It's easier than exporting the certificate over and over. If you update or regenerate the certificate on windows, you might need to run the preceding commands again.
584+
367585
<a name="tcp"></a>
368586

369587
## Troubleshoot certificate problems such as certificate not trusted
@@ -776,6 +994,7 @@ For chromium browsers on Linux:
776994

777995
```cli
778996
certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n localhost -i /usr/local/share/ca-certificates/aspnet/https.crt
997+
certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n localhost -i /usr/local/share/ca-certificates/aspnet/https.crt
779998
```
780999

7811000
* Exit and restart the browser.

0 commit comments

Comments
 (0)