HTTPS certificate not trusted during development – Complete Fix | FreeLearning365.com

HTTPS certificate not trusted during development – Complete Fix | FreeLearning365.com
FreeLearning365.com 🔒 SSL
🚨 Certificate Error

HTTPS certificate not trusted during development
Complete Fix Guide

“NET::ERR_CERT_AUTHORITY_INVALID” — You're trying to test your app locally over HTTPS, but the browser blocks it. This guide provides permanent, secure solutions for trusting development certificates in ASP.NET Core, Angular, Node.js, and all major browsers.

🔍 1. Introduction

You spin up your development server over HTTPS, open your browser, and instead of your app, you see a warning: "Your connection is not private" or "NET::ERR_CERT_AUTHORITY_INVALID". The browser doesn't trust the certificate because it's self-signed — not issued by a trusted Certificate Authority (CA).

This is a common hurdle when developing modern web applications that require HTTPS (e.g., for service workers, secure cookies, or CORS with credentials). The good news is that there are simple, permanent fixes that work for all major development tools.

💡 Key point: You can either trust the certificate globally (recommended) or bypass the warning per browser session (not recommended for long-term development).

🧐 2. Why This Happens

When you use HTTPS in development, the server generates a self‑signed certificate. These certificates are cryptographically valid, but they aren’t signed by a trusted CA that browsers recognize. Browsers display a warning because they can’t verify the certificate’s origin, protecting users from potential man‑in‑the‑middle attacks.

This issue affects:

  • ASP.NET Core (Kestrel) – default HTTPS dev certificate
  • Angular dev server – uses a self‑signed certificate by default
  • Vite / Webpack dev servers with SSL enabled
  • Node.js HTTPS servers (e.g., Express with `https` module)
  • Any local development server running over HTTPS

🖥️ 3. Fix for ASP.NET Core

ASP.NET Core provides a built‑in development certificate. You can trust it with a single command.

📌 Generate and Trust the ASP.NET Core Certificate

# Install and trust the development certificate dotnet dev-certs https --trust

This command creates a new self‑signed certificate and adds it to your system’s trusted root store. After running it, restart your browser and API; the warning should disappear.

✅ Pro tip: If you already have the certificate but it's not trusted, you can reset it: dotnet dev-certs https --clean then dotnet dev-certs https --trust.

📌 Verify the Certificate

# List trusted certificates dotnet dev-certs https --check

This command checks if the certificate is present and trusted.

🅰️ 4. Fix for Angular

Angular’s development server (Angular CLI) can use HTTPS with a certificate. By default it generates a self‑signed certificate. Here’s how to use a trusted certificate.

📌 Option 1: Use a Trusted Certificate (mkcert)

Generate a certificate with mkcert (see next section) and configure Angular to use it.

# Generate certificate for localhost mkcert localhost 127.0.0.1 ::1 # In angular.json, under serve -> options "ssl": true, "sslKey": "localhost-key.pem", "sslCert": "localhost.pem"

📌 Option 2: Use Angular Dev Server with Proxy (Ignore SSL)

If you're only using Angular for the frontend and proxying to a backend that already has a trusted certificate, you can configure the proxy to ignore SSL errors.

// proxy.conf.json { "/api": { "target": "https://localhost:5001", "secure": false, // ✅ Ignore SSL verification "changeOrigin": true } }

🔧 5. Universal Fix with mkcert

mkcert is the gold‑standard tool for creating locally trusted certificates. It installs a local Certificate Authority (CA) on your machine and generates certificates for any domain (localhost, 127.0.0.1, custom domains, etc.) that are automatically trusted by your browser.

📌 Step 1: Install mkcert

# Windows (using Chocolatey) choco install mkcert # macOS (using Homebrew) brew install mkcert # Linux (using apt) sudo apt install libnss3-tools curl -J -L -o mkcert https://github.com/FiloSottile/mkcert/releases/latest/download/mkcert-v*-linux-amd64 chmod +x mkcert sudo mv mkcert /usr/local/bin/

📌 Step 2: Install the Local CA

mkcert -install

This installs the local CA certificate into your system’s trust store.

📌 Step 3: Generate Certificates for Your Hostnames

# For localhost and common aliases mkcert localhost 127.0.0.1 ::1 # For custom domains (e.g., myapp.test) mkcert myapp.test *.myapp.test # For Angular dev server with custom host mkcert angular-dev.local

This generates two files: myapp.test-key.pem and myapp.test.pem (or similar).

📌 Step 4: Use the Certificate in Your Server

Point your development server to the generated certificate and key files. For ASP.NET Core, you can configure Kestrel to use them; for Angular, use the angular.json approach mentioned earlier. For Node.js, use the https module with the cert and key options.

✅ Perfect: Once mkcert is set up, all your local HTTPS services will be trusted automatically, without browser warnings.

🌐 6. Browser-Specific Workarounds

If you can't install a certificate system‑wide, you can bypass the warning per browser. These are temporary solutions and not recommended for daily development.

📌 Chrome / Edge

  • Type thisisunsafe (anywhere) on the warning page – this bypasses the warning.
  • Alternatively, click "Advanced" → "Proceed to localhost (unsafe)".
  • You can also run Chrome with the flag: --ignore-certificate-errors (not secure).

📌 Firefox

  • Click "Advanced" → "Accept the Risk and Continue".
  • You can add a permanent exception via "Add Exception…" and confirm.

📌 Safari

  • Click "Show Details" → "visit this website" (or similar).
  • There's no permanent exception; you'll have to do it each time.
⚠️ Caution: Manually bypassing security warnings in development is okay, but never use these techniques in production or when dealing with sensitive data.

🔄 7. Proxy Ignore SSL Errors

In many full‑stack setups (Angular + ASP.NET Core), you use a proxy to forward API requests. If your backend uses HTTPS with an untrusted certificate, you can tell the proxy to ignore SSL errors.

// proxy.conf.json (Angular) { "/api": { "target": "https://localhost:5001", "secure": false, "changeOrigin": true, "logLevel": "debug" } }

For Vite, you can set secure: false in the proxy options as well. For Node.js servers with http-proxy, you can set rejectUnauthorized: false.

🐞 8. Debugging Tips

  • Check the certificate details: Click the padlock in the browser’s address bar to see the certificate issuer. It should show the local CA (if using mkcert) or your custom CA.
  • Clear browser cache: Sometimes browsers cache certificate errors. Use incognito mode or clear the cache.
  • Verify the certificate file: Use OpenSSL to inspect: openssl x509 -in cert.pem -text -noout.
  • Check the system trust store: On Windows, run certmgr.msc and look for your certificate in "Trusted Root Certification Authorities".
  • Check server logs: The server may have errors if the certificate file is missing or invalid.
❓ Frequently Asked Questions

🏆 10. Best Practices

  • Use mkcert for all local development HTTPS needs – it's the most reliable and secure method.
  • Always trust the certificate system‑wide rather than relying on browser bypasses.
  • Keep your certificates in a project‑specific folder (e.g., .cert/) and add to .gitignore.
  • Document the certificate setup in your project’s README for other developers.
  • Use environment variables to toggle HTTPS and certificate paths in different environments.
  • Automate certificate generation with a script (e.g., using mkcert in a post‑install hook).
  • For production, always use certificates from a trusted CA (e.g., Let's Encrypt, DigiCert).
✅ Final thought: HTTPS is essential for modern web development. With tools like mkcert and the built‑in trust mechanisms of ASP.NET Core and Angular, you can work securely without being blocked by certificate warnings. This guide gives you everything you need to set it up once and forget it.

Post a Comment

0 Comments