7 points · by caivvoacmh · 9y ago · 16 comments
The encryption process is as follows:
# Generate RSA key pair
openssl genrsa -out backup_key.priv.pem 4096
openssl rsa -in backup_key.priv.pem -out backup_key.pub.pem -outform PEM -pubout
# Encrypt the private key (need to enter a password) openssl enc -aes-256-cbc -in backup_key.priv.pem -out backup_key.priv.pem.enc
rm backup_key.priv.pem
# Encrypt backup file openssl rand 64 | tee >(openssl enc -aes-256-cbc -salt -pass stdin -in backup.tar.gz
-out backup.tar.gz.enc) |
openssl rsautl -encrypt -pubin -inkey backup_key.pub.pem -out backup.tar.gz-aeskey.enc
I'm not a cryptographer, but knowing that openssl has suffered from numerous vulnerabilities I decided to google `openssl enc` to get a sense of its security. After reading:"if you use `openssl enc`, make sure your password has high entropy"[2]
"it looks like openssl enc is still using a very weak KDF"[3]
"The commandline utilities in general are fairly minimal wrappers around functionality in libssl and libcrypto, and if you want something complete, polished, convenient, etc. the idea is you should either modify or replace them"[4]
I'm left wondering if using openssl for file encryption is a good choice if security is paramount.
Can crypto experts please comment. Thanks in advance.
[1]: https://summitroute.com/blog/2016/12/25/creating_disaster_recovery_backups/
[2]: https://security.stackexchange.com/a/29139
[3]: https://security.stackexchange.com/questions/29106/openssl-recover-key-and-iv-by-passphrase#comment202222_29139
[4]: https://security.stackexchange.com/a/129067
Another scary thing about this is the fact that you have to keep track of the AES key for the backup as well as your private RSA key and its password. That's going to get nasty for more than a couple of files.
If you're going to do backups like this you're better off just sticking with GPG.
Ask your third-party to supply a gpg public key over a secure channel, then it's very to encrypt files for them (and only them) to read.
I'm personally curious about the best solution...
@Canada, if the "malicious"(untrusted?) server modifies the backup how could you decrypt anyway?
The solution is to generate a hash or a MAC after encrypting. A plain hash would have to be kept locally because the malicious server could modify it if stored there. A MAC could be stored on the server, but then it would be necessary to derive another key for that and store it locally. (Or store the input for deriving the encryption key and MAC key... in any case, annoying)
GPG takes care of all this for you. Bottom line: Avoid OpenSSL command line for this kind of thing.
Is authentication wrt to encryption not when you provide the password to encrypt/decrypt?
For example, I use CryptoPP for AES 256 bit encryption in C++.