Skip to content

Commit 6957ba9

Browse files
committed
set default key format to openpgp
1 parent 6a29629 commit 6957ba9

File tree

10 files changed

+86
-80
lines changed

10 files changed

+86
-80
lines changed

models/asymkey/key.go

Lines changed: 0 additions & 9 deletions
This file was deleted.

modules/git/key.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package git
5+
6+
const (
7+
// KeyTypeOpenPGP is the key type for GPG keys
8+
KeyTypeOpenPGP = "openpgp"
9+
// KeyTypeSSH is the key type for SSH keys
10+
KeyTypeSSH = "ssh"
11+
)
12+
13+
type SigningKey struct {
14+
KeyID string
15+
Format string
16+
}

modules/git/repo_gpg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// LoadPublicKeyContent will load the key from gpg
1616
func (gpgSettings *GPGSettings) LoadPublicKeyContent() error {
17-
if gpgSettings.Format == "ssh" {
17+
if gpgSettings.Format == KeyTypeOpenPGP {
1818
content, err := os.ReadFile(gpgSettings.KeyID)
1919
if err != nil {
2020
return fmt.Errorf("unable to read SSH public key file: %s, %w", gpgSettings.KeyID, err)
@@ -53,7 +53,7 @@ func (repo *Repository) GetDefaultPublicGPGKey(forceUpdate bool) (*GPGSettings,
5353
signingKey, _, _ := NewCommand("config", "--get", "user.signingkey").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
5454
gpgSettings.KeyID = strings.TrimSpace(signingKey)
5555

56-
format, _, _ := NewCommand("config", "--get", "gpg.format").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
56+
format, _, _ := NewCommand("config", "--default", KeyTypeOpenPGP, "--get", "gpg.format").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
5757
gpgSettings.Format = strings.TrimSpace(format)
5858

5959
defaultEmail, _, _ := NewCommand("config", "--get", "user.email").RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})

modules/setting/repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ var (
255255
SigningKey: "default",
256256
SigningName: "",
257257
SigningEmail: "",
258+
SigningFormat: "openpgp",
258259
InitialCommit: []string{"always"},
259260
CRUDActions: []string{"pubkey", "twofa", "parentsigned"},
260261
Merges: []string{"pubkey", "twofa", "basesigned", "commitssigned"},

routers/api/v1/misc/signing.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99

10+
"code.gitea.io/gitea/modules/git"
1011
asymkey_service "code.gitea.io/gitea/services/asymkey"
1112
"code.gitea.io/gitea/services/context"
1213
)
@@ -56,7 +57,7 @@ func SigningKey(ctx *context.APIContext) {
5657
ctx.APIErrorInternal(err)
5758
return
5859
}
59-
if format == "ssh" {
60+
if format != git.KeyTypeOpenPGP {
6061
ctx.APIErrorNotFound(errors.New("SSH keys are used for signing, not GPG"))
6162
return
6263
}
@@ -111,7 +112,7 @@ func SigningKeySSH(ctx *context.APIContext) {
111112
ctx.APIErrorInternal(err)
112113
return
113114
}
114-
if format != "ssh" {
115+
if format != git.KeyTypeSSH {
115116
ctx.APIErrorNotFound(errors.New("GPG keys are used for signing, not SSH"))
116117
return
117118
}

services/asymkey/commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committer *
414414

415415
defaultReason := asymkey_model.NoKeyFound
416416

417-
if setting.Repository.Signing.SigningFormat == "ssh" && setting.Repository.Signing.SigningKey != "" && setting.Repository.Signing.SigningKey != "default" && setting.Repository.Signing.SigningKey != "none" {
417+
if setting.Repository.Signing.SigningFormat == git.KeyTypeSSH && setting.Repository.Signing.SigningKey != "" && setting.Repository.Signing.SigningKey != "default" && setting.Repository.Signing.SigningKey != "none" {
418418
// OK we should try the default key
419419
gpgSettings := git.GPGSettings{
420420
Sign: true,
@@ -442,7 +442,7 @@ func ParseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committer *
442442
}
443443

444444
defaultGPGSettings, err := c.GetRepositoryDefaultPublicGPGKey(false)
445-
if defaultGPGSettings.Format == "ssh" {
445+
if defaultGPGSettings.Format == git.KeyTypeSSH {
446446
if err != nil {
447447
log.Error("Error getting default public gpg key: %v", err)
448448
} else if defaultGPGSettings == nil {

0 commit comments

Comments
 (0)