From 6be798bffc78568b6c2c6e58d712fbe02cc8421c Mon Sep 17 00:00:00 2001 From: anrudolph <49680492+anrudolph@users.noreply.github.com> Date: Sat, 27 Apr 2019 17:40:20 +0200 Subject: [PATCH] Added option to use self-signed certificates (#23139) * Added option to use self-signed certificates I defined a new option for configuration.yaml, 'verify_ssl', which is set to 'True' by default for obvious security reasons. However, in order to work with self-signed certificates, it is now possible to disable the certificate validation.(eg, I use a nextcloud instance with self-signed certificates) Credit for code in line 57 goes to user 'gen2' on the homeassistant community, who suggested this solution. https://community.home-assistant.io/t/caldav-configuration/38198/25 I only took it a step further and made it a config option. * Update calendar.py * Added the import of CONF_VERIFY_SSL I hope this passes the test now... * Update homeassistant/components/caldav/calendar.py Cool! Didn't know about that possibility, my coding experience is literally two weeks. Thanks for sharing! Co-Authored-By: anrudolph <49680492+anrudolph@users.noreply.github.com> * Removed some lines of code I think, in order for the last commit to work, these lines have to be removed. Correct? * Trying to get this passing the checks Trying around to get the simplified code to work --- homeassistant/components/caldav/calendar.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/caldav/calendar.py b/homeassistant/components/caldav/calendar.py index 446473c7f40..594a6473877 100644 --- a/homeassistant/components/caldav/calendar.py +++ b/homeassistant/components/caldav/calendar.py @@ -8,7 +8,7 @@ import voluptuous as vol from homeassistant.components.calendar import ( PLATFORM_SCHEMA, CalendarEventDevice, get_date) from homeassistant.const import ( - CONF_NAME, CONF_PASSWORD, CONF_URL, CONF_USERNAME) + CONF_NAME, CONF_PASSWORD, CONF_URL, CONF_USERNAME, CONF_VERIFY_SSL) import homeassistant.helpers.config_validation as cv from homeassistant.util import Throttle, dt @@ -36,7 +36,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_NAME): cv.string, vol.Required(CONF_SEARCH): cv.string, }) - ])) + ])), + vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean }) MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15) @@ -50,7 +51,8 @@ def setup_platform(hass, config, add_entities, disc_info=None): username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) - client = caldav.DAVClient(url, None, username, password) + client = caldav.DAVClient(url, None, username, password, + ssl_verify_cert=config.get(CONF_VERIFY_SSL)) calendars = client.principal().calendars()