Skip to content

Commit

Permalink
SUP-36185: Enable AEAD encryption for SRT.
Browse files Browse the repository at this point in the history
  • Loading branch information
shamamayair committed Feb 5, 2024
1 parent 6dab0a4 commit 5850647
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ Sets a passphrase for encryption, see the libsrt documentation of the `SRTO_PASS

The parameter value can contain variables.

#### cryptomode
* **syntax**: `cryptomode expr;`
* **default**: ``
* **context**: `srt, server`

Sets a cryptomode for encryption, see the libsrt documentation of the `SRTO_CRYPTOMODE` option for more details.

The parameter value can contain variables.

#### in_buf_size
* **syntax**: `in_buf_size size;`
* **default**: `64k`
Expand Down
1 change: 1 addition & 0 deletions src/ngx_srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct {

ngx_srt_conn_options_t srt_opts;
ngx_srt_complex_value_t *passphrase;
ngx_srt_complex_value_t *cryptomode;
} ngx_srt_core_srv_conf_t;


Expand Down
47 changes: 47 additions & 0 deletions src/ngx_srt_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,7 @@ ngx_srt_listen_callback(void *data, SRTSOCKET ns, int hs_version,
const struct sockaddr *peeraddr, const char *stream_id)
{
int socklen;
int cryptomode;
int serr, serrno;
ngx_str_t value;
ngx_log_t *log;
Expand Down Expand Up @@ -1912,6 +1913,52 @@ ngx_srt_listen_callback(void *data, SRTSOCKET ns, int hs_version,
goto failed;
}

if (cscf->cryptomode != NULL) {
/* evaluate the cryptomode */
if (ngx_srt_complex_value(s, cscf->cryptomode, &value) != NGX_OK) {
ngx_log_error(NGX_LOG_NOTICE, log, 0,
"ngx_srt_listen_callback: complex value failed");
goto failed;
}

if (value.len == 0) {
ngx_destroy_pool(c->pool);
return 0;
}

cryptomode = (int)ngx_atoi(value.data, value.len);

/* set the cryptomode */
if (cryptomode > 2) {
ngx_log_error(NGX_LOG_ERR, log, 0,
"ngx_srt_listen_callback: invalid cryptomode \"%d\"", cryptomode);
goto failed;
}

if (srt_setsockflag(ns, SRTO_CRYPTOMODE, &cryptomode, sizeof(cryptomode)) != 0) {
serr = srt_getlasterror(&serrno);
ngx_log_error(NGX_LOG_ERR, log, serrno,
"ngx_srt_listen_callback: "
"srt_setsockflag(SRTO_CRYPTOMODE) failed %d", serr);
goto failed;
}
}




/* ngx_log_error(NGX_LOG_ERR, log, 0,
"ngx_srt_listen_callback: "
"srt_setsockflag(SRTO_CRYPTOMODE) lal");
if (srt_setsockflag(ns, SRTO_CRYPTOMODE,&blocking, sizeof (blocking)) != 0) {
serr = srt_getlasterror(&serrno);
ngx_log_error(NGX_LOG_ERR, log, serrno,
"ngx_srt_listen_callback: "
"srt_setsockflag(SRTO_CRYPTOMODE) failed %d", serr);
goto failed;
}*/

ngx_destroy_pool(c->pool);

return 0;
Expand Down
11 changes: 11 additions & 0 deletions src/ngx_srt_core_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ static ngx_command_t ngx_srt_core_commands[] = {
offsetof(ngx_srt_core_srv_conf_t, passphrase),
NULL },

{ ngx_string("cryptomode"),
NGX_SRT_MAIN_CONF|NGX_SRT_SRV_CONF|NGX_CONF_TAKE1,
ngx_srt_set_complex_value_slot,
NGX_SRT_SRV_CONF_OFFSET,
offsetof(ngx_srt_core_srv_conf_t, cryptomode),
NULL },

ngx_null_command
};

Expand Down Expand Up @@ -280,6 +287,10 @@ ngx_srt_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
conf->passphrase = prev->passphrase;
}

if (conf->cryptomode == NULL) {
conf->cryptomode = prev->cryptomode;
}

return NGX_CONF_OK;
}

Expand Down

0 comments on commit 5850647

Please sign in to comment.