caddyserver/caddy · error

expected PEM block type to be CERTIFICATE, but got '%s'

Error message

expected PEM block type to be CERTIFICATE, but got '%s'

What it means

Error "expected PEM block type to be CERTIFICATE, but got '%s'" thrown in caddyserver/caddy.

Source

Thrown at modules/caddypki/crypto.go:42

	"encoding/pem"
	"errors"
	"fmt"
	"os"

	"github.com/caddyserver/certmagic"
	"go.step.sm/crypto/pemutil"
)

func pemDecodeCertificate(pemDER []byte) (*x509.Certificate, error) {
	pemBlock, remaining := pem.Decode(pemDER)
	if pemBlock == nil {
		return nil, fmt.Errorf("no PEM block found")
	}
	if len(remaining) > 0 {
		return nil, fmt.Errorf("input contained more than a single PEM block")
	}
	if pemBlock.Type != "CERTIFICATE" {
		return nil, fmt.Errorf("expected PEM block type to be CERTIFICATE, but got '%s'", pemBlock.Type)
	}
	return x509.ParseCertificate(pemBlock.Bytes)
}

func pemDecodeCertificateChain(pemDER []byte) ([]*x509.Certificate, error) {
	chain, err := pemutil.ParseCertificateBundle(pemDER)
	if err != nil {
		return nil, fmt.Errorf("failed parsing certificate chain: %w", err)
	}

	return chain, nil
}

func pemEncodeCert(der []byte) ([]byte, error) {
	return pemEncode("CERTIFICATE", der)
}

func pemEncode(blockType string, b []byte) ([]byte, error) {

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Provide a PEM block whose type is CERTIFICATE, not a private key or other block type.

When it happens

Trigger: Thrown at modules/caddypki/crypto.go:42 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of caddyserver/caddy@50e54ee279 (2026-08-15). Data as JSON: /api/errors/783df55afc480fa9. Report an issue: GitHub.