Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions internal/awstesting/certificate_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,21 @@ func generateRootCA() (

// PEM encode CA certificate and private key
var caPEMBuf bytes.Buffer
pem.Encode(&caPEMBuf, &pem.Block{
err = pem.Encode(&caPEMBuf, &pem.Block{
Type: "CERTIFICATE",
Bytes: caBytes,
})

if err != nil {
return nil, nil, nil, nil, fmt.Errorf("failed to encode CA certificate: %w", err)
}
var caPrivKeyPEMBuf bytes.Buffer
pem.Encode(&caPrivKeyPEMBuf, &pem.Block{
err = pem.Encode(&caPrivKeyPEMBuf, &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(caPrivKey),
})

if err != nil {
return nil, nil, nil, nil, fmt.Errorf("failed to encode CA private key: %w", err)
}
return caPEMBuf.Bytes(), caPrivKeyPEMBuf.Bytes(), caCert, caPrivKey, nil
}

Expand Down Expand Up @@ -143,17 +147,21 @@ func generateLocalCert(parentCert *x509.Certificate, parentPrivKey *rsa.PrivateK

// PEM encode certificate and private key
var certPEMBuf bytes.Buffer
pem.Encode(&certPEMBuf, &pem.Block{
err = pem.Encode(&certPEMBuf, &pem.Block{
Type: "CERTIFICATE",
Bytes: certBytes,
})

if err != nil {
return nil, nil, fmt.Errorf("failed to encode certificate: %w", err)
}
var certPrivKeyPEMBuf bytes.Buffer
pem.Encode(&certPrivKeyPEMBuf, &pem.Block{
err = pem.Encode(&certPrivKeyPEMBuf, &pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(certPrivKey),
})

if err != nil {
return nil, nil, fmt.Errorf("failed to encode private key: %w", err)
}
return certPEMBuf.Bytes(), certPrivKeyPEMBuf.Bytes(), nil
}

Expand Down
Loading