{"record":{"id":"55afd1ba3910cf0b","repo":"hashicorp/packer","slug":"sign-payload-w","errorCode":null,"errorMessage":"sign payload: %w","messagePattern":"sign payload: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/attestation/sign_key.go","lineNumber":64,"sourceCode":"}\n\nfunc (s *pemSigner) Sign(_ context.Context, payloadType string, payload []byte) (Signature, error) {\n\tpae := PreAuthEncode(payloadType, payload)\n\n\tvar message []byte\n\tvar opts crypto.SignerOpts\n\tif _, ok := s.signer.Public().(ed25519.PublicKey); ok {\n\t\tmessage = pae\n\t\topts = crypto.Hash(0)\n\t} else {\n\t\tdigest := sha256.Sum256(pae)\n\t\tmessage = digest[:]\n\t\topts = crypto.SHA256\n\t}\n\n\tsignature, err := s.signer.Sign(rand.Reader, message, opts)\n\tif err != nil {\n\t\treturn Signature{}, fmt.Errorf(\"sign payload: %w\", err)\n\t}\n\n\treturn Signature{\n\t\tKeyID: s.verifier.KeyID(),\n\t\tSig:   signature,\n\t}, nil\n}\n\nfunc (s *pemSigner) Verifier(context.Context, BackendConfig) (Verifier, error) {\n\treturn s.verifier, nil\n}\n\nfunc (v *pemVerifier) Verify(_ context.Context, payloadType string, payload, signature []byte) error {\n\tpae := PreAuthEncode(payloadType, payload)\n\n\tswitch publicKey := v.publicKey.(type) {\n\tcase *rsa.PublicKey:\n\t\tdigest := sha256.Sum256(pae)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/internal/attestation/sign_key.go#L46-L82","documentation":"pemSigner.Sign pre-encodes the payload (PreAuthEncode), hashes it with SHA-256 (except Ed25519, which signs the raw PAE bytes), then delegates to the loaded crypto.Signer's Sign method. Any failure returned by that underlying crypto.Signer.Sign call is wrapped as \"sign payload: %w\". This error means the private-key material itself refused or failed the signing operation, not that the payload was invalid — the original crypto error is preserved in the wrap chain for diagnosis.","triggerScenarios":"Invoking pemSigner.Sign(ctx, payloadType, payload) where the underlying crypto.Signer.Sign(rand.Reader, message, opts) returns an error — e.g. a hardware/PKCS#11-backed key is unavailable, the key handle was invalidated, or the signer implementation rejects the requested hash option.","commonSituations":"Signing with an HSM/smartcard/TPM-backed private key when the device is unplugged, locked, or the session expired; a custom crypto.Signer implementation returning errors for unsupported opts; OS-level key access permission failures; extremely large payloads triggering upstream limits in custom signers.","solutions":["Inspect the wrapped cause (%w chain) with errors.Unwrap or errors.As/Is to identify the underlying crypto.Signer failure (device error, bad opts, permission denied).","If using a hardware-backed key (HSM/TPM/smartcard), verify the device is present, unlocked, and the key handle is still valid, then re-attempt the signing operation.","Confirm the private key loaded via loadPEMSigner is a software key (RSA/ECDSA/Ed25519) compatible with the hash mode Sign selects (SHA-256 digest for RSA/ECDSA, raw PAE with crypto.Hash(0) for Ed25519).","Check file permissions and OS keychain access for the signer key if a platform crypto.Signer was substituted."],"exampleFix":"sig, err := signer.Sign(ctx, payloadType, payload)\nif err != nil {\n\tvar opErr *net.OpError\n\tif errors.As(err, &opErr) {\n\t\t// transient hardware/token error: reconnect and retry\n\t}\n\treturn fmt.Errorf(\"attestation signing failed: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check: ensure the loaded signer can produce a public key and is a supported type\npub := signerSigner.Public()\nswitch pub.(type) {\ncase *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey:\n\t// supported\ndefault:\n\treturn fmt.Errorf(\"signer public key type %T not supported for attestation\", pub)\n}","typeGuard":null,"tryCatchPattern":"sig, err := signer.Sign(ctx, payloadType, payload)\nif err != nil {\n\treturn Signature{}, fmt.Errorf(\"attestation sign payload: %w\", err)\n\t// inspect errors.Unwrap(err) for the crypto.Signer cause;\n\t// retry only for transient device/token errors\n}","preventionTips":["Prefer software PEM keys (PKCS#8 RSA/ECDSA or Ed25519) over hardware-backed signers unless the HSM lifecycle is managed.","Health-check hardware tokens (HSM/TPM) before starting signing operations and reconnect on failure.","Log the wrapped cause via %w/errors.Unwrap instead of swallowing it so root causes are diagnosable.","Construct the Signer once at startup and reuse it; a failed constructor surfaces key problems before traffic."],"tags":["attestation","signing","crypto","wrapped-error"],"backgroundTag":"crypto-sign-operation-failed","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}