{"record":{"id":"7dd807f3b84685cd","repo":"decolua/9router","slug":"failed-to-install-certificate-e-message","errorCode":null,"errorMessage":"Failed to install certificate: ${e.message}","messagePattern":"Failed to install certificate: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mitm/cert/install.js","lineNumber":131,"sourceCode":"  } catch (error) {\n    const msg = error.message?.includes(\"canceled\") ? \"User canceled authorization\" : \"Certificate install failed\";\n    throw new Error(msg);\n  }\n}\n\nasync function installCertWindows(certPath) {\n  // Auto-elevate via UAC popup if not admin (zero popup if already admin).\n  // Delete any stale cert with same CN before adding to avoid duplicates.\n  const script = `\n    certutil -delstore Root ${quotePs(ROOT_CA_CN)} 2>$null | Out-Null\n    $exit = & certutil -addstore Root ${quotePs(certPath)} 2>&1\n    if ($LASTEXITCODE -ne 0) { throw \"certutil exit $LASTEXITCODE\" }\n  `;\n  try {\n    await runElevatedPowerShell(script);\n    log(\"🔐 Cert: ✅ installed to Windows Root store\");\n  } catch (e) {\n    throw new Error(`Failed to install certificate: ${e.message}`);\n  }\n}\n\n/**\n * Uninstall SSL certificate from system store\n */\nasync function uninstallCert(sudoPassword, certPath) {\n  const isInstalled = await checkCertInstalled(certPath);\n  if (!isInstalled) {\n    log(\"🔐 Cert: not found in system store\");\n    return;\n  }\n\n  if (IS_WIN) {\n    await uninstallCertWindows();\n  } else if (IS_MAC) {\n    await uninstallCertMac(sudoPassword, certPath);\n  } else {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/mitm/cert/install.js#L113-L149","documentation":"installCertWindows() runs a certutil script in an elevated PowerShell (UAC). If runElevatedPowerShell fails or certutil exits non-zero ($LASTEXITCODE -ne 0), the error is rethrown as `Failed to install certificate: <detail>`. It wraps any elevation or certutil failure.","triggerScenarios":"installCert() on Windows when: the user declines the UAC elevation prompt, the process is not admin and elevation fails, certutil -addstore Root exits non-zero, or PowerShell execution policy blocks the spawned script.","commonSituations":"User clicks 'No' on UAC popup; running in a non-elevated service/CI context where UAC cannot appear; antivirus blocking certutil; Windows editions where Root store writes require different tooling.","solutions":["Accept the UAC elevation prompt when it appears","Run the dashboard/terminal once as Administrator so elevation is already in place","Manually run `certutil -addstore Root <cert>` in an admin PowerShell to see the raw certutil error","Check antivirus/EDR is not blocking certutil or elevated PowerShell"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const isAdmin = (await exec('net session').catch(() => null)) !== null;\nif (!isAdmin) console.warn('Elevation prompt (UAC) will appear for certificate install');","typeGuard":null,"tryCatchPattern":"try {\n  await installCert(sudoPassword, certPath);\n} catch (e) {\n  if (e.message.startsWith('Failed to install certificate:')) {\n    console.error('certutil/UAC failed:', e.message);\n    // instruct manual: certutil -addstore Root <cert> from an admin shell\n  } else throw e;\n}","preventionTips":["Tell the user a UAC prompt is coming so they don't dismiss it","Offer 'run as Administrator' guidance for headless/service contexts","Test certutil availability (`where certutil`) before attempting install"],"tags":["windows","certificate","uac","elevation"],"backgroundTag":"certificate-install-failed","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}