Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions models/asymkey/display_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package asymkey

import (
"os"

"code.gitea.io/gitea/modules/git"
)

func GetDisplaySigningKey(key *git.SigningKey) (string, error) {
if key != nil {
switch key.Format {
case git.SigningKeyFormatOpenPGP:
return key.KeyID, nil
case git.SigningKeyFormatSSH:
content, readErr := os.ReadFile(key.KeyID)
if readErr != nil {
return "", readErr
}
return CalcFingerprint(string(content))
}
}
return "", nil
}
7 changes: 6 additions & 1 deletion routers/web/repo/issue_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"

activities_model "code.gitea.io/gitea/models/activities"
asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
Expand Down Expand Up @@ -494,7 +495,11 @@ func preparePullViewSigning(ctx *context.Context, issue *issues_model.Issue) {
if ctx.Doer != nil {
sign, key, _, err := asymkey_service.SignMerge(ctx, pull, ctx.Doer, pull.BaseRepo.RepoPath(), pull.BaseBranch, pull.GetGitHeadRefName())
ctx.Data["WillSign"] = sign
ctx.Data["SigningKey"] = key
displayKeyID, displayKeyIDErr := asymkey_model.GetDisplaySigningKey(key)
if displayKeyIDErr != nil {
log.Error("Error whilst getting the display keyID: %s", displayKeyIDErr.Error())
}
ctx.Data["SigningKey"] = displayKeyID
if err != nil {
if asymkey_service.IsErrWontSign(err) {
ctx.Data["WontSignReason"] = err.(*asymkey_service.ErrWontSign).Reason
Expand Down
12 changes: 9 additions & 3 deletions services/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path"
"strings"

asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
Expand Down Expand Up @@ -99,7 +100,7 @@ type CommitFormOptions struct {
UserCanPush bool
RequireSigned bool
WillSign bool
SigningKey *git.SigningKey
SigningKey string
WontSignReason string
CanCreatePullRequest bool
CanCreateBasePullRequest bool
Expand Down Expand Up @@ -139,7 +140,7 @@ func PrepareCommitFormOptions(ctx *Context, doer *user_model.User, targetRepo *r
protectionRequireSigned = protectedBranch.RequireSignedCommits
}

willSign, signKeyID, _, err := asymkey_service.SignCRUDAction(ctx, targetRepo.RepoPath(), doer, targetRepo.RepoPath(), refName.String())
willSign, signKey, _, err := asymkey_service.SignCRUDAction(ctx, targetRepo.RepoPath(), doer, targetRepo.RepoPath(), refName.String())
wontSignReason := ""
if asymkey_service.IsErrWontSign(err) {
wontSignReason = string(err.(*asymkey_service.ErrWontSign).Reason)
Expand All @@ -155,14 +156,19 @@ func PrepareCommitFormOptions(ctx *Context, doer *user_model.User, targetRepo *r
canCreateBasePullRequest := targetRepo.BaseRepo != nil && targetRepo.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests)
canCreatePullRequest := targetRepo.UnitEnabled(ctx, unit_model.TypePullRequests) || canCreateBasePullRequest

displayKeyID, displayKeyIDErr := asymkey_model.GetDisplaySigningKey(signKey)
if displayKeyIDErr != nil {
log.Error("Error whilst getting the display keyID: %s", displayKeyIDErr.Error())
}

opts := &CommitFormOptions{
TargetRepo: targetRepo,
WillSubmitToFork: submitToForkedRepo,
CanCommitToBranch: canCommitToBranch,
UserCanPush: canPushWithProtection,
RequireSigned: protectionRequireSigned,
WillSign: willSign,
SigningKey: signKeyID,
SigningKey: displayKeyID,
WontSignReason: wontSignReason,

CanCreatePullRequest: canCreatePullRequest,
Expand Down