From 132e58fb31be3acac2b2ca1eb281d4d936edcbbb Mon Sep 17 00:00:00 2001 From: Jess Mayo Date: Wed, 8 Jul 2015 11:26:00 +0900 Subject: [PATCH 1/2] obs-outputs: Enable rtmp authentication Authentication code has been updated as per the changes to support multiple streams. Authentication is now also enabled by default, and should be a no-op if the server does not request authentication or username and password details are not provided. --- plugins/obs-outputs/librtmp/rtmp.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/obs-outputs/librtmp/rtmp.c b/plugins/obs-outputs/librtmp/rtmp.c index 0e53454cb..08bf0eb23 100644 --- a/plugins/obs-outputs/librtmp/rtmp.c +++ b/plugins/obs-outputs/librtmp/rtmp.c @@ -23,6 +23,12 @@ * http://www.gnu.org/copyleft/lgpl.html */ +#ifndef NO_AUTH +#ifndef CRYPTO +#define USE_ONLY_MD5 +#endif +#endif + #include "rtmp_sys.h" #include "log.h" @@ -2614,7 +2620,7 @@ PublisherAuth(RTMP *r, AVal *description) RTMP_Log(RTMP_LOGDEBUG, "%s, new app: %.*s tcUrl: %.*s playpath: %s", __FUNCTION__, r->Link.app.av_len, r->Link.app.av_val, r->Link.tcUrl.av_len, r->Link.tcUrl.av_val, - r->Link.playpath.av_val); + r->Link.streams[r->Link.curStreamIdx].playpath.av_val); } else if (strstr(description->av_val, av_authmod_llnw.av_val) != NULL) { @@ -2817,7 +2823,7 @@ PublisherAuth(RTMP *r, AVal *description) RTMP_Log(RTMP_LOGDEBUG, "%s, new app: %.*s tcUrl: %.*s playpath: %s", __FUNCTION__, r->Link.app.av_len, r->Link.app.av_val, r->Link.tcUrl.av_len, r->Link.tcUrl.av_val, - r->Link.playpath.av_val); + r->Link.streams[r->Link.curStreamIdx].playpath.av_val); } else { @@ -4215,11 +4221,15 @@ RTMP_Close(RTMP *r) } #if defined(CRYPTO) || defined(USE_ONLY_MD5) - if (!(r->Link.protocol & RTMP_FEATURE_WRITE) || (r->Link.pFlags & RTMP_PUB_CLEAN)) + for (int idx = 0; idx < r->Link.nStreams; idx++) { - free(r->Link.playpath0.av_val); - r->Link.playpath0.av_val = NULL; + free(r->Link.streams[idx].playpath.av_val); + r->Link.streams[idx].playpath.av_val = NULL; } + + r->Link.curStreamIdx = 0; + r->Link.nStreams = 0; + if ((r->Link.protocol & RTMP_FEATURE_WRITE) && (r->Link.pFlags & RTMP_PUB_CLEAN) && (r->Link.pFlags & RTMP_PUB_ALLOC)) From 65d7f3b63f161228eb6ac8c923da8e708e8c2759 Mon Sep 17 00:00:00 2001 From: Jess Mayo Date: Wed, 8 Jul 2015 11:26:32 +0900 Subject: [PATCH 2/2] rtmp-services: Add auth settings for custom server Username and Password prompts have been added to the custom RTMP server UI and saved in the config file alongside server and key. --- plugins/rtmp-services/data/locale/en-US.ini | 3 ++ plugins/rtmp-services/rtmp-custom.c | 46 ++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/plugins/rtmp-services/data/locale/en-US.ini b/plugins/rtmp-services/data/locale/en-US.ini index 22c18bb52..3e7e8be6a 100644 --- a/plugins/rtmp-services/data/locale/en-US.ini +++ b/plugins/rtmp-services/data/locale/en-US.ini @@ -3,3 +3,6 @@ CustomStreamingServer="Custom Streaming Server" Service="Service" Server="Server" StreamKey="Stream key" +UseAuth="Use authentication" +Username="Username" +Password="Password" diff --git a/plugins/rtmp-services/rtmp-custom.c b/plugins/rtmp-services/rtmp-custom.c index a7a4f167d..da56fa27c 100644 --- a/plugins/rtmp-services/rtmp-custom.c +++ b/plugins/rtmp-services/rtmp-custom.c @@ -2,6 +2,8 @@ struct rtmp_custom { char *server, *key; + bool use_auth; + char *username, *password; }; static const char *rtmp_custom_name(void) @@ -18,6 +20,9 @@ static void rtmp_custom_update(void *data, obs_data_t *settings) service->server = bstrdup(obs_data_get_string(settings, "server")); service->key = bstrdup(obs_data_get_string(settings, "key")); + service->use_auth = obs_data_get_bool(settings, "use_auth"); + service->username = bstrdup(obs_data_get_string(settings, "username")); + service->password = bstrdup(obs_data_get_string(settings, "password")); } static void rtmp_custom_destroy(void *data) @@ -26,6 +31,8 @@ static void rtmp_custom_destroy(void *data) bfree(service->server); bfree(service->key); + bfree(service->username); + bfree(service->password); bfree(service); } @@ -38,16 +45,35 @@ static void *rtmp_custom_create(obs_data_t *settings, obs_service_t *service) return data; } +static bool use_auth_modified(obs_properties_t *ppts, obs_property_t *p, + obs_data_t *settings) +{ + bool use_auth = obs_data_get_bool(settings, "use_auth"); + p = obs_properties_get(ppts, "username"); + obs_property_set_visible(p, use_auth); + p = obs_properties_get(ppts, "password"); + obs_property_set_visible(p, use_auth); + return true; +} + static obs_properties_t *rtmp_custom_properties(void *unused) { UNUSED_PARAMETER(unused); obs_properties_t *ppts = obs_properties_create(); + obs_property_t *p; obs_properties_add_text(ppts, "server", "URL", OBS_TEXT_DEFAULT); obs_properties_add_text(ppts, "key", obs_module_text("StreamKey"), OBS_TEXT_PASSWORD); + + p = obs_properties_add_bool(ppts, "use_auth", obs_module_text("UseAuth")); + obs_properties_add_text(ppts, "username", obs_module_text("Username"), + OBS_TEXT_DEFAULT); + obs_properties_add_text(ppts, "password", obs_module_text("Password"), + OBS_TEXT_PASSWORD); + obs_property_set_modified_callback(p, use_auth_modified); return ppts; } @@ -63,6 +89,22 @@ static const char *rtmp_custom_key(void *data) return service->key; } +static const char *rtmp_custom_username(void *data) +{ + struct rtmp_custom *service = data; + if (!service->use_auth) + return NULL; + return service->username; +} + +static const char *rtmp_custom_password(void *data) +{ + struct rtmp_custom *service = data; + if (!service->use_auth) + return NULL; + return service->password; +} + struct obs_service_info rtmp_custom_service = { .id = "rtmp_custom", .get_name = rtmp_custom_name, @@ -71,5 +113,7 @@ struct obs_service_info rtmp_custom_service = { .update = rtmp_custom_update, .get_properties = rtmp_custom_properties, .get_url = rtmp_custom_url, - .get_key = rtmp_custom_key + .get_key = rtmp_custom_key, + .get_username = rtmp_custom_username, + .get_password = rtmp_custom_password };