Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0320.py @ 4188:5a835b320726
docker (backend-dev): update Debian version + getting OMEMO related packages from git is not necessary anymore
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 11 Dec 2023 00:53:59 +0100 |
parents | 4b842c1fb686 |
children |
rev | line source |
---|---|
4048
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia plugin |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from twisted.words.xish import domish |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from wokkel import disco, iwokkel |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from zope.interface import implementer |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
24 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
25 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
26 from libervia.backend.core.log import getLogger |
4048
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 log = getLogger(__name__) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 NS_JINGLE_DTLS = "urn:xmpp:jingle:apps:dtls:0" |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 PLUGIN_INFO = { |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 C.PI_NAME: "Use of DTLS-SRTP in Jingle Sessions", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 C.PI_IMPORT_NAME: "XEP-0320", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 C.PI_TYPE: "XEP", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_MODES: C.PLUG_MODE_BOTH, |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 C.PI_PROTOCOLS: ["XEP-0320"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_DEPENDENCIES: ["XEP-0176"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_RECOMMENDATIONS: [], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_MAIN: "XEP_0320", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 C.PI_HANDLER: "yes", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_DESCRIPTION: _("""Use of DTLS-SRTP with RTP (for e2ee of A/V calls)"""), |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 } |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 class XEP_0320: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 def __init__(self, host): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization") |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 host.trigger.add("XEP-0176_parse_transport", self._parse_transport_trigger) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 host.trigger.add("XEP-0176_build_transport", self._build_transport_trigger) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 def get_handler(self, client): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 return XEP_0320_handler() |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 def _parse_transport_trigger( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self, transport_elt: domish.Element, ice_data: dict |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 ) -> bool: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 """Parse the <fingerprint> element""" |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 fingerprint_elt = next( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 transport_elt.elements(NS_JINGLE_DTLS, "fingerprint"), None |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 ) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 if fingerprint_elt is not None: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 try: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 ice_data["fingerprint"] = { |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 "hash": fingerprint_elt["hash"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 "setup": fingerprint_elt["setup"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 "fingerprint": str(fingerprint_elt), |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 } |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 except KeyError as e: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 log.warning( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 f"invalid <fingerprint> (attribue {e} is missing): " |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 f"{fingerprint_elt.toXml()})" |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 ) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 return True |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 def _build_transport_trigger( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 self, tranport_elt: domish.Element, ice_data: dict |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 ) -> bool: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 """Build the <fingerprint> element if possible""" |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 try: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 fingerprint_data = ice_data["fingerprint"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 hash_ = fingerprint_data["hash"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 setup = fingerprint_data["setup"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 fingerprint = fingerprint_data["fingerprint"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 except KeyError: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 pass |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 else: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 fingerprint_elt = tranport_elt.addElement( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 (NS_JINGLE_DTLS, "fingerprint"), content=fingerprint |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 ) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 fingerprint_elt["hash"] = hash_ |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 fingerprint_elt["setup"] = setup |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 return True |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 @implementer(iwokkel.IDisco) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 class XEP_0320_handler(XMPPHandler): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 return [disco.DiscoFeature(NS_JINGLE_DTLS)] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 return [] |