[vlc-devel] [PATCH 2/3] access: srt: add support stream encryption

Justin Kim justin.kim at collabora.com
Wed Nov 15 08:47:59 CET 2017


For encrypted transmitting, `passphrase` and `key-length`
properties are added.

Signed-off-by: Justin Kim <justin.kim at collabora.com>
---
 modules/access/srt.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/modules/access/srt.c b/modules/access/srt.c
index 4f61844a0a..6d6444408c 100644
--- a/modules/access/srt.c
+++ b/modules/access/srt.c
@@ -46,6 +46,8 @@
 /* The default latency is 125
  * which uses srt library internally */
 #define SRT_DEFAULT_LATENCY 125
+/* Crypto key length in bytes. */
+#define SRT_DEFAULT_KEY_LENGTH 16
 
 struct stream_sys_t
 {
@@ -55,6 +57,8 @@ struct stream_sys_t
     int         i_latency;
     size_t      i_chunk_size;
     int         i_event_fd;
+    char       *psz_passphrase;
+    int         i_key_length;
 };
 
 static void srt_wait_interrupted(void *p_data)
@@ -186,6 +190,8 @@ static int Open(vlc_object_t *p_this)
     p_sys->i_chunk_size = var_InheritInteger( p_stream, "chunk-size" );
     p_sys->i_poll_timeout = var_InheritInteger( p_stream, "poll-timeout" );
     p_sys->i_latency = var_InheritInteger( p_stream, "latency" );
+    p_sys->psz_passphrase = var_InheritString( p_stream, "passphrase" );
+    p_sys->i_key_length = var_InheritInteger( p_stream, "key-length" );
     p_sys->i_poll_id = -1;
     p_sys->i_event_fd = -1;
     p_stream->p_sys = p_sys;
@@ -219,6 +225,14 @@ static int Open(vlc_object_t *p_this)
     /* Set latency */
     srt_setsockopt( p_sys->sock, 0, SRTO_TSBPDDELAY, &p_sys->i_latency, sizeof( int ) );
 
+    if ( p_sys->psz_passphrase != NULL && p_sys->psz_passphrase[0] != '\0')
+    {
+        srt_setsockopt( p_sys->sock, 0, SRTO_PASSPHRASE,
+            p_sys->psz_passphrase, strlen( p_sys->psz_passphrase ) );
+        srt_setsockopt( p_sys->sock, 0, SRTO_PBKEYLEN,
+            &p_sys->i_key_length, sizeof( int ) );
+    }
+
     p_sys->i_poll_id = srt_epoll_create();
     if ( p_sys->i_poll_id == -1 )
     {
@@ -256,6 +270,12 @@ failed:
         freeaddrinfo( res );
     }
 
+    if ( p_sys->psz_passphrase != NULL)
+    {
+        free (p_sys->psz_passphrase);
+        p_sys->psz_passphrase = NULL;
+    }
+
     if ( p_sys->i_event_fd != -1 )
     {
         close( p_sys->i_event_fd );
@@ -290,6 +310,12 @@ static void Close(vlc_object_t *p_this)
         close( p_sys->i_event_fd );
         p_sys->i_event_fd = -1;
     }
+
+    if ( p_sys->psz_passphrase != NULL)
+    {
+        free (p_sys->psz_passphrase);
+        p_sys->psz_passphrase = NULL;
+    }
 }
 
 /* Module descriptor */
@@ -304,6 +330,9 @@ vlc_module_begin ()
     add_integer( "poll-timeout", SRT_DEFAULT_POLL_TIMEOUT,
             N_("Return poll wait after timeout miliseconds (-1 = infinite)"), NULL, true )
     add_integer( "latency", SRT_DEFAULT_LATENCY, N_("SRT latency (ms)"), NULL, true )
+    add_string( "passphrase", "", N_("Password for stream encryption"), NULL, false )
+    add_integer( "key-length", SRT_DEFAULT_KEY_LENGTH,
+            N_("Crypto key length in bytes [16, 24, 32]"), NULL, false )
 
     set_capability( "access", 0 )
     add_shortcut( "srt" )
-- 
2.15.0



More information about the vlc-devel mailing list