Encrypting Backups

sunsetsystems wrote on Tuesday, August 09, 2011:

Client wants backups to be encrypted with AES-256.  PHP 5.3.0 and above can do that with its openssl functions, but only for strings, not files, and it seems impractical to load up a string that is always huge and can be arbitrarily large.  So I guess I’ll have it (backup.php) optionally exec openssl externally, unless someone has a better idea?  Obviously this requires having the openssl utility installed.

Thought I’d bring this up before submitting code for review. :slight_smile:

Rod
www.sunsetsystems.com

stephen-smith wrote on Tuesday, August 09, 2011:

Are we still even pretending to support PHP 4?  If so, make sure code that need PHP 5.3 has the proper conditionals around it.

sunsetsystems wrote on Tuesday, August 09, 2011:

function_exists() is handy for that, not a problem.  But not an issue if I don’t use the function anyway.

Rod
www.sunsetsystems.com

tmccormi wrote on Tuesday, August 09, 2011:

Another option is to make the backup directory an encrypted file system partition.  Using TrueCrypt is a good option for this.
-Tony

sunsetsystems wrote on Tuesday, August 09, 2011:

Thanks Tony, TrueCrypt is a nice tool, not quite what’s wanted in this case though.

Rod
www.sunsetsystems.com

sunsetsystems wrote on Tuesday, August 09, 2011:

Here’s one easy and flexible way to do it.  Make a global parameter that is itself the encryption command to be EXEC’d, key and all.  If you choose encryption, backup.php would run it through sprintf() to plug in its temporary file names, and then exec().  A sample parameter:

openssl aes-256-ecb -in %s -out %s -K 3132333435363738313233343536373831323334353637383132333435363738

That way just about any encryption command or script could be invoked, and the default would only need the key to be fixed.

Rod
www.sunsetsystems.com

tmccormi wrote on Tuesday, August 09, 2011:

Does that work for windows installations?
-Tony