Replies: 3 comments 7 replies
-
Thanks @sh-dv. I'm still in the process of updating parts of it :) The directory encryption situation is indeed a tricky one, and I'm still not sure what the best solution is.
That can be solved by having an encrypted boolean file header that indicates whether the encrypted file is a file or directory. The ZIP handling shouldn't be a problem after that besides a performance limitation, although it would mean Kryptor wouldn't have to back up the original directory if
That's exactly why I didn't do it this way in the first place, and that's true. However, from a user perspective, Cryptomator works in this fashion. The usefulness of being able to decrypt an individual file really depends on whether file name encryption was used.
The other annoyance is that files have to be created and encrypted to store the directory names if file name encryption is used. This leads to confusing output in the terminal because random files are getting encrypted. It's also an issue if the user renames a directory because then the directory name won't be restored. Performing name encryption like Cryptomator does would be a nightmare as it would limit the maximum length of names and prevent renaming for encrypted files as well. Instead, treating a directory as a single encrypted file solves these problems.
I believe you're describing what I was doing prior to v3. Instead of deriving one KEK for a directory and all subdirectories, I was deriving a new key for each file, which slowed down directory encryption significantly because there was a ~1 second delay per file. That's why I switched to just deriving one key. However, with asymmetric keys, a new is derived for each file.
That's true assuming all the files have the same salt, but then there would be no way of differentiating between a password encrypted directory and a private key encrypted directory, which could lead to lots of unhelpful errors instead of just one helpful error. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the clarification, I got the full picture now. How important is it to preserve the name of the directory ? If you don't store directory names the salt reuse can be avoided, true?
I now can understand your point. I don't know if I am doing this correctly, but what if you do the following : Directory Encryption with name encryption:
Directory Decryption with restoring encrypted directory and file names:
If step 2 fails to identify a file named This should be tricky and I may be wrong, please let me know. |
Beta Was this translation helpful? Give feedback.
-
@sh-dv As an update, my current plan is to go ahead with this ZIP file idea but avoid using compression because a) it's generally a bad idea to Compress-then-Encrypt and b) compressing directories would be significantly slower. Then I can implement an encrypted boolean header to distinguish between a file and directory, as I said before. The file name encryption will also move to an encrypted header. Boosting the file encryption/decryption performance will hopefully help render the decrypting the whole directory issue rather moot. The current performance is all right, but it can definitely be improved, perhaps using something like memory-mapped files. Otherwise, doing this comes with loads of advantages, like preventing encryption of a directory completely if a file has already been encrypted or the file name contains invalid characters when |
Beta Was this translation helpful? Give feedback.
-
I had so much fun going through the updated kryptor documentations once again, I must congratulate you for the work you have put into writing them. I have came across the directory encryption known limitations, where it's mentioned that in the upcoming v4, this limitation will be gone due to the planned work around of zipping the file, Where you end up with one file that gets encrypted like a regular single file.
I think this definitely solves the limitation. However, it opens up few more, Like you have said, you have to figure out if the file is a zipped directory in order to unzip it after decryption. And you have to implement zipping and all that jazz. Users will be limited to always decrypt the whole directory even if they intend to only decrypt one file. And the "one file" idea kind of can be done in v3 if the users zips a directory then encrypts it.
Decrypting a whole directory requires the presence of a
kryptor.salt
file. Meaning, having to rely on the user keeping that file intact in order for future directory decryption, unless they decrypt each file manually. In addition, new users may go encrypt a directory and be surprised by this extra file and go delete it without knowing it's importance.I think in Kryptor the encrypted directory salt file can be avoided by repeating the
EncryptInputFile()
function for all the files in a directory with new salt for each file, this can be done by creating two variables :totalFilesCount
currentFileCount
, and after each file encrypted you increment the currentFileCount variable and repeat theEncryptInputFile()
again. If both variables are equal you display theDirectoryEncryptionComplete
. OR you just make a new salt in theEncryptInputFile
func instead of passing the salt fromUsingPassword
toEncryptEachFileWithPassword
toEncryptInputFile
If you want to keep the directory still encrypted with the same salt, you can manage decrypting all the files without having the salt file there : Since the user already intended to decrypt a whole directory, you can get the
FileHeaders.ReadSalt(inputFile)
just from one file, and this salt applies to all files since it's an encrypted directory. But still this doesn't solve the reused salt.I hope you got my point. Regard, sh-dv.
Beta Was this translation helpful? Give feedback.
All reactions