annotate cagou/core/patches.py @ 439:12d188cb1206

core: use of new profileConnected method: bookmarks cache is now retrieved in profileConnected, as getting it in ProfilePlugged could result in an exception is client was not fully connected (if plugins were not all initialised).
author Goffi <goffi@goffi.org>
date Sat, 07 Mar 2020 00:05:49 +0100
parents 58d3ea442f9c
children 3c9ba4a694ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
399
672880661797 core: minor i18n fix
Goffi <goffi@goffi.org>
parents: 379
diff changeset
1 #!/usr/bin/env python3
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
378
4d660b252487 dates update
Goffi <goffi@goffi.org>
parents: 312
diff changeset
4 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org)
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
19 import urllib.request, urllib.error, urllib.parse
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import ssl
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
22
438
58d3ea442f9c core (patches): renamed `apply` to `disable_tls_validation` which suits better
Goffi <goffi@goffi.org>
parents: 399
diff changeset
23 def disable_tls_validation():
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 # allow to disable certificate validation
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 ctx_no_verify = ssl.create_default_context()
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 ctx_no_verify.check_hostname = False
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 ctx_no_verify.verify_mode = ssl.CERT_NONE
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
29 class HTTPSHandler(urllib.request.HTTPSHandler):
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 no_certificate_check = False
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, *args, **kwargs):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
33 urllib.request._HTTPSHandler_ori.__init__(self, *args, **kwargs)
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 if self.no_certificate_check:
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 self._context = ctx_no_verify
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
37 urllib.request._HTTPSHandler_ori = urllib.request.HTTPSHandler
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
38 urllib.request.HTTPSHandler = HTTPSHandler
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
39 urllib.request.HTTPSHandler.no_certificate_check = True