def loadSession(self, recipientId, deviceId): q = "SELECT record FROM sessions WHERE recipient_id = ? AND device_id = ?" c = self.dbConn.cursor() c.execute(q, (recipientId, deviceId)) result = c.fetchone() if result: return SessionRecord(serialized=result[0]) else: return SessionRecord()
def loadSession(self, recipientId, deviceId): with self.db_locker: q = "SELECT record FROM sessions WHERE recipient_id = ? AND device_id = ?" c = self.dbConn.cursor() try: c.execute(q, (recipientId, deviceId)) result = c.fetchone() if result: return SessionRecord(serialized=result[0]) else: return SessionRecord() except Exception as e: logging.exception(e)
def getAllSessions(self): q = "SELECT recipient_id, device_id, record FROM sessions" c = self.dbConn.cursor() c.execute(q) result = [(r[0], r[1], SessionRecord(serialized=self.cryptostorage.decrypt(r[2]))) for r in c.fetchall()] return result
def loadSession(self, recipientId, deviceId): result = None dbConn = self.get_conn() q = "SELECT record FROM {}_sessions WHERE recipient_id = %s AND device_id = %s".format( self.phoneNumber) try: c = dbConn.cursor() c.execute(q, (recipientId, deviceId)) result = c.fetchone() dbConn.close() except: pass if result: return SessionRecord(serialized=result[0]) else: return SessionRecord()
def update_context_list(self, *args): self.fpr_model.clear() state = self.omemostate if self.notebook.get_current_page() == 1: contact_jid = self.own_jid else: contact_jid = self.contact.jid trust_str = {0: 'False', 1: 'True', 2: 'Undecided'} if self.groupchat and self.notebook.get_current_page() == 0: contact_jids = [] for nick in self.plugin.groupchat[contact_jid]: real_jid = self.plugin.groupchat[contact_jid][nick] if real_jid == self.own_jid: continue contact_jids.append(real_jid) session_db = state.store.getSessionsFromJids(contact_jids) else: session_db = state.store.getSessionsFromJid(contact_jid) for item in session_db: color = { 0: '#FF0040', # red 1: '#2EFE2E', # green 2: '#FF8000' } # orange _id, jid, deviceid, record, active = item active = bool(active) identity_key = SessionRecord(serialized=record). \ getSessionState().getRemoteIdentityKey() fpr = binascii.hexlify(identity_key.getPublicKey().serialize()) fpr = human_hash(fpr[2:]) trust = state.store.isTrustedIdentity(jid, identity_key) if not active: color[trust] = '#585858' # grey self.fpr_model.append( (_id, jid, trust_str[trust], '<tt><span foreground="{}">{}</span></tt>'.format( color[trust], fpr), deviceid))
def update_context_list(self, *args): self.fpr_model.clear() state = self.omemostate if self.notebook.get_current_page() == 1: contact_jid = self.own_jid else: contact_jid = self.contact.jid trust_str = {0: 'False', 1: 'True', 2: 'Undecided'} if self.groupchat and self.notebook.get_current_page() == 0: contact_jids = [] for nick in self.plugin.groupchat[contact_jid]: real_jid = self.plugin.groupchat[contact_jid][nick] if real_jid == self.own_jid: continue contact_jids.append(real_jid) session_db = state.store.getSessionsFromJids(contact_jids) else: session_db = state.store.getSessionsFromJid(contact_jid) for item in session_db: color = {0: '#FF0040', # red 1: '#2EFE2E', # green 2: '#FF8000'} # orange _id, jid, deviceid, record, active = item active = bool(active) identity_key = SessionRecord(serialized=record). \ getSessionState().getRemoteIdentityKey() fpr = binascii.hexlify(identity_key.getPublicKey().serialize()) fpr = human_hash(fpr[2:]) trust = state.store.isTrustedIdentity(jid, identity_key) if not active: color[trust] = '#585858' # grey self.fpr_model.append( (_id, jid, trust_str[trust], '<tt><span foreground="{}">{}</span></tt>'. format(color[trust], fpr), deviceid))
def getActiveSessionsKeys(self, recipientId): q = "SELECT record FROM sessions WHERE active = 1 AND recipient_id = ?" c = self.dbConn.cursor() result = [] for row in c.execute(q, (recipientId, )): public_key = (SessionRecord(serialized=row[0]).getSessionState(). getRemoteIdentityKey().getPublicKey()) result.append(public_key.serialize()) return result
def test_basicSessionV3(self): aliceSessionRecord = SessionRecord() bobSessionRecord = SessionRecord() self.initializeSessionsV3(aliceSessionRecord.getSessionState(), bobSessionRecord.getSessionState()) self.runInteraction(aliceSessionRecord, bobSessionRecord)
def update_context_list(self): log.debug('update_context_list') self.fpr_model.clear() self.device_model.clear() if len(self.account_store) == 0: self.B.get_object('ID').set_markup('') self.B.get_object('fingerprint_label').set_markup('') self.B.get_object('trust_button').set_sensitive(False) self.B.get_object('delfprbutton').set_sensitive(False) self.B.get_object('refresh').set_sensitive(False) self.B.get_object('cleardevice_button').set_sensitive(False) return active = self.B.get_object('account_combobox').get_active() account = self.account_store[active][0] # Set buttons active self.B.get_object('trust_button').set_sensitive(True) self.B.get_object('delfprbutton').set_sensitive(True) self.B.get_object('refresh').set_sensitive(True) if account == 'Local': self.B.get_object('cleardevice_button').set_sensitive(False) else: self.B.get_object('cleardevice_button').set_sensitive(True) # Set FPR Label and DeviceID state = self.plugin.get_omemo_state(account) deviceid = state.own_device_id self.B.get_object('ID').set_markup('<tt>%s</tt>' % deviceid) ownfpr = binascii.hexlify(state.store.getIdentityKeyPair() .getPublicKey().serialize()) ownfpr = human_hash(ownfpr[2:]) self.B.get_object('fingerprint_label').set_markup('<tt>%s</tt>' % ownfpr) # Set Fingerprint List trust_str = {0: 'False', 1: 'True', 2: 'Undecided'} session_db = state.store.getAllSessions() for item in session_db: color = {0: '#FF0040', # red 1: '#2EFE2E', # green 2: '#FF8000'} # orange _id, jid, deviceid, record, active = item active = bool(active) identity_key = SessionRecord(serialized=record). \ getSessionState().getRemoteIdentityKey() fpr = binascii.hexlify(identity_key.getPublicKey().serialize()) fpr = human_hash(fpr[2:]) trust = state.store.isTrustedIdentity(jid, identity_key) if not active: color[trust] = '#585858' # grey self.fpr_model.append( (_id, jid, trust_str[trust], '<tt><span foreground="{}">{}</span></tt>'. format(color[trust], fpr), deviceid)) # Set Device ID List for item in state.own_devices: self.device_model.append([item])
def update_context_list(self): self.fpr_model.clear() self.device_model.clear() self.qrcode = self.B.get_object('qrcode') self.qrinfo = self.B.get_object('qrinfo') if len(self.account_store) == 0: self.B.get_object('ID').set_markup('') self.B.get_object('fingerprint_label').set_markup('') self.B.get_object('trust_button').set_sensitive(False) self.B.get_object('delfprbutton').set_sensitive(False) self.B.get_object('refresh').set_sensitive(False) self.B.get_object('cleardevice_button').set_sensitive(False) self.B.get_object('qrcode').clear() return active = self.B.get_object('account_combobox').get_active() account = self.account_store[active][0].decode() # Set buttons active self.B.get_object('trust_button').set_sensitive(True) self.B.get_object('delfprbutton').set_sensitive(True) self.B.get_object('refresh').set_sensitive(True) if account == 'Local': self.B.get_object('cleardevice_button').set_sensitive(False) else: self.B.get_object('cleardevice_button').set_sensitive(True) # Set FPR Label and DeviceID state = self.plugin.get_omemo_state(account) deviceid = state.own_device_id self.B.get_object('ID').set_markup('<tt>%s</tt>' % deviceid) ownfpr = binascii.hexlify(state.store.getIdentityKeyPair() .getPublicKey().serialize()) human_ownfpr = human_hash(ownfpr[2:]) self.B.get_object('fingerprint_label').set_markup('<tt>%s</tt>' % human_ownfpr) # Set Fingerprint List trust_str = {0: 'False', 1: 'True', 2: 'Undecided'} session_db = state.store.getAllSessions() for item in session_db: color = {0: '#FF0040', # red 1: '#2EFE2E', # green 2: '#FF8000'} # orange _id, jid, deviceid, record, active = item active = bool(active) identity_key = SessionRecord(serialized=record). \ getSessionState().getRemoteIdentityKey() fpr = binascii.hexlify(identity_key.getPublicKey().serialize()) fpr = human_hash(fpr[2:]) trust = state.store.isTrustedIdentity(jid, identity_key) if not active: color[trust] = '#585858' # grey self.fpr_model.append( (_id, jid, trust_str[trust], '<tt><span foreground="{}">{}</span></tt>'. format(color[trust], fpr), deviceid)) # Set Device ID List for item in state.own_devices: self.device_model.append([item]) # Set QR Verification Code if PILLOW: path = self.get_qrcode( gajim.get_jid_from_account(account), deviceid, ownfpr[2:]) self.qrcode.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(path)) self.qrinfo.hide() else: self.qrinfo.show()
def _convert_record(record): return SessionRecord(serialized=record)
def loadSession(self, recipientId, deviceId): query = '''SELECT record as "record [session_record]" FROM sessions WHERE recipient_id = ? AND device_id = ?''' result = self._con.execute(query, (recipientId, deviceId)).fetchone() return result.record if result is not None else SessionRecord()