Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial commits of encrypted files use the wrong salt #118

Closed
Aramgutang opened this issue Mar 31, 2021 · 2 comments
Closed

Partial commits of encrypted files use the wrong salt #118

Aramgutang opened this issue Mar 31, 2021 · 2 comments

Comments

@Aramgutang
Copy link
Contributor

Aramgutang commented Mar 31, 2021

While git add -p doesn't work with transcrypt, and some GUIs (e.g. git-cola) will not let you stage hunks/lines of changes for encrypted files, such partial commits do appear to be possible from VS Code (and possibly other interfaces).

However, such commits have the unfortunate side effect of leaving the repo in a state where (after any uncommited changes are removed, or the commit is pulled on a different machine) git status reports the encrypted file as modified, however git diff shows no changes, and git checkout filename does nothing. This is quite frustrating, as it can prevent pulling, checking out other branches, etc, and can't be worked around with git stash.

The reason this happens is that an incorrectly constructed salt is used when partial changes are committed. Thus, when git puts the local decrypted file through clean, the resulting encrypted binary differs to the encrypted binary that has been committed, even though both files decrypt to produce the exact same output. So the encrypted files differ, but the decrypted files do not, resulting in git's confusion as described above.

The cause of this lies in the parameters passed to OpenSSL in clean to generate the salt. The digest uses the SHA256 hash of the file read from $filename, assuming its contents are the same as the input it received (and stored in $tempfile). But since the former file also contains changes that were not staged for the commit, the contents differ. Thus, when the commit is pulled on another machine, the salt will be generated from the hash of the file without those local changes, and will not match.

As far as I can tell, the fix for this is simple: just replace $filename with $tempfile when generating the salt. I'll make a pull request with the change and leave it to you to verify that it doesn't break anything else.

@jmurty
Copy link
Collaborator

jmurty commented Mar 31, 2021

Thanks for the detailed report and debugging @Aramgutang

If you create a pull request with your proposed fix the automated unit tests should run, giving us a quick check for any unexpected problems.

jmurty pushed a commit that referenced this issue Apr 26, 2021
* Fix incorrect salt when partially staged files are commited. Re #118
@jmurty
Copy link
Collaborator

jmurty commented Apr 26, 2021

This fix is now merged via #119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants