def encrypt_credentials(client, key, **creds): plaintext = security.pad(json.dumps(credentials)) enc_aes_key, aes_iv, enc_creds = security.encrypt( client.public_key, plaintext) creds = credentials.make(dict( key=key, client_id=client._id, aes_iv=bson.Binary(aes_iv), enc_aes_key=bson.Binary(enc_aes_key), enc_creds=bson.Binary(enc_creds))) return creds
def _process(self, key, **contexts): print '... key: ' + key for context, creds in contexts.items(): print '...... context: ' + context plain_cred_data = json.dumps(creds) plaintext = security.pad(plain_cred_data) for cli in M.client.m.find(dict(context=context)): enc_aes_key, aes_iv, ciphertext = security.encrypt(cli.public_key, plaintext) M.credentials.m.collection.update( dict(key=key, client_id=cli._id), {'$set': dict( enc_aes_key=bson.Binary(enc_aes_key), aes_iv=bson.Binary(aes_iv), enc_creds=bson.Binary(ciphertext) ) }, upsert=True)