Mercurial > libervia-desktop-kivy
comparison cagou/core/patches.py @ 280:b0461363bc65
core: certificate validation can be disabled:
By using "no_certificate_validation=true" in sat.conf in [cagou] section, certificate validation can be disabled.
This is mainly useful for developping on local machines with self-signed certificates.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Mar 2019 09:29:44 +0100 |
parents | |
children | 772c170b47a9 |
comparison
equal
deleted
inserted
replaced
279:aea973de55d9 | 280:b0461363bc65 |
---|---|
1 #!/usr//bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
5 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 import urllib2 | |
21 import ssl | |
22 | |
23 | |
24 def apply(): | |
25 # allow to disable certificate validation | |
26 ctx_no_verify = ssl.create_default_context() | |
27 ctx_no_verify.check_hostname = False | |
28 ctx_no_verify.verify_mode = ssl.CERT_NONE | |
29 | |
30 class HTTPSHandler(urllib2.HTTPSHandler): | |
31 no_certificate_check = False | |
32 | |
33 def __init__(self, *args, **kwargs): | |
34 urllib2._HTTPSHandler_ori.__init__(self, *args, **kwargs) | |
35 if self.no_certificate_check: | |
36 self._context = ctx_no_verify | |
37 | |
38 urllib2._HTTPSHandler_ori = urllib2.HTTPSHandler | |
39 urllib2.HTTPSHandler = HTTPSHandler | |
40 urllib2.HTTPSHandler.no_certificate_check = True |