Skip to content
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

SSH signatures support #504

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 26 additions & 1 deletion policy/predicate/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestHasValidSignatures(t *testing.T) {

testCases := []SignatureTestCase{
{
"ValidSignature",
"ValidGpgSignature",
&pulltest.Context{
AuthorValue: "mhaypenny",
CommitsValue: []*pull.Commit{
Expand All @@ -54,6 +54,31 @@ func TestHasValidSignatures(t *testing.T) {
ConditionValues: []string{"valid signatures"},
},
},
{
"ValidSshSignature",
&pulltest.Context{
AuthorValue: "mhaypenny",
CommitsValue: []*pull.Commit{
{
SHA: "abcdef123456789",
Author: "mhaypenny",
Committer: "mhaypenny",
Signature: &pull.Signature{
Type: pull.SignatureSSH,
IsValid: true,
Signer: "ttest",
State: "VALID",
KeyFingerprint: "Hello",
},
},
},
},
&common.PredicateResult{
Satisfied: true,
Values: []string{"abcdef123456789"},
ConditionValues: []string{"valid signatures"},
},
},
{
"InvalidSignature",
&pulltest.Context{
Expand Down
12 changes: 7 additions & 5 deletions pull/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,16 @@ type SignatureType string
const (
SignatureGpg SignatureType = "GpgSignature"
SignatureSmime SignatureType = "SmimeSignature"
SignatureSSH SignatureType = "SshSignature"
)

type Signature struct {
Type SignatureType
IsValid bool
KeyID string
Signer string
State string
Type SignatureType
IsValid bool
KeyID string
KeyFingerprint string
Signer string
State string
}

type Comment struct {
Expand Down
20 changes: 20 additions & 0 deletions pull/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ type v4GitSignature struct {
Type string `graphql:"__typename"`
GPG v4GpgSignature `graphql:"... on GpgSignature"`
SMIME v4SmimeSignature `graphql:"... on SmimeSignature"`
SSH v4SshSignature `graphql:"... on SshSignature"`
}

func (s *v4GitSignature) ToSignature() *Signature {
Expand All @@ -1198,6 +1199,14 @@ func (s *v4GitSignature) ToSignature() *Signature {
State: s.SMIME.State,
Type: SignatureSmime,
}
case SignatureSSH:
return &Signature{
IsValid: s.SSH.IsValid,
KeyFingerprint: s.SSH.KeyFingerprint,
Signer: s.SSH.Signer.GetV3Login(),
State: s.SSH.State,
Type: SignatureSSH,
}
default:
return nil
}
Expand All @@ -1223,3 +1232,14 @@ type v4GpgSignature struct {
State string
WasSignedByGitHub bool
}

type v4SshSignature struct {
Email string
IsValid bool
KeyFingerprint string
Payload string
Signature string
Signer *v4Actor
State string
WasSignedByGitHub bool
}