3

I am self training on using encryption. I am a php developer and in my spare time I am building an online app that provides basic cms features to help me understand encryption design more. I am using encryption to protect the data if stolen and having it accessible to public like what happened to adobe.

My restrictions for this app are:

  1. End users will be using this app and cannot be trusted to remember their password all the time so their password cannot be used in the encryption process as there will be a high chance that they will need to reset their password at some stage.

  2. Cannot afford vendor key management software or hsm.

  3. Cannot have users loading in a key when logging into cms to encrypt or decrypt data during session. In fact users will not have any access to the keys used as they cannot be trusted to keep keys safe. Plus external users such as contractors will have access to cms. So all keys managed by app under the covers.

The data will be stored in a db encrypted. The code will encrypt the data as I am not using the native encryption of mysql.

The data will be encrypted using a symmetric key.

The symmetric key will be stored on another server that is firewalled off and only callable via cms ip. The cms when it needs a particular symmetric key will call the server which stores the symmetric keys and pass a hash value that will be used to look up the correct symmetric key. When the key is located it will send the key back to the cms and the cms will store the key in memcached.

Now I was thinking that I need to protect the symmetric keys so what I thought I should do is encrypt the symmetric keys with asymmetric public key and store the encrypted symmetric key in a db on the non cms server then when the cms gets the key it uses the private key stored on the cms server to decrypt it.

Yesh!

It's like chicken/egg!

I was wondering if anyone can give me some guidance on how to do this correctly. My goal for this project is to protect the data if the db is stolen.

I think it's bad to store the private key on the cms server because if the non cms server which stores the symmetric keys used to encrypt the data is also hacked then all the keys are available.

The app will also be checking inputs for injection attempts, Xss, using ip whitelisting for accessing cms, encrypting session cookie, cleaning input data and other basic security fundamentals.

1 Answer 1

4

Welcome to security.se and to key management!

Storing the keys is always the biggest issue with server-side encryption: on one hand, you need easy and transparent access to the key by your application and on the other hand, you need to protect your data from any unauthorized access.

The usual answer to this is to use a hardware security module (HSM). This type of hardware device (which range from a simple USB key-like device to rack-mounted systems) have special, tamper-proof storage for they key themselves and will handle all crypto operations using these keys (decryption and digital signature, encryption and validation can be done outside the device since you do not need access to the private keys).

Using this approach, assuming you did implement encryption properly, you limit the way in which data can be leaked: even if someone obtain a dump of your database, they will not gain access to the cleartext data unless the physically steal the HSM (which is easier to protect).

However, this kind of setup is very difficult to implement properly and efficiently. While in theory quite secure, it's often still possible to grab cleartext data or even symmetrical encryption keys (if you used the HSM to gain access to these keys) from the process memory. Modern, high-level languages like PHP, Java and C# are particularly prone to keeping that kind of sensitive information in memory for extended period of time since there is no way to explicitly zero and free memory (and even if you do, there is often a trace left in the page file).

Also, you're still left open to any kind of code injection that will grant access to your data after it has been decrypted (for instance, if you use transparent data encryption, it will not protect your data against any kind of SQL injection in your own program).

1
  • Thanks for the comments. For my project my restrictions are not to use hsm nor db encryption. There are more apps using lamp than oracle and other big DBS so advanced db features like tde are out of reach for most.
    – user35032
    Dec 4, 2013 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .