Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Add support for signed commits #616

Merged
merged 2 commits into from
Oct 29, 2017
Merged

Add support for signed commits #616

merged 2 commits into from
Oct 29, 2017

Conversation

darkowlzz
Copy link
Contributor

@darkowlzz darkowlzz commented Oct 8, 2017

This change adds PGPSignature field to Commit object. This is used
to store the signature of the commit, if any.

Related to #605
fixes #524

@@ -28,6 +33,8 @@ type Commit struct {
// Committer is the one performing the commit, might be different from
// Author.
Committer Signature
// GPGSignature is the GPG signature of the commit.
GPGSignature string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be renamed to PGPSignature?

@@ -145,12 +152,33 @@ func (c *Commit) Decode(o plumbing.EncodedObject) (err error) {
r := bufio.NewReader(reader)

var message bool
var gpgsig bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to pgpsig?

if gpgsig {
// Check if it's the end of a PGP signature.
if bytes.Contains(line, []byte(endpgp)) {
c.GPGSignature += string(endpgp) + "\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the cast to string here

gpgsig = false
} else {
// Trim the left padding.
line = bytes.TrimLeft(line, " ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we need to Trim the padding? I notice that we add padding back in when we format the Commit. Will this be necessary for handing the signature into another routine that does the verification of the signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The padding is just git's way of presenting it. The public key block at https://www.gnupg.org/signature_key.html shows it without any left padding. So I thought that's how they are actually stored as a single signature. And yes, I thought it would be easier to perform signature verification in the future, without any need to trim the padding.

@@ -215,6 +243,21 @@ func (b *Commit) Encode(o plumbing.EncodedObject) error {
return err
}

if b.GPGSignature != "" {
if _, err = fmt.Fprint(w, "gpgsig"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should try to mimic the original format of the commit content here (i.e. don't print this gpgsig field that didn't exist in the original commit, just print the signature at the end of the commit comment).

If we do leave this in we should probably rename to pgpsig anyways.

Copy link
Contributor Author

@darkowlzz darkowlzz Oct 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the blob (git cat-file -p) of a commit with signature, I don't think printing the signature at the end of commit comment would be good. The signature is not needed all the time but only when we want to verify. So, I would say we leave it with its own field. And yes, pgpsig, which doesn't matters much because we are using the header and footer of signature to detect them 😊

This change adds `GPGSignature` field to `Commit` object. This is used
to store the signature of the commit, if any.
@codecov
Copy link

codecov bot commented Oct 12, 2017

Codecov Report

Merging #616 into master will decrease coverage by 0.57%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #616      +/-   ##
==========================================
- Coverage   78.26%   77.69%   -0.58%     
==========================================
  Files         130      130              
  Lines       10197    10217      +20     
==========================================
- Hits         7981     7938      -43     
- Misses       1356     1430      +74     
+ Partials      860      849      -11
Impacted Files Coverage Δ
plumbing/object/commit.go 71.32% <80%> (+1.4%) ⬆️
plumbing/transport/ssh/common.go 20.54% <0%> (-45.21%) ⬇️
plumbing/transport/ssh/auth_method.go 31.57% <0%> (-22.81%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b345ed7...9eb1250. Read the comment docs.

@mcuadros mcuadros merged commit 50732e3 into src-d:master Oct 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PGP signed commits
3 participants