This commit is contained in:
Urko 2023-02-15 19:47:52 +01:00
parent e73874986e
commit 868ebbf79d
1 changed files with 12 additions and 4 deletions

View File

@ -47,11 +47,11 @@ func encodePrivateKey(priv *ecdsa.PrivateKey) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("marshal: %s", err)
}
pem.Encode(out, &pem.Block{
err = pem.Encode(out, &pem.Block{
Type: "PRIVATE KEY",
Bytes: privBytes,
})
return out.Bytes(), nil
return out.Bytes(), err
}
// Create a self-signed certificate.
@ -80,7 +80,11 @@ func newRootCA(config *ca.CaConfig) ([]byte, []byte, error) {
}
out := &bytes.Buffer{}
pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: der})
err = pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: der})
if err != nil {
return nil, nil, fmt.Errorf("pem.Encode: %s", err)
}
caPEM := out.Bytes()
keyPEM, err := encodePrivateKey(priv)
if err != nil {
@ -125,7 +129,11 @@ func newClientCert(config *client.ClientCertConfig, rootCA *x509.Certificate, ro
}
out := &bytes.Buffer{}
pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: der})
err = pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: der})
if err != nil {
return nil, nil, fmt.Errorf("pem.Encode: %s", err)
}
certPEM := out.Bytes()
keyPEM, err := encodePrivateKey(priv)
if err != nil {