caddyserver/caddy · error

no CERTIFICATE pem block found in the given pem data

Error message

no CERTIFICATE pem block found in the given pem data

What it means

Guard in convertPEMToDER: pem.Decode yielded a block whose type is not 'CERTIFICATE', so the data cannot be converted to DER certificates. The faulty input is a PEM stream containing other block types (e.g. a PRIVATE KEY) where certificates were expected.

Solutions

  1. Ensure the stored PEM data contains a CERTIFICATE block at the expected storage key.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at modules/caddytls/leafstorageloader.go:111 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/7613c94839fe9b6d. Report an issue: GitHub.

Appendix: source

Thrown at modules/caddytls/leafstorageloader.go:111

		ders, err := convertPEMToDER(certData)
		if err != nil {
			return nil, err
		}
		certs, err := x509.ParseCertificates(ders)
		if err != nil {
			return nil, err
		}
		certificates = append(certificates, certs...)
	}
	return certificates, nil
}

func convertPEMToDER(pemData []byte) ([]byte, error) {
	var ders []byte
	// while block is not nil, we have more certificates in the file
	for block, rest := pem.Decode(pemData); block != nil; block, rest = pem.Decode(rest) {
		if block.Type != "CERTIFICATE" {
			return nil, fmt.Errorf("no CERTIFICATE pem block found in the given pem data")
		}
		ders = append(
			ders,
			block.Bytes...,
		)
	}
	// if we decoded nothing, return an error
	if len(ders) == 0 {
		return nil, fmt.Errorf("no CERTIFICATE pem block found in the given pem data")
	}
	return ders, nil
}

// Interface guard
var (
	_ LeafCertificateLoader = (*LeafStorageLoader)(nil)
	_ caddy.Provisioner     = (*LeafStorageLoader)(nil)
)

View on GitHub (pinned to 50e54ee279)