-
Notifications
You must be signed in to change notification settings - Fork 76
Remove Dev Proxy CA certificate when uninstalling for Win #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bartizan
wants to merge
12
commits into
dotnet:main
Choose a base branch
from
bartizan:847_uninstall-root-certificate-win
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8cf4ae9
Add CLI 'remove' command to remove Dev Proxy certificate
bartizan c42e7be
Update win-installers to remove certificate when uninstalling
bartizan f1a17e1
Fix beta executable name
bartizan 144a2b2
Adjust certificate removal identifier of installer
bartizan 9900992
Merge branch 'main' into 847_uninstall-root-certificate-win
waldekmastykarz 0fef20d
fix: Add prompt confirmation to remove certificates and --force optio…
bartizan a5a0f3f
Merge branch 'main' into 847_uninstall-root-certificate-win
bartizan 234fa26
Update installers to remove cert silently
bartizan 1e85379
Merge branch 'main' into 847_uninstall-root-certificate-win
bartizan fe6544c
Merge branch 'main' into 847_uninstall-root-certificate-mac
bartizan 1ada218
Remove trusted certificate on Mac
bartizan ede001a
Fix project updating resources only if newer one
bartizan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using DevProxy.Abstractions; | ||
using System.CommandLine; | ||
using System.CommandLine.Invocation; | ||
using System.Diagnostics; | ||
using Titanium.Web.Proxy.Helpers; | ||
|
||
namespace DevProxy.CommandHandlers; | ||
|
||
public static class CertRemoveCommandHandler | ||
{ | ||
public static void RemoveCert(ILogger logger, InvocationContext invocationContext, Option<bool> forceOption) | ||
{ | ||
logger.LogTrace("RemoveCert() called"); | ||
ArgumentNullException.ThrowIfNull(logger); | ||
ArgumentNullException.ThrowIfNull(invocationContext); | ||
ArgumentNullException.ThrowIfNull(forceOption); | ||
|
||
try | ||
{ | ||
var isForced = invocationContext.ParseResult.GetValueForOption(forceOption); | ||
if (!isForced) | ||
{ | ||
var isConfirmed = PromptConfirmation("Do you want to remove the root certificate", defaultValue: false); | ||
if (!isConfirmed) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
logger.LogInformation("Uninstalling the root certificate..."); | ||
|
||
RemoveTrustedCertificateOnMac(); | ||
ProxyEngine.ProxyServer.CertificateManager.RemoveTrustedRootCertificate(machineTrusted: false); | ||
|
||
logger.LogInformation("DONE"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
logger.LogError(ex, "Error removing certificate"); | ||
} | ||
finally | ||
{ | ||
logger.LogTrace("RemoveCert() finished"); | ||
} | ||
} | ||
|
||
private static bool PromptConfirmation(string message, bool defaultValue) | ||
{ | ||
while (true) | ||
{ | ||
Console.Write(message + $" ({(defaultValue ? "Y/n" : "y/N")}): "); | ||
var answer = Console.ReadLine(); | ||
|
||
if (string.IsNullOrWhiteSpace(answer)) | ||
{ | ||
return defaultValue; | ||
} | ||
else if (answer.StartsWith("y", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return true; | ||
} | ||
else if (answer.StartsWith("n", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
private static void RemoveTrustedCertificateOnMac() | ||
{ | ||
if (!RunTime.IsMac) | ||
{ | ||
return; | ||
} | ||
|
||
var bashScriptPath = Path.Join(ProxyUtils.AppFolder, "remove-cert.sh"); | ||
ProcessStartInfo startInfo = new() | ||
{ | ||
FileName = "/bin/bash", | ||
Arguments = bashScriptPath, | ||
UseShellExecute = false, | ||
CreateNoWindow = true, | ||
}; | ||
|
||
var process = new Process() { StartInfo = startInfo }; | ||
process.Start(); | ||
process.WaitForExit(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
if [ "$(uname -s)" != "Darwin" ]; then | ||
echo "Error: this shell script should be run on macOS." | ||
exit 1 | ||
fi | ||
|
||
echo -e "\nRemove the self-signed certificate from your Keychain." | ||
|
||
cert_name="Dev Proxy CA" | ||
cert_filename="dev-proxy-ca.pem" | ||
|
||
# export cert from keychain to PEM | ||
echo "Exporting '$cert_name' certificate..." | ||
security find-certificate -c "$cert_name" -a -p > "$cert_filename" | ||
|
||
# add trusted cert to keychain | ||
echo "Removing Dev Proxy trust settings..." | ||
security remove-trusted-cert "$cert_filename" | ||
|
||
# remove exported cert | ||
echo "Cleaning up..." | ||
rm "$cert_filename" | ||
echo -e "\033[0;32mDONE\033[0m\n" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.