Ask HN: Is openssl enc a good choice for file encryption?
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
16 comments
[ 19.6 ms ] story [ 160 ms ] threadAnother 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.
I also see clearly how hashing the encrypted data before "storing it at this 3rd party" would allow you to verify CBC block modifications.
I guess I don't understand GPG well enough to see how it solves this problem better than AES CBC 256. Could you perchance provide a link? Or explain how GPG would take care of this?
Even if you wanted to use a more secure cipher according to [this](https://security.stackexchange.com/questions/128883/basic-qu...) `openssl enc` does not support the more secure ciphers that openssl tls does.
Is this the reason to avoid openssl for file encryption?
AES-CBC is just a block cipher mode of operation. TLS is a protocol that takes care of negotiating algorithms for key exchange, bulk encryption (which may be a block cipher using some mode), authentication, etc. All of these things combined is the "suite" of ciphers. Implementations provide decent tooling for managing keys and preferences.
Like TLS, GPG uses a suite of ciphers to do its job and provides tools to manage it without getting caught up in extremely low level details. Like TLS, the default suite of algorithms it prefers change with the times, but from a user perspective it stays the same.
Furthermore, Canada, what about privately managed machines communicating via TCP and AES 256 CBC symmetrically encrypted messages? I also use a random salt and a transaction number.
Until now, I was thinking that successfully decrypted data would be safe. Is the case for TCP encrypted data the same? I need to have a MAC for each message and verify that between ACK's or something?
EDIT: Did some research: https://en.wikipedia.org/wiki/Authenticated_encryption
It looks like incorporating a MAC within or alongside the encrypted data is not as insecure or as complex as I was afraid.
Can both my TCP encryption and OP's file encryption problem by solved by just appending a HASH of the encrypted data to the end of the encrypted data (EtM), or appending a HASH of the plaintext data to the end of the plaintext data and then encrypting that (MtE)?
I used openssl because I find GPG on servers is awkward to use.
The full article is more clear that I have only one private key, and for all the nightly backups I'm generating AES keys and encrypting them with the public key.
If you don't care if the third party can modify your data, then OK. If you did care though, does this checksum stop "tar xvzf foo.tgz" from writing modified data immediately? Or does it just tell you at the end?
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++.