caddyserver/caddy · error

input contained more than a single PEM block

Error message

input contained more than a single PEM block

What it means

Error "input contained more than a single PEM block" thrown in caddyserver/caddy.

Source

Thrown at modules/caddypki/crypto.go:39

	"crypto/ed25519"
	"crypto/rsa"
	"crypto/x509"
	"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)

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Provide exactly one PEM block; split the input if it contains a chain and pass only the needed certificate.

When it happens

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

Common situations: See trigger scenarios.


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