Skip to content

Commit 8a0bb7c

Browse files
Ensure Subkeys are verified (#12155)
When attempting to verify subkeys the email address verification step requires checking the emails however, these emails are not stored on subkeys but instead on the primary key. This PR will obtain the primaryKey and check against these emails too. Fix #12128 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
1 parent 26e931a commit 8a0bb7c

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

models/gpg_key.go

+41-1
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,18 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *Use
509509
return nil
510510
}
511511
for _, key := range keys {
512+
var primaryKeys []*GPGKey
513+
if key.PrimaryKeyID != "" {
514+
primaryKeys, err = GetGPGKeysByKeyID(key.PrimaryKeyID)
515+
if err != nil {
516+
log.Error("GetGPGKeysByKeyID: %v", err)
517+
return &CommitVerification{
518+
CommittingUser: committer,
519+
Verified: false,
520+
Reason: "gpg.error.failed_retrieval_gpg_keys",
521+
}
522+
}
523+
}
512524
activated := false
513525
if len(email) != 0 {
514526
for _, e := range key.Emails {
@@ -518,6 +530,20 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *Use
518530
break
519531
}
520532
}
533+
if !activated {
534+
for _, pkey := range primaryKeys {
535+
for _, e := range pkey.Emails {
536+
if e.IsActivated && strings.EqualFold(e.Email, email) {
537+
activated = true
538+
email = e.Email
539+
break
540+
}
541+
}
542+
if activated {
543+
break
544+
}
545+
}
546+
}
521547
} else {
522548
for _, e := range key.Emails {
523549
if e.IsActivated {
@@ -526,7 +552,22 @@ func hashAndVerifyForKeyID(sig *packet.Signature, payload string, committer *Use
526552
break
527553
}
528554
}
555+
if !activated {
556+
for _, pkey := range primaryKeys {
557+
for _, e := range pkey.Emails {
558+
if e.IsActivated {
559+
activated = true
560+
email = e.Email
561+
break
562+
}
563+
}
564+
if activated {
565+
break
566+
}
567+
}
568+
}
529569
}
570+
530571
if !activated {
531572
continue
532573
}
@@ -614,7 +655,6 @@ func ParseCommitWithSignature(c *git.Commit) *CommitVerification {
614655
if keyID == "" && sig.IssuerFingerprint != nil && len(sig.IssuerFingerprint) > 0 {
615656
keyID = fmt.Sprintf("%X", sig.IssuerFingerprint[12:20])
616657
}
617-
618658
defaultReason := NoKeyFound
619659

620660
// First check if the sig has a keyID and if so just look at that

0 commit comments

Comments
 (0)