diff options
author | Antoine GIRARD <sapk@users.noreply.github.com> | 2017-03-22 11:43:54 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-03-22 18:43:54 +0800 |
commit | 14fe9010ae8aecc0bcd38059b4c71256524b5341 (patch) | |
tree | 6a4740387d288ea8cd433412d36624e30912d5ee /vendor | |
parent | 9224405155322e096e7f2d0f9eed35633b937951 (diff) | |
download | gitea-14fe9010ae8aecc0bcd38059b4c71256524b5341.tar.gz gitea-14fe9010ae8aecc0bcd38059b4c71256524b5341.zip |
GPG commit validation (#1150)
* GPG commit validation
* Add translation
+ some little fix
* Move hash calc after retrieving of potential key + missing translation
* Add some little test
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/code.gitea.io/git/commit.go | 20 | ||||
-rw-r--r-- | vendor/code.gitea.io/git/repo_commit.go | 6 | ||||
-rw-r--r-- | vendor/code.gitea.io/sdk/gitea/hook.go | 21 | ||||
-rw-r--r-- | vendor/code.gitea.io/sdk/gitea/user_gpgkey.go | 6 | ||||
-rw-r--r-- | vendor/vendor.json | 12 |
5 files changed, 53 insertions, 12 deletions
diff --git a/vendor/code.gitea.io/git/commit.go b/vendor/code.gitea.io/git/commit.go index fa5e185619..28dd264835 100644 --- a/vendor/code.gitea.io/git/commit.go +++ b/vendor/code.gitea.io/git/commit.go @@ -6,6 +6,7 @@ package git import ( "bufio" + "bytes" "container/list" "fmt" "net/http" @@ -22,11 +23,30 @@ type Commit struct { Author *Signature Committer *Signature CommitMessage string + Signature *CommitGPGSignature parents []SHA1 // SHA1 strings submoduleCache *ObjectCache } +// CommitGPGSignature represents a git commit signature part. +type CommitGPGSignature struct { + Signature string + Payload string //TODO check if can be reconstruct from the rest of commit information to not have duplicate data +} + +// similar to https://github.com/git/git/blob/3bc53220cb2dcf709f7a027a3f526befd021d858/commit.c#L1128 +func newGPGSignatureFromCommitline(data []byte, signatureStart int) (*CommitGPGSignature, error) { + sig := new(CommitGPGSignature) + signatureEnd := bytes.LastIndex(data, []byte("-----END PGP SIGNATURE-----")) + if signatureEnd == -1 { + return nil, fmt.Errorf("end of commit signature not found") + } + sig.Signature = strings.Replace(string(data[signatureStart:signatureEnd+27]), "\n ", "\n", -1) + sig.Payload = string(data[:signatureStart-8]) + string(data[signatureEnd+27:]) + return sig, nil +} + // Message returns the commit message. Same as retrieving CommitMessage directly. func (c *Commit) Message() string { return c.CommitMessage diff --git a/vendor/code.gitea.io/git/repo_commit.go b/vendor/code.gitea.io/git/repo_commit.go index 97f44abdac..37219734a0 100644 --- a/vendor/code.gitea.io/git/repo_commit.go +++ b/vendor/code.gitea.io/git/repo_commit.go @@ -78,6 +78,12 @@ l: return nil, err } commit.Committer = sig + case "gpgsig": + sig, err := newGPGSignatureFromCommitline(data, nextline+spacepos+1) + if err != nil { + return nil, err + } + commit.Signature = sig } nextline += eol + 1 case eol == 0: diff --git a/vendor/code.gitea.io/sdk/gitea/hook.go b/vendor/code.gitea.io/sdk/gitea/hook.go index c2f88f4a31..4b45068127 100644 --- a/vendor/code.gitea.io/sdk/gitea/hook.go +++ b/vendor/code.gitea.io/sdk/gitea/hook.go @@ -137,12 +137,21 @@ type PayloadUser struct { // PayloadCommit FIXME: consider use same format as API when commits API are added. type PayloadCommit struct { - ID string `json:"id"` - Message string `json:"message"` - URL string `json:"url"` - Author *PayloadUser `json:"author"` - Committer *PayloadUser `json:"committer"` - Timestamp time.Time `json:"timestamp"` + ID string `json:"id"` + Message string `json:"message"` + URL string `json:"url"` + Author *PayloadUser `json:"author"` + Committer *PayloadUser `json:"committer"` + Verification *PayloadCommitVerification `json:"verification"` + Timestamp time.Time `json:"timestamp"` +} + +// PayloadCommitVerification represent the GPG verification part of a commit. FIXME: like PayloadCommit consider use same format as API when commits API are added. +type PayloadCommitVerification struct { + Verified bool `json:"verified"` + Reason string `json:"reason"` + Signature string `json:"signature"` + Payload string `json:"payload"` } var ( diff --git a/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go b/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go index 911e63f1a3..c8afe92c92 100644 --- a/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go +++ b/vendor/code.gitea.io/sdk/gitea/user_gpgkey.go @@ -38,6 +38,12 @@ type CreateGPGKeyOption struct { ArmoredKey string `json:"armored_public_key" binding:"Required"` } +// ListGPGKeys list all the GPG keys of the user +func (c *Client) ListGPGKeys(user string) ([]*GPGKey, error) { + keys := make([]*GPGKey, 0, 10) + return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/gpg_keys", user), nil, nil, &keys) +} + // ListMyGPGKeys list all the GPG keys of current user func (c *Client) ListMyGPGKeys() ([]*GPGKey, error) { keys := make([]*GPGKey, 0, 10) diff --git a/vendor/vendor.json b/vendor/vendor.json index 91d889c6fa..4b24848ea7 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -3,16 +3,16 @@ "ignore": "test", "package": [ { - "checksumSHA1": "nt2y/SNJe3Rl0tzdaEyGQfCc4L4=", + "checksumSHA1": "bKoCvndU5ZVC5vqtwYjuU3YPJ6k=", "path": "code.gitea.io/git", - "revision": "b4c06a53d0f619e84a99eb042184663d4ad8a32b", - "revisionTime": "2017-02-22T02:52:05Z" + "revision": "337468881d5961d36de8e950a607d6033e73dcf0", + "revisionTime": "2017-03-13T15:07:03Z" }, { - "checksumSHA1": "qXD1HI8bTn7qNJZJOeZqQgxo354=", + "checksumSHA1": "32qRX47gRmdBW4l4hCKGRZbuIJk=", "path": "code.gitea.io/sdk/gitea", - "revision": "8807a1d2ced513880b288a5e2add39df6bf72144", - "revisionTime": "2017-03-04T10:22:44Z" + "revision": "9ceaabb8c70aba1ff73718332db2356356e26ffb", + "revisionTime": "2017-03-09T22:08:57Z" }, { "checksumSHA1": "IyfS7Rbl6OgR83QR7TOfKdDCq+M=", |