uio-bmi / crypt4gh

Crypt4GH standard implementation
https://uio-bmi.github.io/crypt4gh/
MIT License
2 stars 6 forks source link

Decrypt empty files #88

Closed lyytinen closed 1 year ago

lyytinen commented 1 year ago

Describe the pull request:

Pull request long description:

Given an empty file empty.txt, the following succeeds with the command-line utility:

crypt4gh.exe encrypt -f empty.txt -p reader.pub.pem -s writer.sec.pem
crypt4gh.exe decrypt -f empty.txt.c4gh -s reader.sec.pem

However, the Crypt4GHInputStream throws an exception when attempting to process empty.txt.c4gh.

Related issues:

Additional information:

lyytinen commented 1 year ago

To clarify, here I was using the go implementation. It appears that other implementations can have different behavior so need to check those as well. Not sure if the standard leaves room for interpretation when dealing with empty content.

lyytinen commented 1 year ago

Addressed additional issues revealed when attempting to decrypt empty content created by the crypt4gh python module (or the GUI wrapper to be more specific).

Attempting to decrypt empty.go.txt.c4gh causes Crypt4GHInputStream to throw an ArrayIndexOutOfBoundsException. Attempting to decrypt empty.python.txt.c4gh causes Crypt4GHInputStream to throw a NullPointerException.

This pull request now addresses both of these issues. In the end, I'm not sure if the implementations actually are different or if the difference can be explained by the fact that with the Go implementation I used the Crypt4GH keys and with Python I used the OpenSSL keys.

In anycase, accepting this change would solve a very concrete problem for me. I'm transferring millions of encrypted files between research environments and the files are produced by different teams using different tooling. It is therefore important that this library is interoperable with other implementations and that also empty files can be decrypted without issues.