Skip to content

Commit b77ca75

Browse files
committed
Improve dev-certs export error message
During a recent security review of the dev-certs tool, we observed that on export it would create a directory that was potentially world-readable (e.g. based on permissions inherited from the parent directory). We decided it would be more appropriate to let users make the decision of who should have access to the directory. Unfortunately, this removal of functionality broke some app authors' workflows. When dev-certs is run directly, the `--verbose` output makes it clear what went wrong and what needs to happen, but the non-verbose output that appears when another tool does the export is less helpful. This change introduces a new top-level error state for an export failure caused by a non-existent target directory to make it clearer how to fix broken workflows. The behavior changed in dotnet#57108, which included a backport of dotnet#56985, and shipped in 8.0.10. For dotnet#58330
1 parent d624755 commit b77ca75

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

src/Shared/CertificateGeneration/CertificateManager.cs

+1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ public EnsureCertificateResult EnsureAspNetCoreHttpsDevelopmentCertificate(
328328
var exportDir = Path.GetDirectoryName(path);
329329
if (!string.IsNullOrEmpty(exportDir) && !Directory.Exists(exportDir))
330330
{
331+
result = EnsureCertificateResult.ErrorExportingTheCertificateToNonExistentDirectory;
331332
throw new InvalidOperationException($"The directory '{exportDir}' does not exist. Choose permissions carefully when creating it.");
332333
}
333334

src/Shared/CertificateGeneration/EnsureCertificateResult.cs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ internal enum EnsureCertificateResult
1010
ErrorCreatingTheCertificate,
1111
ErrorSavingTheCertificateIntoTheCurrentUserPersonalStore,
1212
ErrorExportingTheCertificate,
13+
ErrorExportingTheCertificateToNonExistentDirectory,
1314
FailedToTrustTheCertificate,
1415
PartiallyFailedToTrustTheCertificate,
1516
UserCancelledTrustStep,

src/Tools/FirstRunCertGenerator/test/CertificateManagerTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public void EnsureCreateHttpsCertificate_CannotExportToNonExistentDirectory()
373373
.EnsureAspNetCoreHttpsDevelopmentCertificate(now, now.AddYears(1), Path.Combine("NoSuchDirectory", CertificateName));
374374

375375
// Assert
376-
Assert.Equal(EnsureCertificateResult.ErrorExportingTheCertificate, result);
376+
Assert.Equal(EnsureCertificateResult.ErrorExportingTheCertificateToNonExistentDirectory, result);
377377
}
378378

379379
[Fact]

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

+4
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,10 @@ private static int EnsureHttpsCertificate(CommandOption exportPath, CommandOptio
425425
case EnsureCertificateResult.ErrorExportingTheCertificate:
426426
reporter.Warn("There was an error exporting the HTTPS developer certificate to a file.");
427427
return ErrorExportingTheCertificate;
428+
case EnsureCertificateResult.ErrorExportingTheCertificateToNonExistentDirectory:
429+
// A distinct warning is useful, but a distinct error code is probably not.
430+
reporter.Warn("There was an error exporting the HTTPS developer certificate to a file. Please create the target directory before exporting.");
431+
return ErrorExportingTheCertificate;
428432
case EnsureCertificateResult.PartiallyFailedToTrustTheCertificate:
429433
// A distinct warning is useful, but a distinct error code is probably not.
430434
reporter.Warn("There was an error trusting the HTTPS developer certificate. It will be trusted by some clients but not by others.");

0 commit comments

Comments
 (0)