I am building a PHP application that allows uploads of files (.doc/pdf etc) for review by a staff member. Some of these files will be somewhat confidential so I need to protect them.
Now the best solution would be to get the sender to encrypt these files with GPG or similar before uploading them and decrypt with a pre-shared key at the other end (on the staff computer, not on the web server).
However it is unrealistic to expect all of the customers to install and learn to use GPG in order to upload files.
So the best solution I can come up with is:
1) Do file uploads over HTTPS on a password protected page.
2) Encrypt files using asymmetric GPG and a public keyfile stored on the webserver.
3) Delete any unencrypted copies of the file in /tmp etc.
4) Send an email for staff notifying them that the file is available for download.
5) Staff member logs in and downloads file, server then deletes encrypted copy.
6) Staff member then decrypts file using their private key that is not stored on the webserver.
The idea here is that ever if the webserver is compromised (it is a dedicated server so not shared with others) the attacker will be unable to decrypt these files because they won't find the key there.
However: I think this is still vulnerable.
Because , if an attacker has root or even just control of the HTTP server user they will be able to read data from /tmp whilst the file is still being uploaded/encrypted and make an unencrypted copy which they can download later.
So perhaps I could do all of this in memory without writing to /tmp? But there is still a risk here that the attacker could discover memory addresses that the data is written to by uploading a file themselves and then use ptrace to inspect and copy those memory addresses.
I can't think of a way to fix this problem as I will need the data in plaintext in order to do the encryption. Is there a way in PHP to make the memory inspection harder? Or is there a third party web service that would be better to use for this?