mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-28 04:05:49 +00:00
fix(asymkey): do not verify OpenPGP signatures with an SSH instance key, require git 2.18 (#39073)
With SIGNING_FORMAT = ssh the OpenPGP verification path builds its GPGSettings from the instance signing key but leaves the format empty, so it runs `gpg -a --export` on an SSH public key path. Depending on the local gpg setup that either exports nothing, so an OpenPGP signed commit reports gpg.error.generate_hash instead of a missing key, or it fails outright and logs an export error for every such commit. Both guards are needed. The first covers SIGNING_KEY set to a path with SIGNING_FORMAT=ssh; the second covers the shipped default SIGNING_KEY=default, where the format comes from git's own gpg.format and never gets reconciled with the hardcoded "openpgp". Drop either one and a working config goes back to broken. Also raise minimum git version to 2.18 which was already required before this change. Fixes: https://github.com/go-gitea/gitea/issues/37452 Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -19,6 +19,40 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCommitSignSettings(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.Repository.Signing.SigningFormat)()
|
||||
defer test.MockVariableValue(&setting.Repository.Signing.SigningKey, "any-content")()
|
||||
|
||||
t.Run("InstanceSettings", func(t *testing.T) {
|
||||
setting.Repository.Signing.SigningFormat = ""
|
||||
css := getInstanceCommitSignSettings(git.SigningKeyFormatOpenPGP)
|
||||
assert.NotNil(t, css)
|
||||
assert.Equal(t, git.SigningKeyFormatOpenPGP, css.Format)
|
||||
css = getInstanceCommitSignSettings(git.SigningKeyFormatSSH)
|
||||
assert.Nil(t, css)
|
||||
|
||||
setting.Repository.Signing.SigningFormat = git.SigningKeyFormatOpenPGP
|
||||
css = getInstanceCommitSignSettings(git.SigningKeyFormatOpenPGP)
|
||||
assert.NotNil(t, css)
|
||||
assert.Equal(t, git.SigningKeyFormatOpenPGP, css.Format)
|
||||
|
||||
setting.Repository.Signing.SigningFormat = git.SigningKeyFormatSSH
|
||||
css = getInstanceCommitSignSettings(git.SigningKeyFormatSSH)
|
||||
assert.NotNil(t, css)
|
||||
assert.Equal(t, git.SigningKeyFormatSSH, css.Format)
|
||||
css = getInstanceCommitSignSettings(git.SigningKeyFormatOpenPGP)
|
||||
assert.Nil(t, css)
|
||||
})
|
||||
|
||||
t.Run("GitGlobalSettings", func(t *testing.T) {
|
||||
css := git.GlobalCommitSignSettings.Value()
|
||||
assert.False(t, css.Sign)
|
||||
assert.Equal(t, git.SigningKeyFormatOpenPGP, css.Format)
|
||||
css = getGitGlobalCommitSignSettings(git.SigningKeyFormatOpenPGP)
|
||||
assert.Nil(t, css)
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseCommitWithSSHSignature(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user