hashicorp/packer · error
unsupported public key type %T
Error message
unsupported public key type %T
What it means
pemVerifier.Verify only supports three public key types: *rsa.PublicKey, *ecdsa.PublicKey, and ed25519.PublicKey. If the verifier's publicKey holds any other type (e.g. *dsa.PublicKey or an X25519 key parsed from a PEM file), it falls through to the default case and returns "unsupported public key type %T" with the Go type name filled in. This is a key-format/algorithm support limitation, surfaced at verification time rather than key-load time.
Source
Thrown at internal/attestation/sign_key.go:96
pae := PreAuthEncode(payloadType, payload)
switch publicKey := v.publicKey.(type) {
case *rsa.PublicKey:
digest := sha256.Sum256(pae)
return rsa.VerifyPKCS1v15(publicKey, crypto.SHA256, digest[:], signature)
case *ecdsa.PublicKey:
digest := sha256.Sum256(pae)
if !ecdsa.VerifyASN1(publicKey, digest[:], signature) {
return fmt.Errorf("ECDSA verification failed")
}
return nil
case ed25519.PublicKey:
if !ed25519.Verify(publicKey, pae, signature) {
return fmt.Errorf("Ed25519 verification failed")
}
return nil
default:
return fmt.Errorf("unsupported public key type %T", v.publicKey)
}
}
func (v *pemVerifier) KeyID() string {
return v.keyID
}
func LoadPEMVerifier(path string) (Verifier, error) {
contents, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("read verifier %q: %w", path, err)
}
publicKey, rawVerifier, err := loadPEMPublicKey(contents)
if err != nil {
return nil, fmt.Errorf("load verifier %q: %w", path, err)
}
View on GitHub (pinned to eb36e3c3e4)
Solutions
- Read the %T in the error message to see the actual Go key type, then replace the verifier PEM with an RSA, ECDSA, or Ed25519 public key (or a certificate whose public key is one of those).
- Regenerate the key pair with an supported algorithm, e.g. `openssl genpkey -algorithm ed25519` or `openssl ecparam -genkey -name prime256v1`, and use the new public key for verification.
- Check the key-generation/rotation process that produced the verifier PEM and restrict it to RSA/ECDSA/Ed25519 so unsupported keys never reach verification.
Example fix
// before: X25519 key loaded as verifier -> unsupported public key type *x25519.PublicKey
verifier, _ := attestation.LoadPEMVerifier("x25519-pub.pem")
// after: use a signing key of a supported type
// openssl genpkey -algorithm ed25519 -out signer.pem
verifier, _ := attestation.LoadPEMVerifier("ed25519-pub.pem") Defensive patterns
Strategy: type-guard
Validate before calling
pub, _, err := loadPEMPublicKey(contents) // or inspect verifier via a debug hook
if err != nil {
return err
}
switch pub.(type) {
case *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey:
// supported, safe to verify
default:
return fmt.Errorf("verifier key type %T unsupported; use RSA, ECDSA, or Ed25519", pub)
} Type guard
func isSupportedVerifierKey(pub crypto.PublicKey) bool {
switch pub.(type) {
case *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey:
return true
default:
return false
}
} Try / catch
if err := verifier.Verify(ctx, payloadType, payload, sig.Sig); err != nil {
var unsupported interface{ Error() string }
if strings.HasPrefix(err.Error(), "unsupported public key type") {
return fmt.Errorf("verifier PEM must contain an RSA/ECDSA/Ed25519 key: %w", err)
}
return err
} Prevention
- Restrict key generation for attestation verifiers to RSA, ECDSA (P-256/P-384), or Ed25519.
- Never use key-agreement keys (X25519/X448) or DSA keys as attestation verifiers.
- Validate the parsed public key type immediately after LoadPEMVerifier, before storing or using the verifier.
- Include the key type in operational checks/CI so an unsupported key never ships in production config.
When it happens
Trigger: Calling pemVerifier.Verify (or LoadPEMVerifier/LoadPEMVerifierBytes, which produce the verifier) with a PEM file whose parsed key is not RSA/ECDSA/Ed25519 — e.g. a PKIX PUBLIC KEY block containing an X25519, DSA, or other key type — so the type switch in Verify hits the default branch.
Common situations: Pointing the verifier at a key-exchange key (X25519) instead of a signing key; using legacy DSA keys; loading a PEM file that accidentally contains a certificate or key of an exotic algorithm; upstream Go x509.ParsePKIXPublicKey succeeding for an algorithm this verifier does not implement.
Related errors
- signing_mode %q does not support Sigstore bundle emission
- decode envelope payload: %w
- decode envelope signature: %w
- signing_mode %q requires signer
- sign payload: %w
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/a763aa11068e0b55.
Report an issue: GitHub.