Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

implement encrypted national identities #4000

Closed
wants to merge 7 commits into from

Conversation

chadwhitacre
Copy link
Contributor

@chadwhitacre chadwhitacre commented Apr 30, 2016

#3994

#3976

#3999#4001

Punchlist

@chadwhitacre
Copy link
Contributor Author

Redid the commit for very minor doc and whitespace tweaks. Previous commit was c55614d.

@chadwhitacre chadwhitacre force-pushed the encrypted-identities branch from c55614d to 7422191 Compare May 2, 2016 01:48
@chadwhitacre
Copy link
Contributor Author

chadwhitacre commented May 2, 2016

Per #3976 (comment), we should require a verified email before storing an identity.

@chadwhitacre
Copy link
Contributor Author

Started a punchlist in the description.

@chadwhitacre chadwhitacre modified the milestone: Bring Back Payroll for Team Gratipay May 4, 2016
@chadwhitacre
Copy link
Contributor Author

I wrote some code to rekey participant_identities.info as part of gratipay/inside.gratipay.com#606. The field doesn't exist yet in #3998, so I'll stub out ./bin/rekey.py there. I'm filing this code here since this is where we will be introducing the participant_identities table.

def rekey(db, packer):
    """Rekey the encrypted data in our database.

    :param GratipayDB db: a database object
    :param EncryptingPacker packer:

    This script features prominently in our procedure for rekeying our
    encrypted data, as documented in the "[Keep
    Secrets](http://inside.gratipay.com/howto/keep-secrets)" howto. It operates
    by loading records from `participant_identities` in batches of 100 based on
    a `_last_keyed` field. It updates `_last_keyed` atomically with the rekeyed
    `info`, so it can safely be rerun in the face of network failure, etc.

    """
    n = 0
    while 1:
        m = _rekey_one_batch(db, packer)
        if m == 0:
            break
        n += m
    return n


def _rekey_one_batch(db, packer):
    batch = db.all("""

        SELECT id, info
          FROM participant_identities
         WHERE _last_keyed < date_trunc('month', now())
         LIMIT 100

    """)
    if not batch:
        return 0

    for rec in batch:
        plaintext = packer.unpack(rec.info)
        new_token = packer.pack(plaintext)
        db.run( "UPDATE participant_identities SET info=%s, _last_keyed=now() WHERE id=%s"
              , (new_token, rec.id)
               )

    return True

@chadwhitacre
Copy link
Contributor Author

Rebased on #3999 at f366481, previous head was 7422191.

@chadwhitacre
Copy link
Contributor Author

Old head was 8f22a0e.

@chadwhitacre chadwhitacre force-pushed the encrypted-identities branch 2 times, most recently from 10da54e to 292ab36 Compare May 9, 2016 12:33
@chadwhitacre chadwhitacre mentioned this pull request May 11, 2016
6 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant