| 1 | From 62c372581b3342d6540e5c11aaea3247ee9f852c Mon Sep 17 00:00:00 2001
|
| 2 | From: Hugo Peixoto <[email protected]>
|
| 3 | Date: Mon, 29 Oct 2018 19:40:18 +0000
|
| 4 | Subject: [PATCH] Keep empty files unencrypted
|
| 5 |
|
| 6 | To work around the issue that git considers the working directory
|
| 7 | dirty when empty files are encrypted, these are kept untouched when
|
| 8 | cleaning/smudging.
|
| 9 |
|
| 10 | Security wise, this is not an issue, as you can check if an encrypted
|
| 11 | file is empty due to the deterministic encryption properties.
|
| 12 |
|
| 13 | Patch-Source: https://github.com/AGWA/git-crypt/issues/53
|
| 14 | ---
|
| 15 | commands.cpp | 9 +++++++++
|
| 16 | 1 file changed, 9 insertions(+)
|
| 17 |
|
| 18 | diff --git a/commands.cpp b/commands.cpp
|
| 19 | index 5ac0b47..a0a8d6e 100644
|
| 20 | |
| 21 | |
| 22 | @@ -748,6 +748,10 @@ int clean (int argc, const char** argv)
|
| 23 | return 1;
|
| 24 | }
|
| 25 |
|
| 26 | + if (file_size == 0) {
|
| 27 | + return 0;
|
| 28 | + }
|
| 29 | +
|
| 30 | // We use an HMAC of the file as the encryption nonce (IV) for CTR mode.
|
| 31 | // By using a hash of the file we ensure that the encryption is
|
| 32 | // deterministic so git doesn't think the file has changed when it really
|
| 33 | @@ -865,6 +869,11 @@ int smudge (int argc, const char** argv)
|
| 34 | // Read the header to get the nonce and make sure it's actually encrypted
|
| 35 | unsigned char header[10 + Aes_ctr_decryptor::NONCE_LEN];
|
| 36 | in.read(reinterpret_cast<char*>(header), sizeof(header));
|
| 37 | +
|
| 38 | + if (in.gcount() == 0) {
|
| 39 | + return 0;
|
| 40 | + }
|
| 41 | +
|
| 42 | if (in.gcount() != sizeof(header) || std::memcmp(header, "\0GITCRYPT\0", 10) != 0) {
|
| 43 | // File not encrypted - just copy it out to stdout
|
| 44 | std::clog << "git-crypt: Warning: file not encrypted" << std::endl;
|