Skip to content

Errors

Every exported sentinel error, grouped by package. All of them are created with gitlab.com/phpboyscout/go/errors, so match them with errors.Is and never by comparing message text.

Three different ErrUnsupportedKeyType sentinels

openpgpkey, local and minisign each declare their own ErrUnsupportedKeyType, and they are not the same value. A check written against the wrong package's sentinel silently never matches.

Sentinel Kind Means
openpgpkey.ErrUnsupportedKeyType signing.openpgpkey.unsupported_key_type The signer's Public() is not *rsa.PublicKey. OpenPGP minting and detached signing here are RSA-only.
local.ErrUnsupportedKeyType signing.local.unsupported_key_type The PEM file holds something other than RSA, ECDSA P-256 or Ed25519, ECDSA on P-384 for instance.
minisign.ErrUnsupportedKeyType signing.minisign.unsupported_key_type The signer's Public() is not ed25519.PublicKey. minisign is Ed25519-only.

Import the package whose function you called, and match that one. Code that routes on errors.KindOf rather than errors.Is can tell the three apart by kind. Up to v0.8.2 all three shared the kind signing.unsupported_key_type.

signing: the registry

Sentinel Raised by Meaning and response
ErrUnknownBackend signing.Get No backend is registered under that name. The message lists the names that are registered, or says the binary "was built without any signing backends compiled in" when the registry is empty. Almost always a missing blank import.
ErrUnknownBackendType signing.NewInstance No factory is registered for that backend type: the binary was built without the backend, or the backend offers no named instances.

An unknown name is quoted only when it could be a backend type. Both ErrUnknownBackend and ErrUnknownBackendType quote the requested name when it matches the type grammar (lowercase letters, digits and hyphens, not starting with a hyphen) and is at most 24 characters, so a typo such as "aws-ksm" is shown. Anything else may be a credential pasted where a type was expected, so the message says a name not shaped like a backend type (not shown) instead. NewInstance checks the type before the instance, so its later errors only ever quote a registered type. Those later errors (a factory that fails, or returns a backend under the wrong name) quote the canonical <type>:<instance> only when the instance passes the same test. Otherwise they name the type and say the instance is not shown, because NewInstance does not check the instance grammar and a caller may pass anything.

signing.Register reports its failures by panicking, not by returning an error: a nil Backend, a Backend whose Name() is empty, or a duplicate name. signing.RegisterFactory panics the same way on an invalid type name, a nil constructor, a duplicate type, or a probe instance whose settings struct is malformed. All of these are programming errors at process init, and failing at startup is preferred to a silently overridden backend. There is no way to unregister a backend outside tests.

NewInstance returns plain errors, with no sentinel, for an empty instance name, a factory that returns nil, a factory whose result is not named <type>:<instance>, and a result whose settings struct is malformed. An error from the factory itself comes back wrapped, so errors.Is still finds the factory's own sentinel. The messages are listed in the backend registry.

verify: trust sets and resolvers

Sentinel Raised by Meaning and response
ErrSignatureInvalid TrustSet.VerifyManifestSignature, VerifyManifestSignatureSigner The signature is empty, malformed, or does not validate under any key in the set, or it or any packet beside it uses a hash other than SHA-256, SHA-384, SHA-512, SHA3-256 or SHA3-512. A weak-hash signature from a revoked key gives this alone, without ErrSignerRevoked. Reject the release.
ErrSignerRevoked TrustSet.VerifyManifestSignature, VerifyManifestSignatureSigner, on a set from a rotating resolver The signature verifies under a key that the applied rotation revoked. It always comes with ErrSignatureInvalid. Reject the release, and report it: a revoked key is still signing, or a mirror is serving a release from before the rotation.
ErrWeakKey LoadTrustSet, and every resolver that builds on it A key failed the minimum-strength policy. Fix the key; do not lower the floor.
ErrKeyResolverMismatch CompositeResolver.Resolve Two successful resolvers returned different fingerprint sets. Treat as possible compromise of an anchor. Never reconcile it.
ErrKeyResolverUnavailable WKD fetches, CompositeResolver.Resolve A resolver could not produce a trust set: network failure, non-200 status, no key at either WKD URL, no returned key matching the address, or (with RequireAll) any child failure at all.
ErrWKDResponseTooLarge the WKD fetch The response body exceeded MaxWKDResponseSize. Returned bare, not wrapped.
ErrSignatureMissing nothing in this module Declared for downstream self-updaters that fetch release assets. This module never returns it.
ErrSignatureTooLarge RotationAuthority.VerifyRotationManifest A rotation manifest's signature exceeded MaxSignatureSize. Nothing else here enforces the cap; it is also declared for downstream release fetchers.

Rotation manifests

