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

Output files are created even if encryption/decryption failed #57

Closed
wgslr opened this issue Dec 30, 2019 · 0 comments
Closed

Output files are created even if encryption/decryption failed #57

wgslr opened this issue Dec 30, 2019 · 0 comments
Milestone

Comments

@wgslr
Copy link

wgslr commented Dec 30, 2019

Environment

What were you trying to do

Decrypt a file without providing the -i argument and subsequently fix the mistake.

What happened

The first decryption attempt already created an empty output file, and a next invocation with fixed argument refused to overwrite it.

$ echo 'Hello age' | age -a -r 'age1fh296r26vut9rpdarl89765z5qh9pavgmlam3w9s69uh5t82darqat8yat' -o encrypted.age.ascii
$ age -d -o decrypted.txt encrypted.age.ascii
Error: no identity matched a recipient
[ Did age not do what you expected? Could an error be more useful? Tell us: https://filippo.io/age/report ]
# fix the mistake
$ age -d -o decrypted.txt -i key.txt encrypted.age.ascii 
Error: failed to open output file "decrypted.txt": open decrypted.txt: file exists
[ Did age not do what you expected? Could an error be more useful? Tell us: https://filippo.io/age/report ]
$ ls -lh
total 8.0K
-rw-r--r-- 1 wojciech wojciech   0 Dec 30 01:52 decrypted.txt

Encryption

Creation of empty files is observed also when encrypting, when given incorrect -r argument:

$ echo 'Hello age' | age -a -o encrypted -r BAD
Error: unknown recipient type: "BAD"
$ ls -l encrypted
-rw-r--r-- 1 wojciech wojciech 0 Dec 30 02:02 encrypted

UX side

Apart from the incorrect, I assume, behaviour of creating empty files, I am not a fan of the no-overwrite policy. I think it would be better to match most unix tools' behaviour of overwriting by default or add an -f/--force flag.

* would be nice to have age --version to properly check that

FiloSottile added a commit that referenced this issue Jan 2, 2021
This avoids leaving behind an empty file when an error occurs before we
write the header (for example, because the passphrase is invalid). Do a
best-effort check before taking user input for whether the file exists
so we don't waste user effort. An error might still happen after user
input if other kind of open errors happen (for example, a permission
issue, or disk full).

Fixes #159
Fixes #57
Closes #169
FiloSottile added a commit that referenced this issue Jan 3, 2021
This avoids leaving behind an empty file when an error occurs before we
write the header (for example, because the passphrase is invalid). Do a
best-effort check before taking user input for whether the file exists
so we don't waste user effort. An error might still happen after user
input if other kind of open errors happen (for example, a permission
issue, or disk full).

Fixes #159
Fixes #57
Closes #169
@FiloSottile FiloSottile added this to the v1.0.0 milestone Apr 22, 2021
FiloSottile added a commit that referenced this issue Jun 16, 2024
FiloSottile added a commit that referenced this issue Jun 16, 2024
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