From 77b3405da3e6158f915bd025066285291f4e8c0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20D=C3=B6ring?= <simon.doering@stud.hs-bochum.de>
Date: Tue, 16 Feb 2021 10:43:30 +0100
Subject: [PATCH] Add support for Janus admin key

---
 README.md                             | 16 ++++++++++++++++
 camera-server/example-config.json     |  3 ++-
 camera-server/src/config/config.ts    |  4 +++-
 camera-server/src/janus/janus-api.ts  |  1 +
 camera-server/src/janus/janus-room.ts |  3 ++-
 5 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index b1a4dd4..b26eb1d 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +88,22 @@ Below is a description of the config file's properties:
 * `janusBitrate`: The default bitrate with which a camera feed is transmitted by Janus.
   Defaults to `128000`.
 
+* `janusAdminKey`: Admin key for the Janus API, which is required to create new rooms.
+  It is recommended to use this feature becuase it reduces attack possibilities.
+  Defaults to an empty string.
+
+  **Important**: This key needs to match the admin key in the config file for the
+  Janus videoroom plugin. In the used development environment it is located at
+  `/opt/janus/etc/janus/janus.plugin.videoroom.jcfg`. The admin key can be set
+  in the `general: { ... }` block of the janus config using the `admin_key` directive.
+
+  Example:
+  ```
+  general: {
+    admin_key = "MySafeAdminKey"
+  }
+  ```
+
 ## Stdin-Interface
 
 The camera server is controlled by PULT via its stdin. One could also implement the interface in any other program to manage the CVH-Camera.
diff --git a/camera-server/example-config.json b/camera-server/example-config.json
index 5bfb42b..c16619d 100644
--- a/camera-server/example-config.json
+++ b/camera-server/example-config.json
@@ -6,5 +6,6 @@
   "janusRoom": 1000,
   "janusRoomSecret": "changeit",
   "janusRoomPin": "abc123",
-  "janusBitrate": 128000
+  "janusBitrate": 128000,
+  "janusAdminKey": "changeit"
 }
diff --git a/camera-server/src/config/config.ts b/camera-server/src/config/config.ts
index f74834a..c14023f 100644
--- a/camera-server/src/config/config.ts
+++ b/camera-server/src/config/config.ts
@@ -10,6 +10,7 @@ interface Config {
     janusRoomSecret: string;
     janusRoomPin: string;
     janusBitrate: number;
+    janusAdminKey: string;
 }
 
 // Required to access config with config[key]
@@ -44,7 +45,8 @@ const indexableConfig: IndexableConfig = {
     janusRoom: 1000,
     janusRoomSecret: 'default',
     janusRoomPin: '',
-    janusBitrate: 128000
+    janusBitrate: 128000,
+    janusAdminKey: ''
 };
 
 if (fileContent) {
diff --git a/camera-server/src/janus/janus-api.ts b/camera-server/src/janus/janus-api.ts
index fb0df2a..7328277 100644
--- a/camera-server/src/janus/janus-api.ts
+++ b/camera-server/src/janus/janus-api.ts
@@ -14,6 +14,7 @@ interface RoomConfig {
     secret?: string;
     pin?: string;
     description?: string;
+    admin_key?: string;
 }
 
 export const api = axios.create({
diff --git a/camera-server/src/janus/janus-room.ts b/camera-server/src/janus/janus-room.ts
index cb21b58..8836eba 100644
--- a/camera-server/src/janus/janus-room.ts
+++ b/camera-server/src/janus/janus-room.ts
@@ -128,7 +128,8 @@ class JanusRoom {
                 bitrate: config.janusBitrate,
                 publishers: config.cameraSlots,
                 pin: config.janusRoomPin,
-                secret: config.janusRoomSecret
+                secret: config.janusRoomSecret,
+                admin_key: config.janusAdminKey
             }
         );
 
-- 
GitLab