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

Hugo Beauzée-Luyssen hugo at beauzee.fr
Wed Nov 15 09:43:52 CET 2017


Hi,

On Wed, Nov 15, 2017, at 08:47 AM, Justin Kim wrote:
> 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;

You don't seem to be using those variables (except for releasing them)
out of the Open function, in which case they do not belong in your
stream_sys_t structure.

>  };
>  
>  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)

No need to check for NULL before calling free. I'd also argue that if
you make psz_passphrase a local variable, you don't need to set it back
to NULL afterward.

> +    {
> +        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)

That seems like a no-op since you freed that variable already in Open()

> +    {
> +        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 )

If only a few values are correct, you might want to use
change_integer_list

>  
>      set_capability( "access", 0 )
>      add_shortcut( "srt" )
> -- 
> 2.15.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel

Regards,

-- 
  Hugo Beauzée-Luyssen
  hugo at beauzee.fr


More information about the vlc-devel mailing list