2

In my Rails app users are submitting sensitive username/password combinations to their webshop systems so my app can interact with them. I need to enforce a high data-at-rest security for these data.

From what I read in e.g. this answer the attr_encrypted gem is a good solution for encrypting model fields in MongoDB. But I don't like the fact that functionality as well as encrypted data and keys are handled/stored on a single server. And I would like to use a unique key for each encryption. So I am considering to store usernames on one server, encrypted passwords on a second and keys on a third.

Do you see any red flags in this approach?

This is how I handle the users submission of a new webshop:

1) My main server receives webshop data from a user and saves the username, but it forwards the password:

def create_webshop
  webshop = current_user.webshops.create(username: params[:username])
  HTTParty.get("https://passwords.mydomain.com/create_password?password=#{params[:password]}&webshop_id=#{webshop._id}")
end

2) My password server receives the password and generates a key. It then encrypts the password and saves it, but forwards the key:

def create_password
  key              = SecureRandom.base64
  password         = AESCrypt.encrypt(params[:password], key)
  password_holder  = PasswordHolder.create(webshop_id: params[:webshop_id], password: password)
  HTTParty.get("https://keys.mydomain.com/create_key?password_holder_id=#{password_holder._id}&key=#{key}")
  render :json => {}, :status => :ok
end

3) My key server receives the keyand saves it:

def create_key
  KeyHolder.create(password_holder_id: params[:password_holder_id], key: params[:key])
  render :json => {}, :status => :ok
end

This is how I get the password for a webshop:

1) My main server queries for the password to a given webshop_id:

def get_password(webshop)
  password_response = HTTParty.get("https://passwords.mydomain.com/get_password?webshop_id=#{webshop._id}")
  password          = JSON.parse(password_response.body)["password"]
  # Do stuff...
end

2) My password server receives the password query and queries for the key to a given password_id:

def get_password
  password_holder = PasswordHolder.where(webshop_id: params[:webshop_id]).first
  key_response    = HTTParty.get("https://keys.mydomain.com/get_key?password_holder_id=#{password_holder_id._id}")
  key             = JSON.parse(key_response.body)["key"]
  password        = AESCrypt.decrypt(password_holder.password, key)
  render :json => {:password => password}, :status => :ok
end

3) My key server receives the key query and returns the key:

def get_key
  render :json => {:key => KeyHolder.where(password_holder_id: params[:password_holder_id]).first.key}, :status => :ok
end

My password server then decrypts the password and returns it to my main server.

closed as unclear what you're asking by Iszi, user45139, Steve, Neil Smithline, Deer Hunter Oct 12 '15 at 19:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What is it that you are trying to protect against? Malware on your main server seems to have access to all the data despite all of these efforts. Are you strictly worried about someone getting a dump of a database? Someone get a disk drive image? Other? – Neil Smithline Oct 12 '15 at 18:34
  • PS: Keep in mind that questions that are closed as being unclear can frequently be updated and reopened. You can also use the comments to ask for advice about improving your questions if you are unsure how to update them. – Neil Smithline Oct 12 '15 at 18:36