From 5b64cfaca3a7939473c0ca5fe438be80d78ab596 Mon Sep 17 00:00:00 2001 From: Johan Sternerup Date: Fri, 25 Sep 2020 17:18:10 +0200 Subject: [PATCH] webrtcice: Add webrtc ALPN header for HTTP proxy Section 3.4 in RFC8835 states that if a WebRTC endpoint uses an HTTP proxy to access the Internet it MUST include the "ALPN" header. This commit adds this header. By default the ALPN used when connecting to the TURN/TCP server via a proxy is set to "webrtc". It can be changed by adding an alpn url option for the http-proxy. For example: http://user:pass@my.http.proxy.com:8080?alpn=c-webrtc This will add the header "ALPN: c-webrtc" to the HTTP proxy CONNECT request. Part-of: --- girs/GstWebRTC-1.0.gir | 12 ++++++------ .../docs/plugins/gst_plugins_cache.json | 2 +- .../gst-plugins-bad/ext/webrtc/gstwebrtcbin.c | 4 ++-- .../gst-plugins-bad/gst-libs/gst/webrtc/ice.c | 4 ++-- .../gst-libs/gst/webrtc/nice/nice.c | 14 +++++++++++++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/girs/GstWebRTC-1.0.gir b/girs/GstWebRTC-1.0.gir index 8e60e23513..dd7df6fad5 100644 --- a/girs/GstWebRTC-1.0.gir +++ b/girs/GstWebRTC-1.0.gir @@ -764,7 +764,7 @@ for more information. URI of the HTTP proxy of the form - http://[username:password@]hostname[:port] + http://[username:password@]hostname[:port][?alpn=<alpn>] Get HTTP Proxy to be used when connecting to TURN server. @@ -897,7 +897,7 @@ Get HTTP Proxy to be used when connecting to TURN server. URI of the HTTP proxy of the form - http://[username:password@]hostname[:port] + http://[username:password@]hostname[:port][?alpn=<alpn>] @@ -1144,7 +1144,7 @@ Get HTTP Proxy to be used when connecting to TURN server. URI of the HTTP proxy of the form - http://[username:password@]hostname[:port] + http://[username:password@]hostname[:port][?alpn=<alpn>] Get HTTP Proxy to be used when connecting to TURN server. @@ -1287,7 +1287,7 @@ Get HTTP Proxy to be used when connecting to TURN server. URI of the HTTP proxy of the form - http://[username:password@]hostname[:port] + http://[username:password@]hostname[:port][?alpn=<alpn>] @@ -1833,7 +1833,7 @@ stops automatic ICE gathering. URI of the HTTP proxy of the form - http://[username:password@]hostname[:port] + http://[username:password@]hostname[:port][?alpn=<alpn>] @@ -1844,7 +1844,7 @@ stops automatic ICE gathering. URI of the HTTP proxy of the form - http://[username:password@]hostname[:port] + http://[username:password@]hostname[:port][?alpn=<alpn>] Get HTTP Proxy to be used when connecting to TURN server. diff --git a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json index b7ad68571d..6246d458e9 100644 --- a/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json +++ b/subprojects/gst-plugins-bad/docs/plugins/gst_plugins_cache.json @@ -237931,7 +237931,7 @@ "writable": false }, "http-proxy": { - "blurb": "A HTTP proxy for use with TURN/TCP of the form http://[username:password@]hostname[:port]", + "blurb": "A HTTP proxy for use with TURN/TCP of the form http://[username:password@]hostname[:port][?alpn=]", "conditionally-available": false, "construct": false, "construct-only": false, diff --git a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c index a5b023155b..1f728e386c 100644 --- a/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c +++ b/subprojects/gst-plugins-bad/ext/webrtc/gstwebrtcbin.c @@ -8776,7 +8776,7 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass) * GstWebRTCBin:http-proxy: * * A HTTP proxy for use with TURN/TCP of the form - * http://[username:password@]hostname[:port] + * http://[username:password@]hostname[:port][?alpn=] * * Since: 1.22 */ @@ -8784,7 +8784,7 @@ gst_webrtc_bin_class_init (GstWebRTCBinClass * klass) PROP_HTTP_PROXY, g_param_spec_string ("http-proxy", "HTTP Proxy", "A HTTP proxy for use with TURN/TCP of the form " - "http://[username:password@]hostname[:port]", + "http://[username:password@]hostname[:port][?alpn=]", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /** diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c index 22446ffd87..82a685940a 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/ice.c @@ -458,7 +458,7 @@ gst_webrtc_ice_get_turn_server (GstWebRTCICE * ice) * gst_webrtc_ice_set_http_proxy: * @ice: The #GstWebRTCICE * @uri: (transfer none): URI of the HTTP proxy of the form - * http://[username:password@]hostname[:port] + * http://[username:password@]hostname[:port][?alpn=] * * Set HTTP Proxy to be used when connecting to TURN server. * @@ -478,7 +478,7 @@ gst_webrtc_ice_set_http_proxy (GstWebRTCICE * ice, const gchar * uri_s) * @ice: The #GstWebRTCICE * * Returns: (transfer full): URI of the HTTP proxy of the form - * http://[username:password@]hostname[:port] + * http://[username:password@]hostname[:port][?alpn=] * * Get HTTP Proxy to be used when connecting to TURN server. * diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c index ce15cb6cf0..4e902868e6 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c +++ b/subprojects/gst-plugins-bad/gst-libs/gst/webrtc/nice/nice.c @@ -1351,8 +1351,10 @@ on_http_proxy_resolved (GstWebRTCICE * ice, GAsyncResult * res, const gchar *userinfo; gchar *user = NULL; gchar *pass = NULL; + const gchar *alpn = NULL; gchar *ip = NULL; guint port = GST_URI_NO_PORT; + GHashTable *extra_headers; if (!(addresses = resolve_host_finish (nice, res, &error))) { GST_WARNING_OBJECT (ice, "Failed to resolve http proxy: %s", @@ -1382,13 +1384,23 @@ on_http_proxy_resolved (GstWebRTCICE * ice, GAsyncResult * res, userinfo = gst_uri_get_userinfo (uri); _parse_userinfo (userinfo, &user, &pass); + alpn = gst_uri_get_query_value (uri, "alpn"); + if (!alpn) { + alpn = "webrtc"; + } + extra_headers = g_hash_table_new_full (g_str_hash, + g_str_equal, g_free, g_free); + g_hash_table_insert (extra_headers, g_strdup ("ALPN"), g_strdup (alpn)); + g_object_set (nice->priv->nice_agent, "proxy-ip", ip, "proxy-port", port, "proxy-type", NICE_PROXY_TYPE_HTTP, - "proxy-username", user, "proxy-password", pass, NULL); + "proxy-username", user, "proxy-password", pass, "proxy-extra-headers", + extra_headers, NULL); g_free (ip); g_free (user); g_free (pass); + g_hash_table_unref (extra_headers); } static GstUri *