Sentinel Raised by Meaning and response
ErrRotationManifestTooLarge ParseRotationManifest, VerifyRotationManifest, CheckRotation The manifest exceeded MaxRotationManifestSize.
ErrRotationManifestMalformed ParseRotationManifest, VerifyRotationManifest, SignRotationManifest, CheckRotation, Apply, ApplyRotation The manifest does not parse, or breaks a rule that holds whatever has been applied: the schema, the reason, an epoch of 0, not_after not after issued_at, a fingerprint that is not 40 hex characters or appears twice, or an added key whose armoured text is anything but the declared public key: one PGP PUBLIC KEY BLOCK with no armour headers, nothing but ASCII whitespace around it, no blank lines, stray carriage returns or trailing spaces inside it, and at most one checksum line, which must match, holding only public-key, user-ID and signature packets. Private key material, a second block and any packet a public key does not carry are refused, so a secret cannot be published beside the key by accident. The check is not a guarantee against an issuer who means to hide bytes, which a field a public key may carry, such as a user ID or a signature notation, can still hold. Some ordinary exports are refused too: an armour with Comment: headers (sq's default), a key with a photo ID, and a gpg --export-options backup export. Delete the header lines, or export the key again without the backup option, and without the photo ID with gpg --export --armor --export-options no-export-attributes <key>, which keeps every user ID. A weak added key returns ErrWeakKey instead.
ErrRotationSignatureInvalid VerifyRotationManifest, Apply, ApplyRotation No authority key verified the signature, or Apply was given a manifest that only ParseRotationManifest had seen. Fail the update.
ErrRotationRefused Apply, CheckRotation, ApplyRotation, MemoryRotationStore.Save, and Resolve on a rotating resolver A verified manifest cannot be applied: issued_at is more than five minutes ahead, not_after has passed, the epoch is more than 1024 above the applied one, it reuses the applied epoch with different adds or with a revoke the stored record lacks, it names an anchor-only key, or no key that may sign a release would be left. Resolve returns it when the stored record would leave no such key. Save returns it when a different record is already stored at that epoch, or when the record lacks a revoke already stored. CheckRotation returns it only for an anchor-only key, an empty set, or a nil trust set: it has no clock or epoch to check.
ErrRotationReplayed Apply, ApplyRotation, MemoryRotationStore.Save The manifest's epoch is below the applied epoch, or a save would lower the stored epoch. The same manifest again at the applied epoch is not an error: it changes nothing, and so does one at that epoch with the same adds and fewer revokes.

Why ErrSignatureInvalid covers so much

VerifyManifestSignature deliberately does not distinguish a forged signature from an unparseable one, because for a caller's purposes they are the same answer. Nor does the error name which key rejected the signature, so logging the sentinel leaks nothing about the trust set.

The same sentinel also covers cases decided inside go-crypto: a revoked primary key, a revoked primary identity, a revoked or expired signing subkey, an expired signature, an expired key and an unknown critical notation. Expiry is judged against the current clock at verification time. It covers a signer below the strength policy too, which this module checks a second time after verification.

One case is told apart: a signature by a key that a rotation manifest revoked also matches ErrSignerRevoked. It is reported only when the signature really verifies under that key, because anyone can write a key's ID into a signature. That needs the key itself, so a revoked key that no anchor carries is reported as unknown. The error never names the key.

Otherwise, the underlying go-crypto error is folded into the message rather than the error chain, so errors.Is against a go-crypto sentinel will not match. If you need to tell an expired key from a forgery, read the message text, and treat both as "do not trust" regardless.

What CompositeResolver does to child errors

With RequireAll: true, the first child error is re-wrapped as ErrKeyResolverUnavailable using the child's message text only. The child's own sentinel is not preserved in the chain, so a child that failed with ErrWeakKey surfaces as ErrKeyResolverUnavailable and errors.Is(err, verify.ErrWeakKey) returns false. The original wording is still in the message, prefixed with composite: resolver "<name>".

Errors with no sentinel

Some failures return a plain error with no sentinel to match on. Detect them by failing closed, not by string comparison:

  • LoadTrustSet: no keys provided, and per-key parse failures.
  • composite: no resolvers configured.
  • wkd: email is required, wkd: HTTPClient is required, wkd: invalid email …, and the domain-validation failures.
  • wkd: refusing non-HTTPS URL, raised before any request is made.
  • wkd: parsing key response: the WKD body was not a parseable binary keyring.
  • The key_source=… configuration errors listed in Configuration fields.

openpgpkey: minting and signing

Sentinel Raised by Meaning and response
ErrUnsupportedKeyType Entity, ArmoredPublicKey, WriteArmoredPublicKey, DetachSign The signer is not RSA. Use an RSA key for the OpenPGP path, or minisign for Ed25519 artefact signing.
ErrZeroCreationTime Entity, ArmoredPublicKey, WriteArmoredPublicKey The creation time is the zero time.Time. OpenPGP would store it as 2042-07-14, and go-crypto will not sign with a key created in the future. Pass the key's real creation time and keep it stable, because it is part of the fingerprint. Generate is the exception, and takes a zero time to mean now.
ErrCreationTimeOutOfRange Entity, ArmoredPublicKey, WriteArmoredPublicKey, Generate, ValidateGenerateOptions, DetachSign The key's or the signature's creation time is outside 1970-01-01T00:00:00Z to 2106-02-07T06:28:15Z, which is all a 32-bit OpenPGP timestamp holds. Before 1970 the key cannot sign; after 2106 the time would be stored as a different one, changing the fingerprint. The error quotes the time it got.
ErrSignedBeforeKeyCreated DetachSign The signature is dated before the key's creation time. go-crypto will not make one, and GnuPG rejects it. Usually a mistyped key creation time or signature time. The error quotes both.

DetachSign has three further failure modes that return plain errors, and each means something specific:

  • expected exactly one entity in armored public key, got N: the public key blob holds a keyring, not a single key.
  • armored public key has no User ID; cannot sign with an unidentified key: a bare public-key packet was passed instead of a self-signed key.
  • signer's RSA public half does not match the public key block — wrong key?: the signer and the published key are different keys. Signing anyway would produce a signature naming the published fingerprint that no verifier accepts.

WriteWKDTree returns plain errors for an empty entry list, an invalid domain, an unparseable Email or SubmissionAddress, an Entry with no keys, an invalid Method, or a key that parses as neither armoured nor binary OpenPGP.

local: the PEM backend

Sentinel Raised by Meaning and response
ErrMissingPEMBlock local.NewSigner The file decoded to no PEM block at all, or to a block whose type is neither RSA PRIVATE KEY nor PRIVATE KEY. The message names the path or the offending block type.
ErrOpenPGPSecretKey local.NewSigner The file is an armored OpenPGP secret key (-----BEGIN PGP PRIVATE KEY BLOCK-----), such as the .priv.asc that keys generate --algorithm ed25519 writes by default. The message names the path, and the hint says to write the private half as PKCS#8 PEM (--private-format pem).
ErrEncryptedPEMUnsupported local.NewSigner The block type is ENCRYPTED PRIVATE KEY. Decrypt out of band first, or use a KMS backend.
ErrUnsupportedKeyType local.NewSigner The key parsed but is not RSA, ECDSA on P-256, or Ed25519 (ECDSA on P-384, for instance). The message names the concrete type.

A missing or unreadable file surfaces as a wrapped os error under reading PEM file, not as a sentinel.

minisign: artefact signatures

Sentinel Raised by Meaning and response
ErrUnsupportedKeyType SignDigest (so also Sign) The signer's public half is not Ed25519. An RSA KMS key cannot produce minisign signatures.
ErrUnsupportedAlgorithm VerifyDigest (so also Verify, VerifyFile) The signature carries a tag other than the prehashed "ED", usually a legacy pure "Ed" signature. cargo-binstall rejects those too.
ErrMalformedSignature ParseSignature, SignDigest, VerifyDigest The file lacks its four fields, a base64 body will not decode, a body is the wrong length, or a supplied digest is not 64 bytes.
ErrMalformedPublicKey NewPublicKey, ParsePublicKey, VerifyDigest The key is not 32 bytes, no base64 body was found, or the decoded body is the wrong length.
ErrKeyIDMismatch VerifyDigest The signature names a different key. Checked before any signature maths runs.
ErrBadSignature VerifyDigest The artefact signature does not verify under the key. Reject the artefact.
ErrBadGlobalSignature VerifyDigest The artefact signature verified but the global signature did not, so the trusted comment has been tampered with. Reject the artefact.
ErrInvalidComment PublicKey.File, SignDigest A comment contains a carriage return or newline, which would corrupt the line-oriented format and could forge extra fields.
ErrCommentTooLong PublicKey.File, SignDigest A comment exceeds the reference implementation's limit. The Rust verifiers do not enforce these limits, so without this check an over-long comment would pass every test here and fail against upstream minisign -V.
ErrSignerOutput SignDigest The signer returned something other than a raw 64-byte Ed25519 signature (a DER-wrapped value, for instance). Both Rust consumers require the raw form.

keyfile: writing key files

Sentinel Raised by Meaning and response
ErrKeyFileExists Write, WritePair An output file already exists and the write was not forced. Nothing was written. Force it, or choose another path.
ErrIsDirectory Write, WritePair An output path is a directory, or a link to one. Forcing cannot fix it.
ErrSameOutput WritePair Both halves name one file. This is checked before anything is written, and checked again under force once the private half is in place, for aliases only the file system knows about (NFC and NFD spellings on APFS, for instance). Either way the old pair is left as it was, unless ErrPrivateHalfReplaced comes with it.
ErrPrivateHalfReplaced WritePair, forced The public half failed after the private half was renamed into place, and the new private half is still there with no public half for it. The file system had no hard links to keep the old one with, or there was nothing at the path before and removing the new one failed. Derive the public half from the new private key, or write the pair again.
ErrOldPrivateHalfKept WritePair, forced Comes with ErrPrivateHalfReplaced, and means the old private half could not be put back. The message names the hidden .<name>.old.* directory beside the private path that holds it. Move it back by hand, or delete it if the old key is no longer wanted.

A forced WritePair that fails on the public side otherwise leaves the old pair as it was, and returns only the cause.

A crash can leave the old private key behind. Between replacing the private half and finishing, a forced WritePair holds the old private half in a hidden .<name>.old.* directory beside the private path, and removes it at the end. If the process dies in between, nothing removes it. After replacing a key because it was compromised, check for that directory and delete it.