Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

I am writing a web backend/api for an iOS application using Node.js and MySQL. In my database I have a table for posts. I would like the posts content to be encrypted. Let's say I'm using this AES for encryption.

I would like to be able to safely encrypt and decrypt data on the server. Data sent back and forth to the client will be unencrypted, but sent over HTTPS (is this a good idea)?

My Questions:

  1. How should I generate the keys? Should they be random strings?

  2. Where should I store the keys since there is going to be a different key for each message.

Adversary Model
I would like to protect against someone who already has access to my server running the https API (written in Node.js) and has access to my MySQL DB. I would like to project against that person being able to decrypt the encrypted data in that table. So it is important that even if they have lots of encrypted data, and how the encryption works still cannot decrypt the data.

share|improve this question
    
Who is your adversary? You must define an adversary model before you design a protection scheme. –  mikeazo Apr 24 at 17:55
    
Here is an example so you'll know what I mean. Let's say you just simply store the keys in the PHP script (or whatever language you are using on the backend). An adversary can break into the machine, steal the DB and the PHP code and now decrypt the entire DB. On the other hand, you could store the keys on a separate server. To decrypt, the main server must send a request to the other server to do the decryption. Now an attacker has to break into both in order to get the data. Which is better? There is no better. Only tradeoffs that can be understood only when an adversary model is specified. –  mikeazo Apr 24 at 18:00
    
@mikeazo I would like to protect against someone who already has access to my server running the https API (written in Node.js) and has access to my MySQL DB. I would like to project against that person being able to decrypt the encrypted data in that table. So it is important that even if they have lots of encrypted data, and how the encryption works still cannot decrypt the data. –  Jason Silberman Apr 24 at 21:23
    
What kind of access does the person have to the server? Physical or over the network? Admin or just the privileges of the HTTP server, or some other user level privileges? –  mikeazo Apr 25 at 14:11
    
@mikeazo I'm not sure what you mean by that. I think only over the network. –  Jason Silberman Apr 25 at 17:36

1 Answer 1

up vote 1 down vote accepted

Hopefully I am understanding this properly. Client sends message to server over SSL encrypted connection. Server gets the message and stores it in a database. You are worried that if someone breaks into the server, they can read the database and see all the messages.

So, encryption seems like a natural fit. Encrypt the messages (each with a different key) before storing them in the database. The problem now is, what do to with the keys. You can't just store them on the server as the attacker is on the server. They can easily find the keys, pull the entire database and decrypt everything.

It would appear your best options are storing the keys on a different machine and let that machine do the encryption/decryption. That way the attacker would first have to break into your machine, then into the encryption/decryption machine. Not impossible, but hopefully much harder.

Another option would be some cryptographic hardware. This is beyond my expertise, but companies sell hardware that performs cryptographic operations including key storage, encryption and decryption.

Here is the tricky part. What stops the attacker from querying the other machine or the cryptographic hardware repeatedly until he has decrypted all the messages? You'll have to build some sort of detection on there or something like that.

In short, given your adversary model (attacker with root privileges on the box), the problem is pretty hard. Hopefully one of these two options will be useful to you, or at least generate some other answers.

share|improve this answer
    
My only other question is how would I communicate with the decryption/encryption machine? –  Jason Silberman Apr 25 at 18:32
    
@JasonSilberman You'll have to weigh the risks. You could have a second NIC in the server and have that connected to the encryption/decryption machine. The encryption/decryption machine could be on the same LAN. Then you'd have to write a program for each that allows them to talk (sockets or some higher layer communications). –  mikeazo Apr 25 at 18:34
    
Ah ok! Thanks for all of the help! –  Jason Silberman Apr 25 at 18:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.