Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0320.py @ 4048:04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
rel 421
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 15 May 2023 17:02:40 +0200 |
parents | |
children | c23cad65ae99 |
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 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Libervia plugin |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # 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
|
6 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # 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
|
8 # 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
|
9 # 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
|
10 # (at your option) any later version. |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # 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
|
13 # 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
|
14 # 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
|
15 # 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
|
16 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # 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
|
18 # 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
|
19 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 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
|
21 from twisted.words.xish import domish |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from wokkel import disco, iwokkel |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from zope.interface import implementer |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.core.constants import Const as C |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from sat.core.i18n import _ |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from sat.core.log import getLogger |
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 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 log = getLogger(__name__) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 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
|
33 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 PLUGIN_INFO = { |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 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
|
36 C.PI_IMPORT_NAME: "XEP-0320", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_TYPE: "XEP", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 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
|
39 C.PI_PROTOCOLS: ["XEP-0320"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_DEPENDENCIES: ["XEP-0176"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_RECOMMENDATIONS: [], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 C.PI_MAIN: "XEP_0320", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_HANDLER: "yes", |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 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
|
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 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 class XEP_0320: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 def __init__(self, host): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 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
|
51 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
|
52 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
|
53 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 def get_handler(self, client): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 return XEP_0320_handler() |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 def _parse_transport_trigger( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 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
|
59 ) -> bool: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 """Parse the <fingerprint> element""" |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 fingerprint_elt = next( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 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
|
63 ) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 if fingerprint_elt is not None: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 try: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 ice_data["fingerprint"] = { |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 "hash": fingerprint_elt["hash"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 "setup": fingerprint_elt["setup"], |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 "fingerprint": str(fingerprint_elt), |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 } |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 except KeyError as e: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 log.warning( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 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
|
74 f"{fingerprint_elt.toXml()})" |
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 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 return True |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 def _build_transport_trigger( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 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
|
81 ) -> bool: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 """Build the <fingerprint> element if possible""" |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 try: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 fingerprint_data = ice_data["fingerprint"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 hash_ = fingerprint_data["hash"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 setup = fingerprint_data["setup"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 fingerprint = fingerprint_data["fingerprint"] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 except KeyError: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 pass |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 else: |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 fingerprint_elt = tranport_elt.addElement( |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 (NS_JINGLE_DTLS, "fingerprint"), content=fingerprint |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 ) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 fingerprint_elt["hash"] = hash_ |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 fingerprint_elt["setup"] = setup |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 return True |
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 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 @implementer(iwokkel.IDisco) |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 class XEP_0320_handler(XMPPHandler): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 return [disco.DiscoFeature(NS_JINGLE_DTLS)] |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
04e21d6c9188
plugin XEP-0320: Use of DTLS-SRTP in Jingle Sessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 return [] |