annotate cagou/core/patches.py @ 378:4d660b252487

dates update
author Goffi <goffi@goffi.org>
date Wed, 29 Jan 2020 09:52:46 +0100
parents 772c170b47a9
children 1da3c379205b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr//bin/env python2
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
378
4d660b252487 dates update
Goffi <goffi@goffi.org>
parents: 312
diff changeset
5 # 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
6
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # 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
8 # 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
9 # 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
10 # (at your option) any later version.
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # 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
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # 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
18 # 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
19
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
20 import urllib.request, urllib.error, urllib.parse
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import ssl
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
22
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
23
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 def apply():
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 # allow to disable certificate validation
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 ctx_no_verify = ssl.create_default_context()
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 ctx_no_verify.check_hostname = False
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 ctx_no_verify.verify_mode = ssl.CERT_NONE
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
30 class HTTPSHandler(urllib.request.HTTPSHandler):
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 no_certificate_check = False
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def __init__(self, *args, **kwargs):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
34 urllib.request._HTTPSHandler_ori.__init__(self, *args, **kwargs)
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 if self.no_certificate_check:
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 self._context = ctx_no_verify
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
38 urllib.request._HTTPSHandler_ori = urllib.request.HTTPSHandler
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
39 urllib.request.HTTPSHandler = HTTPSHandler
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 280
diff changeset
40 urllib.request.HTTPSHandler.no_certificate_check = True