Skip to content

Commit 4f48107

Browse files
committed
Use PowerShell to install/uninstall CA on Windows
certutil -delstore cannot remove protected certs from the trust store, causing subsequent certutil -addstore to silently fail. Use PowerShell cert store provider (Remove-Item / Import-Certificate) instead.
1 parent a71e06d commit 4f48107

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

src/platform.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,17 @@ pub fn install_ca(ca_cert_path: &Path, common_name: &str) -> Result<()> {
316316

317317
match std::env::consts::OS {
318318
"windows" => {
319+
let path = ca_cert_path.to_string_lossy();
319320
run_command(
320-
"certutil",
321-
&["-f", "-addstore", "Root", &ca_cert_path.to_string_lossy()],
321+
"powershell",
322+
&[
323+
"-NoProfile",
324+
"-Command",
325+
&format!(
326+
"Import-Certificate -FilePath '{}' -CertStoreLocation Cert:\\LocalMachine\\Root",
327+
path
328+
),
329+
],
322330
)?;
323331
}
324332
"macos" => {
@@ -470,7 +478,17 @@ fn macos_loopback_aliases(config: &AppConfig) -> Vec<String> {
470478
pub fn uninstall_ca(common_name: &str) -> Result<()> {
471479
match std::env::consts::OS {
472480
"windows" => {
473-
run_command("certutil", &["-delstore", "Root", common_name])?;
481+
let _ = run_command(
482+
"powershell",
483+
&[
484+
"-NoProfile",
485+
"-Command",
486+
&format!(
487+
"Get-ChildItem Cert:\\LocalMachine\\Root\\* | Where-Object {{ $_.Subject -like '*{}*' }} | Remove-Item -Force",
488+
common_name
489+
),
490+
],
491+
);
474492
}
475493
"macos" => {
476494
let _ = run_command(

0 commit comments

Comments
 (0)