-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Optionally disable ssl certificate validity check. #9181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,42 +21,46 @@ | |
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| CONF_TLS = 'tls' | ||
| CONF_VERIFY = 'verify' | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_SENDER): cv.string, | ||
| vol.Required(CONF_PASSWORD): cv.string, | ||
| vol.Required(CONF_RECIPIENT): cv.string, | ||
| vol.Optional(CONF_TLS, default=True): cv.boolean, | ||
| vol.Optional(CONF_VERIFY, default=True): cv.boolean, | ||
| }) | ||
|
|
||
|
|
||
| def get_service(hass, config, discovery_info=None): | ||
| """Get the Jabber (XMPP) notification service.""" | ||
| return XmppNotificationService( | ||
| config.get(CONF_SENDER), config.get(CONF_PASSWORD), | ||
| config.get(CONF_RECIPIENT), config.get(CONF_TLS)) | ||
| config.get(CONF_RECIPIENT), config.get(CONF_TLS), | ||
| config.get(CONF_VERIFY)) | ||
|
|
||
|
|
||
| class XmppNotificationService(BaseNotificationService): | ||
| """Implement the notification service for Jabber (XMPP).""" | ||
|
|
||
| def __init__(self, sender, password, recipient, tls): | ||
| def __init__(self, sender, password, recipient, tls, verify): | ||
| """Initialize the service.""" | ||
| self._sender = sender | ||
| self._password = password | ||
| self._recipient = recipient | ||
| self._tls = tls | ||
| self._verify = verify | ||
|
|
||
| def send_message(self, message="", **kwargs): | ||
| """Send a message to a user.""" | ||
| title = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT) | ||
| data = '{}: {}'.format(title, message) if title else message | ||
|
|
||
| send_message('{}/home-assistant'.format(self._sender), self._password, | ||
| self._recipient, self._tls, data) | ||
| self._recipient, self._tls, self._verify, data) | ||
|
|
||
|
|
||
| def send_message(sender, password, recipient, use_tls, message): | ||
| def send_message(sender, password, recipient, use_tls, verify_certificate, message): | ||
| """Send a message over XMPP.""" | ||
| import sleekxmpp | ||
|
|
||
|
|
@@ -73,6 +77,9 @@ def __init__(self): | |
| self.use_ipv6 = False | ||
| self.add_event_handler('failed_auth', self.check_credentials) | ||
| self.add_event_handler('session_start', self.start) | ||
| if not verify_certificate: | ||
| self.add_event_handler('ssl_invalid_cert', self.discard_ssl_invalid_cert) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (89 > 79 characters) |
||
|
|
||
| self.connect(use_tls=self.use_tls, use_ssl=False) | ||
| self.process() | ||
|
|
||
|
|
@@ -87,4 +94,9 @@ def check_credentials(self, event): | |
| """Disconnect from the server if credentials are invalid.""" | ||
| self.disconnect() | ||
|
|
||
| def discard_ssl_invalid_cert(self, event): | ||
| """Do nothing if ssl certificate is invalid.""" | ||
| _LOGGER.info('Ignoring invalid ssl certificate as requested.') | ||
| return | ||
|
|
||
| SendNotificationBot() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (84 > 79 characters)