Skip to content

Commit 8cf4ae9

Browse files
committed
Add CLI 'remove' command to remove Dev Proxy certificate
1 parent 4587a22 commit 8cf4ae9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace DevProxy.CommandHandlers;
6+
7+
public static class CertRemoveCommandHandler
8+
{
9+
public static void RemoveCert(ILogger logger)
10+
{
11+
logger.LogTrace("RemoveCert() called");
12+
13+
try
14+
{
15+
logger.LogInformation("Uninstalling the root certificate...");
16+
ProxyEngine.ProxyServer.CertificateManager.RemoveTrustedRootCertificate(machineTrusted: false);
17+
logger.LogInformation("DONE");
18+
}
19+
catch (Exception ex)
20+
{
21+
logger.LogError(ex, "Error removing certificate");
22+
}
23+
24+
logger.LogTrace("RemoveCert() finished");
25+
}
26+
}

dev-proxy/ProxyHost.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ private static Command CreateCertCommand(ILogger logger)
382382

383383
var sortedCommands = new[]
384384
{
385-
CreateCertEnsureCommand(logger)
385+
CreateCertEnsureCommand(logger),
386+
CreateCertRemoveCommand(logger),
386387
}.OrderByName();
387388

388389
certCommand.AddCommands(sortedCommands);
@@ -396,6 +397,13 @@ private static Command CreateCertEnsureCommand(ILogger logger)
396397
return certEnsureCommand;
397398
}
398399

400+
private static Command CreateCertRemoveCommand(ILogger logger)
401+
{
402+
var certRemoveCommand = new Command("remove", "Remove the certificate from Root Store");
403+
certRemoveCommand.SetHandler(() => CertRemoveCommandHandler.RemoveCert(logger));
404+
return certRemoveCommand;
405+
}
406+
399407
private static Command CreateJwtCommand()
400408
{
401409
var jwtCommand = new Command("jwt", "Manage JSON Web Tokens");

0 commit comments

Comments
 (0)