MacOSCertificateManager not aborting on failure to write cert to profile folder
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
Here is the `--clean --verbose` output:
```
Cleaning HTTPS development certificates from the machine. This operation might require elevated privileges. If that is the case, a prompt for credentials will be displayed.
[1] Listing certificates from CurrentUser\My
[2] Found certificates: 1 certificate
1) 0189345FA755EED9D2CC930E9C7DCD30B4304429 - CN=localhost - Valid from 2024-08-08 08:06:34Z to 2025-08-08 08:06:34Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[6] Finished listing certificates.
[8] Filtered certificates: 1 certificate
1) 0189345FA755EED9D2CC930E9C7DCD30B4304429 - CN=localhost - Valid from 2024-08-08 08:06:34Z to 2025-08-08 08:06:34Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[9] Excluded certificates: no certificates
[39] Removing the certificate from the keychain /Users/oliviermatrot/Library/Keychains/login.keychain-db 0189345FA755EED9D2CC930E9C7DCD30B4304429 - CN=localhost - Valid from 2024-08-08 08:06:34Z to 2025-08-08 08:06:34Z - IsHttpsDevelopmentCertificate: true - IsExportable: true.
Password:
[40] Finished removing the certificate from the keychain.
[42] Removing the certificate from the user store 0189345FA755EED9D2CC930E9C7DCD30B4304429 - CN=localhost - Valid from 2024-08-08 08:06:34Z to 2025-08-08 08:06:34Z - IsHttpsDevelopmentCertificate: true - IsExportable: true.
[43] Finished removing the certificate from the user store.
HTTPS development certificates successfully removed from the machine.
```
And the output of the `--trust --verbose` one:
```
[1] Listing certificates from CurrentUser\My
[2] Found certificates: 1 certificate
1) BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[3] Checking certificates validity
[4] Valid certificates: 1 certificate
1) BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[5] Invalid certificates: no certificates
[6] Finished listing certificates.
One or more certificates might be in an invalid state. We will try to access the certificate key for each certificate and as a result you might be prompted one or more times to enter your password to access the user keychain. When that happens, select 'Always Allow' to grant 'dotnet' access to the certificate key in the future.
Trusting the HTTPS development certificate was requested. If the certificate is not already trusted we will run the following command:
'security add-trusted-cert -p basic -p ssl -k <> <>'
This command might prompt you for your password to install the certificate on the keychain. To undo these changes: 'security remove-trusted-cert <>'
[1] Listing certificates from CurrentUser\My
[2] Found certificates: 1 certificate
1) BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[3] Checking certificates validity
[4] Valid certificates: 1 certificate
1) BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[5] Invalid certificates: no certificates
[6] Finished listing certificates.
[1] Listing certificates from LocalMachine\My
[2] Found certificates: no certificates
[3] Checking certificates validity
[4] Valid certificates: no certificates
[5] Invalid certificates: no certificates
[6] Finished listing certificates.
[8] Filtered certificates: 1 certificate
1) BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[9] Excluded certificates: no certificates
[51] Correcting the the certificate state for 'BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true'.
[23] Saving certificate 'BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true' to /Users/oliviermatrot/.aspnet/dev-certs/https/aspnetcore-localhost-BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F.pfx with private key.
[24] Exporting certificate with private key but no password.
[25] Creating directory /Users/oliviermatrot/.aspnet/dev-certs/https.
[27] Writing the certificate to: /Users/oliviermatrot/.aspnet/dev-certs/https/aspnetcore-localhost-BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F.pfx.
[28] An error has occurred while writing the certificate to disk: System.UnauthorizedAccessException: Access to the path '/Users/oliviermatrot/.aspnet/dev-certs/https/aspnetcore-localhost-BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F.pfx' is denied.
---> System.IO.IOException: Permission denied
--- End of inner exception stack trace ---
at System.IO.FileSystem.MoveFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at System.IO.File.Move(String sourceFileName, String destFileName, Boolean overwrite)
at Microsoft.AspNetCore.Certificates.Generation.CertificateManager.ExportCertificate(X509Certificate2 certificate, String path, Boolean includePrivateKey, String password, CertificateKeyExportFormat format).
[68] An error has occurred while saving certificate 'BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F' in the user profile folder: Access to the path '/Users/oliviermatrot/.aspnet/dev-certs/https/aspnetcore-localhost-BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F.pfx' is denied..
[52] Finished correcting the certificate state.
[14] Valid certificates: 1 certificate
1) BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[15] Selected certificate: BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
[29] Trusting the certificate to: BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true.
[23] Saving certificate 'BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true' to /var/folders/cy/_jv029g957v39t4mw86fngjw0000gn/T/tmpNmu0yD.tmp without private key.
[25] Creating directory /var/folders/cy/_jv029g957v39t4mw86fngjw0000gn/T.
[27] Writing the certificate to: /var/folders/cy/_jv029g957v39t4mw86fngjw0000gn/T/tmpNmu0yD.tmp.
[23] Saving certificate 'BAA9E6F0A2EB5494AF22F9A2365FAC9A9B07ED9F - CN=localhost - Valid from 2024-08-19 10:57:18Z to 2025-08-19 10:57:18Z - IsHttpsDevelopmentCertificate: true - IsExportable: true' to /var/folders/cy/_jv029g957v39t4mw86fngjw0000gn/T/tmpLRTA00.tmp without private key.
[25] Creating directory /var/folders/cy/_jv029g957v39t4mw86fngjw0000gn/T.
[27] Writing the certificate to: /var/folders/cy/_jv029g957v39t4mw86fngjw0000gn/T/tmpLRTA00.tmp.
[32] Running the trust command security add-trusted-cert -p basic -p ssl -k "/Users/oliviermatrot/Library/Keychains/login.keychain-db" /var/folders/cy/_jv029g957v39t4mw86fngjw0000gn/T/tmpLRTA00.tmp.
[33] Finished running the trust command.
[30] Finished trusting the certificate.
Successfully trusted the existing HTTPS certificate.
```
As you said, there is a permission problem to copy the certificate to the folder `~/.aspnet/dev-certs/https`.
So I started over giving myself read&write permission to the folder, and it worked.
May I suggest that you abort the process if there is a permission problem with the folder ?
Thanks.
_Originally posted by @omatrot in https://github.com/dotnet/aspnetcore/issues/56853#issuecomment-2296059908_
Contributor guide
Assessment
This issue has not been assessed yet.