asymkey

package
v3.1.22 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BadSignature is used as the reason when the signature has a KeyID that is in the db
	// but no key that has that ID verifies the signature. This is a suspicious failure.
	BadSignature = "gpg.error.probable_bad_signature"
	// BadDefaultSignature is used as the reason when the signature has a KeyID that matches the
	// default Key but is not verified by the default key. This is a suspicious failure.
	BadDefaultSignature = "gpg.error.probable_bad_default_signature"
	// NoKeyFound is used as the reason when no key can be found to verify the signature.
	NoKeyFound = "gpg.error.no_gpg_keys_found"
)
View Source
const (
	// KeyTypeUser specifies the user key
	KeyTypeUser = iota + 1
	// KeyTypeDeploy specifies the deploy key
	KeyTypeDeploy
	// KeyTypePrincipal specifies the authorized principal key
	KeyTypePrincipal
)
View Source
const AuthorizedStringCommentPrefix = `# gitea public key`

AuthorizedStringCommentPrefix is a magic tag some functions like RegeneratePublicKeys needs this tag to skip the keys generated by Gitea, while keep other keys

Variables

View Source
var ErrKeyIsPrivate = util.ErrorWrap(util.ErrInvalidArgument, "the provided key is a private key")

ErrKeyIsPrivate is returned when the provided key is a private key not a public key

Functions

func AddPublicKeysBySource

func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string, verified bool) bool

AddPublicKeysBySource add a users public keys. Returns true if there are changes.

func AuthorizedStringForKey

func AuthorizedStringForKey(key *PublicKey) (string, error)

AuthorizedStringForKey creates the authorized keys string appropriate for the provided key

func Base64EncPubKey

func Base64EncPubKey(pubkey *packet.PublicKey) (string, error)

Base64EncPubKey encode public key content to base 64

func CalcFingerprint

func CalcFingerprint(publicKeyContent string) (string, error)

CalcFingerprint calculate public key's fingerprint

func CalculateTrustStatus

func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_model.TrustModelType, isOwnerMemberCollaborator func(*user_model.User) (bool, error), keyMap *map[string]bool) error

CalculateTrustStatus will calculate the TrustStatus for a commit verification within a repository There are several trust models in Gitea

func CheckArmoredGPGKeyString

func CheckArmoredGPGKeyString(content string) (openpgp.EntityList, error)

CheckArmoredGPGKeyString checks if the given key string is a valid GPG armored key. The function returns the actual public key on success

func CheckPrincipalKeyString

func CheckPrincipalKeyString(ctx context.Context, user *user_model.User, content string) (_ string, err error)

CheckPrincipalKeyString strips spaces and returns an error if the given principal contains newlines

func CheckPublicKeyString

func CheckPublicKeyString(content string) (_ string, err error)

CheckPublicKeyString checks if the given public key string is recognized by SSH. It returns the actual public key line on success.

func DeleteGPGKey

func DeleteGPGKey(ctx context.Context, doer *user_model.User, id int64) (err error)

DeleteGPGKey deletes GPG key information in database.

func ExtractSignature

func ExtractSignature(s string) (*packet.Signature, error)

func GPGKeyToEntity

func GPGKeyToEntity(ctx context.Context, k *GPGKey) (*openpgp.Entity, error)

GPGKeyToEntity retrieve the imported key and the traducted entity

func GetDisplaySigningKey

func GetDisplaySigningKey(key *git.SigningKey) string

func HasDeployKey

func HasDeployKey(ctx context.Context, keyID, repoID int64) bool

HasDeployKey returns true if public key is a deploy key of given repository.

func IsDeployKeyExistByKeyID

func IsDeployKeyExistByKeyID(ctx context.Context, keyID int64) (bool, error)

IsDeployKeyExistByKeyID return true if there is at least one deploykey with the key id

func IsErrDeployKeyAlreadyExist

func IsErrDeployKeyAlreadyExist(err error) bool

IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.

func IsErrDeployKeyNameAlreadyUsed

func IsErrDeployKeyNameAlreadyUsed(err error) bool

IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.

func IsErrDeployKeyNotExist

func IsErrDeployKeyNotExist(err error) bool

IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.

func IsErrGPGInvalidTokenSignature

func IsErrGPGInvalidTokenSignature(err error) bool

IsErrGPGInvalidTokenSignature checks if an error is a ErrGPGInvalidTokenSignature.

func IsErrGPGKeyAccessDenied

func IsErrGPGKeyAccessDenied(err error) bool

IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.

func IsErrGPGKeyIDAlreadyUsed

func IsErrGPGKeyIDAlreadyUsed(err error) bool

IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.

func IsErrGPGKeyImportNotExist

func IsErrGPGKeyImportNotExist(err error) bool

IsErrGPGKeyImportNotExist checks if an error is a ErrGPGKeyImportNotExist.

func IsErrGPGKeyNotExist

