Esempio n. 1
0
 def __init__(self, userid, publickey_pem, services=None,
              privatekey_pem=None, meta=None):
     self.userid = userid
     self.services = services
     self.publickey_pem = publickey_pem
     self.meta = meta or {}
     if publickey_pem is not None:
         self.publickey = cryptohelper.import_key(publickey_pem)
     else:
         self.publickey = None
     if privatekey_pem is not None:
         self.privatekey = cryptohelper.import_key(privatekey_pem)
     else:
         self.privatekey = None
     self.data = {}
Esempio n. 2
0
    def get(self):
        showid = self.get_argument('showid')
        shares = self.get_arguments('share')
        passphrase = cryptohelper.recover_passphrase(shares)
        privkey_show = yield get_show_privatekey(showid, passphrase)

        result = {
            'showid': showid,
            'users': [],
        }
        users = yield get_user_keypair_from_showid(showid)
        for user in users:
            user_id = user['id']
            user_privkey_pem = cryptohelper.decrypt_blob(
                privkey_show, user['enc_private_key'])
            cur_result = {
                'id': user_id,
                'publickey': user['public_key'],
            }
            user_privkey = cryptohelper.import_key(user_privkey_pem)
            access_tokens = yield get_user_tokens(user_id)
            for key, value in access_tokens.items():
                if not isinstance(value, bytes):
                    continue
                cur_result[key] = cryptohelper.decrypt_blob(
                    user_privkey, value)
            result['users'].append(cur_result)
        return self.api_response(result)
Esempio n. 3
0
    def get(self):
        showid = self.get_argument('showid')
        shares = self.get_arguments('share')
        passphrase = cryptohelper.recover_passphrase(shares)
        privkey_show = yield get_show_privatekey(showid, passphrase)

        result = {
            'showid': showid,
            'users': [],
        }
        users = yield get_user_keypair_from_showid(showid)
        for user in users:
            user_id = user['id']
            user_privkey_pem = cryptohelper.decrypt_blob(
                privkey_show,
                user['enc_private_key']
            )
            cur_result = {
                'id': user_id,
                'publickey': user['public_key'],
            }
            user_privkey = cryptohelper.import_key(user_privkey_pem)
            access_tokens = yield get_user_tokens(user_id)
            for key, value in access_tokens.items():
                if not isinstance(value, bytes):
                    continue
                cur_result[key] = cryptohelper.decrypt_blob(
                    user_privkey,
                    value
                )
            result['users'].append(cur_result)
        return self.api_response(result)
 def get(self):
     showid = self.get_argument('showtime_id')
     shares = self.get_arguments('share')
     passphrase = self.get_argument('passphrase', None)
     if not (bool(shares) ^ bool(passphrase)):
         return self.error(
             400,
             'Either shares or passphrase needs to be provided'
         )
     if not passphrase:
         passphrase = cryptohelper.recover_passphrase(shares)
     privkey_show = yield get_show_privatekey(showid, passphrase)
     show_info = yield get_showtime(showid)
     result = {
         'showid': showid,
         'date': show_info['date'],
         'users': [],
     }
     users = yield get_user_keypair_from_showid(showid)
     for user in users:
         user_id = user['id']
         user_blob = yield get_user(user_id)
         user_privkey_pem = cryptohelper.decrypt_blob(
             privkey_show,
             user['enc_private_key']
         )
         meta = dict(showid=showid, **user_blob)
         cur_result = {
             'id': user_id,
             'meta': meta,
             'publickey': user['public_key'],
             'privatekey': user_privkey_pem,
             'services': {},
         }
         user_privkey = cryptohelper.import_key(user_privkey_pem)
         access_tokens = yield get_user_tokens(user_id)
         if access_tokens is not None:
             for key, value in access_tokens.items():
                 if not isinstance(value, bytes):
                     continue
                 cur_result['services'][key] = cryptohelper.decrypt_blob(
                     user_privkey,
                     value
                 )
         else:
             cur_result['services'] = {}
         result['users'].append(cur_result)
     return self.api_response(result)
Esempio n. 5
0
def get_user_publickey(userid):
    conn = yield connection()
    publickey = yield r.table('encryption_user'). \
        get(userid).get_field('public_key').run(conn)
    return cryptohelper.import_key(publickey)
Esempio n. 6
0
def get_show_privatekey(showid, passphrase=None):
    conn = yield connection()
    privatekey = yield r.table('encryption_show'). \
        get(showid).get_field('private_key').run(conn)
    return cryptohelper.import_key(privatekey, passphrase)
Esempio n. 7
0
def get_show_publickey(showid):
    conn = yield connection()
    publickey = yield r.table('encryption_show'). \
        get(showid).get_field('public_key').run(conn)
    return cryptohelper.import_key(publickey)