Skip to content

Commit c8a1d05

Browse files
authored
Merge branch 'main' into fix-submodule-relpath
2 parents 5c363af + 7cc47da commit c8a1d05

File tree

18 files changed

+165
-270
lines changed

18 files changed

+165
-270
lines changed

models/asymkey/ssh_key_fingerprint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"xorm.io/builder"
1414
)
1515

16-
// The database is used in checkKeyFingerprint however most of these functions probably belong in a module
16+
// The database is used in checkKeyFingerprint. However, most of these functions probably belong in a module
1717

18-
// checkKeyFingerprint only checks if key fingerprint has been used as public key,
18+
// checkKeyFingerprint only checks if key fingerprint has been used as a public key,
1919
// it is OK to use same key as deploy key for multiple repositories/users.
2020
func checkKeyFingerprint(ctx context.Context, fingerprint string) error {
2121
has, err := db.Exist[PublicKey](ctx, builder.Eq{"fingerprint": fingerprint})

models/fixtures/public_key.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
created_unix: 1559593109
1010
updated_unix: 1565224552
1111
login_source_id: 0
12+
verified: false

services/asymkey/commit.go

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ func ParseCommitWithSignature(ctx context.Context, c *git.Commit) *asymkey_model
3636
}
3737

3838
// ParseCommitWithSignatureCommitter parses a commit's GPG or SSH signature.
39+
// The caller guarantees that the committer user is related to the commit by checking its activated email addresses or no-reply address.
3940
// If the commit is singed by an instance key, then committer can be nil.
40-
// If the signature exists, even if committer is nil, the returned CommittingUser will be a non-nil fake user.
41+
// If the signature exists, even if committer is nil, the returned CommittingUser will be a non-nil fake user (e.g.: instance key)
4142
func ParseCommitWithSignatureCommitter(ctx context.Context, c *git.Commit, committer *user_model.User) *asymkey_model.CommitVerification {
4243
// If no signature, just report the committer
4344
if c.Signature == nil {
@@ -114,20 +115,11 @@ func parseCommitWithGPGSignature(ctx context.Context, c *git.Commit, committer *
114115
}
115116
}
116117

117-
committerEmailAddresses, _ := cache.GetWithContextCache(ctx, cachegroup.UserEmailAddresses, committer.ID, user_model.GetEmailAddresses)
118-
activated := false
119-
for _, e := range committerEmailAddresses {
120-
if e.IsActivated && strings.EqualFold(e.Email, c.Committer.Email) {
121-
activated = true
122-
break
123-
}
124-
}
125-
126118
for _, k := range keys {
127119
// Pre-check (& optimization) that emails attached to key can be attached to the committer email and can validate
128120
canValidate := false
129121
email := ""
130-
if k.Verified && activated {
122+
if k.Verified {
131123
canValidate = true
132124
email = c.Committer.Email
133125
}
@@ -217,8 +209,8 @@ func checkKeyEmails(ctx context.Context, email string, keys ...*asymkey_model.GP
217209
return true, e.Email
218210
}
219211
}
220-
if user.KeepEmailPrivate && strings.EqualFold(email, user.GetEmail()) {
221-
return true, user.GetEmail()
212+
if user != nil && strings.EqualFold(email, user.GetPlaceholderEmail()) {
213+
return true, user.GetPlaceholderEmail()
222214
}
223215
}
224216
}
@@ -388,21 +380,8 @@ func parseCommitWithSSHSignature(ctx context.Context, c *git.Commit, committerUs
388380
}
389381
}
390382

