Add a tree sha512 hash to merge commits #9871

pull sipa wants to merge 1 commits into bitcoin:master from sipa:merge_sha512 changing 1 files +43 −3
  1. sipa commented at 1:31 AM on February 27, 2017: member

    This adds a SHA512 hash of the resulting merged tree to merge commit messages. Assuming gpg uses a sufficiently strong hash internally, this results in our gpg signed commits avoiding any potential SHA1 issues w.r.t. the commit's resulting contents (but NOT its history).

    The hash can be verified by running git ls-tree --full-tree -r --name-only HEAD | LANG=C sort | xargs -n 1 sha512sum | sha512sum in the repository root.

  2. Add SHA512 tree hash to merge commits fa89670d34
  3. sipa force-pushed on Feb 27, 2017
  4. petertodd commented at 1:43 AM on February 27, 2017: contributor

    Given how few lines of code this requires and how easy it is to independently calculate, concept ACK as a quick fix.

  5. fanquake added the label Brainstorming on Feb 27, 2017
  6. fanquake added the label Scripts and tools on Feb 27, 2017
  7. da2ce7 commented at 4:10 AM on February 27, 2017: none

    Creating a 'git-sha512-treehashes.txt' file in the root folder of the repo. That is a list of every sha512 tree hash for every merge commit (in this reop history).

    Each new merge commit should append it's sha512-tree-hash to this file. This would make falsifying sha1 root hash far-harder as modifying any file will update the root-hash from two different locations.

  8. TheBlueMatt commented at 4:19 AM on February 27, 2017: member

    Hmm, what we really need to do is have a second PGP signature over just this hash in the commit message that can be verified completely independently from git.

    On February 26, 2017 8:31:24 PM EST, Pieter Wuille notifications@github.com wrote:

    This adds a SHA512 hash of the resulting merged tree to merge commit messages. This may or may not make SHA1 collision attacks harder (since the GPG signatures sign a SHA1 hash of the commit's contents, this is not a final solution at all).

    The hash can be verified by running git ls-tree --full-tree -r --name-only HEAD | LANG=C sort | xargs -n 1 sha512sum | sha512sum in the repository root. You can view, comment on, or merge this pull request online at:

    #9871

    -- Commit Summary --

    • Make TestBlockValidity optional in CreateNewBlock
    • Support construction of multiple subsequent block templates
    • Abstract out BlockAssembler options
    • Make CNB validity test an option
    • Add SHA512 tree hash to merge commits

    -- File Changes --

    M contrib/devtools/github-merge.py (46) M qa/rpc-tests/segwit.py (6) M src/init.cpp (3) M src/miner.cpp (66) M src/miner.h (13) M src/test/miner_tests.cpp (72) M src/validation.cpp (1) M src/validation.h (2)

    -- Patch Links --

    https://github.com/bitcoin/bitcoin/pull/9871.patch https://github.com/bitcoin/bitcoin/pull/9871.diff

    -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/9871

  9. in contrib/devtools/github-merge.py:None in fa89670d34
      80 | +            piece = fi.read(65536)
      81 | +            if piece:
      82 | +                intern.update(piece)
      83 | +            else:
      84 | +                break
      85 | +        fi.close()
    


    kallewoof commented at 4:31 AM on February 27, 2017:

    Nit: use with instead of open/close:

    with open(f, 'rb') as fi:
        while True:
            piece = fi.read(65536)
            if piece:
                intern.update(piece)
            else:
                break
    
  10. kallewoof commented at 4:32 AM on February 27, 2017: member

    utACK fa89670

  11. petertodd commented at 4:37 AM on February 27, 2017: contributor

    @TheBlueMatt The PGP signature on a git commit signs the entire commit object, including the message and thus SHA512 hash. So the SHA512 tree hash can be verified directly; you don't need another PGP signature.

  12. TheBlueMatt commented at 4:41 AM on February 27, 2017: member

    @petertodd oh? IIRC it just signs a few SHA1 hashes, not the message directly.

    On February 26, 2017 11:37:48 PM EST, Peter Todd notifications@github.com wrote:

    @TheBlueMatt The PGP signature on a git commit signs the entire commit object, including the message and thus SHA512 hash. So the SHA512 tree hash can be verified directly; you don't need another PGP signature.

    -- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/9871#issuecomment-282626312

  13. petertodd commented at 4:48 AM on February 27, 2017: contributor
  14. sipa commented at 4:50 AM on February 27, 2017: member

    It signs the SHA1 hash of the entire commit object (excluding the signature, of course).

  15. petertodd commented at 4:53 AM on February 27, 2017: contributor

    @sipa Nope, that's simply not how git works. The commit object itself is what's piped to GnuPG, not just the hash of that object.

  16. sipa commented at 4:54 AM on February 27, 2017: member

    @petertodd I'm aware. But GnuPG then takes a SHA1 hash of that. It's hardcoded by git to use SHA1, I believe.

  17. petertodd commented at 4:55 AM on February 27, 2017: contributor

    @sipa GnuPG uses whatever hash algorithm you've told it to use; defaults used to be SHA1, but that's both easy to change, and IIRC the default is now SHA256. EDIT: Just checked with 1.4.18, default is now SHA256.

  18. sipa commented at 4:58 AM on February 27, 2017: member

    @petertodd I don't think so (but I'd be glad to be wrong). Look at the actual data with git cat-file -p <commit>. It does not include the otherwise mandatory hash type line, so I assume gpg prepends that before verification. That can't work if it's anything but the default. git does not use detached signatures.

  19. petertodd commented at 5:00 AM on February 27, 2017: contributor

    @sipa It's missing because it's not a clearsigned signature; it's an ascii encoded detached signature.

  20. sipa commented at 5:01 AM on February 27, 2017: member

    Hmm, I read conflicting information. I hope I'm wrong.

  21. petertodd commented at 5:04 AM on February 27, 2017: contributor

    @sipa Don't worry, you are wrong. :)

    Like I said above, look at the git integration code I linked above from the OpenTimestamps client. Notably, the command line flags -bsau are passed to gpg by git when signing, which creates an ascii-encoded detached signature.

  22. dcousens commented at 5:08 AM on February 27, 2017: contributor
  23. petertodd commented at 5:20 AM on February 27, 2017: contributor

    @dcousens They're talking about the equivalent of segwit vs how Bitcoin works now; it's not relevant to what we're talking about here.

  24. dcousens commented at 5:23 AM on February 27, 2017: contributor

    @petertodd no worries, did git change since that SO question or was your comment noting that the GPG signing process used here (in bitcoin/bitcoin) is different?

    FWIW, I also saw https://grimoire.ca/git/detached-sigs

  25. petertodd commented at 5:25 AM on February 27, 2017: contributor

    @dcousens The "detached sigs" your links are referring to isn't the same thing as the "detached sigs" we're talking about above.

  26. sipa commented at 5:41 AM on February 27, 2017: member

    Cool, so this is much more useful than I thought :)

  27. achow101 commented at 5:44 AM on February 27, 2017: member

    So as long as the merge commit signers use SHA512 (or something like that, maybe SHA256) for GPG this solution is essentially perfect (besides git upgrading to a new hash function).

    And for those who care, this is where git calls gpg for signing.

  28. sipa renamed this:
    [RFC] Add a tree sha512 hash to merge commits
    Add a tree sha512 hash to merge commits
    on Feb 27, 2017
  29. laanwj commented at 7:18 AM on February 27, 2017: member

    I'm not sure how this works: git ls-tree --full-tree -r --name-only HEAD returns a list of filenames. Is it enough assurance to hash that, you don't need the file contents?

    Travis fails are, as usual, unrelated.

  30. sipa commented at 7:21 AM on February 27, 2017: member

    I read in the actual files, and hash those, and then hash the result as like the result of sha512sum (look at the command line).

  31. achow101 commented at 7:22 AM on February 27, 2017: member

    @laanwj it does that command to grab the list of files. Then it opens each file in the list and hashes it.

  32. laanwj commented at 7:27 AM on February 27, 2017: member

    I read in the actual files, and hash those, and then hash the result as like the result of sha512sum (look at the command line).

    Oh, then things are alright again, thanks :)

    Going to test this.

  33. laanwj commented at 7:48 AM on February 27, 2017: member
  34. in contrib/devtools/github-merge.py:None in fa89670d34
     210 | +        try:
     211 | +            subprocess.check_call([GIT,'commit','--amend','-m',message.encode('utf-8')])
     212 | +        except subprocess.CalledProcessError as e:
     213 | +            printf("ERROR: Cannot update message.",file=stderr)
     214 | +            exit(4)
     215 | +        second_sha512 = tree_sha512sum()
    


    MarcoFalke commented at 2:22 PM on February 27, 2017:

    Why is the above call to tree_sha512sum() guarded by a try except clause and this one is not?

    Anyway, I think the right place to put the second check would be verify-commits.sh.

  35. MarcoFalke commented at 2:31 PM on February 27, 2017: member

    Concept ACK

  36. jonasschnelli approved
  37. jonasschnelli commented at 3:37 PM on February 27, 2017: contributor

    utACK fa89670d34ac7839e7e2fe6f59fdfd6cc76c4483

  38. achow101 commented at 4:05 PM on February 27, 2017: member

    utACK fa89670

  39. TheBlueMatt commented at 5:09 PM on February 27, 2017: member

    We should probably have some better handling for symlinks, no?

  40. sipa commented at 8:40 AM on February 28, 2017: member

    @TheBlueMatt I think that may be overkill, but ok... how would you construct something that's easily shell-verifiable?

  41. laanwj commented at 10:53 AM on February 28, 2017: member

    We should probably have some better handling for symlinks, no?

    What about just rejecting symlinks? We don't use them in this repository and probably shouldn't as not all OSes have that concept.

  42. TheBlueMatt commented at 2:12 PM on February 28, 2017: member

    @sipa not sure about shell-verifiable, but git-cat has some symlinks options. I'm more than happy to reject them wholesale, however, given the dubious value and obvious annoyance/risk.

    On February 28, 2017 5:53:15 AM EST, "Wladimir J. van der Laan" notifications@github.com wrote:

    We should probably have some better handling for symlinks, no?

    What about just rejecting symlinks? We don't use them in this repository and probably shouldn't as not all OSes have that concept.

    -- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/bitcoin/bitcoin/pull/9871#issuecomment-283007962

  43. petertodd commented at 1:23 AM on March 1, 2017: contributor

    ACK to rejecting symlinks.

    We don't need to go overkill here and make this a scheme every project could adopt.

  44. laanwj commented at 9:03 AM on March 1, 2017: member

    I'm just going to merge this - this is a nice and simple change that alleviates the direct worries about SHA1 compromise. More advanced things or functionality to reject symlinks can be added to the script later.

  45. laanwj merged this on Mar 1, 2017
  46. laanwj closed this on Mar 1, 2017

  47. laanwj referenced this in commit be8ba2cfa4 on Mar 1, 2017
  48. sipa deleted the branch on Jun 23, 2017
  49. PastaPastaPasta referenced this in commit cfd3310274 on Dec 28, 2018
  50. PastaPastaPasta referenced this in commit b1b10c5d91 on Dec 29, 2018
  51. PastaPastaPasta referenced this in commit 0d37c78227 on Dec 29, 2018
  52. PastaPastaPasta referenced this in commit 73505a55b5 on Dec 31, 2018
  53. PastaPastaPasta referenced this in commit 30e1305190 on Jan 2, 2019
  54. PastaPastaPasta referenced this in commit 280c266865 on Jan 3, 2019
  55. PastaPastaPasta referenced this in commit 34f2fbede0 on Jan 5, 2019
  56. PastaPastaPasta referenced this in commit 94ade73faa on Jan 7, 2019
  57. PastaPastaPasta referenced this in commit 9166d4f853 on Jan 7, 2019
  58. PastaPastaPasta referenced this in commit 3d1a0b3abc on Jan 23, 2019
  59. PastaPastaPasta referenced this in commit e3c1c9acd6 on Jan 25, 2019
  60. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me