-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add support for ssh commit signing #17743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
8d38285
Add support for ssh commit signing
42wim 9b1182b
Split out ssh verification to separate file
42wim 9f113c3
Show ssh key fingerprint on commit page
42wim af5fc14
Update sshsig lib
42wim 7b6b1a1
Make sure we verify against correct namespace
42wim 741ad05
Add ssh public key verification via ssh signatures
42wim bea996d
Remove some gpg references and make verify key optional
42wim 5439269
Fix spaces indentation
42wim 2d0bdf0
Update options/locale/locale_en-US.ini
42wim fd91370
Update templates/user/settings/keys_ssh.tmpl
42wim 543c972
Update options/locale/locale_en-US.ini
42wim 4ab202f
Update options/locale/locale_en-US.ini
42wim 1172df7
Update models/ssh_key_commit_verification.go
42wim 496b0aa
Reword ssh/gpg_key_success message
42wim d216536
Merge branch 'main' into ssh-sign
42wim b02effc
Change Badsignature to NoKeyFound
42wim 378f119
Merge branch 'main' into ssh-sign
42wim 670cc92
Add sign/verify tests
42wim 2ccc73d
Merge branch 'main' into ssh-sign
42wim fcf0178
Fix upstream api changes to user_model User
42wim aa5074b
Merge branch 'main' into ssh-sign
wxiaoguang 3b406a3
Match exact on SSH signature
42wim bf66261
Merge branch 'main' into ssh-sign
42wim 72a8d09
Fix code review remarks
42wim 4b22267
Merge branch 'main' into ssh-sign
42wim 882a980
Merge branch 'main' into ssh-sign
lunny 9da693f
Merge branch 'main' into ssh-sign
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package asymkey | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
user_model "code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/log" | ||
|
||
"github.com/42wim/sshsig" | ||
) | ||
|
||
// ParseCommitWithSSHSignature check if signature is good against keystore. | ||
func ParseCommitWithSSHSignature(c *git.Commit, committer *user_model.User) *CommitVerification { | ||
// Now try to associate the signature with the committer, if present | ||
if committer.ID != 0 { | ||
keys, err := ListPublicKeys(committer.ID, db.ListOptions{}) | ||
if err != nil { // Skipping failed to get ssh keys of user | ||
log.Error("ListPublicKeys: %v", err) | ||
return &CommitVerification{ | ||
CommittingUser: committer, | ||
Verified: false, | ||
Reason: "gpg.error.failed_retrieval_gpg_keys", | ||
} | ||
} | ||
|
||
committerEmailAddresses, err := user_model.GetEmailAddresses(committer.ID) | ||
if err != nil { | ||
log.Error("GetEmailAddresses: %v", err) | ||
} | ||
|
||
activated := false | ||
for _, e := range committerEmailAddresses { | ||
if e.IsActivated && strings.EqualFold(e.Email, c.Committer.Email) { | ||
activated = true | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
break | ||
} | ||
} | ||
|
||
for _, k := range keys { | ||
if k.Verified && activated { | ||
commitVerification := verifySSHCommitVerification(c.Signature.Signature, c.Signature.Payload, k, committer, committer, c.Committer.Email) | ||
if commitVerification != nil { | ||
return commitVerification | ||
} | ||
} | ||
} | ||
} | ||
|
||
return &CommitVerification{ | ||
CommittingUser: committer, | ||
Verified: false, | ||
Reason: NoKeyFound, | ||
} | ||
} | ||
|
||
func verifySSHCommitVerification(sig, payload string, k *PublicKey, committer, signer *user_model.User, email string) *CommitVerification { | ||
if err := sshsig.Verify(bytes.NewBuffer([]byte(payload)), []byte(sig), []byte(k.Content), "git"); err != nil { | ||
return nil | ||
} | ||
|
||
return &CommitVerification{ // Everything is ok | ||
CommittingUser: committer, | ||
Verified: true, | ||
Reason: fmt.Sprintf("%s / %s", signer.Name, k.Fingerprint), | ||
SigningUser: signer, | ||
SigningSSHKey: k, | ||
SigningEmail: email, | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.