391-
committerEmailAddresses, err := cache.GetWithContextCache(ctx, cachegroup.UserEmailAddresses, committerUser.ID, user_model.GetEmailAddresses)
392-
if err != nil {
393-
log.Error("GetEmailAddresses: %v", err)
394-
}
395-
396-
activated := false
397-
for _, e := range committerEmailAddresses {
398-
if e.IsActivated && strings.EqualFold(e.Email, c.Committer.Email) {
399-
activated = true
400-
break
401-
}
402-
}
403-
404383
for _, k := range keys {
405-
if k.Verified && activated {
384+
if k.Verified {
406385
commitVerification := verifySSHCommitVerification(c.Signature.Signature, c.Signature.Payload, k, committerUser, committerUser, c.Committer.Email)
407386
if commitVerification != nil {
408387
return commitVerification

services/asymkey/commit_test.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"strings"
88
"testing"
99

10+
asymkey_model "code.gitea.io/gitea/models/asymkey"
11+
"code.gitea.io/gitea/models/db"
12+
"code.gitea.io/gitea/models/unittest"
1013
user_model "code.gitea.io/gitea/models/user"
1114
"code.gitea.io/gitea/modules/git"
1215
"code.gitea.io/gitea/modules/setting"
@@ -17,7 +20,49 @@ import (
1720
)
1821

1922
func TestParseCommitWithSSHSignature(t *testing.T) {
20-
// Here we only test the TrustedSSHKeys. The complete signing test is in tests/integration/gpg_ssh_git_test.go
23+
assert.NoError(t, unittest.PrepareTestDatabase())
24+
25+
// Here we only need to do some tests that "tests/integration/gpg_ssh_git_test.go" doesn't cover
26+
27+
// -----BEGIN OPENSSH PRIVATE KEY-----
28+
// b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
29+
// QyNTUxOQAAACC6T6zF0oPak8dOIzzT1kXB7LrcsVo04SKc3GjuvMllZwAAAJgy08upMtPL
30+
// qQAAAAtzc2gtZWQyNTUxOQAAACC6T6zF0oPak8dOIzzT1kXB7LrcsVo04SKc3GjuvMllZw
31+
// AAAEDWqPHTH51xb4hy1y1f1VeWL/2A9Q0b6atOyv5fx8x5prpPrMXSg9qTx04jPNPWRcHs
32+
// utyxWjThIpzcaO68yWVnAAAAEXVzZXIyQGV4YW1wbGUuY29tAQIDBA==
33+
// -----END OPENSSH PRIVATE KEY-----
34+
sshPubKey, err := asymkey_model.AddPublicKey(t.Context(), 999, "user-ssh-key-any-name", "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILpPrMXSg9qTx04jPNPWRcHsutyxWjThIpzcaO68yWVn", 0)
35+
require.NoError(t, err)
36+
_, err = db.GetEngine(t.Context()).ID(sshPubKey.ID).Cols("verified").Update(&asymkey_model.PublicKey{Verified: true})
37+
require.NoError(t, err)
38+
39+
t.Run("UserSSHKey", func(t *testing.T) {
40+
commit, err := git.CommitFromReader(nil, git.Sha1ObjectFormat.EmptyObjectID(), strings.NewReader(`tree a3b1fad553e0f9a2b4a58327bebde36c7da75aa2
41+
author user2 <[email protected]> 1752194028 -0700
42+
committer user2 <[email protected]> 1752194028 -0700
43+
gpgsig -----BEGIN SSH SIGNATURE-----
44+
U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAguk+sxdKD2pPHTiM809ZFwey63L
45+
FaNOEinNxo7rzJZWcAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5
46+
AAAAQBfX+6mcKZBnXckwHcBFqRuXMD3vTKi1yv5wgrqIxTyr2LWB97xxmO92cvjsr0POQ2
47+
2YA7mQS510Cg2s1uU1XAk=
48+
-----END SSH SIGNATURE-----
49+
50+
init project
51+
`))
52+
require.NoError(t, err)
53+
54+
// the committingUser is guaranteed by the caller, parseCommitWithSSHSignature doesn't do any more checks
55+
committingUser := &user_model.User{ID: 999, Name: "user-x"}
56+
ret := parseCommitWithSSHSignature(t.Context(), commit, committingUser)
57+
require.NotNil(t, ret)
58+
assert.True(t, ret.Verified)
59+
assert.Equal(t, committingUser.Name+" / "+sshPubKey.Fingerprint, ret.Reason)
60+
assert.False(t, ret.Warning)
61+
assert.Equal(t, committingUser, ret.SigningUser)
62+
assert.Equal(t, committingUser, ret.CommittingUser)
63+
assert.Equal(t, sshPubKey.ID, ret.SigningSSHKey.ID)
64+
})
65+
2166
t.Run("TrustedSSHKey", func(t *testing.T) {
2267
defer test.MockVariableValue(&setting.Repository.Signing.SigningName, "gitea")()
2368
defer test.MockVariableValue(&setting.Repository.Signing.SigningEmail, "[email protected]")()

templates/repo/commits_list_small.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<button class="ui button ellipsis-button show-panel toggle" data-panel="[data-singular-commit-body-for='{{$tag}}']">...</button>
2323
{{end}}
2424

25-
<span class="tw-flex tw-items-center tw-gap-2">
25+
<span class="flex-text-block">
2626
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
2727
{{template "repo/commit_sign_badge" dict "Commit" . "CommitBaseLink" $commitBaseLink "CommitSignVerification" .Verification}}
2828
</span>

templates/repo/diff/comments.tmpl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
{{$createdStr:= DateUtils.TimeSince .CreatedUnix}}
44
<div class="comment" id="{{.HashTag}}">
5-
{{if .OriginalAuthor}}
6-
<span class="avatar">{{ctx.AvatarUtils.Avatar nil}}</span>
7-
{{else}}
8-
{{template "shared/user/avatarlink" dict "user" .Poster}}
9-
{{end}}
5+
<div class="tw-mt-2 tw-mr-4">
6+
{{if .OriginalAuthor}}
7+
<span class="avatar">{{ctx.AvatarUtils.Avatar nil}}</span>
8+
{{else}}
9+
{{template "shared/user/avatarlink" dict "user" .Poster}}
10+
{{end}}
11+
</div>
1012
<div class="content comment-container">
11-
<div class="comment-header">
13+
<div class="comment-header avatar-content-left-arrow">
1214
<div class="comment-header-left">
1315
{{if .OriginalAuthor}}
1416
<span class="text black tw-font-semibold tw-mr-1">

templates/repo/editor/commit_form.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="commit-form-wrapper">
22
{{ctx.AvatarUtils.Avatar .SignedUser 40 "commit-avatar"}}
3-
<div class="commit-form">
3+
<div class="commit-form avatar-content-left-arrow">
44
<h3>{{- if .CommitFormOptions.WillSign}}
55
<span title="{{ctx.Locale.Tr "repo.signing.will_sign" .CommitFormOptions.SigningKey}}">{{svg "octicon-lock" 24}}</span>
66
{{ctx.Locale.Tr "repo.editor.commit_signed_changes"}}

templates/repo/issue/new_form.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<div class="issue-content-left">
55
<div class="ui comments">
66
<div class="comment">
7-
{{ctx.AvatarUtils.Avatar .SignedUser 40}}
8-
<div class="ui segment content tw-my-0">
7+
<div class=" tw-mr-4 not-mobile">{{ctx.AvatarUtils.Avatar .SignedUser 40}}</div>
8+
<div class="ui segment content tw-my-0 avatar-content-left-arrow">
99
<div class="field">
1010
<input name="title" data-global-init="initInputAutoFocusEnd" id="issue_title" required maxlength="255" autocomplete="off"
1111
placeholder="{{ctx.Locale.Tr "repo.milestones.title"}}"

templates/repo/issue/view_content.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</a>
1414
{{end}}
1515
<div class="content comment-container">
16-
<div class="comment-header" role="heading" aria-level="3">
16+
<div class="comment-header avatar-content-left-arrow" role="heading" aria-level="3">
1717
<div class="comment-header-left">
1818
{{if .Issue.OriginalAuthor}}
1919
<span class="text black tw-font-semibold">
@@ -78,7 +78,7 @@
7878
{{ctx.AvatarUtils.Avatar .SignedUser 40}}
7979
</a>
8080
<div class="content">
81-
<div class="ui segment">
81+
<div class="ui segment avatar-content-left-arrow">
8282
<form class="ui form form-fetch-action" id="comment-form" action="{{$.RepoLink}}/issues/{{.Issue.Index}}/comments" method="post">
8383
{{template "repo/issue/comment_tab" .}}
8484
{{.CsrfTokenHtml}}

0 commit comments

Comments
 (0)