Skip to content

Commit 0f78baf

Browse files
authored
Merge pull request #219 from opentok/add-e2ee
Add e2ee
2 parents 4b4d82f + 2c6505e commit 0f78baf

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

CHANGES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# Release v3.4.0
1+
# Release v3.5.0
2+
- Support for end-to-end encryption (E2EE) that can be specified by a user when creating an OpenTok session.
23

4+
# Release v3.4.0
35
- Support for Audio Connector API via `connect_audio_to_websocket` method
46

57
# Release v3.3.0

README.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Import the package at the top of any file where you will use it. At the very lea
4848
Creating Sessions
4949
~~~~~~~~~~~~~~~~~
5050

51-
To create an OpenTok Session, use the ``opentok.create_session()`` method. There are three optional
51+
To create an OpenTok Session, use the ``opentok.create_session()`` method. There are optional
5252
keyword parameters for this method:
5353

5454
* ``location`` which can be set to a string containing an IP address.
@@ -62,6 +62,10 @@ keyword parameters for this method:
6262
* ``archive_mode`` which specifies whether the session will be automatically archived (``always``)
6363
or not (``manual``).
6464

65+
* ``e2ee`` which is a boolean. This specifies whether to enable
66+
`end-to-end encryption <https://tokbox.com/developer/guides/end-to-end-encryption/>`_
67+
for the OpenTok session.
68+
6569
This method returns a ``Session`` object. Its ``session_id`` attribute is useful when saving to a persistent
6670
store (such as a database).
6771

opentok/opentok.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ def create_session(
301301
location=None,
302302
media_mode=MediaModes.relayed,
303303
archive_mode=ArchiveModes.manual,
304+
e2ee=False,
304305
):
305306
"""
306307
Creates a new OpenTok session and returns the session ID, which uniquely identifies
@@ -359,6 +360,9 @@ def create_session(
359360
situate the session in its global network. If you do not set a location hint,
360361
the OpenTok servers will be based on the first client connecting to the session.
361362
363+
:param Boolean e2ee: Whether to enable end-to-end encryption for a routed session
364+
(see https://tokbox.com/developer/guides/end-to-end-encryption/).
365+
362366
:rtype: The Session object. The session_id property of the object is the session ID.
363367
"""
364368

@@ -395,6 +399,7 @@ def create_session(
395399
).format(location)
396400
)
397401
options[u("location")] = location
402+
options["e2ee"] = e2ee
398403

399404
try:
400405
logger.debug(
@@ -436,13 +441,14 @@ def create_session(
436441

437442
session_id = (
438443
dom.getElementsByTagName("session_id")[0].childNodes[0].nodeValue
439-
)
444+
)
440445
return Session(
441446
self,
442447
session_id,
443448
location=location,
444449
media_mode=media_mode,
445450
archive_mode=archive_mode,
451+
e2ee=e2ee,
446452
)
447453
except Exception as e:
448454
raise OpenTokException("Failed to generate session: %s" % str(e))

opentok/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# see: http://legacy.python.org/dev/peps/pep-0440/#public-version-identifiers
2-
__version__ = "3.4.0"
2+
__version__ = "3.5.0"
33

tests/test_session_creation.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_create_default_session(self):
5454
)
5555
expect(session).to(have_property(u("media_mode"), MediaModes.relayed))
5656
expect(session).to(have_property(u("location"), None))
57+
expect(session).to(have_property(u("e2ee"), False))
5758

5859
@httpretty.activate
5960
def test_create_routed_session(self):
@@ -87,6 +88,7 @@ def test_create_routed_session(self):
8788
)
8889
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
8990
expect(session).to(have_property(u("location"), None))
91+
expect(session).to(have_property(u("e2ee"), False))
9092

9193
@httpretty.activate
9294
def test_failure_create_routed_session(self):
@@ -138,6 +140,7 @@ def test_create_session_with_location_hint(self):
138140
)
139141
expect(session).to(have_property(u("media_mode"), MediaModes.relayed))
140142
expect(session).to(have_property(u("location"), u("12.34.56.78")))
143+
expect(session).to(have_property(u("e2ee"), False))
141144

142145
@httpretty.activate
143146
def test_create_routed_session_with_location_hint(self):
@@ -174,6 +177,7 @@ def test_create_routed_session_with_location_hint(self):
174177
)
175178
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
176179
expect(session).to(have_property(u("location"), u("12.34.56.78")))
180+
expect(session).to(have_property(u("e2ee"), False))
177181

178182
@httpretty.activate
179183
def test_create_manual_archive_mode_session(self):
@@ -209,6 +213,7 @@ def test_create_manual_archive_mode_session(self):
209213
)
210214
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
211215
expect(session).to(have_property(u("archive_mode"), ArchiveModes.manual))
216+
expect(session).to(have_property(u("e2ee"), False))
212217

213218
@httpretty.activate
214219
def test_create_always_archive_mode_session(self):
@@ -244,6 +249,7 @@ def test_create_always_archive_mode_session(self):
244249
)
245250
expect(session).to(have_property(u("media_mode"), MediaModes.routed))
246251
expect(session).to(have_property(u("archive_mode"), ArchiveModes.always))
252+
expect(session).to(have_property(u("e2ee"), False))
247253

248254
@httpretty.activate
249255
def test_complains_about_always_archive_mode_and_relayed_session(self):
@@ -263,5 +269,32 @@ def test_complains_about_always_archive_mode_and_relayed_session(self):
263269
archive_mode=ArchiveModes.always,
264270
)
265271

272+
@httpretty.activate
273+
def test_create_session_with_e2ee(self):
274+
httpretty.register_uri(
275+
httpretty.POST,
276+
u("https://api.opentok.com/session/create"),
277+
body=u(
278+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><sessions><Session><session_id>1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg</session_id><partner_id>123456</partner_id><create_dt>Mon Mar 17 00:41:31 PDT 2014</create_dt></Session></sessions>'
279+
),
280+
status=200,
281+
content_type=u("text/xml"),
282+
)
283+
284+
session = self.opentok.create_session(e2ee=True)
285+
286+
body = parse_qs(httpretty.last_request().body)
287+
expect(body).to(have_key(b("e2ee"), [b'True']))
288+
expect(session).to(be_a(Session))
289+
expect(session).to(
290+
have_property(
291+
u("session_id"),
292+
u(
293+
"1_MX4xMjM0NTZ-fk1vbiBNYXIgMTcgMDA6NDE6MzEgUERUIDIwMTR-MC42ODM3ODk1MzQ0OTQyODA4fg"
294+
),
295+
)
296+
)
297+
expect(session).to(have_property(u("e2ee"), True))
298+
266299
# TODO: all the cases that throw exceptions
267300
# TODO: custom api_url requests

0 commit comments

Comments
 (0)