Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_android.py @ 3245:2a0a16b906ac
plugin android: use `certifi` SSL root certicates
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 01 Apr 2020 22:28:50 +0200 |
parents | dcebc585c29f |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3244:b10d207f95f9 | 3245:2a0a16b906ac |
---|---|
19 import sys | 19 import sys |
20 import os | 20 import os |
21 import os.path | 21 import os.path |
22 import json | 22 import json |
23 from pathlib import Path | 23 from pathlib import Path |
24 from sat.core.i18n import _, D_ | 24 from zope.interface import implementer |
25 from sat.core.constants import Const as C | |
26 from sat.core.log import getLogger | |
27 from sat.core import exceptions | |
28 from sat.tools.common import async_process | |
29 from sat.memory import params | |
30 from twisted.names import client as dns_client | 25 from twisted.names import client as dns_client |
31 from twisted.python.procutils import which | 26 from twisted.python.procutils import which |
32 from twisted.internet import defer | 27 from twisted.internet import defer |
33 from twisted.internet import reactor | 28 from twisted.internet import reactor |
34 from twisted.internet import protocol | 29 from twisted.internet import protocol |
35 from twisted.internet import abstract | 30 from twisted.internet import abstract |
36 from twisted.internet import error as int_error | 31 from twisted.internet import error as int_error |
32 from twisted.internet import _sslverify | |
33 from sat.core.i18n import _, D_ | |
34 from sat.core.constants import Const as C | |
35 from sat.core.log import getLogger | |
36 from sat.core import exceptions | |
37 from sat.tools.common import async_process | |
38 from sat.memory import params | |
39 | |
37 | 40 |
38 log = getLogger(__name__) | 41 log = getLogger(__name__) |
39 | 42 |
40 PLUGIN_INFO = { | 43 PLUGIN_INFO = { |
41 C.PI_NAME: "Android", | 44 C.PI_NAME: "Android", |
52 if sys.platform != "android": | 55 if sys.platform != "android": |
53 raise exceptions.CancelError("this module is not needed on this platform") | 56 raise exceptions.CancelError("this module is not needed on this platform") |
54 | 57 |
55 | 58 |
56 import re | 59 import re |
60 import certifi | |
57 from plyer import vibrator | 61 from plyer import vibrator |
58 from android import api_version | 62 from android import api_version |
59 from plyer.platforms.android import activity | 63 from plyer.platforms.android import activity |
60 from plyer.platforms.android.notification import AndroidNotification | 64 from plyer.platforms.android.notification import AndroidNotification |
61 from jnius import autoclass | 65 from jnius import autoclass |
107 NET_TYPE_NONE = "no network" | 111 NET_TYPE_NONE = "no network" |
108 NET_TYPE_WIFI = "wifi" | 112 NET_TYPE_WIFI = "wifi" |
109 NET_TYPE_MOBILE = "mobile" | 113 NET_TYPE_MOBILE = "mobile" |
110 NET_TYPE_OTHER = "other" | 114 NET_TYPE_OTHER = "other" |
111 INTENT_EXTRA_ACTION = AndroidString("org.salut-a-toi.IntentAction") | 115 INTENT_EXTRA_ACTION = AndroidString("org.salut-a-toi.IntentAction") |
116 | |
117 | |
118 @implementer(_sslverify.IOpenSSLTrustRoot) | |
119 class AndroidTrustPaths: | |
120 | |
121 def _addCACertsToContext(self, context): | |
122 # twisted doesn't have access to Android root certificates | |
123 # we use certifi to work around that (same thing is done in Kivy) | |
124 context.load_verify_locations(certifi.where()) | |
125 | |
126 | |
127 def platformTrust(): | |
128 return AndroidTrustPaths() | |
112 | 129 |
113 | 130 |
114 class Notification(AndroidNotification): | 131 class Notification(AndroidNotification): |
115 # We extend plyer's AndroidNotification instead of creating directly with jnius | 132 # We extend plyer's AndroidNotification instead of creating directly with jnius |
116 # because it already handles issues like backward compatibility, and we just want to | 133 # because it already handles issues like backward compatibility, and we just want to |
273 self.notif_player = MediaPlayer() | 290 self.notif_player = MediaPlayer() |
274 self.notif_player.setDataSource(str(notif_path)) | 291 self.notif_player.setDataSource(str(notif_path)) |
275 self.notif_player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION) | 292 self.notif_player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION) |
276 self.notif_player.prepare() | 293 self.notif_player.prepare() |
277 | 294 |
295 # SSL fix | |
296 _sslverify.platformTrust = platformTrust | |
297 log.info("SSL Android patch applied") | |
298 | |
278 # DNS fix | 299 # DNS fix |
279 defer.ensureDeferred(self.updateResolver()) | 300 defer.ensureDeferred(self.updateResolver()) |
280 | 301 |
281 # Connectivity handling | 302 # Connectivity handling |
282 self.cm = activity.getSystemService(Context.CONNECTIVITY_SERVICE) | 303 self.cm = activity.getSystemService(Context.CONNECTIVITY_SERVICE) |