Hi guys!
Inspired by your great service and open-source client, I decided to make a Rust↔Filen API interface. Things were looking good, I got a lot of API queries working. It was fun implementing window.crypto/CryptoJS calls in native lib terms, and looking at filen-desktop source code to the point of memorizing it. However, recently I kinda hit a wall, with wall being implementing file upload, aka doUpload()
from filen-desktop.
I am grateful for any help received, but if you are too busy to help, I would understand. So, to the point:
My encrypted file chunks can be uploaded to Filen successfully, at least Filen returns "Chunk stored" for every chunk. However, when I try to mark even small one-chunk uploaded file as done, Filen returns "Upload chunks are not matching." It would be really helpful if someone told me what this message really means :)
I guess I may have botched either encryption algorithms or file upload process. But encryption algorithms are tested for compatibility with their JS counterparts and should be working, since I can decrypt downloaded files and process metadata successfully. So that leaves upload process as the most probable culprit.
Current process of file upload is as follows:
Step 1, encrypt file information, shared by all chunks:
- For now, set parent uuid to the user folder with 'default: true' property.
- Generate new file uuid v4.
- Gather file properties: name, size, last modified, mime type.
- Generate file key, add it to file properties and encrypt them all as file's metadata.
- Encrypt each file property with file key to their corresponding encrypted strings, also encrypt name with hashFn() for nameHashed.
- Encryption uses
version
set to 1 everywhere, so it is AES-256 (CBC mode) with Pkcs7 padding.
- Generate upload key and 'rm', whatever it is, to be shared by all chunks.
Step 2, upload file chunks using file information from step 1:
- Divide file into chunks, with last chunk possibly being uneven. E.g. for a file of size 5 and chunk size 2 chunks would be: [(offset 0, chunk size 2, index 0), (offset 2, chunk size 2, index 1), (offset 4, chunk size 1, index 2)].
- Encrypt each chunk with file key from step 1 and encryption
version
set to 1.
- Post each encrypted binary blob to different random Filen upload server at
/v1/upload?
endpoint, passing the same data from step 1 in URL query params (except for index
, which is the only different param for each chunk).
- Do not retry to reupload chunks with 'status: false', just fail the entire upload.
- If all chunks resulted in 'status: true' from Filen, send upload key from step 1 to random Filen API server
/v1/upload/done
.
- Receive "Upload chunks are not matching." Why-y, everything seems analogous to filen-desktop, and yet it fails...
Please pardon my intrusion alongside a wall of text, I am at the wits' end with this one. Anyway, thanks for creating Filen and have a good day.