简体   繁体   中英

Predict git commit id and commit a file which contains that commit id

How to do something like this:

  1. Create a with following content:

    $ cat testfile.txt
    This file will be committed with this id: 83b90a07620ef578450c40a6d38bacc42de7ad2d

  2. Commit testfile.txt
    $ git add testfile.txt
    $ git commit -m 'Thank you'

  3. Execute git log to verify predicted commit id:
    $ git log
    commit 83b90a07620ef578450c40a6d38bacc42de7ad2d
    Author: rohit01 < * @gmail.com>
    Date: Fri Feb 21 23:46:52 2014 +0530

Basically, predict the next git commit id and commit a file which contains that commit id.

That is cryptographically impossible.

The git commit ID is an SHA1 hash of the contents of the commit.
Any change you make in the commit will also affect the ID.

Are CPU cycles an issue? If you have infinite time this works:

This file will be committed with this id: 83b90a07620ef578450c40a6d38bacc42de7ad2d

Junk characters: VGhpcyBpcyBhbiBlYXN0ZXIgZWdnISBJIGNvdWxkbid0IHRoaW5rIG9mIGFueXRoaW5nIGdyZWF0IHRvIHB1dCBoZXJlLiBVc2luZyBiYXNlNjQgdG8gZ2VuZXJhdGUganVuay1sb29raW5nIGp1bmsgaXMga2luZCBvZiBzaWxseSwgYnV0IHRoaXMgc2hvdWxkIGJlIGVub3VnaCwgcmlnaHQ/ICBJZGsuIFVwdm90ZSBwbHo/

Then enumerate all possible junk characters until you get something like a fixed point under hashing. By pigeonhole principle since there can be many more junk characters and assuming hashes are "random" this will work eventually.

But this is impossible in any reasonable sense because you are trying to find a string S with the property that Hash(S) = 83b90a07620ef578450c40a6d38bacc42de7ad2d , which is by definition impossible for a secure hashing algorithm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM