projectdiscovery/nuclei · error

failed to parse PEM block containing the certificate

Error message

failed to parse PEM block containing the certificate

What it means

Error "failed to parse PEM block containing the certificate" thrown in projectdiscovery/nuclei.

Source

Thrown at pkg/templates/signer/handler.go:83

func (k *KeyHandler) ReadPrivateKey(envName, dir string) error {
	// read from env
	if privateKey := k.getEnvContent(envName); privateKey != nil {
		k.PrivateKey = privateKey
		return nil
	}
	// read from disk
	if privateKey, err := os.ReadFile(filepath.Join(dir, PrivateKeyFilename)); err == nil {
		k.PrivateKey = privateKey
		return nil
	}
	return ErrNoPrivateKey
}

// ParseUserCert parses the user certificate and returns the public key
func (k *KeyHandler) ParseUserCert() error {
	block, _ := pem.Decode(k.UserCert)
	if block == nil {
		return fmt.Errorf("failed to parse PEM block containing the certificate")
	}
	cert, err := x509.ParseCertificate(block.Bytes)
	if err != nil {
		return err
	}
	if cert.Subject.CommonName == "" {
		return fmt.Errorf("invalid certificate: expected common name to be set")
	}
	k.cert = cert
	var ok bool
	k.ecdsaPubKey, ok = cert.PublicKey.(*ecdsa.PublicKey)
	if !ok {
		return fmt.Errorf("failed to parse ecdsa public key from cert")
	}
	return nil
}

// ParsePrivateKey parses the private key and returns the private key

View on GitHub (pinned to 265b3a3dec)

When it happens

Trigger: Thrown at pkg/templates/signer/handler.go:83 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15). Data as JSON: /api/errors/1bd9b7c294e0a1ec. Report an issue: GitHub.