Compare commits
	
		
			5 Commits
		
	
	
		
			slix-1.2.2
			...
			slix-1.2.3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | fb3ac78bf9 | ||
|   | ffd9436e5c | ||
|   | bbb1344d79 | ||
|   | 457785b286 | ||
|   | 4847f834bd | 
							
								
								
									
										8
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.gitlab-ci.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| test: | ||||
|   tags: | ||||
|     - docker | ||||
|   image: ubuntu:latest | ||||
|   script: | ||||
|     - apt update | ||||
|     - apt install -y python3 cython3 | ||||
|     - ./run_tests.py | ||||
| @@ -15,6 +15,7 @@ | ||||
| import asyncio | ||||
| import logging | ||||
|  | ||||
| from slixmpp.jid import JID | ||||
| from slixmpp.stanza import StreamFeatures | ||||
| from slixmpp.basexmpp import BaseXMPP | ||||
| from slixmpp.exceptions import XMPPError | ||||
| @@ -110,7 +111,13 @@ class ClientXMPP(BaseXMPP): | ||||
|                      self._handle_stream_features)) | ||||
|         def roster_push_filter(iq): | ||||
|             from_ = iq['from'] | ||||
|             if from_ and from_ != self.boundjid.bare: | ||||
|             if from_ and from_ != JID('') and from_ != self.boundjid.bare: | ||||
|                 reply = iq.reply() | ||||
|                 reply['type'] = 'error' | ||||
|                 reply['error']['type'] = 'cancel' | ||||
|                 reply['error']['code'] = 503 | ||||
|                 reply['error']['condition'] = 'service-unavailable' | ||||
|                 reply.send() | ||||
|                 return | ||||
|             self.event('roster_update', iq) | ||||
|         self.register_handler( | ||||
|   | ||||
							
								
								
									
										15
									
								
								slixmpp/plugins/xep_0380/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								slixmpp/plugins/xep_0380/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| """ | ||||
|     Slixmpp: The Slick XMPP Library | ||||
|     Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | ||||
|     This file is part of Slixmpp. | ||||
|  | ||||
|     See the file LICENSE for copying permission. | ||||
| """ | ||||
|  | ||||
| from slixmpp.plugins.base import register_plugin | ||||
|  | ||||
| from slixmpp.plugins.xep_0380.stanza import Encryption | ||||
| from slixmpp.plugins.xep_0380.eme import XEP_0380 | ||||
|  | ||||
|  | ||||
| register_plugin(XEP_0380) | ||||
							
								
								
									
										69
									
								
								slixmpp/plugins/xep_0380/eme.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								slixmpp/plugins/xep_0380/eme.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| """ | ||||
|     Slixmpp: The Slick XMPP Library | ||||
|     Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | ||||
|     This file is part of Slixmpp. | ||||
|  | ||||
|     See the file LICENSE for copying permission. | ||||
| """ | ||||
|  | ||||
| import logging | ||||
|  | ||||
| import slixmpp | ||||
| from slixmpp.stanza import Message | ||||
| from slixmpp.xmlstream.handler import Callback | ||||
| from slixmpp.xmlstream.matcher import StanzaPath | ||||
| from slixmpp.xmlstream import register_stanza_plugin, ElementBase, ET | ||||
| from slixmpp.plugins import BasePlugin | ||||
| from slixmpp.plugins.xep_0380 import stanza, Encryption | ||||
|  | ||||
|  | ||||
| log = logging.getLogger(__name__) | ||||
|  | ||||
|  | ||||
| class XEP_0380(BasePlugin): | ||||
|  | ||||
|     """ | ||||
|     XEP-0380: Explicit Message Encryption | ||||
|     """ | ||||
|  | ||||
|     name = 'xep_0380' | ||||
|     description = 'XEP-0380: Explicit Message Encryption' | ||||
|     dependencies = {'xep_0030'} | ||||
|     default_config = { | ||||
|         'template': 'This message is encrypted with {name} ({namespace})', | ||||
|     } | ||||
|  | ||||
|     mechanisms = { | ||||
|         'jabber:x:encrypted': 'Legacy OpenPGP', | ||||
|         'urn:xmpp:ox:0': 'OpenPGP for XMPP', | ||||
|         'urn:xmpp:otr:0': 'OTR', | ||||
|         'eu.siacs.conversations.axolotl': 'Legacy OMEMO', | ||||
|         'urn:xmpp:omemo:0': 'OMEMO', | ||||
|     } | ||||
|  | ||||
|     def plugin_init(self): | ||||
|         self.xmpp.register_handler( | ||||
|             Callback('Explicit Message Encryption', | ||||
|                      StanzaPath('message/eme'), | ||||
|                      self._handle_eme)) | ||||
|  | ||||
|         register_stanza_plugin(Message, Encryption) | ||||
|  | ||||
|     def plugin_end(self): | ||||
|         self.xmpp.remove_handler('Chat State') | ||||
|  | ||||
|     def session_bind(self, jid): | ||||
|         self.xmpp.plugin['xep_0030'].add_feature(Encryption.namespace) | ||||
|  | ||||
|     def has_eme(self, msg): | ||||
|         return msg.xml.find('{%s}encryption' % Encryption.namespace) is not None | ||||
|  | ||||
|     def replace_body_with_eme(self, msg): | ||||
|         eme = msg['eme'] | ||||
|         namespace = eme['namespace'] | ||||
|         name = self.mechanisms[namespace] if namespace in self.mechanisms else eme['name'] | ||||
|         body = self.config['template'].format(name=name, namespace=namespace) | ||||
|         msg['body'] = body | ||||
|  | ||||
|     def _handle_eme(self, msg): | ||||
|         self.xmpp.event('message_encryption', msg) | ||||
							
								
								
									
										16
									
								
								slixmpp/plugins/xep_0380/stanza.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								slixmpp/plugins/xep_0380/stanza.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| """ | ||||
|     Slixmpp: The Slick XMPP Library | ||||
|     Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | ||||
|     This file is part of Slixmpp. | ||||
|  | ||||
|     See the file LICENSE for copying permission. | ||||
| """ | ||||
|  | ||||
| from slixmpp.xmlstream import ElementBase | ||||
|  | ||||
|  | ||||
| class Encryption(ElementBase): | ||||
|     name = 'encryption' | ||||
|     namespace = 'urn:xmpp:eme:0' | ||||
|     plugin_attrib = 'eme' | ||||
|     interfaces = {'namespace', 'name'} | ||||
| @@ -9,5 +9,5 @@ | ||||
| # We don't want to have to import the entire library | ||||
| # just to get the version info for setup.py | ||||
|  | ||||
| __version__ = '1.2.2' | ||||
| __version_info__ = (1, 2, 2) | ||||
| __version__ = '1.2.3' | ||||
| __version_info__ = (1, 2, 3) | ||||
|   | ||||
							
								
								
									
										37
									
								
								tests/test_stanza_xep_0380.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								tests/test_stanza_xep_0380.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| import unittest | ||||
| from slixmpp import Message | ||||
| from slixmpp.test import SlixTest | ||||
| import slixmpp.plugins.xep_0380 as xep_0380 | ||||
| from slixmpp.xmlstream import register_stanza_plugin | ||||
|  | ||||
|  | ||||
| class TestEME(SlixTest): | ||||
|  | ||||
|     def setUp(self): | ||||
|         register_stanza_plugin(Message, xep_0380.stanza.Encryption) | ||||
|  | ||||
|     def testCreateEME(self): | ||||
|         """Testing creating EME.""" | ||||
|  | ||||
|         xmlstring = """ | ||||
|           <message> | ||||
|             <encryption xmlns="urn:xmpp:eme:0" namespace="%s"%s /> | ||||
|           </message> | ||||
|         """ | ||||
|  | ||||
|         msg = self.Message() | ||||
|         self.check(msg, "<message />") | ||||
|  | ||||
|         msg['eme']['namespace'] = 'urn:xmpp:otr:0' | ||||
|         self.check(msg, xmlstring % ('urn:xmpp:otr:0', '')) | ||||
|  | ||||
|         msg['eme']['namespace'] = 'urn:xmpp:openpgp:0' | ||||
|         self.check(msg, xmlstring % ('urn:xmpp:openpgp:0', '')) | ||||
|  | ||||
|         msg['eme']['name'] = 'OX' | ||||
|         self.check(msg, xmlstring % ('urn:xmpp:openpgp:0', ' name="OX"')) | ||||
|  | ||||
|         del msg['eme'] | ||||
|         self.check(msg, "<message />") | ||||
|  | ||||
| suite = unittest.TestLoader().loadTestsFromTestCase(TestEME) | ||||
		Reference in New Issue
	
	Block a user