func IsErrGPGKeyNotExist(err error) bool

IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.

func IsErrGPGKeyParsing

func IsErrGPGKeyParsing(err error) bool

IsErrGPGKeyParsing checks if an error is a ErrGPGKeyParsing.

func IsErrGPGNoEmailFound

func IsErrGPGNoEmailFound(err error) bool

IsErrGPGNoEmailFound checks if an error is a ErrGPGNoEmailFound.

func IsErrKeyAccessDenied

func IsErrKeyAccessDenied(err error) bool

IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.

func IsErrKeyAlreadyExist

func IsErrKeyAlreadyExist(err error) bool

IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.

func IsErrKeyNameAlreadyUsed

func IsErrKeyNameAlreadyUsed(err error) bool

IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.

func IsErrKeyNotExist

func IsErrKeyNotExist(err error) bool

IsErrKeyNotExist checks if an error is a ErrKeyNotExist.

func IsErrKeyUnableVerify

func IsErrKeyUnableVerify(err error) bool

IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.

func IsErrSSHInvalidTokenSignature

func IsErrSSHInvalidTokenSignature(err error) bool

IsErrSSHInvalidTokenSignature checks if an error is a ErrSSHInvalidTokenSignature.

func PaddedKeyID

func PaddedKeyID(keyID string) string

PaddedKeyID show KeyID padded to 16 characters

func PublicKeyIsExternallyManaged

func PublicKeyIsExternallyManaged(ctx context.Context, id int64) (bool, error)

PublicKeyIsExternallyManaged returns whether the provided KeyID represents an externally managed Key

func PublicKeysAreExternallyManaged

func PublicKeysAreExternallyManaged(ctx context.Context, keys []*PublicKey) ([]bool, error)

PublicKeysAreExternallyManaged returns whether the provided KeyID represents an externally managed Key

func RegeneratePublicKeys

func RegeneratePublicKeys(ctx context.Context, t io.Writer) error

RegeneratePublicKeys regenerates the authorized_keys file

func SSHNativeParsePublicKey

func SSHNativeParsePublicKey(keyLine string) (string, int, error)

SSHNativeParsePublicKey extracts the key type and length using the golang SSH library.

func SynchronizePublicKeys

func SynchronizePublicKeys(ctx context.Context, usr *user_model.User, s *auth.Source, sshPublicKeys []string, verified bool) bool

SynchronizePublicKeys updates a user's public keys. Returns true if there are changes.

func TryGetKeyIDFromSignature

func TryGetKeyIDFromSignature(sig *packet.Signature) string

func UpdateDeployKeyCols

func UpdateDeployKeyCols(ctx context.Context, key *DeployKey, cols ...string) error

UpdateDeployKeyCols updates deploy key information in the specified columns.

func UpdatePublicKeyUpdated

func UpdatePublicKeyUpdated(ctx context.Context, id int64) error

UpdatePublicKeyUpdated updates public key use time.

func VerificationToken

func VerificationToken(user *user_model.User, minutes int) string

VerificationToken returns token for the user that will be valid in minutes (time)

func VerifyGPGKey

func VerifyGPGKey(ctx context.Context, ownerID int64, keyID, token, signature string) (string, error)

VerifyGPGKey marks a GPG key as verified

func VerifySSHKey

func VerifySSHKey(ctx context.Context, ownerID int64, fingerprint, token, signature string) (string, error)

VerifySSHKey marks a SSH key as verified

func WithSSHOpLocker

func WithSSHOpLocker(f func() error) error

func WriteAuthorizedStringForValidKey

func WriteAuthorizedStringForValidKey(key *PublicKey, w io.Writer) error

WriteAuthorizedStringForValidKey writes the authorized key for the provided key. If the key is invalid, it does nothing.

Types

type CommitVerification

type CommitVerification struct {
	Verified       bool
	Warning        bool
	Reason         string
	SigningUser    *user_model.User // if Verified, then SigningUser is non-nil
	CommittingUser *user_model.User // if Verified, then CommittingUser is non-nil
	SigningEmail   string
	SigningKey     *GPGKey // FIXME: need to refactor it to a new name like "SigningGPGKey", it is also used in some templates
	SigningSSHKey  *PublicKey
	TrustStatus    string
}

CommitVerification represents a commit validation of signature

func HashAndVerifyWithSubKeysCommitVerification

func HashAndVerifyWithSubKeysCommitVerification(sig *packet.Signature, payload string, k *GPGKey, committer, signer *user_model.User, email string) *CommitVerification

type DeployKey

type DeployKey struct {
	ID          int64 `xorm:"pk autoincr"`
	KeyID       int64 `xorm:"UNIQUE(s) INDEX"`
	RepoID      int64 `xorm:"UNIQUE(s) INDEX"`
	Name        string
	Fingerprint string
	Content     string `xorm:"-"`

	Mode perm.AccessMode `xorm:"NOT NULL DEFAULT 1"`