def add_contact_manage(self, contact): self.contacts_rows = [] self.cbb_contacts.grab_focus() for c in gajim.contacts.iter_contacts(self.account): jid = gajim.get_jid_without_resource(c.get_full_jid()) r = self.ts_contacts.insert(None, len(self.ts_contacts), (jid, )) if c.get_full_jid() == contact.get_full_jid(): self.cbb_contacts.set_active_iter(r) self.contacts_rows.append(r) self.manage_vbox2.set_sensitive(True) self.bt_remove.set_sensitive(False) self.add_file_list(self.plugin.database.get_files_name(self.account, gajim.get_jid_without_resource(contact.get_full_jid())), self.ts_files)
def message_received(self, msg): if msg.stanza.getTag('encrypted', namespace=NS_OMEMO) and \ msg.mtype == 'chat': account = msg.conn.name log.debug(account + ' => OMEMO msg received') state = self.get_omemo_state(account) if msg.forwarded and msg.sent: from_jid = str(msg.stanza.getTo()) # why gajim? why? log.debug('message was forwarded doing magic') else: from_jid = str(msg.stanza.getFrom()) msg_dict = unpack_encrypted(msg.stanza.getTag ('encrypted', namespace=NS_OMEMO)) msg_dict['sender_jid'] = gajim.get_jid_without_resource(from_jid) plaintext = state.decrypt_msg(msg_dict) if not plaintext: return msg.msgtxt = plaintext # bug? there must be a body or the message gets dropped from history msg.stanza.setBody(plaintext) contact_jid = gajim.get_jid_without_resource(from_jid) if account in self.ui_list and \ contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].activate_omemo() return False elif msg.stanza.getTag('body') and msg.mtype == 'chat': account = msg.conn.name from_jid = str(msg.stanza.getFrom()) jid = gajim.get_jid_without_resource(from_jid) state = self.get_omemo_state(account) omemo_enabled = state.encryption.is_active(jid) if omemo_enabled: msg.msgtxt = '**Unencrypted** ' + msg.msgtxt # msg.stanza.setBody(msg.msgtxt) try: gui = self.ui_list[account].get(jid, None) if gui and gui.encryption_active(): gui.plain_warning() except KeyError: log.debug('No Ui present for ' + jid + ', Ui Warning not shown')
def message_received(self, msg): if msg.stanza.getTag('encrypted', namespace=NS_OMEMO) and \ msg.mtype == 'chat': account = msg.conn.name log.debug(account + ' => OMEMO msg received') state = self.get_omemo_state(account) if msg.forwarded and msg.sent: from_jid = str(msg.stanza.getTo()) # why gajim? why? log.debug('message was forwarded doing magic') else: from_jid = str(msg.stanza.getFrom()) self.print_msg_to_log(msg.stanza) msg_dict = unpack_encrypted( msg.stanza.getTag('encrypted', namespace=NS_OMEMO)) msg_dict['sender_jid'] = gajim.get_jid_without_resource(from_jid) plaintext = state.decrypt_msg(msg_dict) if not plaintext: return msg.msgtxt = plaintext # bug? there must be a body or the message gets dropped from history msg.stanza.setBody(plaintext) contact_jid = gajim.get_jid_without_resource(from_jid) if account in self.ui_list and \ contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].activate_omemo() return False elif msg.stanza.getTag('body') and msg.mtype == 'chat': account = msg.conn.name from_jid = str(msg.stanza.getFrom()) jid = gajim.get_jid_without_resource(from_jid) state = self.get_omemo_state(account) omemo_enabled = state.encryption.is_active(jid) if omemo_enabled: msg.msgtxt = '**Unencrypted** ' + msg.msgtxt # msg.stanza.setBody(msg.msgtxt) try: gui = self.ui_list[account].get(jid, None) if gui and gui.encryption_active(): gui.plain_warning() except KeyError: log.debug('No Ui present for ' + jid + ', Ui Warning not shown')
def set_entity_time(self, obj): if obj.conn.name != self.account: return if self.xml.get_object('information_notebook').get_n_pages() < 5: return if self.gc_contact: if obj.fjid != self.contact.jid: return elif gajim.get_jid_without_resource(obj.fjid) != self.contact.jid: return i = 0 time_s = '' while i in self.time_info: if self.time_info[i]['resource'] == obj.resource: if obj.time_info: self.time_info[i]['time'] = obj.time_info else: self.time_info[i]['time'] = Q_('?Time:Unknown') else: if not self.time_info[i]['time']: self.time_info[i]['time'] = Q_('?Time:Unknown') if i > 0: time_s += '\n' time_s += self.time_info[i]['time'] i += 1 self.xml.get_object('time_label').set_text(time_s) self.entity_time_arrived = True
def get_contact_from_iter(self, treestore, iter_): toplevel = treestore.get_iter_root() while toplevel: if treestore.is_ancestor(toplevel, iter_): return gajim.get_jid_without_resource(treestore.get_value( toplevel, 0)) toplevel = treestore.iter_next(toplevel)
def handle_outgoing_stanza(self, event): try: if not event.msg_iq.getTag('body'): return account = event.conn.name state = self.get_omemo_state(account) full_jid = str(event.msg_iq.getAttr('to')) to_jid = gajim.get_jid_without_resource(full_jid) if not state.encryption.is_active(to_jid): return # Delete previous Message out of Correction Message Stanza if event.msg_iq.getTag('replace', namespace=NS_CORRECT): event.msg_iq.delChild('encrypted') plaintext = event.msg_iq.getBody().encode('utf8') msg_dict = state.create_msg(gajim.get_jid_from_account(account), to_jid, plaintext) if not msg_dict: return True encrypted_node = OmemoMessage(msg_dict) event.msg_iq.delChild('body') event.msg_iq.addChild(node=encrypted_node) store = Node('store', attrs={'xmlns': NS_HINTS}) event.msg_iq.addChild(node=store) self.print_msg_to_log(event.msg_iq) except Exception as e: log.debug(e) return True
def close(ctrl): if reason is not None: # We are leaving gc with a status message ctrl.shutdown(reason) else: # We are leaving gc without status message or it's a chat ctrl.shutdown() # Update external state gajim.events.remove_events(ctrl.account, ctrl.get_full_jid, types=['printed_msg', 'chat', 'gc_msg']) fjid = ctrl.get_full_jid() jid = gajim.get_jid_without_resource(fjid) fctrl = self.get_control(fjid, ctrl.account) bctrl = self.get_control(jid, ctrl.account) # keep last_message_time around unless this was our last control with # that jid if not fctrl and not bctrl: del gajim.last_message_time[ctrl.account][fjid] # Disconnect tab DnD only if GTK version < 2.10 if gtk.pygtk_version < (2, 10, 0) or gtk.gtk_version < (2, 10, 0): self.disconnect_tab_dnd(ctrl.widget) self.notebook.remove_page(self.notebook.page_num(ctrl.widget)) del self._controls[ctrl.account][fjid] if len(self._controls[ctrl.account]) == 0: del self._controls[ctrl.account] self.check_tabs() self.show_title()
def start_file_transfer(self, jid, file_props, request=False): logger.info("start file transfer with file: %s" % file_props) contact = gajim.contacts.get_contact_with_highest_priority(self.name, gajim.get_jid_without_resource(jid)) if gajim.contacts.is_gc_contact(self.name,jid): gcc = jid.split('/') if len(gcc) == 2: contact = gajim.contacts.get_gc_contact(self.name, gcc[0], gcc[1]) if contact is None: return use_security = contact.supports(nbxmpp.NS_JINGLE_XTLS) jingle = JingleSession(self, weinitiate=True, jid=jid, werequest=request) # this is a file transfer jingle.session_type_FT = True self._sessions[jingle.sid] = jingle file_props.sid = jingle.sid if contact.supports(nbxmpp.NS_JINGLE_BYTESTREAM): transport = JingleTransportSocks5() elif contact.supports(nbxmpp.NS_JINGLE_IBB): transport = JingleTransportIBB() c = JingleFileTransfer(jingle, transport=transport, file_props=file_props, use_security=use_security) file_props.algo = self.__hash_support(contact) jingle.add_content('file' + helpers.get_random_string_16(), c) jingle.start_session() return c.transport.sid
def on_ok(_waitid): # if timeout: # self._owner.set_timeout(timeout) to = stanza.getTo() to = gajim.get_jid_without_resource(to) try: item = self.roster[to] except KeyError: # Contact offline item = None conn = None if to in self.recipient_to_hash: conn = self.connections[self.recipient_to_hash[to]] elif item: the_address = None for address in item['addresses']: if address['address'] in self.ip_to_hash: the_address = address if the_address and the_address['address'] in self.ip_to_hash: hash_ = self.ip_to_hash[the_address['address']] if self.hash_to_port[hash_] == the_address['port']: conn = self.connections[hash_] if func: conn.Dispatcher.on_responses[_waitid] = (func, args) conn.onreceive(conn.Dispatcher._WaitForData) conn.Dispatcher._expected[_waitid] = None
def _remove_transfer(self, iter_, sid, file_props): self.model.remove(iter_) if 'tt_account' in file_props: # file transfer is set account = file_props['tt_account'] if account in gajim.connections: # there is a connection to the account gajim.connections[account].remove_transfer(file_props) if file_props['type'] == 'r': # we receive a file other = file_props['sender'] else: # we send a file other = file_props['receiver'] if isinstance(other, unicode): jid = gajim.get_jid_without_resource(other) else: # It's a Contact instance jid = other.jid for ev_type in ('file-error', 'file-completed', 'file-request-error', 'file-send-error', 'file-stopped'): for event in gajim.events.get_events(account, jid, [ev_type]): if event.parameters['sid'] == file_props['sid']: gajim.events.remove_events(account, jid, event) gajim.interface.roster.draw_contact(jid, account) gajim.interface.roster.show_title() del(self.files_props[sid[0]][sid[1:]]) del(file_props)
def handle_device_list_update(self, event): """ Check if the passed event is a device list update and store the new device ids. Parameters ---------- event : MessageReceivedEvent Returns ------- bool True if the given event was a valid device list update event See also -------- 4.2 Discovering peer support http://conversations.im/xeps/multi-end.html#usecases-discovering """ if event.pep_type != 'headline': return False devices_list = unpack_device_list_update(event.stanza, event.conn.name) if len(devices_list) == 0: return False account_name = event.conn.name contact_jid = gajim.get_jid_without_resource(event.fjid) state = self.get_omemo_state(account_name) my_jid = gajim.get_jid_from_account(account_name) if contact_jid == my_jid: log.info(account_name + ' => Received own device list:' + str( devices_list)) state.set_own_devices(devices_list) state.store.sessionStore.setActiveState(devices_list, my_jid) if not state.own_device_id_published() or anydup( state.own_devices): # Our own device_id is not in the list, it could be # overwritten by some other client? # Is a Device ID duplicated? self.publish_own_devices_list(account_name, state) else: log.info(account_name + ' => Received device list for ' + contact_jid + ':' + str(devices_list)) state.set_devices(contact_jid, set(devices_list)) state.store.sessionStore.setActiveState(devices_list, contact_jid) if (account_name in self.ui_list and contact_jid not in self.ui_list[account_name]): chat_control = gajim.interface.msg_win_mgr.get_control( contact_jid, account_name) if chat_control is not None: self.connect_ui(chat_control) # Look if Device Keys are missing and fetch them self.are_keys_missing(account_name, contact_jid) return True
def handle_outgoing_stanza(self, event): if not event.msg_iq.getTag('body'): return plaintext = event.msg_iq.getBody().encode('utf8') account = event.conn.name state = self.get_omemo_state(account) full_jid = str(event.msg_iq.getAttr('to')) to_jid = gajim.get_jid_without_resource(full_jid) if not state.encryption.is_active(to_jid): return False if not state.store.identityKeyStore.getTrustedFingerprints(to_jid): msg = "To send an encrypted message, you have to " \ "first trust the fingerprint of your contact!" if account in self.ui_list and \ to_jid in self.ui_list[account]: self.ui_list[account][to_jid].chat_control. \ print_conversation_line(msg, 'status', '', None) return True try: msg_dict = state.create_msg( gajim.get_jid_from_account(account), to_jid, plaintext) if not msg_dict: return True encrypted_node = OmemoMessage(msg_dict) event.msg_iq.delChild('body') event.msg_iq.addChild(node=encrypted_node) store = Node('store', attrs={'xmlns': NS_HINTS}) event.msg_iq.addChild(node=store) log.debug(account + ' => ' + str(event.msg_iq)) except: return True
def close(ctrl): if reason is not None: # We are leaving gc with a status message ctrl.shutdown(reason) else: # We are leaving gc without status message or it's a chat ctrl.shutdown() # Update external state gajim.events.remove_events(ctrl.account, ctrl.get_full_jid, types = ['printed_msg', 'chat', 'gc_msg']) fjid = ctrl.get_full_jid() jid = gajim.get_jid_without_resource(fjid) fctrl = self.get_control(fjid, ctrl.account) bctrl = self.get_control(jid, ctrl.account) # keep last_message_time around unless this was our last control with # that jid if not fctrl and not bctrl: del gajim.last_message_time[ctrl.account][fjid] # Disconnect tab DnD only if GTK version < 2.10 if gtk.pygtk_version < (2, 10, 0) or gtk.gtk_version < (2, 10, 0): self.disconnect_tab_dnd(ctrl.widget) self.notebook.remove_page(self.notebook.page_num(ctrl.widget)) del self._controls[ctrl.account][fjid] if len(self._controls[ctrl.account]) == 0: del self._controls[ctrl.account] self.check_tabs() self.show_title()
def __init__(self, conn, jid, thread_id, type_): stanza_session.StanzaSession.__init__(self, conn, jid, thread_id, type_) contact = gajim.contacts.get_contact(conn.name, gajim.get_jid_without_resource(str(jid))) self.name = contact.get_shown_name() self.base = None self.control = None
def gajim_log(cls, msg, account, fjid, no_print=False, is_status_message=True, thread_id=None): if not isinstance(fjid, unicode): fjid = unicode(fjid) if not isinstance(account, unicode): account = unicode(account) resource = gajim.get_resource_from_jid(fjid) jid = gajim.get_jid_without_resource(fjid) tim = time.localtime() if is_status_message is True: if not no_print: ctrl = cls.get_control(fjid, account) if ctrl: ctrl.print_conversation_line(u"[OTR] %s" % msg, "status", "", None) id = gajim.logger.write("chat_msg_recv", fjid, message=u"[OTR: %s]" % msg, tim=tim) # gajim.logger.write() only marks a message as unread (and so # only returns an id) when fjid is a real contact (NOT if it's a # GC private chat) if id: gajim.logger.set_read_messages([id]) else: session = gajim.connections[account].get_or_create_session(fjid, thread_id) session.received_thread_id |= bool(thread_id) session.last_receive = time.time() if not session.control: # look for an existing chat control without a session ctrl = cls.get_control(fjid, account) if ctrl: session.control = ctrl session.control.set_session(session) msg_id = gajim.logger.write("chat_msg_recv", fjid, message=u"[OTR: %s]" % msg, tim=tim) session.roster_message(jid, msg, tim=tim, msg_id=msg_id, msg_type="chat", resource=resource)
def get_contact_from_iter(self, treestore, iter_): toplevel = treestore.get_iter_root() while toplevel: if treestore.is_ancestor(toplevel, iter_): return gajim.get_jid_without_resource( treestore.get_value(toplevel, 0)) toplevel = treestore.iter_next(toplevel)
def add_contact_manage(self, contact): self.contacts_rows = [] self.cbb_contacts.grab_focus() for c in gajim.contacts.iter_contacts(self.account): jid = gajim.get_jid_without_resource(c.get_full_jid()) r = self.ts_contacts.insert(None, len(self.ts_contacts), (jid, )) if c.get_full_jid() == contact.get_full_jid(): self.cbb_contacts.set_active_iter(r) self.contacts_rows.append(r) self.manage_vbox2.set_sensitive(True) self.bt_remove.set_sensitive(False) self.add_file_list( self.plugin.database.get_files_name( self.account, gajim.get_jid_without_resource(contact.get_full_jid())), self.ts_files)
def on_ok(_waitid): # if timeout: # self._owner.set_timeout(timeout) to = unicode(stanza.getTo()) to = gajim.get_jid_without_resource(to) try: item = self.roster[to] except KeyError: # Contact offline item = None conn = None if to in self.recipient_to_hash: conn = self.connections[self.recipient_to_hash[to]] elif item: the_address = None for address in item['addresses']: if address['address'] in self.ip_to_hash: the_address = address if the_address and the_address['address'] in self.ip_to_hash: hash_ = self.ip_to_hash[the_address['address']] if self.hash_to_port[hash_] == the_address['port']: conn = self.connections[hash_] if func: conn.Dispatcher.on_responses[_waitid] = (func, args) conn.onreceive(conn.Dispatcher._WaitForData) conn.Dispatcher._expected[_waitid] = None
def _remove_transfer(self, iter_, sid, file_props): self.model.remove(iter_) if not file_props: return if file_props.tt_account: # file transfer is set account = file_props.tt_account if account in gajim.connections: # there is a connection to the account gajim.connections[account].remove_transfer(file_props) if file_props.type_ == 'r': # we receive a file other = file_props.sender else: # we send a file other = file_props.receiver if isinstance(other, str): jid = gajim.get_jid_without_resource(other) else: # It's a Contact instance jid = other.jid for ev_type in ('file-error', 'file-completed', 'file-request-error', 'file-send-error', 'file-stopped'): for event in gajim.events.get_events(account, jid, [ev_type]): if event.file_props.sid == file_props.sid: gajim.events.remove_events(account, jid, event) gajim.interface.roster.draw_contact(jid, account) gajim.interface.roster.show_title() FilesProp.deleteFileProp(file_props) del(file_props)
def start_file_transfer(self, jid, file_props, request=False): logger.info("start file transfer with file: %s", file_props) contact = gajim.contacts.get_contact_with_highest_priority( self.name, gajim.get_jid_without_resource(jid)) if gajim.contacts.is_gc_contact(self.name, jid): gcc = jid.split('/') if len(gcc) == 2: contact = gajim.contacts.get_gc_contact( self.name, gcc[0], gcc[1]) if contact is None: return use_security = contact.supports(nbxmpp.NS_JINGLE_XTLS) jingle = JingleSession(self, weinitiate=True, jid=jid, werequest=request) # this is a file transfer jingle.session_type_FT = True self._sessions[jingle.sid] = jingle file_props.sid = jingle.sid if contact.supports(nbxmpp.NS_JINGLE_BYTESTREAM): transport = JingleTransportSocks5() elif contact.supports(nbxmpp.NS_JINGLE_IBB): transport = JingleTransportIBB() c = JingleFileTransfer(jingle, transport=transport, file_props=file_props, use_security=use_security) file_props.algo = self.__hash_support(contact) jingle.add_content('file' + helpers.get_random_string_16(), c) jingle.start_session() return c.transport.sid
def _remove_transfer(self, iter_, sid, file_props): self.model.remove(iter_) if not file_props: return if file_props.tt_account: # file transfer is set account = file_props.tt_account if account in gajim.connections: # there is a connection to the account gajim.connections[account].remove_transfer(file_props) if file_props.type_ == 'r': # we receive a file other = file_props.sender else: # we send a file other = file_props.receiver if isinstance(other, str): jid = gajim.get_jid_without_resource(other) else: # It's a Contact instance jid = other.jid for ev_type in ('file-error', 'file-completed', 'file-request-error', 'file-send-error', 'file-stopped'): for event in gajim.events.get_events(account, jid, [ev_type]): if event.parameters.sid == file_props.sid: gajim.events.remove_events(account, jid, event) gajim.interface.roster.draw_contact(jid, account) gajim.interface.roster.show_title() FilesProp.deleteFileProp(file_props) del(file_props)
def mam_message_received(self, msg): """ Handles an incoming MAM message Payload is decrypted and the plaintext is written into the event object. Afterwards the event is passed on further to Gajim. Parameters ---------- msg : MamMessageReceivedEvent Returns ------- Return means that the Event is passed on to Gajim """ account = msg.conn.name if account in self.disabled_accounts: return if msg.msg_.getTag('openpgp', namespace=NS_PGP): return omemo_encrypted_tag = msg.msg_.getTag('encrypted', namespace=NS_OMEMO) if omemo_encrypted_tag: log.debug(account + ' => OMEMO MAM msg received') state = self.get_omemo_state(account) from_jid = str(msg.msg_.getAttr('from')) from_jid = gajim.get_jid_without_resource(from_jid) msg_dict = unpack_encrypted(omemo_encrypted_tag) msg_dict['sender_jid'] = from_jid plaintext = state.decrypt_msg(msg_dict) if not plaintext: return self.print_msg_to_log(msg.msg_) msg.msgtxt = plaintext contact_jid = msg.with_ if account in self.ui_list and \ contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].activate_omemo() return False elif msg.msg_.getTag('body'): account = msg.conn.name jid = msg.with_ state = self.get_omemo_state(account) omemo_enabled = state.encryption.is_active(jid) if omemo_enabled: msg.msgtxt = '**Unencrypted** ' + msg.msgtxt
def save_if_not_exists(self, with_, direction, tim, msg='', nick=None, additional_data=None): if additional_data is None: additional_data = {} if tim: time_col = float(tim) else: time_col = float(time.time()) if not msg: return if self.jid_is_from_pm(with_) or nick: # It's a groupchat message if nick: # It's a message from a groupchat occupent type_ = 'gc_msg' with_ = with_ + '/' + nick else: # It's a server message message, we don't log them return else: if direction == 'from': type_ = 'chat_msg_recv' elif direction == 'to': type_ = 'chat_msg_sent' jid_id = self.get_jid_id(with_) where_sql = 'jid_id = %s AND message=?' % jid_id if type_ == 'gc_msg': # We cannot differentiate gc message and pm messages, so look in # both logs with_2 = gajim.get_jid_without_resource(with_) if with_ != with_2: jid_id2 = self.get_jid_id(with_2) where_sql = 'jid_id in (%s, %s) AND message=?' % (jid_id, jid_id2) start_time = time_col - 300 # 5 minutes arrount given time end_time = time_col + 300 # 5 minutes arrount given time self.cur.execute( ''' SELECT log_line_id FROM logs WHERE (%s) AND time BETWEEN %d AND %d ORDER BY time ''' % (where_sql, start_time, end_time), (msg, )) results = self.cur.fetchall() if results: log.debug('Log already in DB, ignoring it') return log.debug('New log received from server archives, storing it') self.write(type_, with_, message=msg, tim=tim, additional_data=additional_data)
def _nec_raw_message(self, obj): if not HAS_GOOCANVAS: return if obj.stanza.getTag('sxe', namespace=NS_SXE): account = obj.conn.name try: fjid = helpers.get_full_jid_from_iq(obj.stanza) except helpers.InvalidFormat: obj.conn.dispatch('ERROR', (_('Invalid Jabber ID'), _('A message from a non-valid JID arrived, it has been ' 'ignored.'))) jid = gajim.get_jid_without_resource(fjid) ctrl = (gajim.interface.msg_win_mgr.get_control(fjid, account) or gajim.interface.msg_win_mgr.get_control(jid, account)) if not ctrl: return sxe = obj.stanza.getTag('sxe') if not sxe: return sid = sxe.getAttr('session') if (jid, sid) not in obj.conn._sessions: pass # newjingle = JingleSession(con=self, weinitiate=False, jid=jid, sid=sid) # self.addJingle(newjingle) # we already have such session in dispatcher... session = obj.conn.get_jingle_session(fjid, sid) cn = session.contents[('initiator', 'xhtml')] error = obj.stanza.getTag('error') if error: action = 'iq-error' else: action = 'edit' cn.on_stanza(obj.stanza, sxe, error, action) # def __editCB(self, stanza, content, error, action): #new_tags = sxe.getTags('new') #remove_tags = sxe.getTags('remove') #if new_tags is not None: ## Process new elements #for tag in new_tags: #if tag.getAttr('type') == 'element': #ctrl.whiteboard.recieve_element(tag) #elif tag.getAttr('type') == 'attr': #ctrl.whiteboard.recieve_attr(tag) #ctrl.whiteboard.apply_new() #if remove_tags is not None: ## Delete rids #for tag in remove_tags: #target = tag.getAttr('target') #ctrl.whiteboard.image.del_rid(target) # Stop propagating this event, it's handled return True
def send_file_approval(self, file_props): """ Send iq, confirming that we want to download the file """ # user response to ConfirmationDialog may come after we've disconneted if not self.connection or self.connected < 2: return # file transfer initiated by a jingle session log.info("send_file_approval: jingle session accept") if file_props.session_type == 'jingle': session = self.get_jingle_session(file_props.sender, file_props.sid) if not session: return content = None for c in session.contents.values(): if c.transport.sid == file_props.transport_sid: content = c break if not content: return if not session.accepted: content = session.get_content('file', content.name) if content.use_security: fingerprint = content.x509_fingerprint if not jingle_xtls.check_cert( gajim.get_jid_without_resource(file_props.sender), fingerprint): id_ = jingle_xtls.send_cert_request( self, file_props.sender) jingle_xtls.key_exchange_pend(id_, content.on_cert_received, []) return session.approve_session() session.approve_content('file', content.name) return iq = nbxmpp.Iq(to=file_props.sender, typ='result') iq.setAttr('id', file_props.request_id) si = iq.setTag('si', namespace=nbxmpp.NS_SI) if file_props.offset: file_tag = si.setTag('file', namespace=nbxmpp.NS_FILE) range_tag = file_tag.setTag('range') range_tag.setAttr('offset', file_props.offset) feature = si.setTag('feature', namespace=nbxmpp.NS_FEATURE) _feature = nbxmpp.DataForm(typ='submit') feature.addChild(node=_feature) field = _feature.setField('stream-method') field.delAttr('type') if nbxmpp.NS_BYTESTREAM in file_props.stream_methods: field.setValue(nbxmpp.NS_BYTESTREAM) else: file_props.transport_sid = file_props.sid field.setValue(nbxmpp.NS_IBB) self.connection.send(iq)
def send(self, stanza, is_message=False, now=False, on_ok=None, on_not_ok=None): to = stanza.getTo() if to is None: # Can’t send undirected stanza over Zeroconf. return -1 to = gajim.get_jid_without_resource(to) stanza.setFrom(self.roster.zeroconf.name) try: item = self.roster[to] except KeyError: # Contact offline return -1 # look for hashed connections if to in self.recipient_to_hash: conn = self.connections[self.recipient_to_hash[to]] id_ = stanza.getID() or '' if conn.add_stanza(stanza, is_message): if on_ok: on_ok(id_) return the_address = None for address in item['addresses']: if address['address'] in self.ip_to_hash: the_address = address if the_address and the_address['address'] in self.ip_to_hash: hash_ = self.ip_to_hash[the_address['address']] if self.hash_to_port[hash_] == the_address['port']: conn = self.connections[hash_] id_ = stanza.getID() or '' if conn.add_stanza(stanza, is_message): if on_ok: on_ok(id_) return # otherwise open new connection if not stanza.getID(): stanza.setID('zero') addresses_ = [] for address in item['addresses']: addresses_ += [{ 'host': address['address'], 'address': address['address'], 'port': address['port'] }] P2PClient(None, addresses_, self, [(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
def handle_agent_info_received(self, event): global jid_to_servers if NS_HTTPUPLOAD in event.features and gajim.jid_is_transport(event.jid): own_jid = gajim.get_jid_without_resource(str(event.stanza.getTo())) jid_to_servers[own_jid] = event.jid # map own jid to upload component's jid log.info(own_jid + " can do http uploads via component " + event.jid) # update all buttons for base in self.controls: self.update_button_state(base.chat_control)
def send_file_approval(self, file_props): """ Send iq, confirming that we want to download the file """ # user response to ConfirmationDialog may come after we've disconneted if not self.connection or self.connected < 2: return # file transfer initiated by a jingle session log.info("send_file_approval: jingle session accept") if file_props.session_type == 'jingle': session = self.get_jingle_session(file_props.sender, file_props.sid) if not session: return content = None for c in session.contents.values(): if c.transport.sid == file_props.transport_sid: content = c break if not content: return if not session.accepted: content = session.get_content('file', content.name) if content.use_security: fingerprint = content.x509_fingerprint if not jingle_xtls.check_cert( gajim.get_jid_without_resource(file_props.sender), fingerprint): id_ = jingle_xtls.send_cert_request(self, file_props.sender) jingle_xtls.key_exchange_pend(id_, content.on_cert_received, []) return session.approve_session() session.approve_content('file', content.name) return iq = nbxmpp.Iq(to=unicode(file_props.sender), typ='result') iq.setAttr('id', file_props.request_id) si = iq.setTag('si', namespace=nbxmpp.NS_SI) if file_props.offset: file_tag = si.setTag('file', namespace=nbxmpp.NS_FILE) range_tag = file_tag.setTag('range') range_tag.setAttr('offset', file_props.offset) feature = si.setTag('feature', namespace=nbxmpp.NS_FEATURE) _feature = nbxmpp.DataForm(typ='submit') feature.addChild(node=_feature) field = _feature.setField('stream-method') field.delAttr('type') if nbxmpp.NS_BYTESTREAM in file_props.stream_methods: field.setValue(nbxmpp.NS_BYTESTREAM) else: file_props.transport_sid = file_props.sid field.setValue(nbxmpp.NS_IBB) self.connection.send(iq)
def gc_presence_received(self, event): account = event.conn.name if account in self.disabled_accounts: return if not hasattr(event, 'real_jid') or not event.real_jid: return room = event.room_jid jid = gajim.get_jid_without_resource(event.real_jid) nick = event.nick if '303' in event.status_code: # Nick Changed if room in self.groupchat: if nick in self.groupchat[room]: del self.groupchat[room][nick] self.groupchat[room][event.new_nick] = jid log.debug('Nick Change: old: %s, new: %s, jid: %s ', nick, event.new_nick, jid) log.debug('Members after Change: %s', self.groupchat[room]) else: if nick in self.temp_groupchat[room]: del self.temp_groupchat[room][nick] self.temp_groupchat[room][event.new_nick] = jid return if room not in self.groupchat: if room not in self.temp_groupchat: self.temp_groupchat[room] = {} if nick not in self.temp_groupchat[room]: self.temp_groupchat[room][nick] = jid else: # Check if we received JID over Memberlist if jid in self.groupchat[room]: del self.groupchat[room][jid] # Add JID with Nick if nick not in self.groupchat[room]: self.groupchat[room][nick] = jid log.debug('JID Added: ' + jid) if '100' in event.status_code: # non-anonymous Room (Full JID) if room not in self.groupchat: self.groupchat[room] = self.temp_groupchat[room] log.debug('OMEMO capable Room found: %s', room) gajim.connections[account].get_affiliation_list(room, 'owner') gajim.connections[account].get_affiliation_list(room, 'admin') gajim.connections[account].get_affiliation_list(room, 'member') self.ui_list[account][room].sensitive(True)
def gajim_log(cls, msg, account, fjid, no_print=False, is_status_message=True, thread_id=None): if not isinstance(fjid, unicode): fjid = unicode(fjid) if not isinstance(account, unicode): account = unicode(account) resource = gajim.get_resource_from_jid(fjid) jid = gajim.get_jid_without_resource(fjid) tim = time.localtime() if is_status_message is True: if not no_print: ctrl = cls.get_control(fjid, account) if ctrl: ctrl.print_conversation_line(u'[OTR] %s' % msg, 'status', '', None) if gajim.config.should_log(account, jid): id = gajim.logger.write('chat_msg_recv', fjid, message=u'[OTR: %s]' % msg, tim=tim) # gajim.logger.write() only marks a message as unread (and so # only returns an id) when fjid is a real contact (NOT if it's a # GC private chat) if id: gajim.logger.set_read_messages([id]) else: session = gajim.connections[account].get_or_create_session( fjid, thread_id) session.received_thread_id |= bool(thread_id) session.last_receive = time.time() if not session.control: # look for an existing chat control without a session ctrl = cls.get_control(fjid, account) if ctrl: session.control = ctrl session.control.set_session(session) if gajim.config.should_log(account, jid): msg_id = gajim.logger.write('chat_msg_recv', fjid, message=u'[OTR: %s]' % msg, tim=tim) session.roster_message(jid, msg, tim=tim, msg_id=msg_id, msg_type='chat', resource=resource)
def handle_device_list_update(self, event): """ Check if the passed event is a device list update and store the new device ids. Parameters ---------- event : MessageReceivedEvent Returns ------- bool True if the given event was a valid device list update event See also -------- 4.2 Discovering peer support http://conversations.im/xeps/multi-end.html#usecases-discovering """ if event.pep_type != 'headline': return False devices_list = unpack_device_list_update(event) if len(devices_list) == 0: return False account = event.conn.name contact_jid = gajim.get_jid_without_resource(event.fjid) state = self.get_omemo_state(account) my_jid = gajim.get_jid_from_account(account) log.debug(account + ' ⇒ Received OMEMO pep for jid ' + contact_jid) if contact_jid == my_jid: log.debug(state.name + ' ⇒ Received own device_list ' + str( devices_list)) state.add_own_devices(devices_list) if not state.own_device_id_published() or anydup( state.own_devices): # Our own device_id is not in the list, it could be # overwritten by some other client? # also remove duplicates devices_list = list(set(state.own_devices)) devices_list.append(state.own_device_id) self.publish_own_devices_list(state) else: state.add_devices(contact_jid, devices_list) if account in self.ui_list and contact_jid in self.ui_list[ account]: self.ui_list[account][contact_jid].toggle_omemo(True) self.update_prekeys(account, contact_jid) return True
def handle_device_list_update(self, event): """ Check if the passed event is a device list update and store the new device ids. Parameters ---------- event : MessageReceivedEvent Returns ------- bool True if the given event was a valid device list update event See also -------- 4.2 Discovering peer support http://conversations.im/xeps/multi-end.html#usecases-discovering """ if event.pep_type != 'headline': return False devices_list = unpack_device_list_update(event) if len(devices_list) == 0: return False account = event.conn.name contact_jid = gajim.get_jid_without_resource(event.fjid) state = self.get_omemo_state(account) my_jid = gajim.get_jid_from_account(account) log.debug(account + ' ⇒ Received OMEMO pep for jid ' + contact_jid) if contact_jid == my_jid: log.debug(state.name + ' ⇒ Received own device_list ' + str(devices_list)) state.add_own_devices(devices_list) if not state.own_device_id_published() or anydup( state.own_devices): # Our own device_id is not in the list, it could be # overwritten by some other client? # also remove duplicates devices_list = list(set(state.own_devices)) devices_list.append(state.own_device_id) self.publish_own_devices_list(state) else: state.add_devices(contact_jid, devices_list) if account in self.ui_list and contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].toggle_omemo(True) self.update_prekeys(account, contact_jid) return True
def get_control(fjid, account): # first try to get the window with the full jid ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account) if ctrl: # got one, be happy return ctrl # otherwise try without the resource ctrl = gajim.interface.msg_win_mgr.get_control(gajim.get_jid_without_resource(fjid), account) # but only use it when it's not a GC window if ctrl and ctrl.TYPE_ID == TYPE_CHAT: return ctrl
def __on_transport_info(self, stanza, content, error, action): log.info("__on_transport_info") candError = content.getTag('transport').getTag('candidate-error') candUsed = content.getTag('transport').getTag('candidate-used') if (candError or candUsed) and \ self.state >= STATE_CAND_SENT_AND_RECEIVED: raise nbxmpp.NodeProcessed if candError: if not gajim.socks5queue.listener.connections: gajim.socks5queue.listener.disconnect() self.nominated_cand['peer-cand'] = False if self.state == STATE_CAND_SENT: if not self.nominated_cand['our-cand'] and \ not self.nominated_cand['peer-cand']: if not self.weinitiate: return self.__state_changed(STATE_TRANSPORT_REPLACE) else: response = stanza.buildReply('result') response.delChild(response.getQuery()) self.session.connection.connection.send(response) self.__state_changed(STATE_TRANSFERING) raise nbxmpp.NodeProcessed else: args = {'candError' : True} self.__state_changed(STATE_CAND_RECEIVED, args) return if candUsed: streamhost_cid = candUsed.getAttr('cid') streamhost_used = None for cand in self.transport.candidates: if cand['candidate_id'] == streamhost_cid: streamhost_used = cand break if streamhost_used == None or streamhost_used['type'] == 'proxy': if gajim.socks5queue.listener and \ not gajim.socks5queue.listener.connections: gajim.socks5queue.listener.disconnect() if content.getTag('transport').getTag('activated'): self.state = STATE_TRANSFERING jid = gajim.get_jid_without_resource(self.session.ourjid) gajim.socks5queue.send_file(self.file_props, self.session.connection.name, 'client') return args = {'content' : content, 'sendCand' : False} if self.state == STATE_CAND_SENT: self.__state_changed(STATE_CAND_SENT_AND_RECEIVED, args) self.__state_changed(STATE_TRANSFERING) raise nbxmpp.NodeProcessed else: self.__state_changed(STATE_CAND_RECEIVED, args)
def get_control(fjid, account): # first try to get the window with the full jid ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account) if ctrl: # got one, be happy return ctrl # otherwise try without the resource ctrl = gajim.interface.msg_win_mgr.get_control( gajim.get_jid_without_resource(fjid), account) # but only use it when it's not a GC window if ctrl and ctrl.TYPE_ID == TYPE_CHAT: return ctrl
def __on_transport_info(self, stanza, content, error, action): log.info("__on_transport_info") cand_error = content.getTag('transport').getTag('candidate-error') cand_used = content.getTag('transport').getTag('candidate-used') if (cand_error or cand_used) and \ self.state >= State.CAND_SENT_AND_RECEIVED: raise nbxmpp.NodeProcessed if cand_error: if not gajim.socks5queue.listener.connections: gajim.socks5queue.listener.disconnect() self.nominated_cand['peer-cand'] = False if self.state == State.CAND_SENT: if not self.nominated_cand['our-cand'] and \ not self.nominated_cand['peer-cand']: if not self.weinitiate: return self.__state_changed(State.TRANSPORT_REPLACE) else: response = stanza.buildReply('result') response.delChild(response.getQuery()) self.session.connection.connection.send(response) self.__state_changed(State.TRANSFERING) raise nbxmpp.NodeProcessed else: args = {'cand_error': True} self.__state_changed(State.CAND_RECEIVED, args) return if cand_used: streamhost_cid = cand_used.getAttr('cid') streamhost_used = None for cand in self.transport.candidates: if cand['candidate_id'] == streamhost_cid: streamhost_used = cand break if streamhost_used is None or streamhost_used['type'] == 'proxy': if gajim.socks5queue.listener and \ not gajim.socks5queue.listener.connections: gajim.socks5queue.listener.disconnect() if content.getTag('transport').getTag('activated'): self.state = State.TRANSFERING jid = gajim.get_jid_without_resource(self.session.ourjid) gajim.socks5queue.send_file(self.file_props, self.session.connection.name, 'client') return args = {'content': content, 'sendCand': False} if self.state == State.CAND_SENT: self.__state_changed(State.CAND_SENT_AND_RECEIVED, args) self.__state_changed(State.TRANSFERING) raise nbxmpp.NodeProcessed else: self.__state_changed(State.CAND_RECEIVED, args)
def generate(self): msg_type = self.base_event.stanza.attrs.get("type", None) if msg_type == u"chat": self.stanza = self.base_event.stanza self.conn = self.base_event.conn self.from_jid = helpers.get_full_jid_from_iq(self.stanza) self.from_jid_without_resource = gajim.get_jid_without_resource(self.from_jid) self.account = self.conn.name self.from_nickname = gajim.get_contact_name_from_jid(self.account, self.from_jid_without_resource) self.msg_text = "".join(self.stanza.kids[0].data) return True return False
def __send_hash(self): # Send hash in a session info checksum = nbxmpp.Node(tag='checksum', payload=[nbxmpp.Node(tag='file', payload=[self._calcHash()])]) checksum.setNamespace(nbxmpp.NS_JINGLE_FILE_TRANSFER) self.session.__session_info(checksum ) pjid = gajim.get_jid_without_resource(self.session.peerjid) file_info = {'name' : self.file_props.name, 'file-name' : self.file_props.file_name, 'hash' : self.file_props.hash_, 'size' : self.file_props.size, 'date' : self.file_props.date, 'peerjid' : pjid } self.session.connection.set_file_info(file_info)
def message_received(self, msg): if msg.stanza.getTag('encrypted', namespace=NS_OMEMO): account = msg.conn.name log.debug(account + ' ⇒ OMEMO msg received') state = self.get_omemo_state(account) if msg.forwarded and msg.sent: from_jid = str(msg.stanza.getAttr('to')) # why gajim? why? log.debug('message was forwarded doing magic') else: from_jid = str(msg.stanza.getAttr('from')) msg_dict = unpack_message(msg.stanza) msg_dict['sender_jid'] = gajim.get_jid_without_resource(from_jid) plaintext = state.decrypt_msg(msg_dict) if not plaintext: return msg.msgtxt = plaintext msg.stanza.setBody(msg.msgtxt) self.update_prekeys(account, msg_dict['sender_jid']) contact_jid = gajim.get_jid_without_resource(msg.fjid) if account in self.ui_list and \ contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].activate_omemo() return False elif msg.stanza.getTag('body'): account = msg.conn.name from_jid = str(msg.stanza.getAttr('from')) jid = gajim.get_jid_without_resource(from_jid) gui = self.ui_list[account][jid] if gui and gui.encryption_active(): gui.plain_warning()
def message_received(self, msg): if msg.stanza.getTag('encrypted', namespace=NS_OMEMO): account = msg.conn.name log.debug(account + ' ⇒ OMEMO msg received') state = self.get_omemo_state(account) if msg.forwarded and msg.sent: from_jid = str(msg.stanza.getAttr('to')) # why gajim? why? log.debug('message was forwarded doing magic') else: from_jid = str(msg.stanza.getAttr('from')) msg_dict = unpack_message(msg.stanza) msg_dict['sender_jid'] = gajim.get_jid_without_resource(from_jid) plaintext = state.decrypt_msg(msg_dict) if not plaintext: return msg.msgtxt = plaintext msg.stanza.setBody(msg.msgtxt) self.update_prekeys(account, msg_dict['sender_jid']) contact_jid = gajim.get_jid_without_resource(msg.fjid) if account in self.ui_list and \ contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].activate_omemo() return False elif msg.stanza.getTag('body'): account = msg.conn.name from_jid = str(msg.stanza.getAttr('from')) jid = gajim.get_jid_without_resource(from_jid) gui = self.ui_list[account].get(jid, None) if gui and gui.encryption_active(): gui.plain_warning()
def add_contact_browse(self, contact): fjid = contact.get_full_jid() jid = gajim.get_jid_without_resource(fjid) contacts = gajim.contacts.get_contacts(self.account, jid) for con in contacts: if con.show in ('offline', 'error') and not \ con.supports(fshare_protocol.NS_FILE_SHARING): break cjid = con.get_full_jid() r = self.ts_search.insert(None, 0, (cjid, )) self.browse_jid[cjid] = r pro = fshare.FileSharePlugin.prohandler[self.account] # Request list of files from peer stanza = pro.request(cjid) if pro.conn.connection: pro.conn.connection.send(stanza)
def generate(self): msg_type = self.base_event.stanza.attrs.get('type', None) if msg_type == u'chat': self.stanza = self.base_event.stanza self.conn = self.base_event.conn self.from_jid = helpers.get_full_jid_from_iq(self.stanza) self.from_jid_without_resource = gajim.get_jid_without_resource( self.from_jid) self.account = self.conn.name self.from_nickname = gajim.get_contact_name_from_jid( self.account, self.from_jid_without_resource) self.msg_text = ''.join(self.stanza.kids[0].data) return True return False
def on_send_ok(): no_log_for = gajim.config.get_per('accounts', self.name, 'no_log_for') ji = gajim.get_jid_without_resource(jid) if session.is_loggable() and self.name not in no_log_for and\ ji not in no_log_for: log_msg = msg if subject: log_msg = _('Subject: %(subject)s\n%(message)s') % \ {'subject': subject, 'message': msg} if log_msg: if type_ == 'chat': kind = 'chat_msg_sent' else: kind = 'single_msg_sent' gajim.logger.write(kind, jid, log_msg) self.dispatch('MSGSENT', (jid, msg, keyID))
def __send_hash(self): # Send hash in a session info checksum = nbxmpp.Node( tag='checksum', payload=[nbxmpp.Node(tag='file', payload=[self._compute_hash()])]) checksum.setNamespace(nbxmpp.NS_JINGLE_FILE_TRANSFER) self.session.__session_info(checksum) pjid = gajim.get_jid_without_resource(self.session.peerjid) file_info = { 'name': self.file_props.name, 'file-name': self.file_props.file_name, 'hash': self.file_props.hash_, 'size': self.file_props.size, 'date': self.file_props.date, 'peerjid': pjid } self.session.connection.set_file_info(file_info)
def save_if_not_exists(self, with_, direction, tim, msg='', nick=None, additional_data={}): if tim: time_col = int(float(time.mktime(tim))) else: time_col = int(float(time.time())) if not msg: return if self.jid_is_from_pm(with_) or nick: # It's a groupchat message if nick: # It's a message from a groupchat occupent type_ = 'gc_msg' with_ = with_ + '/' + nick else: # It's a server message message, we don't log them return else: if direction == 'from': type_ = 'chat_msg_recv' elif direction == 'to': type_ = 'chat_msg_sent' jid_id = self.get_jid_id(with_) where_sql = 'jid_id = %s AND message=?' % jid_id if type_ == 'gc_msg': # We cannot differentiate gc message and pm messages, so look in # both logs with_2 = gajim.get_jid_without_resource(with_) if with_ != with_2: jid_id2 = self.get_jid_id(with_2) where_sql = 'jid_id in (%s, %s) AND message=?' % (jid_id, jid_id2) start_time = time_col - 300 # 5 minutes arrount given time end_time = time_col + 300 # 5 minutes arrount given time self.cur.execute(''' SELECT log_line_id FROM logs WHERE (%s) AND time BETWEEN %d AND %d ORDER BY time ''' % (where_sql, start_time, end_time), (msg,)) results = self.cur.fetchall() if results: log.debug('Log already in DB, ignoring it') return log.debug('New log received from server archives, storing it') self.write(type_, with_, message=msg, tim=tim, additional_data=additional_data)
def handle_new_cert(con, obj, jid_from): jid = gajim.get_jid_without_resource(jid_from) certpath = os.path.join(os.path.expanduser(gajim.MY_PEER_CERTS_PATH), jid) certpath += '.cert' id_ = obj.getAttr('id') x509cert = obj.getTag('pubkeys').getTag('keyinfo').getTag('x509cert') cert = x509cert.getData() f = open(certpath, 'w') f.write('-----BEGIN CERTIFICATE-----\n') f.write(cert) f.write('-----END CERTIFICATE-----\n') f.close() approve_pending_content(id_)
def mam_message_received(self, msg): if msg.msg_.getTag('encrypted', namespace=NS_OMEMO): account = msg.conn.name log.debug(account + ' => OMEMO MAM msg received') self.print_msg_to_log(msg.msg_) state = self.get_omemo_state(account) from_jid = str(msg.msg_.getAttr('from')) from_jid = gajim.get_jid_without_resource(from_jid) msg_dict = unpack_encrypted( msg.msg_.getTag('encrypted', namespace=NS_OMEMO)) msg_dict['sender_jid'] = from_jid plaintext = state.decrypt_msg(msg_dict) if not plaintext: return msg.msgtxt = plaintext contact_jid = msg.with_ if account in self.ui_list and \ contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].activate_omemo() return False elif msg.msg_.getTag('body'): account = msg.conn.name jid = msg.with_ state = self.get_omemo_state(account) omemo_enabled = state.encryption.is_active(jid) if omemo_enabled: msg.msgtxt = '**Unencrypted** ' + msg.msgtxt try: gui = self.ui_list[account].get(jid, None) if gui and gui.encryption_active(): gui.plain_warning() except KeyError: log.debug('No Ui present for ' + jid + ', Ui Warning not shown')
def mam_message_received(self, msg): if msg.msg_.getTag('encrypted', namespace=NS_OMEMO): account = msg.conn.name log.debug(account + ' => OMEMO MAM msg received') log.debug(msg.msg_) state = self.get_omemo_state(account) from_jid = str(msg.msg_.getAttr('from')) from_jid = gajim.get_jid_without_resource(from_jid) msg_dict = unpack_encrypted(msg.msg_.getTag ('encrypted', namespace=NS_OMEMO)) msg_dict['sender_jid'] = from_jid plaintext = state.decrypt_msg(msg_dict) if not plaintext: return msg.msgtxt = plaintext contact_jid = msg.with_ if account in self.ui_list and \ contact_jid in self.ui_list[account]: self.ui_list[account][contact_jid].activate_omemo() return False elif msg.msg_.getTag('body'): account = msg.conn.name jid = msg.with_ state = self.get_omemo_state(account) omemo_enabled = state.encryption.is_active(jid) if omemo_enabled: msg.msgtxt = '**Unencrypted** ' + msg.msgtxt try: gui = self.ui_list[account].get(jid, None) if gui and gui.encryption_active(): gui.plain_warning() except KeyError: log.debug('No Ui present for ' + jid + ', Ui Warning not shown')
def send(self, stanza, is_message=False, now=False, on_ok=None, on_not_ok=None): stanza.setFrom(self.roster.zeroconf.name) to = unicode(stanza.getTo()) to = gajim.get_jid_without_resource(to) try: item = self.roster[to] except KeyError: # Contact offline return -1 # look for hashed connections if to in self.recipient_to_hash: conn = self.connections[self.recipient_to_hash[to]] id_ = stanza.getID() or '' if conn.add_stanza(stanza, is_message): if on_ok: on_ok(id_) return the_address = None for address in item['addresses']: if address['address'] in self.ip_to_hash: the_address = address if the_address and the_address['address'] in self.ip_to_hash: hash_ = self.ip_to_hash[the_address['address']] if self.hash_to_port[hash_] == the_address['port']: conn = self.connections[hash_] id_ = stanza.getID() or '' if conn.add_stanza(stanza, is_message): if on_ok: on_ok(id_) return # otherwise open new connection if not stanza.getID(): stanza.setID('zero') addresses_ = [] for address in item['addresses']: addresses_ += [{'host': address['address'], 'address': address['address'], 'port': address['port']}] P2PClient(None, addresses_, self, [(stanza, is_message)], to, on_ok=on_ok, on_not_ok=on_not_ok)
def __on_session_accept(self, stanza, content, error, action): log.info("__on_session_accept") con = self.session.connection security = content.getTag('security') if not security: # responder can not verify our fingerprint self.use_security = False else: fingerprint = security.getTag('fingerprint') if fingerprint: fingerprint = fingerprint.getData() self.x509_fingerprint = fingerprint if not jingle_xtls.check_cert(gajim.get_jid_without_resource( self.session.responder), fingerprint): id_ = jingle_xtls.send_cert_request(con, self.session.responder) jingle_xtls.key_exchange_pend(id_, self.continue_session_accept, [stanza]) raise nbxmpp.NodeProcessed self.continue_session_accept(stanza)
def handle_outgoing_msgs(self, event): if not event.msg_iq.getTag('body'): return plaintext = event.msg_iq.getBody().encode('utf8') account = event.conn.name state = self.get_omemo_state(account) full_jid = str(event.msg_iq.getAttr('to')) to_jid = gajim.get_jid_without_resource(full_jid) if to_jid not in state.omemo_enabled: return False try: msg_dict = state.create_msg(gajim.get_jid_from_account(account), to_jid, plaintext) if not msg_dict: return True encrypted_node = OmemoMessage(msg_dict) event.msg_iq.delChild('body') event.msg_iq.addChild(node=encrypted_node) log.debug(account + ' → ' + str(event.msg_iq)) except: return True
def __on_session_accept(self, stanza, content, error, action): log.info("__on_session_accept") con = self.session.connection security = content.getTag('security') if not security: # responder can not verify our fingerprint self.use_security = False else: fingerprint = security.getTag('fingerprint') if fingerprint: fingerprint = fingerprint.getData() self.x509_fingerprint = fingerprint if not jingle_xtls.check_cert( gajim.get_jid_without_resource(self.session.responder), fingerprint): id_ = jingle_xtls.send_cert_request( con, self.session.responder) jingle_xtls.key_exchange_pend(id_, self.continue_session_accept, [stanza]) raise nbxmpp.NodeProcessed self.continue_session_accept(stanza)
def handle_outgoing_msgs(self, event): if not event.msg_iq.getTag('body'): return plaintext = event.msg_iq.getBody().encode('utf8') account = event.conn.name state = self.get_omemo_state(account) full_jid = str(event.msg_iq.getAttr('to')) to_jid = gajim.get_jid_without_resource(full_jid) if to_jid not in state.omemo_enabled: return False try: msg_dict = state.create_msg( gajim.get_jid_from_account(account), to_jid, plaintext) if not msg_dict: return True encrypted_node = OmemoMessage(msg_dict) event.msg_iq.delChild('body') event.msg_iq.addChild(node=encrypted_node) log.debug(account + ' → ' + str(event.msg_iq)) except: return True