diff --git a/cert.go b/cert.go index 4ce36ccf..383c2094 100644 --- a/cert.go +++ b/cert.go @@ -300,10 +300,17 @@ func (m *mkcert) loadCA() { keyPEMBlock, err := ioutil.ReadFile(filepath.Join(m.CAROOT, rootKeyName)) fatalIfErr(err, "failed to read the CA key") keyDERBlock, _ := pem.Decode(keyPEMBlock) - if keyDERBlock == nil || keyDERBlock.Type != "PRIVATE KEY" { + if keyDERBlock == nil || keyDERBlock.Type != "PRIVATE KEY" && keyDERBlock.Type != "RSA PRIVATE KEY" && keyDERBlock.Type != "EC PRIVATE KEY" { log.Fatalln("ERROR: failed to read the CA key: unexpected content") } - m.caKey, err = x509.ParsePKCS8PrivateKey(keyDERBlock.Bytes) + switch keyDERBlock.Type { + case "RSA PRIVATE KEY": + m.caKey, err = x509.ParsePKCS1PrivateKey(keyDERBlock.Bytes) + case "EC PRIVATE KEY": + m.caKey, err = x509.ParseECPrivateKey(keyDERBlock.Bytes) + default: + m.caKey, err = x509.ParsePKCS8PrivateKey(keyDERBlock.Bytes) + } fatalIfErr(err, "failed to parse the CA key") }