Encryption and stuffs

PHParlor GBG #1, 2014-08-28

Disclaimer

  • IT-security is fun
  • IT-security is hard
  • Don't take my advice!

Case:

Statistics for Sweden's national test

(nationella provet)

Simple system

  • Teachers enter students grades
  • Creators of the test gets statistics

For ease of use: Teachers can enter students name

Requirement:

  • Username and password only
  • Password reset needs to work

First version

  • Have to meet deadline
  • What can we do in a short period of time?

Solution:

  • Two tables which needed encryption
  • Straight AES with static key per table
  • Wipe keys as soon as teachers are finished

Pros

  1. We delivered in time
  2. We can't directly see names
  3. An attacker needs disk access for keys
  4. No extra work for the user (teacher)

Cons

  1. Doesn't really provide anonymity
  2. Teacher information was not encrypted
  3. Same key for every user
  4. ?? Probably lot's more

Second version

  • The basic code is in place
  • How can we improve this?
  • Without adding any complexity for the user

"Good enough" solution:

  • Treat username (email) as a secret
    (pass through PBKDF2 before storing)
  • Use real username as part of AES key w/ static keys
  • Store real username in memcache during the session

Pros

  1. Resetting password still works!
  2. Username / email is hashed before storage
  3. After signing out (or restarting memcache) keys are gone
  4. (still) No extra work for the user

Cons

  1. During a session, user and key is known
  2. Hard to find users to give them support
  3. Still not really anonymous?
// Event listener
public function prePersist(LifecycleEventArgs $eventArgs)
{
    $entity = $eventArgs->getEntity();

    if ($entity instanceof EncryptedEntity) {
        $this->encryption->encrypt($entity);
    }
}
// Encryption service
public function encrypt(EncryptedEntity $entity)
{
    $fields = $entity->getSecureFields();

    foreach ($fields as $field) {
        if (!$entity->isSecure($field)) {
            // ...
        }
    }
}
// Encrypted entity
public function setName($name)
{
    $this->name = $name;
    $this->setInsecure('name');

    return $this;
}

@rickard2

https://about.me/rickard2
www.montania.se