Permalink
Browse files

Fix dependencies and add ignore_ssl option

  • Loading branch information...
ajdiaz committed Jan 27, 2013
1 parent aaa8a71 commit 7eb11ab10cd15148a6505bbc6a65af7c7bc98581
Showing with 20 additions and 4 deletions.
  1. +2 −1 config/example.conf
  2. +3 −1 setup.py
  3. +13 −2 whistler/bot.py
  4. +2 −0 whistler/scripts.py
View
@@ -7,7 +7,8 @@ resource = whistler
#password = doesnotmatter # do not required in anonymous server
#port = 5222
#use_tls = False
-#loglevel = 10 # DEBUG
+#loglevel = 10
+#ignore_ssl_cert = True
# Define mixins. To define mixins to be loaded, just create a section with
# the name of the mixin and the prefix "mixin:".
View
@@ -27,7 +27,9 @@ def get_file_contents(filename):
]
},
install_requires = [
- "sleekxmpp>=1.0"
+ "sleekxmpp>=1.0",
+ "pyasn1>=0.1.4",
+ "pyasn1-modules>=0.0.4"
],
classifiers=[
'Development Status :: 4 - Beta',
View
@@ -151,7 +151,7 @@ class WhistlerBot(object):
"""
def __init__(self, jid, password, server=None, rooms=None,
- resource=None, log=None, users=[], use_tls=False):
+ resource=None, log=None, users=[], use_tls=False, ignore_ssl_cert=True):
"""Initialize a Whistler bot.
Create a new :class:`WhistlerBot` object, the :func:`__init__`
@@ -169,13 +169,17 @@ def __init__(self, jid, password, server=None, rooms=None,
*stdout* if none is provided.
:param `users`: a :class:`set` of valid JID as strings which
identify master users.
-
+ :param use_tls: if set to true, try to use TLS where available
+ :param ignore_ssl_cert: if set to false raise an exception when
+ certificate do not match with hostname or any other kind of
+ invalid certificate.
"""
self.jid = jid
self.password = password
self.server = server
self.log = log or WhistlerLog()
self.use_tls = use_tls
+ self.ignore_ssl_cert = ignore_ssl_cert
self._initial_users = users
self.handlers = { EVENT_CONNECT: [], EVENT_DISCONNECT: [],
EVENT_REGISTER: [], EVENT_JOIN: [],
@@ -255,6 +259,10 @@ def register_plugin(self, plugin_name):
self.client.register_plugin(plugin_name)
+ def handle_invalid_cert(self, pem_cert):
+ """Handle a invalid certification request."""
+ self.log.warning("Invalid certificated found, but continue anyway.")
+
def connect(self):
"""Perform a connection to the server.
@@ -273,6 +281,9 @@ def connect(self):
self.client.add_event_handler("message", self.handle_message)
self.client.add_event_handler("changed_status", self.handle_changed_status)
+ if self.ignore_ssl_cert:
+ self.client.add_event_handler("ssl_invalid_cert", self.handle_invalid_cert)
+
# Add plug-ins
self.client.register_plugin("xep_0030") # Service Discovery
self.client.register_plugin("xep_0004") # Data Forms
View
@@ -34,6 +34,7 @@
"password": "doesnotmatter",
"port": 5222,
"use_tls": False,
+ "ignore_ssl_cert": True,
"loglevel": logging.WARNING
}
@@ -81,6 +82,7 @@ def main():
server = ( config.get("DEFAULT", "server"),
config.getint("DEFAULT", "port") ),
rooms = rooms,
+ ignore_ssl_cert = config.get("DEFAULT", "ignore_ssl_cert")
)
try:

0 comments on commit 7eb11ab

Please sign in to comment.