signature

package
v0.50.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const SSHSignatureNamespace = "git"

Variables

View Source
var (
	// ErrSignatureEmpty is returned when no signature was provided.
	ErrSignatureEmpty = errors.New("signature is empty")

	// ErrPayloadEmpty is returned when no payload was provided.
	ErrPayloadEmpty = errors.New("payload is empty")

	// ErrSignatureFormat is returned when the provided signature is not in
	// the format expected by the verification function, for example an SSH
	// signature handed to VerifyPGPSignature.
	ErrSignatureFormat = errors.New("signature format mismatch")

	// ErrNoMatchingKey is returned when verification was attempted against
	// at least one key ring or authorized_keys input and none of them could
	// verify the signature against the payload.
	ErrNoMatchingKey = errors.New("no matching key")
)

Sentinel errors returned by the verification functions. Callers can use errors.Is to branch on these conditions; errors returned by the verification functions wrap one or more of these as appropriate.

Errors from the underlying sshsig library (e.g. sshsig.ErrPublicKeyMismatch, sshsig.ErrNamespaceMismatch, sshsig.ErrUnsupportedHashAlgorithm) are preserved in the error chain when VerifySSHSignature exhausts all authorized keys without a match, so callers may also branch on those.

Functions

func GetSignatureType

func GetSignatureType(signature string) string

GetSignatureType returns the type of the signature as a string. It returns "openpgp" for PGP signatures, "ssh" for SSH signatures, "x509" for S/MIME signatures, "empty" for an empty signature and "unknown" for unrecognized signatures.

func IsEmptySignature

func IsEmptySignature(signature string) bool

IsEmptySignature tests if the given signature string is empty. It returns true if the signature string has a length of 0.

func IsPGPSignature

func IsPGPSignature(signature string) bool

IsPGPSignature tests if the given signature is of type PGP. It returns true if the signature starts with the PGP signature prefix.

func IsSSHSignature

func IsSSHSignature(signature string) bool

IsSSHSignature tests if the given signature is of type SSH. It returns true if the signature starts with the SSH signature prefix.

func IsX509Signature

func IsX509Signature(signature string) bool

IsX509Signature tests if the given signature is of type x509 (S/MIME). It returns true if the signature starts with the x509 signature prefix.

The signature package does not yet verify x509 signatures; this helper exists so GetSignatureType and the verify functions can report "x509" in their error messages, helping callers distinguish an x509 signature from a corrupt or truly unknown one. Tracked upstream at https://github.com/fluxcd/source-controller/issues/1996.

func ParseAuthorizedKeys

func ParseAuthorizedKeys(authorizedKeys string) ([]gossh.PublicKey, error)

ParseAuthorizedKeys parses the given authorized_keys-formatted string and returns the public keys it contains. Empty lines and lines whose first non-whitespace character is '#' are skipped.

Parsing is fail-fast: if any non-comment line cannot be parsed as an SSH public key the function returns (nil, err), discarding any keys successfully parsed earlier in the input. This is intentional — a malformed entry typically indicates user error and silently dropping it would hide that. Callers that want best-effort behaviour should split the input themselves and call ParseAuthorizedKeys per line.

func VerifyPGPSignature

func VerifyPGPSignature(signature string, payload []byte, keyRings ...string) (string, error)

VerifyPGPSignature verifies the PGP signature against the payload using the provided key rings. It returns the key ID of the key that successfully verified the signature, or an error.

func VerifySSHSignature

func VerifySSHSignature(signature string, payload []byte, authorizedKeys ...string) (string, error)

VerifySSHSignature verifies the SSH signature against the payload using the provided authorized keys. It returns the fingerprint of the key that successfully verified the signature, or an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL