Skip to content
Snippets Groups Projects
Commit 1e38be3a authored by Marvin Steadfast's avatar Marvin Steadfast
Browse files

Added username and password for turn server

It makes it possible to use a turn server that needs a username and
password instead of a token.
parent 841c2285
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,9 @@ class VoipConfig(Config): ...@@ -19,7 +19,9 @@ class VoipConfig(Config):
def read_config(self, config): def read_config(self, config):
self.turn_uris = config.get("turn_uris", []) self.turn_uris = config.get("turn_uris", [])
self.turn_shared_secret = config["turn_shared_secret"] self.turn_shared_secret = config.get("turn_shared_secret")
self.turn_username = config.get("turn_username")
self.turn_password = config.get("turn_password")
self.turn_user_lifetime = self.parse_duration(config["turn_user_lifetime"]) self.turn_user_lifetime = self.parse_duration(config["turn_user_lifetime"])
def default_config(self, **kwargs): def default_config(self, **kwargs):
......
...@@ -32,18 +32,26 @@ class VoipRestServlet(ClientV1RestServlet): ...@@ -32,18 +32,26 @@ class VoipRestServlet(ClientV1RestServlet):
turnUris = self.hs.config.turn_uris turnUris = self.hs.config.turn_uris
turnSecret = self.hs.config.turn_shared_secret turnSecret = self.hs.config.turn_shared_secret
turnUsername = self.hs.config.turn_username
turnPassword = self.hs.config.turn_password
userLifetime = self.hs.config.turn_user_lifetime userLifetime = self.hs.config.turn_user_lifetime
if not turnUris or not turnSecret or not userLifetime:
defer.returnValue((200, {}))
expiry = (self.hs.get_clock().time_msec() + userLifetime) / 1000 if turnUris and turnSecret and userLifetime:
username = "%d:%s" % (expiry, requester.user.to_string()) expiry = (self.hs.get_clock().time_msec() + userLifetime) / 1000
username = "%d:%s" % (expiry, requester.user.to_string())
mac = hmac.new(turnSecret, msg=username, digestmod=hashlib.sha1)
# We need to use standard padded base64 encoding here
# encode_base64 because we need to add the standard padding to get the
# same result as the TURN server.
password = base64.b64encode(mac.digest())
mac = hmac.new(turnSecret, msg=username, digestmod=hashlib.sha1) elif turnUris and turnUsername and turnPassword and userLifetime:
# We need to use standard padded base64 encoding here username = turnUsername
# encode_base64 because we need to add the standard padding to get the password = turnPassword
# same result as the TURN server.
password = base64.b64encode(mac.digest()) else:
defer.returnValue((200, {}))
defer.returnValue((200, { defer.returnValue((200, {
'username': username, 'username': username,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment