From 44634e42421afb8df8ced2e07333f632f1fbea3b Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 1 Mar 2023 18:55:10 -0500 Subject: [PATCH] add patch for mod_httapi to handle signed AWS URLs --- .../files/avmd.conf.xml | 73 +++++++++++++++++++ .../files/mod_httapi.c.patch | 55 ++++++++++++++ .../scripts/install_freeswitch.sh | 7 +- packer/jambonz-feature-server/template.json | 18 ++--- packer/jambonz-mini/files/mod_httapi.c.patch | 55 ++++++++++++++ .../scripts/install_freeswitch.sh | 7 +- 6 files changed, 202 insertions(+), 13 deletions(-) create mode 100644 packer/jambonz-feature-server/files/avmd.conf.xml create mode 100644 packer/jambonz-feature-server/files/mod_httapi.c.patch create mode 100644 packer/jambonz-mini/files/mod_httapi.c.patch diff --git a/packer/jambonz-feature-server/files/avmd.conf.xml b/packer/jambonz-feature-server/files/avmd.conf.xml new file mode 100644 index 0000000..2e1df4c --- /dev/null +++ b/packer/jambonz-feature-server/files/avmd.conf.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packer/jambonz-feature-server/files/mod_httapi.c.patch b/packer/jambonz-feature-server/files/mod_httapi.c.patch new file mode 100644 index 0000000..eab370d --- /dev/null +++ b/packer/jambonz-feature-server/files/mod_httapi.c.patch @@ -0,0 +1,55 @@ +--- mod_httapi.c 2023-03-01 13:57:28 ++++ mod_httapi.c.new 2023-03-01 14:19:34 +@@ -2472,6 +2472,12 @@ + char *ua = NULL; + const char *profile_name = NULL; + int tries = 10; ++ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL && ++ strstr(url, "X-Amz-Algorithm") != NULL && ++ strstr(url, "X-Amz-Credential") != NULL && ++ strstr(url, "X-Amz-Date") != NULL && ++ strstr(url, "X-Amz-Expires") != NULL && ++ strstr(url, "X-Amz-SignedHeaders") != NULL; + + if (context->url_params) { + profile_name = switch_event_get_header(context->url_params, "profile_name"); +@@ -2614,7 +2620,7 @@ + switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) client); + } else { + switch_curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1); +- switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1); ++ if (!awsSignedUrl) switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1); + } + + if (headers) { +@@ -2783,6 +2789,12 @@ + char *metadata; + const char *ext = NULL; + const char *err_msg = NULL; ++ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL && ++ strstr(url, "X-Amz-Algorithm") != NULL && ++ strstr(url, "X-Amz-Credential") != NULL && ++ strstr(url, "X-Amz-Date") != NULL && ++ strstr(url, "X-Amz-Expires") != NULL && ++ strstr(url, "X-Amz-SignedHeaders") != NULL; + + load_cache_data(context, url); + +@@ -2831,7 +2843,7 @@ + + if (!unreachable && !zstr(context->metadata)) { + metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s", +- url, ++ awsSignedUrl ? context->cache_file : url, + switch_event_get_header_nil(headers, "last-modified"), + switch_event_get_header_nil(headers, "etag"), + switch_event_get_header_nil(headers, "content-length"), +@@ -2855,7 +2867,7 @@ + + + metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s", +- url, ++ awsSignedUrl ? context->cache_file : url, + switch_event_get_header_nil(headers, "last-modified"), + switch_event_get_header_nil(headers, "etag"), + switch_event_get_header_nil(headers, "content-length"), diff --git a/packer/jambonz-feature-server/scripts/install_freeswitch.sh b/packer/jambonz-feature-server/scripts/install_freeswitch.sh index e012041..5ee8565 100644 --- a/packer/jambonz-feature-server/scripts/install_freeswitch.sh +++ b/packer/jambonz-feature-server/scripts/install_freeswitch.sh @@ -74,7 +74,7 @@ sudo cp -r /usr/local/src/drachtio-freeswitch-modules/modules/mod_dialogflow /us sudo sed -i -r -e 's/(.*AM_CFLAGS\))/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am sudo sed -i -r -e 's/(.*-std=c++11)/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am -# copy Makefiles into place +# copy Makefiles and patches into place cp /tmp/configure.ac.extra /usr/local/src/freeswitch/configure.ac cp /tmp/Makefile.am.extra /usr/local/src/freeswitch/Makefile.am cp /tmp/modules.conf.in.extra /usr/local/src/freeswitch/build/modules.conf.in @@ -83,13 +83,16 @@ cp /tmp/avmd.conf.xml /usr/local/src/freeswitch/conf/vanilla/autoload_configs/av cp /tmp/switch_rtp.c.patch /usr/local/src/freeswitch/src cp /tmp/switch_core_media.c.patch /usr/local/src/freeswitch/src cp /tmp/mod_avmd.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_avmd +cp /tmp/mod_httapi.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_httapi # patch freeswitch cd /usr/local/src/freeswitch/src patch < switch_rtp.c.patch patch < switch_core_media.c.patch -cd mod/applications/mod_avmd +cd /usr/local/src/freeswitch/src/mod/applications/mod_avmd patch < mod_avmd.c.patch +cd /usr/local/src/freeswitch/src/mod/applications/mod_httapi +patch < mod_httapi.c.patch # build libwebsockets cd /usr/local/src/libwebsockets diff --git a/packer/jambonz-feature-server/template.json b/packer/jambonz-feature-server/template.json index f15d0f7..404d15f 100644 --- a/packer/jambonz-feature-server/template.json +++ b/packer/jambonz-feature-server/template.json @@ -80,6 +80,15 @@ "type": "shell", "script": "scripts/install_os_tuning.sh" }, + { + "type": "shell", + "environment_vars": [ + "ARCH={{user `ami_base_image_arch`}}", + "MEDIA_SERVER_NAME={{user `mediaserver_name`}}", + "PREFERRED_CODEC_LIST={{user `preferred_codec_list`}}" + ], + "script": "scripts/install_freeswitch.sh" + }, { "type": "shell", "script": "scripts/install_nodejs.sh" @@ -98,15 +107,6 @@ "execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `install_telegraf`}}", "script": "scripts/install_telegraf.sh" }, - { - "type": "shell", - "environment_vars": [ - "ARCH={{user `ami_base_image_arch`}}", - "MEDIA_SERVER_NAME={{user `mediaserver_name`}}", - "PREFERRED_CODEC_LIST={{user `preferred_codec_list`}}" - ], - "script": "scripts/install_freeswitch.sh" - }, { "type": "shell", "execute_command": "chmod +x {{ .Path }}; sudo '{{ .Path }}' {{user `drachtio_version`}}", diff --git a/packer/jambonz-mini/files/mod_httapi.c.patch b/packer/jambonz-mini/files/mod_httapi.c.patch new file mode 100644 index 0000000..eab370d --- /dev/null +++ b/packer/jambonz-mini/files/mod_httapi.c.patch @@ -0,0 +1,55 @@ +--- mod_httapi.c 2023-03-01 13:57:28 ++++ mod_httapi.c.new 2023-03-01 14:19:34 +@@ -2472,6 +2472,12 @@ + char *ua = NULL; + const char *profile_name = NULL; + int tries = 10; ++ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL && ++ strstr(url, "X-Amz-Algorithm") != NULL && ++ strstr(url, "X-Amz-Credential") != NULL && ++ strstr(url, "X-Amz-Date") != NULL && ++ strstr(url, "X-Amz-Expires") != NULL && ++ strstr(url, "X-Amz-SignedHeaders") != NULL; + + if (context->url_params) { + profile_name = switch_event_get_header(context->url_params, "profile_name"); +@@ -2614,7 +2620,7 @@ + switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) client); + } else { + switch_curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1); +- switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1); ++ if (!awsSignedUrl) switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1); + } + + if (headers) { +@@ -2783,6 +2789,12 @@ + char *metadata; + const char *ext = NULL; + const char *err_msg = NULL; ++ int awsSignedUrl = strstr(url, "X-Amz-Signature") != NULL && ++ strstr(url, "X-Amz-Algorithm") != NULL && ++ strstr(url, "X-Amz-Credential") != NULL && ++ strstr(url, "X-Amz-Date") != NULL && ++ strstr(url, "X-Amz-Expires") != NULL && ++ strstr(url, "X-Amz-SignedHeaders") != NULL; + + load_cache_data(context, url); + +@@ -2831,7 +2843,7 @@ + + if (!unreachable && !zstr(context->metadata)) { + metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s", +- url, ++ awsSignedUrl ? context->cache_file : url, + switch_event_get_header_nil(headers, "last-modified"), + switch_event_get_header_nil(headers, "etag"), + switch_event_get_header_nil(headers, "content-length"), +@@ -2855,7 +2867,7 @@ + + + metadata = switch_core_sprintf(context->pool, "%s:%s:%s:%s:%s", +- url, ++ awsSignedUrl ? context->cache_file : url, + switch_event_get_header_nil(headers, "last-modified"), + switch_event_get_header_nil(headers, "etag"), + switch_event_get_header_nil(headers, "content-length"), diff --git a/packer/jambonz-mini/scripts/install_freeswitch.sh b/packer/jambonz-mini/scripts/install_freeswitch.sh index 54e175a..d6eeba6 100644 --- a/packer/jambonz-mini/scripts/install_freeswitch.sh +++ b/packer/jambonz-mini/scripts/install_freeswitch.sh @@ -73,7 +73,7 @@ sudo cp -r /usr/local/src/drachtio-freeswitch-modules/modules/mod_dialogflow /us sudo sed -i -r -e 's/(.*AM_CFLAGS\))/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am sudo sed -i -r -e 's/(.*-std=c++11)/\1 -g -O0/g' /usr/local/src/freeswitch/src/mod/applications/mod_audio_fork/Makefile.am -# copy Makefiles into place +# copy Makefiles and patches into place cp /tmp/configure.ac.extra /usr/local/src/freeswitch/configure.ac cp /tmp/Makefile.am.extra /usr/local/src/freeswitch/Makefile.am cp /tmp/modules.conf.in.extra /usr/local/src/freeswitch/build/modules.conf.in @@ -82,13 +82,16 @@ cp /tmp/avmd.conf.xml /usr/local/src/freeswitch/conf/vanilla/autoload_configs/av cp /tmp/switch_rtp.c.patch /usr/local/src/freeswitch/src cp /tmp/switch_core_media.c.patch /usr/local/src/freeswitch/src cp /tmp/mod_avmd.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_avmd +cp /tmp/mod_httapi.c.patch /usr/local/src/freeswitch/src/mod/applications/mod_httapi # patch freeswitch cd /usr/local/src/freeswitch/src patch < switch_rtp.c.patch patch < switch_core_media.c.patch -cd mod/applications/mod_avmd +cd /usr/local/src/freeswitch/src/mod/applications/mod_avmd patch < mod_avmd.c.patch +cd /usr/local/src/freeswitch/src/mod/applications/mod_httapi +patch < mod_httapi.c.patch # build libwebsockets cd /usr/local/src/libwebsockets