PKCS#12 bundles written world-readable with a fixed, disclosed password
Affected versions: confirmed on master HEAD, commit 1c1dc4ed27ed5936046b6398d39cab4d657a2d8e.
Summary
Running mkcert -pkcs12 <name> generates a certificate and private key, packages them into a PKCS#12 bundle encrypted with the literal, hardcoded password changeit, and writes the file with mode 0644. Under a standard 022/0002 umask this leaves the file world-readable. Since the decryption password is both constant and printed directly to the operator's terminal, file-permission confidentiality is the only actual protection on the embedded private key, and that protection is defeated by the mode the tool itself requests.
Details
cert.go:
domainCert, _ := x509.ParseCertificate(cert)
pfxData, err := pkcs12.Encode(rand.Reader, priv, domainCert, []*x509.Certificate{m.caCert}, "changeit")
fatalIfErr(err, "failed to generate PKCS#12")
...
err = ioutil.WriteFile(p12File, pfxData, 0644)
fatalIfErr(err, "failed to save PKCS#12")
ioutil.WriteFile requests mode 0644 regardless of whether the process umask would have allowed something tighter, and preserves an existing file's mode on overwrite. The password is not user-configurable and is announced to the operator every time mkcert runs, so any other local user who can read the file can decrypt it immediately.
Steps To Reproduce
(available upon request)
Impact
- Any local user who can read a
.p12file produced bymkcert -pkcs12(shared/tmp, a world-readable home directory, a CI artifact, a backup, a misconfigured shared host) can recover the certificate's private key with zero additional effort, using only publicly documented tooling and the password mkcert itself discloses. - Limited to the issued development certificate's key, not the CA root key.
- Severity is tempered by
-pkcs12being opt-in and by the output needing to land in a directory traversable by another user, but neither of those preconditions is unusual in CI, shared dev boxes, or containers.