Skip to content

Commit

Permalink
Keep empty files unencrypted
Browse files Browse the repository at this point in the history
To work around the issue that git considers the working directory
dirty when empty files are encrypted, these are kept untouched when
cleaning/smudging.

Security wise, this is not an issue, as you can check if an encrypted
file is empty due to the deterministic encryption properties.
  • Loading branch information
hugopeixoto committed Oct 29, 2018
1 parent 546664f commit 62c3725
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ int clean (int argc, const char** argv)
return 1;
}

if (file_size == 0) {
return 0;
}

// We use an HMAC of the file as the encryption nonce (IV) for CTR mode.
// By using a hash of the file we ensure that the encryption is
// deterministic so git doesn't think the file has changed when it really
Expand Down Expand Up @@ -865,6 +869,11 @@ int smudge (int argc, const char** argv)
// Read the header to get the nonce and make sure it's actually encrypted
unsigned char header[10 + Aes_ctr_decryptor::NONCE_LEN];
std::cin.read(reinterpret_cast<char*>(header), sizeof(header));

if (std::cin.gcount() == 0) {
return 0;
}

if (std::cin.gcount() != sizeof(header) || std::memcmp(header, "\0GITCRYPT\0", 10) != 0) {
// File not encrypted - just copy it out to stdout
std::clog << "git-crypt: Warning: file not encrypted" << std::endl;
Expand Down

0 comments on commit 62c3725

Please sign in to comment.