Documentation
¶
Index ¶
- Constants
- Variables
- func AddPublicKeysBySource(ctx context.Context, usr *user_model.User, s *auth.Source, ...) bool
- func AuthorizedStringForKey(key *PublicKey) (string, error)
- func Base64EncPubKey(pubkey *packet.PublicKey) (string, error)
- func CalcFingerprint(publicKeyContent string) (string, error)
- func CalculateTrustStatus(verification *CommitVerification, repoTrustModel repo_model.TrustModelType, ...) error
- func CheckArmoredGPGKeyString(content string) (openpgp.EntityList, error)
- func CheckPrincipalKeyString(ctx context.Context, user *user_model.User, content string) (_ string, err error)
- func CheckPublicKeyString(content string) (_ string, err error)
- func DeleteGPGKey(ctx context.Context, doer *user_model.User, id int64) (err error)
- func ExtractSignature(s string) (*packet.Signature, error)
- func GPGKeyToEntity(ctx context.Context, k *GPGKey) (*openpgp.Entity, error)
- func GetDisplaySigningKey(key *git.SigningKey) string
- func HasDeployKey(ctx context.Context, keyID, repoID int64) bool
- func IsDeployKeyExistByKeyID(ctx context.Context, keyID int64) (bool, error)
- func IsErrDeployKeyAlreadyExist(err error) bool
- func IsErrDeployKeyNameAlreadyUsed(err error) bool
- func IsErrDeployKeyNotExist(err error) bool
- func IsErrGPGInvalidTokenSignature(err error) bool
- func IsErrGPGKeyAccessDenied(err error) bool
- func IsErrGPGKeyIDAlreadyUsed(err error) bool
- func IsErrGPGKeyImportNotExist(err error) bool
- func IsErrGPGKeyNotExist(err error) bool
- func IsErrGPGKeyParsing(err error) bool
- func IsErrGPGNoEmailFound(err error) bool
- func IsErrKeyAccessDenied(err error) bool
- func IsErrKeyAlreadyExist(err error) bool
- func IsErrKeyNameAlreadyUsed(err error) bool
- func IsErrKeyNotExist(err error) bool
- func IsErrKeyUnableVerify(err error) bool
- func IsErrSSHInvalidTokenSignature(err error) bool
- func PaddedKeyID(keyID string) string
- func PublicKeyIsExternallyManaged(ctx context.Context, id int64) (bool, error)
- func PublicKeysAreExternallyManaged(ctx context.Context, keys []*PublicKey) ([]bool, error)
- func RegeneratePublicKeys(ctx context.Context, t io.Writer) error
- func SSHNativeParsePublicKey(keyLine string) (string, int, error)
- func SynchronizePublicKeys(ctx context.Context, usr *user_model.User, s *auth.Source, ...) bool
- func TryGetKeyIDFromSignature(sig *packet.Signature) string
- func UpdateDeployKeyCols(ctx context.Context, key *DeployKey, cols ...string) error
- func UpdatePublicKeyUpdated(ctx context.Context, id int64) error
- func VerificationToken(user *user_model.User, minutes int) string
- func VerifyGPGKey(ctx context.Context, ownerID int64, keyID, token, signature string) (string, error)
- func VerifySSHKey(ctx context.Context, ownerID int64, fingerprint, token, signature string) (string, error)
- func WithSSHOpLocker(f func() error) error
- func WriteAuthorizedStringForValidKey(key *PublicKey, w io.Writer) error
- type CommitVerification
- type DeployKey
- type ErrDeployKeyAlreadyExist
- type ErrDeployKeyNameAlreadyUsed
- type ErrDeployKeyNotExist
- type ErrGPGInvalidTokenSignature
- type ErrGPGKeyAccessDenied
- type ErrGPGKeyIDAlreadyUsed
- type ErrGPGKeyImportNotExist
- type ErrGPGKeyNotExist
- type ErrGPGKeyParsing
- type ErrGPGNoEmailFound
- type ErrKeyAccessDenied
- type ErrKeyAlreadyExist
- type ErrKeyNameAlreadyUsed
- type ErrKeyNotExist
- type ErrKeyUnableVerify
- type ErrSSHInvalidTokenSignature
- type FindGPGKeyOptions
- type FindPublicKeyOptions
- type GPGKey
- type GPGKeyImport
- type GPGKeyList
- type KeyType
- type ListDeployKeysOptions
- type PublicKey
- func AddPublicKey(ctx context.Context, ownerID int64, name, content string, authSourceID int64, ...) (*PublicKey, error)
- func GetPublicKeyByID(ctx context.Context, keyID int64) (*PublicKey, error)
- func SearchPublicKeyByContent(ctx context.Context, content string) (*PublicKey, error)
- func SearchPublicKeyByContentExact(ctx context.Context, content string) (*PublicKey, error)
- type SignCommit
Constants ¶
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" )
const ( // KeyTypeUser specifies the user key KeyTypeUser = iota + 1 // KeyTypeDeploy specifies the deploy key KeyTypeDeploy // KeyTypePrincipal specifies the authorized principal key KeyTypePrincipal )
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 ¶
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 ¶
AuthorizedStringForKey creates the authorized keys string appropriate for the provided key
func Base64EncPubKey ¶
Base64EncPubKey encode public key content to base 64
func CalcFingerprint ¶
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 ¶
CheckPublicKeyString checks if the given public key string is recognized by SSH. It returns the actual public key line on success.
func DeleteGPGKey ¶
DeleteGPGKey deletes GPG key information in database.
func GPGKeyToEntity ¶
GPGKeyToEntity retrieve the imported key and the traducted entity
func GetDisplaySigningKey ¶
func GetDisplaySigningKey(key *git.SigningKey) string
func HasDeployKey ¶
HasDeployKey returns true if public key is a deploy key of given repository.
func IsDeployKeyExistByKeyID ¶
IsDeployKeyExistByKeyID return true if there is at least one deploykey with the key id
func IsErrDeployKeyAlreadyExist ¶
IsErrDeployKeyAlreadyExist checks if an error is a ErrDeployKeyAlreadyExist.
func IsErrDeployKeyNameAlreadyUsed ¶
IsErrDeployKeyNameAlreadyUsed checks if an error is a ErrDeployKeyNameAlreadyUsed.
func IsErrDeployKeyNotExist ¶
IsErrDeployKeyNotExist checks if an error is a ErrDeployKeyNotExist.
func IsErrGPGInvalidTokenSignature ¶
IsErrGPGInvalidTokenSignature checks if an error is a ErrGPGInvalidTokenSignature.
func IsErrGPGKeyAccessDenied ¶
IsErrGPGKeyAccessDenied checks if an error is a ErrGPGKeyAccessDenied.
func IsErrGPGKeyIDAlreadyUsed ¶
IsErrGPGKeyIDAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
func IsErrGPGKeyImportNotExist ¶
IsErrGPGKeyImportNotExist checks if an error is a ErrGPGKeyImportNotExist.
func IsErrGPGKeyNotExist ¶
IsErrGPGKeyNotExist checks if an error is a ErrGPGKeyNotExist.
func IsErrGPGKeyParsing ¶
IsErrGPGKeyParsing checks if an error is a ErrGPGKeyParsing.
func IsErrGPGNoEmailFound ¶
IsErrGPGNoEmailFound checks if an error is a ErrGPGNoEmailFound.
func IsErrKeyAccessDenied ¶
IsErrKeyAccessDenied checks if an error is a ErrKeyAccessDenied.
func IsErrKeyAlreadyExist ¶
IsErrKeyAlreadyExist checks if an error is a ErrKeyAlreadyExist.
func IsErrKeyNameAlreadyUsed ¶
IsErrKeyNameAlreadyUsed checks if an error is a ErrKeyNameAlreadyUsed.
func IsErrKeyNotExist ¶
IsErrKeyNotExist checks if an error is a ErrKeyNotExist.
func IsErrKeyUnableVerify ¶
IsErrKeyUnableVerify checks if an error is a ErrKeyUnableVerify.
func IsErrSSHInvalidTokenSignature ¶
IsErrSSHInvalidTokenSignature checks if an error is a ErrSSHInvalidTokenSignature.
func PaddedKeyID ¶
PaddedKeyID show KeyID padded to 16 characters
func PublicKeyIsExternallyManaged ¶
PublicKeyIsExternallyManaged returns whether the provided KeyID represents an externally managed Key
func PublicKeysAreExternallyManaged ¶
PublicKeysAreExternallyManaged returns whether the provided KeyID represents an externally managed Key
func RegeneratePublicKeys ¶
RegeneratePublicKeys regenerates the authorized_keys file
func SSHNativeParsePublicKey ¶
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 UpdateDeployKeyCols ¶
UpdateDeployKeyCols updates deploy key information in the specified columns.
func UpdatePublicKeyUpdated ¶
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
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