Vite Proxy Using Http2 returns "unable to verify the first certificate"

Viewed 242

I am trying to setup a development environment using HTTP2 requests with Vite and a local backend. I proxy requests between client and server both running on localhost. The server is configured with a generated certificate using Mkcert (https://github.com/FiloSottile/mkcert).

Configuration:

To configure the certificate I run the following steps:

  1. mkcert.exe -pkcs12 "test" "127.0.0.1" "localhost"
  2. Configure the backend to use the generated cert
  3. mkcert.exe -install
  4. Use the following vite configuration:
server: {
  https: {
    pfx: fs.readFileSync(`./cert/test.pfx`),
    passphrase: "some-phrase",
  },
  proxy: {
    "/api": {
      target: `https://localhost:15000`,
      changeOrigin: true,
      secure: true,
    },
  },
},

Currently this configuration works on Mac but fails on Windows. Both use the same backend and certificates but on Windows the proxy will fail with: "unable to verify the first certificate". In the browser the certificate chain is a correctly validated.

Troubleshooting:

When I run openssl s_client -showcerts -connect localhost:15000 -servername localhost the query results in "unable to verify the first certificate" as well basically indicating that the mkcert Root CA isn't properly found.

Using openssl s_client -showcerts -CAfile "C:\Users\SomeUser\AppData\Local\mkcert\rootCA.pem" -connect localhost:15000 -servername localhost the certificates will be correctly validated. This should indicate that the proxy lacks a reference to the rootCA of Mkcert.

I have tried supplying the rootCA using the following script in package.json:

"dev": "cross-env NODE_EXTRA_CA_CERTS=\"C:\\Users\\SomeUser\\AppData\\Local\\mkcert\\rootCA.pem\" && vite",

This doesn't help however and the proxy still fails with the same error. I assume Mac and Windows work differently when supplying the CA root certs to Node or fails silently?

Anyway, how can this solved? I have been thinking about supplying the full cert chain in a cert that I supply to Vite, but this shouldn't be needed if Node could just reference the RootCA correctly.

0 Answers
Related