caddyserver/caddy · error

no PEM block found

Error message

no PEM block found

What it means

Error "no PEM block found" thrown in caddyserver/caddy.

Source

Thrown at modules/caddypki/crypto.go:36

	"bytes"
	"crypto"
	"crypto/ecdsa"
	"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
}

View on GitHub (pinned to 50e54ee279)

Solutions

  1. Provide input containing a PEM-encoded block; check the file or data is not empty and uses PEM encoding.

When it happens

Trigger: Thrown at modules/caddypki/crypto.go:36 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/77eba429fc72b645. Report an issue: GitHub.