views:

316

answers:

5

Background: I got some data encrypted with AES (ie symmetric crypto) in a database. A server side application, running on a (assumed) secure and isolated Linux box, uses this data. It reads the encrypted data from the DB, and writes back encrypted data, only dealing with the unencrypted data in memory. So, in order to do this, the app is required to have the key stored in memory.

The question is, is there any good best practices for this? Securing the key in memory.

A few ideas:

  1. Keeping it in unswappable memory (for linux: setting SHM_LOCK with shmctl(2)?)
  2. Splitting the key over multiple memory locations.
  3. Encrypting the key. With what, and how to keep the...key key.. secure?
  4. Loading the key from file each time its required (slow and if the evildoer can read our memory, he can probably read our files too)

Some scenarios on why the key might leak: evildoer getting hold of mem dump/core dump; bad bounds checking in code leading to information leakage;

The first one seems like a good and pretty simple thing to do, but how about the rest? Other ideas? Any standard specifications/best practices?

Thanks for any input!

+3  A: 

All depends on the level of your paranoia and the sensitivity of the key/data. In the extreme cases, as soon as you have an unencrypted key in memory, one can retrieve it using coldboot techniques. There is an interesting development at frozencache to try to defeat that. I merely casually read it, did not try it in practice, but it seems like an interesting approach to try.

With the tinfoil hat off, though - (1), (2), (3) do seem reasonable. (4) won't cut it precisely for the reason you mentioned. (Not only it is slow, but assuming you read into the stack, with different stack depths the key might become visible more than once).

Assuming the decrypted data is worth it, and it would be in the swappable memory, you definitely should encrypt the swap itself as well. Also, the root, /tmp partitions should also be encrypted. This is a fairly standard setup which is readily available in most guides for the OSes.

And then, of course, you want to ensure the high level of physical security for the machine itself and minimize the functions that it performs - the less code runs, the less the exposure is. You also might want to see how you can absolutely minimize the possibilities for the remote access to this machine as well - i.e. use the RSA-keys based ssh, which would be blocked by another ACL controlled from another host. portknocking can be used as one of the additional vectors of authentications before being able to log in to that second host. To ensure that if the host is compromised, it is more difficult to get the data out, ensure this host does not have the direct routable connection to the internet. In general, the more painful you make it to get to the sensitive data, the less chance someone is going to going to get there, however there this is also going to make the life painful for the regular users - so there needs to be a balance.

In case the application is serious and the amount of things at stake is high, it is best to build the more explicit overall threat model and see what are the possible attack vectors that you can foresee, and verify that your setup effectively handles them. (and don't forget to include the human factor :-)

Update: and indeed, you might use the specialized hardware to deal with the encryption/decryption. Then you don't have to deal with the storage of the keys - See Hamish' answer.

Andrew Y
Firewire devices can also be used to read keys from memory. They can directly address memory, and a specially designed one could make a full copy of memory for later analysis. See http://mmadan.wordpress.com/2008/03/14/physical-hack-via-firewire-port/
Eric J.
+1  A: 

The big problem is the program has to read the key from somewhere. Unless you accept direct keyboard input each time the server reboots, it pretty much has to exist on disk somewhere.

In general you have to assume the evildoer doesn't have access to the root level operating system or hardware as when that's the case they'll eventually manage to get the key even if it's only in RAM.

So you assume the server's OS is secure. But let's say somebody can come and steal the hard drive so starting the server would give them the key. Then let the server ask another server for half of the key, the remote server validates the request (using ip, private/public key pairs) and supplies half the key. Then your server has a complete key, and the remote server never has more than half. That seems to me an improved level of protection.

Kristoffon
+3  A: 

If you are serious about security then you might consider a separate cryptographic subsystem. Preferably one that is FIPS 140-2/3 certified (list of certified modules).
Then the key is held in tamper proof memory (non-extractable) and all cryptographic operations are performed inside the crypto boundary.
Expensive but for some applications necessary.

Hamish Smith
I believe that Mozilla's NSS library will do just that, and it is free
Adam Batkin
+1, very good point. I somehow managed to forget about the dedicated crypto :-)
Andrew Y
+1  A: 

I'd be looking at what

do when handling keys. They're sufficiently paranoid about such security matters...

Stobor
A: 

Also don't forget the threat of core dumps and your memory being swapped out!

On both POSIX (like Linux) and Windows systems, there are techniques to prevent that from happening if you're dealing with C language - see this section from CERT Secure Coding Standards:

MEM06-C. Ensure that sensitive data is not written out to disk

Aleksander Adamowski