Giter Site home page Giter Site logo

nginx-secure-token-module's Introduction

Secure token module for Nginx Build Status

Generates CDN tokens, either as a cookie or as a query string parameter (m3u8,mpd,f4m only). Currently supports Akamai v2 tokens, and Amazon CloudFront tokens. In addition, the module supports the encryption of URIs with a configured key.

Build

To link statically against nginx, cd to nginx source directory and execute:

./configure --add-module=/path/to/nginx-secure-token-module

To compile as a dynamic module (nginx 1.9.11+), use:

./configure --add-dynamic-module=/path/to/nginx-secure-token-module

In this case, the load_module directive should be used in nginx.conf to load the module.

Requires OpenSSL.

Configuration

Generic token parameters

secure_token

  • syntax: secure_token value
  • default: none
  • context: http, server, location

Sets the value of the token that should be embedded in the manifest/returned as a cookie. The parameter value can contain variables, and often points to variables set by this module (using secure_token_akamai / secure_token_cloudfront blocks)

secure_token_avoid_cookies

  • syntax: secure_token_avoid_cookies on/off
  • default: on
  • context: http, server, location

When enabled the module prefers to use a query string token instead of a cookie token. A query string token is currently supported only for the following mime types (other mime types return a cookie token):

  • application/vnd.apple.mpegurl
  • application/dash+xml
  • video/f4m

secure_token_types

  • syntax: secure_token_types mime_type ...
  • default: none
  • context: http, server, location

Defines a set of mime types that should return a token

secure_token_uri_filename_prefix

  • syntax: secure_token_uri_filename_prefix prefix
  • default: none
  • context: http, server, location

Defines a set of prefixes that will be matched against the URI file name, only URIs whose file name starts with one of the defined prefixes will return a token

secure_token_expires_time

  • syntax: secure_token_expires_time time
  • default: none
  • context: http, server, location

Sets the expiration time of responses that are not tokenized (determines the values of the Cache-Control and Expires HTTP headers)

secure_token_cookie_token_expires_time

  • syntax: secure_token_cookie_token_expires_time time
  • default: none
  • context: http, server, location

Sets the expiration time of responses that are tokenized with a cookie token (determines the values of the Cache-Control and Expires HTTP headers)

secure_token_query_token_expires_time

  • syntax: secure_token_query_token_expires_time time
  • default: none
  • context: http, server, location

Sets the expiration time of responses that are tokenized with a query string token (determines the values of the Cache-Control and Expires HTTP headers)

secure_token_cache_scope

  • syntax: secure_token_cache_scope scope
  • default: public
  • context: http, server, location

Sets the cache scope (public/private) of responses that are not tokenized

secure_token_token_cache_scope

  • syntax: secure_token_token_cache_scope scope
  • default: private
  • context: http, server, location

Sets the cache scope (public/private) of responses that are tokenized (query / cookie)

secure_token_last_modified

  • syntax: secure_token_last_modified time
  • default: Sun, 19 Nov 2000 08:52:00 GMT
  • context: http, server, location

Sets the value of the last-modified header of responses that are not tokenized. An empty string leaves the value of last-modified unaltered, while the string "now" sets the header to the server current time.

secure_token_token_last_modified

  • syntax: secure_token_token_last_modified time
  • default: now
  • context: http, server, location

Sets the value of the last-modified header of responses that are tokenized (query / cookie) An empty string leaves the value of last-modified unaltered, while the string "now" sets the header to the server current time.

secure_token_content_type_m3u8

  • syntax: secure_token_content_type_m3u8 type
  • default: application/vnd.apple.mpegurl
  • context: http, server, location

Sets the content type that should be parsed as m3u8 for token insertion

secure_token_content_type_mpd

  • syntax: secure_token_content_type_mpd type
  • default: application/dash+xml
  • context: http, server, location

Sets the content type that should be parsed as mpd for token insertion

secure_token_content_type_f4m

  • syntax: secure_token_content_type_f4m type
  • default: video/f4m
  • context: http, server, location

Sets the content type that should be parsed as f4m for token insertion

Akamai token parameters

secure_token_akamai

  • syntax: secure_token_akamai $variable { ... }
  • context: http

Creates a new variable whose value is an Akamai token, created according to the parameters specified within the block.

The block supports the following parameters:

key

  • syntax: key key_hex
  • default: N/A (mandatory)

Sets the secret key.

param_name

  • syntax: param_name name
  • default: __hdnea__

Sets the token parameter name (either the name of the cookie or the query string parameter)

acl

  • syntax: acl acl
  • default: $secure_token_baseuri_comma

Sets the signed part of the URL (ACL). The parameter value can contain variables.

start

  • syntax: start time
  • default: 0

Sets the start time of the token (see Time format below)

end

  • syntax: end time
  • default: 86400

Sets the end time of the token (see Time format below)

ip_address

  • syntax: ip_address address
  • default: none

Sets the IP address that should be embedded in the token. The parameter value can contain variables, e.g. $remote_addr.

CloudFront token parameters

secure_token_cloudfront

  • syntax: secure_token_cloudfront $variable { ... }
  • context: http

Creates a new variable whose value is a CloudFront token, created according to the parameters specified within the block.

The block supports the following parameters:

private_key_file

  • syntax: private_key_file filename
  • default: N/A (mandatory)

Sets the file name of the private key (PEM file)

key_pair_id

  • syntax: key_pair_id id
  • default: N/A (mandatory)

Sets the key pair id

acl

  • syntax: acl acl
  • default: $secure_token_baseuri_comma

Sets the signed part of the URL (ACL). The parameter value can contain variables.

end

  • syntax: end time
  • default: 86400

Sets the end time of the token (see Time format below)

ip_address

  • syntax: ip_address address
  • default: none

Sets the IP address that should be embedded in the token. The parameter value can contain variables, e.g. $remote_addr/32 can be used to limit the token to the specific IP of the client.

Broadpeak token parameters

secure_token_broadpeak

  • syntax: secure_token_broadpeak $variable { ... }
  • context: http

Creates a new variable whose value is a Broadpeak token, created according to the parameters specified within the block.

The block supports the following parameters:

key

  • syntax: key key
  • default: N/A (mandatory)

Sets the secret key. The parameter value can contain variables.

param_name

  • syntax: param_name name
  • default: token

Sets the token parameter name (either the name of the cookie or the query string parameter)

acl

  • syntax: acl acl
  • default: $secure_token_baseuri_comma

Sets the signed part of the URL (ACL). The parameter value can contain variables.

start

  • syntax: start time
  • default: 0

Sets the start time of the token (see Time format below)

end

  • syntax: end time
  • default: 86400

Sets the end time of the token (see Time format below)

session_start

  • syntax: session_start time
  • default: N/A

Sets the start time of the session, required for catchup. The parameter value can contain variables.

session_end

  • syntax: session_end time
  • default: N/A

Sets the end time of the session, required for catchup. The parameter value can contain variables.

additional_querylist

  • syntax: additional_querylist expr
  • default: N/A

Sets the primary token value, the value needs to be a list of name=value pairs without any separator. For example, "ip=${arg_ip}account=${arg_account}device=${arg_device}". The parameter value can contain variables.

URI encryption parameters

secure_token_encrypt_uri

  • syntax: secure_token_encrypt_uri on/off
  • default: off
  • context: http, server, location

Enables/disables uri encryption

secure_token_encrypt_uri_key

  • syntax: secure_token_encrypt_uri_key key_hex
  • default: none
  • context: http, server, location

Sets the encryption key, the key has to be 256 bits (64 hex characters)

secure_token_encrypt_uri_iv

  • syntax: secure_token_encrypt_uri_iv iv_hex
  • default: none
  • context: http, server, location

Sets the encryption iv, the iv has to be 128 bits (32 hex characters)

secure_token_encrypt_uri_part

  • syntax: secure_token_encrypt_uri_part expression
  • default: none
  • context: http, server, location

An expression that calculates the part of the URL that should be encrypted in regular expression locations. For non-regular expression locations, the encrypted part is everything following the path defined on the location block.

Example 1:

  location /secret_param/([^/]+)/some_other_param/.* {
  	secure_token_encrypt_uri_part $1;
	...
  }

In this configuration, only the value of secret_param will be encrypted/decrypted.

Example 2:

  location /base/ {
    ...
  }

In this configuration, everything following /base/ will be encrypted/decrypted.

secure_token_encrypt_uri_hash_size

  • syntax: secure_token_encrypt_uri_hash_size size
  • default: 8
  • context: http, server, location

The size in bytes of hash used to validate the uri after decryption, the value has to be between 0 and 16.

Time format

Some of the configuration parameters mentioned above, support both absolute timestamps, and timestamps relative to now. These parameters can be set in the configuration using one of the following formats:

  • epoch - unix timestamp 0 (01/01/1970)
  • max - unix timestamp 2147483647 (18/01/2038)
  • @1481230000 - unix timestamp 1481230000 (8/12/2016)
  • 10d / +10d - now + 10 days
  • -5m - now - 5 minutes

Sample configurations

HLS packaging with Akamai tokens

	secure_token_akamai $token {
		key 1234;
		acl "$secure_token_baseuri_comma*";
	}

	server {
	
		location ~ ^/hls/p/\d+/(sp/\d+/)?serveFlavor/ {
			vod hls;

			g2o        on;

			secure_token $token;
			secure_token_types application/vnd.apple.mpegurl;
			
			secure_token_expires_time 100d;
			secure_token_query_token_expires_time 1h;

			more_set_headers 'Access-Control-Allow-Headers: *';
			more_set_headers 'Access-Control-Expose-Headers: Server,range,Content-Length,Content-Range';
			more_set_headers 'Access-Control-Allow-Methods: GET, HEAD, OPTIONS';
			more_set_headers 'Access-Control-Allow-Origin: *';
		}
		
	}

HDS packaging with CloudFront tokens

	secure_token_cloudfront $token {
		private_key_file /path/to/pem;
		key_pair_id ABCDEF;
		acl "$scheme://$http_host$secure_token_baseuri_comma*";
	}

	server {
	
		location ~ ^/hds/p/\d+/(sp/\d+/)?serveFlavor/ {
			vod hds;
			vod_segment_duration 6000;
			vod_align_segments_to_key_frames on;
			vod_segment_count_policy last_rounded;

			secure_token $token;
			secure_token_types video/f4m;
			
			secure_token_expires_time 100d;
			secure_token_query_token_expires_time 1h;

			more_set_headers 'Access-Control-Allow-Headers: *';
			more_set_headers 'Access-Control-Expose-Headers: Server,range,Content-Length,Content-Range';
			more_set_headers 'Access-Control-Allow-Methods: GET, HEAD, OPTIONS';
			more_set_headers 'Access-Control-Allow-Origin: *';
		}
		
	}

Encrypted HLS with token security on the encryption key

This configuration enables token security while having static URLs for the video segments, this enables the caching of the segments transparently by proxies.

	secure_token_akamai $token {
		key 1234;
		acl "$secure_token_baseuri_comma*";
	}

	server {
	
		location ~ ^/s/hls/enc/p/\d+/(sp/\d+/)?serveFlavor/ {
			vod hls;
			vod_secret_key "password$vod_filepath";

			secure_token $token;
			secure_token_types application/vnd.apple.mpegurl;
			
			secure_token_expires_time 100d;
			secure_token_query_token_expires_time 1h;
			
			secure_token_uri_filename_prefix index;
			secure_token_tokenize_segments off;

			akamai_token_validate $arg___hdnea__;
			akamai_token_validate_key 1234;
			akamai_token_validate_uri_filename_prefix encryption;
			akamai_token_validate_uri_filename_prefix index;
		}
		
	}

Note: this configuration requires the module https://github.com/kaltura/nginx-akamai-token-validate-module in addition to nginx-secure-token-module

Adding token security on top of an existing HDS/HLS live stream

	secure_token_akamai $token {
		key 1234;
		acl "$secure_token_baseuri_comma*";
	}

	server {
	
		location /secure-live/ {
			proxy_pass http://original.live.domain;

			secure_token $token;
			secure_token_types text/xml application/vnd.apple.mpegurl;		
			secure_token_content_type_f4m text/xml;
			
			secure_token_expires_time 100d;
			secure_token_query_token_expires_time 1h;

			akamai_token_validate $arg___hdnea__;
			akamai_token_validate_key 1234;
			akamai_token_validate_strip_token __hdnea__;
		}
	
	}

Note: this configuration requires the module https://github.com/kaltura/nginx-akamai-token-validate-module in addition to nginx-secure-token-module

URI encryption

	location ~ ^/hls/p/\d+/(sp/\d+/)?serveFlavor/entryId/([^/]+)/(.*) {
		vod hls;
		vod_secret_key "password$2";

		secure_token_encrypt_uri on;
		secure_token_encrypt_uri_key 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f;
		secure_token_encrypt_uri_iv 00000000000000000000000000000000;
		secure_token_encrypt_uri_part $3;
		secure_token_types application/vnd.apple.mpegurl;

		add_header Last-Modified "Sun, 19 Nov 2000 08:52:00 GMT";
		expires 100d;
	}

Nginx variables

The module adds the following nginx variables:

  • $secure_token_baseuri - contains the value of the $uri built in variable truncated up to the last slash (/). For exmaple, if $uri is /a/b/c.htm then $secure_token_baseuri will be /a/b/.
  • $secure_token_baseuri_comma - same as $secure_token_baseuri, except that if this value contains a comma (,) the value is truncated up to the comma position. For exmaple, if $uri is /a/b/c.htm then $secure_token_baseuri_comma will be /a/b/; if $uri is /a/b,c/d.htm then $secure_token_baseuri_comma will be /a/b.
  • $secure_token_original_uri - contains the original (encrypted) uri when using uri encryption. Note that the built in $uri variable contains the modified (decrypted) uri in this case.

Copyright & License

All code in this project is released under the AGPLv3 license unless a different license for a particular library is specified in the applicable library path.

Copyright © Kaltura Inc. All rights reserved.

nginx-secure-token-module's People

Contributors

cstranex avatar david-winder-kaltura avatar erankor avatar kuroishi avatar luaxy avatar vs-adm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx-secure-token-module's Issues

Help cofiguring module

Hello im having a hard time working this module out. Could someone share some of their configuration so i can get some idea how can i make this module work for me?

kaltura vod module is already working for me all i want to achieve right now is to tokenize the source video file so others won't leach on the source video file.

i already added nginxsecure module, nginx akamai token validate module and nginx vod module. I just dont know where to start.

If there's any tutorial on how to do this would be a great help as the documentation isn't clear for me.

here's the sample website that im working on. as you can see the video is already working but the source video url is not encrypted.

Last-Modified issue with secure token module

Hello,

When I am activating the secure token module, there is always the same Last-Modified date/time.

For example, this is the request:

https://cdnuser1.example.com/hls/5d15498d3b4e13.57348983/1024_576_2200_5d15498d3b4e13.57348983_00063.ts?token=st=1570570271~exp=1570656671~acl=/hls/5d15498d3b4e13.57348983/*~hmac=e5ba663a0e01481b77663d997ad7be092fbc7df69a52add27f9cb6381f2bcc50

and the headers:

Accept-Ranges: bytes
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Origin,X-Auth-Token,Authorization,Accept,Client-Security-Token
Access-Control-Allow-Methods: OPTIONS, GET
Access-Control-Allow-Origin: *
Cache-Control: max-age=31536000
Connection: keep-alive
Content-Length: 565880
Content-Type: video/mp2t
Date: Tue, 08 Oct 2019 21:39:14 GMT
ETag: "865fb8019c16a38da2a6c7cbe0158441"
Last-Modified: Sun, 19 Nov 2000 08:52:00 GMT
Pragma: public
Server: nginx/1.17.0
X-Cache-Status: HIT
X-Proxy-Cache: HIT
X-Upstream-Http-Cache-Control: no-cache

and this is the token config in nginx

 akamai_token_validate $test_token;
 akamai_token_validate_key 58D8B91F68EE967B;
 secure_token $token;
 secure_token_types text/xml application/vnd.apple.mpegurl;
 secure_token_tokenize_segments on;

Have you seen something similar? I can't figure out way is using the default Last-Modified: Sun, 19 Nov 2000 08:52:00 GMT

Regards,
Andrew

Nginx 1.17.0 & Secure/Akamai token issue

Hello,

I compiled Nginx with the following modules:

configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt='-I /usr/local/include' --with-ld-opt='-L /usr/local/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --user=www --group=www --modules-path=/usr/local/libexec/nginx --with-file-aio --http-client-body-temp-path=/var/tmp/nginx/client_body_temp --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp --http-proxy-temp-path=/var/tmp/nginx/proxy_temp --http-scgi-temp-path=/var/tmp/nginx/scgi_temp --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp --http-log-path=/var/log/nginx/access.log --with-http_v2_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-pcre --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module --with-mail_ssl_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-mail=dynamic --add-module=/tmp/nginx-secure-token-module-master --add-module=/tmp/nginx-akamai-token-validate-module-master

and i added the follow config for the akamai token:

in HTTP

secure_token_akamai $token {
		key aa11bb22;
		acl "$secure_token_baseuri_comma*";
                param_name token;
    }

in Server

if ($arg_token) {
			set $test_token $arg_token;
        }

	if ($cookie_token) {
			set $test_token $cookie_token;
       	}

and in the location

akamai_token_validate $test_token;
           akamai_token_validate_key aa11bb22;
	   secure_token $token;
	   secure_token_types text/xml application/vnd.apple.mpegurl;		
	   secure_token_content_type_f4m text/xml;
	   secure_token_expires_time 100d;
	   secure_token_query_token_expires_time 1h;
           secure_token_tokenize_segments on;

I used the akamai python script to generate the token:
token=exp=1562280369~acl=/hls/*~hmac=c3b073ebed05a4b462dc0cdeda3df4987cc7b79d67ccafda5ef59868fbeff4a6

and the request for the manifest was successful:

Request URL: https://example.com/hls/5d134afe91b970.80939375/playlist.m3u8?token=exp=1562280369~acl=/hls/*~hmac=c3b073ebed05a4b462dc0cdeda3df4987cc7b79d67ccafda5ef59868fbeff4a6
Request Method: GET
Status Code: 200 OK

However the request for the other manifests was returning 403:

Request URL: https://example.com/hls/5d134afe91b970.80939375/768_432_1000_5d134afe91b970.80939375.m3u8
Request Method: GET
Status Code: 403 Forbidden

Do i need to send (via the player) the same token parameters for all m3u8 as well as ts files ?

Can you please explain to me how the request should work?

Thanks
ANdrew

CloudFront tokens incompatible with vod module remote upstream?

I'm trying to get an experimental setup going in AWS. Currently the configuration consists of:

CloudFront backed by an origin:

EC2 instance
nginx built with:

  • nginx-vod-module
  • nginx-secure-token-module
  • headers-more-nginx-module
    pulling content out of an S3 bucket

This works fine until I try to enable cloudfront URL tokens.

Config with tokens disabled - works fine:

#user  croll;
worker_processes  1;
daemon off;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;
error_log  logs/error.log  debug;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile           on;
    tcp_nopush         on;
    keepalive_timeout  65;
    gzip               on;

    upstream vod_s3 {
        server vod-s3-test.s3-us-west-1.amazonaws.com:80;
        #server localhost:8186;
    }

    server {
        listen       80;
        server_name  localhost;

        location ^~ /__child_request__/ {
            internal;
            vod_child_request;
        }

        location ^~ /public/ {
            vod hls;
            vod_mode remote;
            vod_moov_cache moov_cache 512m;
            vod_secret_key "BigSecretHere$vod_suburi";
            #vod_hls_encryption_method aes-128;
            vod_align_segments_to_key_frames on;
            vod_segment_count_policy last_rounded;
            vod_hls_encryption_method none;
            vod_child_request_path /__child_request__/;
            vod_upstream vod_s3;
            vod_upstream_host_header vod-s3-test.s3-us-west-1.amazonaws.com;
            #gzip_types application/vnd.apple.mpegurl;
            vod_bootstrap_segment_durations 2000;
            vod_segment_duration 5000;
            vod_segments_base_url "http://d22ovrjxux10n8.cloudfront.net:80";

            #TOKEN GENERATION
            #secure_token cloudfront;
            #secure_token_window 7200;
            #secure_token_expires_time 100d;
            #secure_token_query_token_expires_time 1h;
            #secure_token_avoid_cookies on;
            #secure_token_cloudfront_private_key_file "/home/ec2-user/rsa-xxxxxxxxxx.pem";
            #secure_token_cloudfront_key_pair_id "xxxxxxxxxx";

            #more_set_headers 'Access-Control-Allow-Headers: *';
            #more_set_headers 'Access-Control-Expose-Headers: Server,range,Content-Length,Content-Range';
            #more_set_headers 'Access-Control-Allow-Methods: GET, HEAD, OPTIONS';
            #more_set_headers 'Access-Control-Allow-Origin: *';
        }

        location ^~ /status/ {
            vod_mode remote;
            vod_status;
            vod_moov_cache moov_cache 512m;
            vod_secret_key "zzzzzzzzzzzzzzzzzzzzzzz$vod_suburi";
            vod_hls_encryption_method none;
            vod_child_request_path /__child_request__/;
            vod_upstream vod_s3;
            #gzip_types application/vnd.apple.mpegurl;
        }
    }
}

If I try to enable tokens by uncommenting the config under "TOKEN GENERATION" it fails with:

nginx: [emerg] "vod_upstream" directive cannot be loaded in /usr/local/nginx/conf/nginx.conf:88

Indicentally, gzip_types has a similar problem.

Is this due to a basic incompatibility when using the nginx-vod-module as an upstream remote?
Any thoughts on workarounds?

nginx and the modules are all cloned from github and recent (as in a day or two old).

undefined reference to `ngx_secure_token_broadpeak_block'

When building nginx from source I get the following error
undefined reference to `ngx_secure_token_broadpeak_block'

I have the following configure:
./configure --prefix=/usr/local/nginx --add-module=../nginx-vod-module --add-module=../nginx-akamai-token-validate-module --add-module=../nginx-secure-token-module --with-http_ssl_module --with-file-aio --with-threads --with-cc-opt="-O3"

all pulling latest via clone from github for each module. Fails on make with the complete error:

cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O3 -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs
-o objs/ngx_modules.o
objs/ngx_modules.c
cc -o objs/nginx
objs/src/core/nginx.o
objs/src/core/ngx_log.o
objs/src/core/ngx_palloc.o
objs/src/core/ngx_array.o
objs/src/core/ngx_list.o
objs/src/core/ngx_hash.o
objs/src/core/ngx_buf.o
objs/src/core/ngx_queue.o
objs/src/core/ngx_output_chain.o
objs/src/core/ngx_string.o
objs/src/core/ngx_parse.o
objs/src/core/ngx_parse_time.o
objs/src/core/ngx_inet.o
objs/src/core/ngx_file.o
objs/src/core/ngx_crc32.o
objs/src/core/ngx_murmurhash.o
objs/src/core/ngx_md5.o
objs/src/core/ngx_sha1.o
objs/src/core/ngx_rbtree.o
objs/src/core/ngx_radix_tree.o
objs/src/core/ngx_slab.o
objs/src/core/ngx_times.o
objs/src/core/ngx_shmtx.o
objs/src/core/ngx_connection.o
objs/src/core/ngx_cycle.o
objs/src/core/ngx_spinlock.o
objs/src/core/ngx_rwlock.o
objs/src/core/ngx_cpuinfo.o
objs/src/core/ngx_conf_file.o
objs/src/core/ngx_module.o
objs/src/core/ngx_resolver.o
objs/src/core/ngx_open_file_cache.o
objs/src/core/ngx_crypt.o
objs/src/core/ngx_proxy_protocol.o
objs/src/core/ngx_syslog.o
objs/src/event/ngx_event.o
objs/src/event/ngx_event_timer.o
objs/src/event/ngx_event_posted.o
objs/src/event/ngx_event_accept.o
objs/src/event/ngx_event_udp.o
objs/src/event/ngx_event_connect.o
objs/src/event/ngx_event_pipe.o
objs/src/os/unix/ngx_time.o
objs/src/os/unix/ngx_errno.o
objs/src/os/unix/ngx_alloc.o
objs/src/os/unix/ngx_files.o
objs/src/os/unix/ngx_socket.o
objs/src/os/unix/ngx_recv.o
objs/src/os/unix/ngx_readv_chain.o
objs/src/os/unix/ngx_udp_recv.o
objs/src/os/unix/ngx_send.o
objs/src/os/unix/ngx_writev_chain.o
objs/src/os/unix/ngx_udp_send.o
objs/src/os/unix/ngx_udp_sendmsg_chain.o
objs/src/os/unix/ngx_channel.o
objs/src/os/unix/ngx_shmem.o
objs/src/os/unix/ngx_process.o
objs/src/os/unix/ngx_daemon.o
objs/src/os/unix/ngx_setaffinity.o
objs/src/os/unix/ngx_setproctitle.o
objs/src/os/unix/ngx_posix_init.o
objs/src/os/unix/ngx_user.o
objs/src/os/unix/ngx_dlopen.o
objs/src/os/unix/ngx_process_cycle.o
objs/src/os/unix/ngx_linux_init.o
objs/src/event/modules/ngx_epoll_module.o
objs/src/os/unix/ngx_linux_sendfile_chain.o
objs/src/os/unix/ngx_linux_aio_read.o
objs/src/core/ngx_thread_pool.o
objs/src/os/unix/ngx_thread_cond.o
objs/src/os/unix/ngx_thread_mutex.o
objs/src/os/unix/ngx_thread_id.o
objs/src/event/ngx_event_openssl.o
objs/src/event/ngx_event_openssl_stapling.o
objs/src/core/ngx_regex.o
objs/src/http/ngx_http.o
objs/src/http/ngx_http_core_module.o
objs/src/http/ngx_http_special_response.o
objs/src/http/ngx_http_request.o
objs/src/http/ngx_http_parse.o
objs/src/http/modules/ngx_http_log_module.o
objs/src/http/ngx_http_request_body.o
objs/src/http/ngx_http_variables.o
objs/src/http/ngx_http_script.o
objs/src/http/ngx_http_upstream.o
objs/src/http/ngx_http_upstream_round_robin.o
objs/src/http/ngx_http_file_cache.o
objs/src/http/ngx_http_write_filter_module.o
objs/src/http/ngx_http_header_filter_module.o
objs/src/http/modules/ngx_http_chunked_filter_module.o
objs/src/http/modules/ngx_http_range_filter_module.o
objs/src/http/modules/ngx_http_gzip_filter_module.o
objs/src/http/ngx_http_postpone_filter_module.o
objs/src/http/modules/ngx_http_ssi_filter_module.o
objs/src/http/modules/ngx_http_charset_filter_module.o
objs/src/http/modules/ngx_http_userid_filter_module.o
objs/src/http/modules/ngx_http_headers_filter_module.o
objs/src/http/ngx_http_copy_filter_module.o
objs/src/http/modules/ngx_http_not_modified_filter_module.o
objs/src/http/modules/ngx_http_static_module.o
objs/src/http/modules/ngx_http_autoindex_module.o
objs/src/http/modules/ngx_http_index_module.o
objs/src/http/modules/ngx_http_mirror_module.o
objs/src/http/modules/ngx_http_try_files_module.o
objs/src/http/modules/ngx_http_auth_basic_module.o
objs/src/http/modules/ngx_http_access_module.o
objs/src/http/modules/ngx_http_limit_conn_module.o
objs/src/http/modules/ngx_http_limit_req_module.o
objs/src/http/modules/ngx_http_geo_module.o
objs/src/http/modules/ngx_http_map_module.o
objs/src/http/modules/ngx_http_split_clients_module.o
objs/src/http/modules/ngx_http_referer_module.o
objs/src/http/modules/ngx_http_rewrite_module.o
objs/src/http/modules/ngx_http_ssl_module.o
objs/src/http/modules/ngx_http_proxy_module.o
objs/src/http/modules/ngx_http_fastcgi_module.o
objs/src/http/modules/ngx_http_uwsgi_module.o
objs/src/http/modules/ngx_http_scgi_module.o
objs/src/http/modules/ngx_http_memcached_module.o
objs/src/http/modules/ngx_http_empty_gif_module.o
objs/src/http/modules/ngx_http_browser_module.o
objs/src/http/modules/ngx_http_upstream_hash_module.o
objs/src/http/modules/ngx_http_upstream_ip_hash_module.o
objs/src/http/modules/ngx_http_upstream_least_conn_module.o
objs/src/http/modules/ngx_http_upstream_random_module.o
objs/src/http/modules/ngx_http_upstream_keepalive_module.o
objs/src/http/modules/ngx_http_upstream_zone_module.o
objs/addon/dash/edash_packager.o
objs/addon/hls/aes_cbc_encrypt.o
objs/addon/hls/eac3_encrypt_filter.o
objs/addon/hls/frame_encrypt_filter.o
objs/addon/hls/sample_aes_avc_filter.o
objs/addon/mp4/mp4_aes_ctr.o
objs/addon/mp4/mp4_cbcs_encrypt.o
objs/addon/mp4/mp4_cenc_decrypt.o
objs/addon/mp4/mp4_cenc_encrypt.o
objs/addon/mp4/mp4_cenc_passthrough.o
objs/addon/mss/mss_playready.o
objs/addon/nginx-vod-module/ngx_http_vod_thumb.o
objs/addon/nginx-vod-module/ngx_http_vod_volume_map.o
objs/addon/filters/audio_decoder.o
objs/addon/filters/audio_encoder.o
objs/addon/filters/volume_map.o
objs/addon/thumb/thumb_grabber.o
objs/addon/nginx-vod-module/ngx_async_open_file_cache.o
objs/addon/nginx-vod-module/ngx_buffer_cache.o
objs/addon/nginx-vod-module/ngx_child_http_request.o
objs/addon/nginx-vod-module/ngx_file_reader.o
objs/addon/nginx-vod-module/ngx_http_vod_conf.o
objs/addon/nginx-vod-module/ngx_http_vod_dash.o
objs/addon/nginx-vod-module/ngx_http_vod_hds.o
objs/addon/nginx-vod-module/ngx_http_vod_hls.o
objs/addon/nginx-vod-module/ngx_http_vod_module.o
objs/addon/nginx-vod-module/ngx_http_vod_mss.o
objs/addon/nginx-vod-module/ngx_http_vod_request_parse.o
objs/addon/nginx-vod-module/ngx_http_vod_status.o
objs/addon/nginx-vod-module/ngx_http_vod_submodule.o
objs/addon/nginx-vod-module/ngx_http_vod_utils.o
objs/addon/nginx-vod-module/ngx_perf_counters.o
objs/addon/vod/avc_parser.o
objs/addon/vod/avc_hevc_parser.o
objs/addon/vod/buffer_pool.o
objs/addon/vod/codec_config.o
objs/addon/vod/common.o
objs/addon/dash/dash_packager.o
objs/addon/vod/dynamic_buffer.o
objs/addon/filters/audio_filter.o
objs/addon/filters/concat_clip.o
objs/addon/filters/dynamic_clip.o
objs/addon/filters/filter.o
objs/addon/filters/gain_filter.o
objs/addon/filters/mix_filter.o
objs/addon/filters/rate_filter.o
objs/addon/hds/hds_amf0_encoder.o
objs/addon/hds/hds_fragment.o
objs/addon/hds/hds_manifest.o
objs/addon/vod/hevc_parser.o
objs/addon/hls/adts_encoder_filter.o
objs/addon/hls/buffer_filter.o
objs/addon/hls/frame_joiner_filter.o
objs/addon/hls/hls_muxer.o
objs/addon/hls/id3_encoder_filter.o
objs/addon/hls/m3u8_builder.o
objs/addon/hls/mp4_to_annexb_filter.o
objs/addon/hls/mpegts_encoder_filter.o
objs/addon/input/silence_generator.o
objs/addon/input/frames_source_cache.o
objs/addon/input/frames_source_memory.o
objs/addon/input/read_cache.o
objs/addon/vod/json_parser.o
objs/addon/vod/language_code.o
objs/addon/vod/manifest_utils.o
objs/addon/vod/media_format.o
objs/addon/vod/media_set_parser.o
objs/addon/mkv/ebml.o
objs/addon/mkv/mkv_builder.o
objs/addon/mkv/mkv_defs.o
objs/addon/mkv/mkv_format.o
objs/addon/mp4/mp4_clipper.o
objs/addon/mp4/mp4_format.o
objs/addon/mp4/mp4_fragment.o
objs/addon/mp4/mp4_init_segment.o
objs/addon/mp4/mp4_muxer.o
objs/addon/mp4/mp4_parser.o
objs/addon/mp4/mp4_parser_base.o
objs/addon/mss/mss_packager.o
objs/addon/subtitle/cap_format.o
objs/addon/subtitle/subtitle_format.o
objs/addon/subtitle/ttml_builder.o
objs/addon/subtitle/webvtt_builder.o
objs/addon/subtitle/webvtt_format.o
objs/addon/vod/parse_utils.o
objs/addon/vod/segmenter.o
objs/addon/vod/udrm.o
objs/addon/vod/write_buffer.o
objs/addon/vod/write_buffer_queue.o
objs/addon/nginx-akamai-token-validate-module/ngx_http_akamai_token_validate_module.o
objs/addon/akamai/ngx_http_secure_token_akamai.o
objs/addon/cdnvideo/ngx_http_secure_token_cdnvideo.o
objs/addon/chinacache/ngx_http_secure_token_chinacache.o
objs/addon/cht/ngx_http_secure_token_cht.o
objs/addon/cloudfront/ngx_http_secure_token_cloudfront.o
objs/addon/iijpta/ngx_http_secure_token_iijpta.o
objs/addon/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.o
objs/addon/nginx-secure-token-module/ngx_http_secure_token_filter_module.o
objs/addon/nginx-secure-token-module/ngx_http_secure_token_m3u8.o
objs/addon/nginx-secure-token-module/ngx_http_secure_token_processor_base.o
objs/addon/nginx-secure-token-module/ngx_http_secure_token_utils.o
objs/addon/nginx-secure-token-module/ngx_http_secure_token_xml.o
objs/ngx_modules.o
-lpthread -lcrypt -lz -lcrypto -lpthread -lavcodec -lavutil -lm -lswscale -lpcre -lssl -lcrypto -lpthread -lz
-Wl,-E
/usr/bin/ld: objs/addon/nginx-secure-token-module/ngx_http_secure_token_filter_module.o:(.data.rel+0x398): undefined reference to `ngx_secure_token_broadpeak_block'
collect2: error: ld returned 1 exit status
make[1]: *** [objs/Makefile:345: objs/nginx] Error 1

Decrypt $args

Hello,
You can make sure that the module decrypts not only $uri, but also arguments $args.
Example:

  location ~* "^/stream/(.*)" {

    secure_token_encrypt_uri on;
    secure_token_encrypt_uri_key 112313123131313123;
    secure_token_encrypt_uri_iv  1231312312331231;
    secure_token_encrypt_uri_part $1;
}

Its work, all fine.

  location ~* "^/stream/" {

    secure_token_encrypt_uri on;
    secure_token_encrypt_uri_key 112313123131313123;
    secure_token_encrypt_uri_iv  1231312312331231;
    secure_token_encrypt_uri_part $arg_somearg;
}

Its didnt work, send error log

ngx_http_secure_token_get_encryted_part: failed to find the encrypted uri part

Can encrypted URL expire?

I did read #55, as this ticket is from 2 years ago and I'm a bit confused about the parameters secure_token_expires_time/secure_token_query_token_expires_time, is this still the case? :)

Thanks for your great work.

Can't find a way to compile it on windows.. maybe you got it ?

Hello,

I'm unable to compile it with rtmp module on Windows.. Mostly because it says that it doesn't found some makefiles .. Just don't get it at all.. :/

I thought that the author might have had it compiled for his own use and might be okay to share it with me ? (through a hosting file service like 1fichier.com or else ?)

I'm kind of tired and sad of failing, maybe you can help me...

Thanks !

MrFrieza..

Token insert twice when 2 servers using secure token module

Hi @erankor,

I am using secure token module in simple case to embed secure token into all url of m3u8 playlist. Configuration is simple like this:

secure_token $args;

In usual set up like this it's ok:

NGINX_GATEWAY(with secure token module) -> VOD_PAKAGER

But when setup gets complicated

NGINX_GATEWAY-2(with secure token module) -> NGINX_GATEWAY-1 (with secure token module) -> VOD_PAKAGER

secure token is inserted twice, because it's already inserted by NGINX_GATEWAY-1

I currently fixed it by search thought all response body, look for "?" in m3u8 response body, if it's found I will return immediately and do nothing. Although it work, but I know you will be able to have better way.

The code is simply like this:

for (cl = in; cl; cl = cl->next) {

			p = cl->buf->pos;

			for (p = cl->buf->pos; p < cl->buf->last; p++) {
				if (*p == '?') {
					ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
								"[NGX_SECURE_TOKEN_MODULE] query string exist, ignore");
					return ngx_http_next_body_filter(r, in);
				}
			}
		}

Other than that, if query string already exist in ts url, secure token failed to insert right query string, for example, ts has uri:

a/ts?abc=1&def=2

and token token=34nbekkdf, in my test secure module will change uri to

a/ts?abc=1&def=2?token=34nbekkdf

which make uri bad.

do you have any idea?

Dynamic IV

Hi,

I'm searching a way to handle dynamic IV with your module.
But, according to nginx error.log (secure_token_encrypt_uri_key" directive invalid hex string), and reading the sources, I understood that it's not possible actually.
Am I right ?

Do you plan to add this feature ?

Here is a configuration example:

        location ~ "^/(?<iv>([^/]+))/(?<key>([^/]+))" {
                secure_token_encrypt_uri        on;
                secure_token_encrypt_uri_key    000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f;
                secure_token_encrypt_uri_iv     $iv;
                secure_token_encrypt_uri_part   $key;
        }

Thanks.

Decrypting URL and the rewriting issue video/flv

I am using the nginx-flv-module and trying to decrypt a URL in a location block, and then rewriting to another location block. I'm not sure the portion of the URL gets decrypted. I am trying to watch a video, and the URL of the video looks like:

https://server/flv/1935/live/123safgfrg456563fdhd
location ~ ^/flv/1935/live/(.*)$ {    

        secure_token_encrypt_uri on;
        secure_token_encrypt_uri_key 174fe5551119cb234d38012effdd6309fffffffffffff10231bbbbaaa1ede431;
        secure_token_encrypt_uri_iv 00000000000000000000000000000000;
        secure_token_query_token_expires_time 10s;
        secure_token_encrypt_uri_part $1;
        secure_token_types video/flv;
        rewrite /flv/1935/live/(.*)$ /flv-live?port=1935&app=live&stream=$1 last;
}  

location /flv-live {  
        ...
}

It should work with those directives. But when I am trying to watch the video, it doesn't play. Am I doing it correctly?

DRM Endpoint stops responding

Hello,

We recently ran various performance tests with DRM Enabled endpoint and noticed that after some period of time the endpoint stops responding. The debug message indicates that the endpoint is failing to access the upstream location where DRM key repo is. While DRM endpoint fails to respond, the non-DRM endpoint continues to respond as planned. The non-DRM endpoint uses AES-128 encryption.

Initially, we ran 1000 concurrent connections and noticed that while the test ran for a short period, the system was responding with DRM endpoint producing proper segments. However, after a while, once we stopped requesting streams, the endpoint stopped responding. I've reloaded the nginx vod and restarted testing with a lower number of concurrent connections, about 200. We ran a test for about 12 hours. The system stopped responding to the requests at all. At this point, I believe there some kind of issue with DRM endpoint, perhaps race condition or memory leak. Keep in mind that non-DRM endpoint is still producing the output, the non-DRM endpoint still uses encryption, but not retrieving licenses/encrypting using licenses. We tested the endpoint that produces licenses and it continues to work well, while the DRM NGINX location via secure token module stopped working.

I hope this makes sense. Please let me know if there is anything else you need to help an understanding of the core of the issue.

Encrypt live stream key in HLS URL

Hello, I am trying to encrypt the stream key in an HLS URL. The stream key is used for publishing a live stream. When I check the Developer Tools in my browser, the HLS URL is showing that stream key, so it needs to be encrypted. I have tried different Nginx configs, but so far I can't get it to work, I get mostly 404's sometimes 400 responses. I'm not sure if the location regex is correct.

This is how my HLS URLs look like:

https://server/hls/abcd1234/index.m3u8
https://server/hls/abcd1234/0.ts (1.ts 2.ts etc..)

I want to encrypt the abcd1234 part of the URL. I encrypt the URL in PHP like this:

$baseUrl = "https://server/hls/";
$streamkey = "abcd1234";
$encrypted = encryptUrl($streamkey);
$url = $baseUrl . $encrypted . "/index.m3u8";

The function encryptUrl is taken from the encryptUrl.php script. And my Nginx config:

location ~ /hls/([a-zA-Z0-9_\-]+)/(.*).(m3u8|ts)$ {
        secure_token_encrypt_uri on;
        secure_token_encrypt_uri_key 174feaa90106cbf66d3a012e44ca6309f2fffffeeffff30101addecca2g7e125;
        secure_token_encrypt_uri_iv 00000000000000000000000000000000;
        secure_token_encrypt_uri_part $1;
        secure_token_types application/vnd.apple.mpegurl video/mp2t;
        
        add_header Cache-Control no-cache;
        add_header 'Access-Control-Allow-Origin' '*' always;
        add_header 'Access-Control-Expose-Headers' 'Content-Length';

        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
        }

        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }

        alias /tmp/hls;
}

What is incorrect in my config? Thanks.

spaces in url gives a problem playing any HLS video.

Hi,
I had another issue earlier and did not understand completely what was happening.
Anyway I now found on why I was so confused.
When having spaces in the url of the video I want to play things get weird:

My configuration:
` location /hls/ {
vod hls;
alias /videos/;

   		#vod_upstream_extra_args "st=$arg_st&e=$arg_e&name=$arg_name";
    		secure_token_types application/vnd.apple.mpegurl application/dash+xml text/xml;
					secure_token $token;
					secure_token_expires_time 100d;
					secure_token_query_token_expires_time 1h;

					if ($arg_token) {
						set $input_token $arg_token;
					}
					akamai_token_validate $input_token;
					akamai_token_validate_key 09903e590dcd4edac8c7b4134356770a;


					add_header Last-Modified "Sun, 19 Nov 2000 08:52:00 GMT";
					add_header Access-Control-Allow-Headers "*";
					add_header Access-Control-Expose-Headers "Server,range,Content-Length,Content-Range";
					add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS";
					add_header Access-Control-Allow-Origin "*";
					expires 100d;

    }   `

when playing a video without spaces in the url things works perfectly. However I have pity enough a lot of videos with spaces in the url and then things go wrong

The m3u8 file is accepted with code 200 but the TS files are getting code 403. so no video play.

I log the URI I and in case of the m3u8 file it is like this:
"/vid/test video spaces.mp4/index.m3u8"
No problem there but the segments are truncated:
"/vid/test"
so error 403.

I tried to replace the spaces for the escape %20 but that is simply not accepted by the module and the player gives me no compatible video found.

If I take out all token checks it works without problems but have no security at all in that case.
I actually also tried the secure link module but experiencing the same problems.

Seems spaces are really a problem for the system when using secure tokens.

compile error

Hi,
I want to compile nginx with module (--add-module=../nginx-secure-token-module) and with the newest origin/master branch an error occured. Last commit (ab0f4c7) 2016-12-10 20:55:06, before it works and I get no error.

I've tested with nginx-1.11.6 and 1.11.7.

../nginx-secure-token-module/cht/ngx_http_secure_token_cht.c: In function 'ngx_secure_token_cht_get_var':
../nginx-secure-token-module/cht/ngx_http_secure_token_cht.c:55:21: error: 'MD5_DIGEST_LENGTH' undeclared (first use in this function)
  u_char md5hash_buf[MD5_DIGEST_LENGTH];
                     ^
../nginx-secure-token-module/cht/ngx_http_secure_token_cht.c:55:21: note: each undeclared identifier is reported only once for each function it appears in
../nginx-secure-token-module/cht/ngx_http_secure_token_cht.c:56:9: error: unused variable 'token_buf' [-Werror=unused-variable]
  u_char token_buf[ngx_base64_encoded_length(MD5_DIGEST_LENGTH)];
         ^
../nginx-secure-token-module/cht/ngx_http_secure_token_cht.c:55:9: error: unused variable 'md5hash_buf' [-Werror=unused-variable]
  u_char md5hash_buf[MD5_DIGEST_LENGTH];
         ^
cc1: all warnings being treated as errors
objs/Makefile:2480: recipe for target 'objs/addon/cht/ngx_http_secure_token_cht.o' failed
make[1]: *** [objs/addon/cht/ngx_http_secure_token_cht.o] Error 1

Thanks for your help!

Dynamic Long Token Expiry Time

Is there a option to use long token expiry time from query params, so that long token expiry time is dynamic instead of default which is 86400 or controlled by "end" directive in module

http://example.com?longttl=3600

secure_token_akamai $live {
key 4044798f7f59bfd433ff72b2c1ccd8fc;
param_name hdnts;
end $arg_longttl;
acl "$secure_token_baseuri*";
}

Configure URI encryption

Hello,

I would like to ask, how can I encrypt the URI. Is enough to just add the following in the config by generating the key and IV?

URI encryption
	location ~ ^/hls/p/\d+/(sp/\d+/)?serveFlavor/entryId/([^/]+)/(.*) {
		vod hls;
		vod_secret_key "password$2";

		secure_token_encrypt_uri on;
		secure_token_encrypt_uri_key 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f;
		secure_token_encrypt_uri_iv 00000000000000000000000000000000;
		secure_token_encrypt_uri_part $3;
		secure_token_types application/vnd.apple.mpegurl;

		add_header Last-Modified "Sun, 19 Nov 2000 08:52:00 GMT";
		expires 100d;
	}

I already have the appropriate modules compiled with Nginx

Thanks
Andrew

Problem with whitespace!

Hi all,

I have problem when my file have whitespace in path, how can i fixed it? Decrypted is ok, but encrypted failed.

Original file path: https://example.com/Cong suat dien/01_360.mp4

Thank in advance.

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:10.000,
https://example.com/EkVN0ppqbSIeojyNRocD-Q suat dien/01_360.mp4/seg-1-v1-a1.ts
#EXTINF:10.000,
https://example.com/EkVN0ppqbSIeojyNRocD-Q suat dien/01_360.mp4/seg-2-v1-a1.ts
#EXTINF:10.000,
https://example.com/EkVN0ppqbSIeojyNRocD-Q suat dien/01_360.mp4/seg-3-v1-a1.ts
#EXTINF:9.755,
https://example.com/EkVN0ppqbSIeojyNRocD-Q suat dien/01_360.mp4/seg-4-v1-a1.ts
#EXT-X-ENDLIST

token contains ? twice when the m3u8 file contains ?

Hi,

We are using the nginx-secure-token-module and it seems to work perfectly when the m3u8 file does not contain any '?' in the ts, but if it contains '?', the '?' is appended twice.

I have attached

  1. nginx.txt
  2. playlist11.txt
  3. playlist12.txt
    nginx.txt
    playlist11.txt
    playlist12.txt

The playlist files should be renamed to m3u8 extension, and placed in "/var/www/html/video/" folder.
nginx.txt should be renamed to nginx.conf.

Thereafter, after starting the server, we hit two urls.

curl -X GET 'http://localhost/video/playlist11.m3u8?__hdnea__=abc'

The above gives output

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:11
#EXTINF:10.343667,
z_video1_cuhunk_0.ts?hdnea=st=1608196639exp=1608283039acl=/*hmac=b0ba41f5206c1965c0e8bf423192230bdd042016becd5640a56097be5d2b62fe
#EXTINF:9.776433,
z_video1_cuhunk_1.ts?hdnea=st=1608196639
exp=1608283039acl=/*hmac=b0ba41f5206c1965c0e8bf423192230bdd042016becd5640a56097be5d2b62fe
#EXTINF:9.976633,
z_video1_cuhunk_2.ts?hdnea=st=1608196639
exp=1608283039
acl=/*~hmac=b0ba41f5206c1965c0e8bf423192230bdd042016becd5640a56097be5d2b62fe
#EXT-X-ENDLIST

The second url
curl -X GET 'http://localhost/video/playlist12.m3u8?__hdnea__=abc'

gives the wrong output, as it appends '?' twice.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:11
#EXTINF:10.343667,
z_video1_cuhunk_0.ts?a=b?hdnea=st=1608196781exp=1608283181acl=/*hmac=d55c2028f8bc4dca8f6e3811349a627f3e4855ffcf6cf44cc67d154ef4160824
#EXTINF:9.776433,
z_video1_cuhunk_1.ts?a=b?hdnea=st=1608196781
exp=1608283181acl=/*hmac=d55c2028f8bc4dca8f6e3811349a627f3e4855ffcf6cf44cc67d154ef4160824
#EXTINF:9.976633,
z_video1_cuhunk_2.ts?a=b?hdnea=st=1608196781
exp=1608283181
acl=/*~hmac=d55c2028f8bc4dca8f6e3811349a627f3e4855ffcf6cf44cc67d154ef4160824
#EXT-X-ENDLIST

It is because the playlist12.m3u8 has ?a=b in it. For simplicity, i have disabled the validation.
Is it a bug or am i doing something wrong here?

There seem to be other issues raised who have raised this, like this and this

unknown directive

akamai_token_validate on;
akamai_token_validate_key 1234;
akamai_token_validate_uri_filename_prefix encryption;
akamai_token_validate_uri_filename_prefix index;

this config opt does't work

[emerg] unknown directive "akamai_token_validate"

It's normal ? I get config example for "Encrypted HLS with token security on the encryption key"

how does possibleto generate valid token ?

Hello , I appreciate to response us promptly . Actually i try to run complete NGINX-Secure-Token module .However i have problem on Token side . I would like o elaborate my problem its nice of you to help me to solve my problem in short time . Indeed I am going to use URI encryption . How does possible to generate valid token to perform function of URI encryption . Now i have problem to parse a module to run : Pls look at below .

http://192.168.249.132:8800/11.mp4?token=4IH6Ycedmlxpb45PivDgEw&expire=1437523198
'Do you think possible to work Nginx-secure-token module with such as this pattern aforementioned?

some ts url with token is not inserted

Hi @erankor ,

Look like the bug this module has, config:

secure_token $args;

Then sometime I had an output m3u8 with some ts url without token:


ams5-n.com-299-v1-a1.ts?token=322424424
#EXTINF:9.000,
ams5-n.com-300-v1-a1.ts?token=322424424
#EXTINF:9.000,
ams5-n.com-301-v1-a1.ts
#EXTINF:9.000,
ams5-n.com-302-v1-a1.ts?token=322424424
#EXTINF:9.000,
.....

openSSL 3 support

openSSL 1.1 is now EOL, though some distro will provide support for security fix for longer, it would be nice to see support for the newer LTS openSSL version.
I know this could be a problem because there's some major performance issue in this new version that could force for a rewrite of some crypto function in the code I think this is a mandatory move for the usuability of this module in the long run.

Some reference if it can help:

I don't know C or I would try to help but I hope this module will be able to move forward with openSSL 3 which is ship in every big recent linux distro (rhel 8, ubuntu 22.04, Amazon Linux 2023...)

rewrite

Hello! I am already use your module.
I had some problems whis rewrite. I am need it for parsing url.

Some code

    location ~* /stream2/.*/(.*) {
        secure_token_encrypt_uri on;
        secure_token_encrypt_uri_key 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f;
        secure_token_encrypt_uri_iv 00000000000000000000000000000000;
        secure_token_encrypt_uri_part $1;

        #rewrite "$uri" /test/ break;

        proxy_pass http://127.0.0.1:81$uri;
    }

Now it proxypass on itself, where i am rewrite

server {
  listen 81;
  #rewrite_log on;
  error_log /var/log/nginx/error.log;
  root /srv/www;
  proxy_buffering off;
  proxy_max_temp_file_size 0;
  try_files $uri $uri/ =404;
  include /etc/nginx/sites-available/php;

  location ~* ^/stream2/ {
        resolver 8.8.8.8 ipv6=off valid=5s;
        rewrite "^/stream2/(.*)/(.*)/index" $2 break;

        proxy_pass https://$2/index?$args;
  }
}

How i can make rewrite on first location whis nginx-secure-token-module?

Unable to compile

#0 25.91 objs/src/http/modules/ngx_http_upstream_zone_module.o \
#0 25.91 objs/ngx_modules.o \
#0 25.91 -lpcre2-8 -lz \
#0 25.91 -Wl,-E
#0 26.03 cc -c -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules \
#0 26.03 	-o objs/addon/akamai/ngx_http_secure_token_akamai.o \
#0 26.03 	/usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c
#0 26.16 /usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c: In function 'ngx_secure_token_akamai_get_var':
#0 26.16 /usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c:150:9: error: 'HMAC_CTX_new' is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
#0 26.16   150 |         hmac = HMAC_CTX_new();
#0 26.16       |         ^~~~
#0 26.16 In file included from /usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c:5:
#0 26.16 /usr/include/openssl/hmac.h:33:33: note: declared here
#0 26.16    33 | OSSL_DEPRECATEDIN_3_0 HMAC_CTX *HMAC_CTX_new(void);
#0 26.16       |                                 ^~~~~~~~~~~~
#0 26.16 /usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c:159:9: error: 'HMAC_Init_ex' is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
#0 26.16   159 |         HMAC_Init_ex(hmac, token->key.data, token->key.len, EVP_sha256(), NULL);
#0 26.16       |         ^~~~~~~~~~~~
#0 26.16 /usr/include/openssl/hmac.h:43:27: note: declared here
#0 26.16    43 | OSSL_DEPRECATEDIN_3_0 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
#0 26.16       |                           ^~~~~~~~~~~~
#0 26.16 /usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c:160:9: error: 'HMAC_Update' is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
#0 26.16   160 |         HMAC_Update(hmac, signed_part.data, signed_part.len);
#0 26.16       |         ^~~~~~~~~~~
#0 26.16 /usr/include/openssl/hmac.h:45:27: note: declared here
#0 26.16    45 | OSSL_DEPRECATEDIN_3_0 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data,
#0 26.16       |                           ^~~~~~~~~~~
#0 26.16 /usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c:161:9: error: 'HMAC_Final' is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
#0 26.16   161 |         HMAC_Final(hmac, hash, &hash_len);
#0 26.16       |         ^~~~~~~~~~
#0 26.16 /usr/include/openssl/hmac.h:47:27: note: declared here
#0 26.16    47 | OSSL_DEPRECATEDIN_3_0 int HMAC_Final(HMAC_CTX *ctx, unsigned char *md,
#0 26.16       |                           ^~~~~~~~~~
#0 26.16 /usr/local/src/nginx-secure-token-module/akamai/ngx_http_secure_token_akamai.c:163:9: error: 'HMAC_CTX_free' is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
#0 26.16   163 |         HMAC_CTX_free(hmac);
#0 26.16       |         ^~~~~~~~~~~~~
#0 26.16 /usr/include/openssl/hmac.h:35:28: note: declared here
#0 26.16    35 | OSSL_DEPRECATEDIN_3_0 void HMAC_CTX_free(HMAC_CTX *ctx);
#0 26.16       |                            ^~~~~~~~~~~~~
#0 26.20 cc1: all warnings being treated as errors
#0 26.21 make[1]: *** [objs/Makefile:1244: objs/addon/akamai/ngx_http_secure_token_akamai.o] Error 1
#0 26.21 make[1]: Leaving directory '/usr/local/src/nginx'
#0 26.21 make: *** [Makefile:10: build] Error 2
------
failed to solve: process "/bin/sh -c cd /usr/local/src     && git clone --depth 1 https://github.com/kaltura/nginx-secure-token-module.git     && MODULEDIR=$(pwd)/nginx-secure-token-module     && cd /usr/local/src/nginx

This works:

CFLAGS=-Wno-error ./configure --with-compat $CONFARGS --add-dynamic-module=$MODULEDIR --with-cc-opt="-O3"

I'm building this inside the nginx-mainline docker (latest).

Thanks!

Nginx 1.17.0 error during compiling

Hello,

I have nginx 1.17.0 and i am trying to compile it with the secure-token-module but i am getting an error.
This is the configure command:
./configure --prefix=/usr/local/etc/nginx --with-cc-opt='-I /usr/local/include' --with-ld-opt='-L /usr/local/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --user=www --group=www --modules-path=/usr/local/libexec/nginx --with-file-aio --http-client-body-temp-path=/var/tmp/nginx/client_body_temp --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp --http-proxy-temp-path=/var/tmp/nginx/proxy_temp --http-scgi-temp-path=/var/tmp/nginx/scgi_temp --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp --http-log-path=/var/log/nginx/access.log --with-http_v2_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-pcre --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module --with-mail_ssl_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-mail=dynamic --with-stream=dynamic --add-module=/tmp/nginx-secure-token-module-master

Configure command has been completed, however make command failed:

/tmp/nginx-secure-token-module-master/iijpta/ngx_http_secure_token_iijpta.c:123:8: error: implicit declaration of function 'htobe64' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        end = htobe64(end);
              ^
/tmp/nginx-secure-token-module-master/iijpta/ngx_http_secure_token_iijpta.c:130:8: error: implicit declaration of function 'htobe32' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        crc = htobe32(crc);
              ^
/tmp/nginx-secure-token-module-master/iijpta/ngx_http_secure_token_iijpta.c:130:8: note: did you mean 'htobe64'?
/tmp/nginx-secure-token-module-master/iijpta/ngx_http_secure_token_iijpta.c:123:8: note: 'htobe64' declared here
        end = htobe64(end);
              ^
2 errors generated.
*** Error code 1

Stop.
make[1]: stopped in /tmp/nginx-1.17.0
*** Error code 1

Stop.
make: stopped in /tmp/nginx-1.17.0

Thank you
Andrew

How to protect forwarding tokens between people?

Hello guys.
Customer in my service can pay for access to private stream (HLS). I need to have one token per one real person. Because now person A can send his token to person B. So only one person will pay for private stream, but stream can be watched by more people with the same token.
Dynamic token is not solution, because person A can make his own app to send token to his friends.

Any solution?

URI encryption doesn't work

I'm using nginx-secure-token-module for uri encryption.
I want to encrypt my uri from root so add the bellow configuration to location "/":
location /
{

	proxy_pass http://192.168.252.3:80;
	proxy_set_header Host	$host;
	secure_token_encrypt_uri on;
	secure_token_encrypt_uri_key 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f;
	secure_token_encrypt_uri_iv 00000000000000000000000000000000;
	secure_token_types text/html;
			
}

but when open my site,by clicking on any uri got response 400 and on got the bellow error on nginx error log :
ngx_http_secure_token_decrypt_uri: ngx_decode_base64url failed -1, client: 192.168.0.100, server: example.com, request: "GET /tmp/ HTTP/1.1", host: "example.com"

MD5_DIGEST_LENGTH not defined

I'm trying to build nginx with nginx-vod-module and nginx-secure-token-module, but get an undefined symbol:

    make -f objs/Makefile
    make[1]: Entering directory `/home/bson/evs-nginx-vod/.build/nginx'
    cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DNDK_SET_VAR  -I src/\

core -I src/event -I src/event/modules -I src/os/unix -I /home/bson/evs-nginx-vod/.build/ngx_devel_kit/objs -I objs/addon/ndk -I /home/bson
/evs-nginx-vod/.build/lua-nginx-module/src/api -I objs -I src/http -I src/http/modules -I /home/bson/evs-nginx-vod/.build/ngx_devel_kit/src
-I /home/bson/evs-nginx-vod/.build/ngx_devel_kit/src -I /home/bson/evs-nginx-vod/.build/ngx_devel_kit/objs -I objs/addon/ndk -I src/mail
-o objs/addon/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.o
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c: In function ‘ngx_http_secure_token_d
ecrypt_uri’:
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c:201: error: ‘MD5_DIGEST_LENGTH’ undec
lared (first use in this function)
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c:201: error: (Each undeclared identifi
er is reported only once
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c:201: error: for each function it appe
ars in.)
cc1: warnings being treated as errors
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c:201: error: unused variable ‘md5hash’
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c: In function ‘ngx_http_secure_token_e
ncrypt_uri’:
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c:321: error: ‘MD5_DIGEST_LENGTH’ undec
lared (first use in this function)
/home/bson/evs-nginx-vod/.build/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.c:321: error: unused variable ‘md5hash’
make[1]: *** [objs/addon/nginx-secure-token-module/ngx_http_secure_token_encrypt_uri.o] Error 1
make[1]: Leaving directory `/home/bson/evs-nginx-vod/.build/nginx'
make: *** [build] Error 2

Looking through nginx, it doesn't define MD5_DIGEST_LENGTH anywhere. In fact, ngx_md5.h uses uchar[16] for the digests. The only place I find it defined on the system is in /usr/include/openssl/md5.h, but this doesn't seem to be anywhere in the include chain.

Here's the nginx configure options (excluding module list):

--with-http_secure_link_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-debug --with-threads

And the complete list of modules:
https://github.com/openresty/headers-more-nginx-module.git
https://github.com/kaltura/nginx-vod-module.git
https://github.com/kaltura/nginx-secure-token-module.git
https://github.com/openresty/lua-nginx-module.git
https://github.com/simpl/ngx_devel_kit.git
ttps://github.com/openresty/set-misc-nginx-module.git

Not all the latest, but nginx and the two kaltura modules are current pulls from master.

It seems either MD5_DIGEST_LENGTH is obsolete and we need to define our own, or it's an undocumented dependency not caught by autoconf.

Uri Encryption for sub path

Hi ,
I have a /mp4/12345/x/y/z/t/test.mp4 path.
12345 is dynamic path , a changeable field . I want to encrypt ( x/y/z/t/testFile.mp4 ) , like

https://www.example.com/mp4/12345/1PxEDJP720nr2xesR2afGoTHbLp8dD3q9HqwVYU4kLw
https://www.example.com/mp4/67383/1PxEDJP720nr2xesR2afGoTHbLp8dD3q9HqwVYU4kLw
https://www.example.com/mp4/40987/1PxEDJP720nr2xesR2afGoTHbLp8dD3q9HqwVYU4kLw

I couldn't solve the regex part, can you support me?
My config file is below,


aws_auth $aws_token {
access_key xxxxxxxxxxxxxxxxxxxxxxx;
secret_key yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy;
service s3;
region eu-west-1;
}

location ~ /mp4_proxy/[^/]+/(.*) {
internal;
proxy_redirect off;
proxy_set_header Referer $host;
proxy_pass http://testbucket-v2.s3.eu-west-1.wasabisys.com/video/data/$1;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Amz-Date $aws_auth_date;
proxy_set_header X-Amz-Content-SHA256 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz;
proxy_set_header Authorization $aws_token;
proxy_hide_header Access-Control-Allow-Headers;
proxy_hide_header Access-Control-Expose-Headers;
proxy_hide_header Access-Control-Allow-Methods;
proxy_hide_header Access-Control-Allow-Origin;

}

location /mp4/ {

secure_token_encrypt_uri_part $1;

vod none;
vod_mode remote;
vod_upstream_location /mp4_proxy;
vod_secret_key "password$2";

secure_token_encrypt_uri on;
secure_token_encrypt_uri_key e7525184f9e5eed52e8d8d1c05ee531faaad368410f06bdd0b40e87263e1eefe;
secure_token_encrypt_uri_iv 4a24416bcd97b1047a397a6726b80655;
secure_token_types application/vnd.apple.mpegurl;

add_header Last-Modified "Sun, 19 Nov 2000 08:52:00 GMT";
add_header Access-Control-Allow-Headers "*";
add_header Access-Control-Expose-Headers "Server,range,Content-Length,Content-Range";
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS";

expires 120s;
add_header Edge-Control "public, max-age=120";
add_header Cache-Control "public, max-age=120";

}


encryption script

/encrypt_url.py https://www.example.com/mp4/12345/ x/y/z/t/test.mp4 e7525184f9e5eed52e8d8d1c05ee531faaad368410f06bdd0b40e87263e1eefe 4a24416bcd97b1047a397a6726b80655

https://www.example.com/mp4/12345/1PxEDJP720nr2xesR2afGoTHbLp8dD3q9HqwVYU4kLw

/encrypt_url.py https://www.example.com/mp4/67383/ x/y/z/t/test.mp4 e7525184f9e5eed52e8d8d1c05ee531faaad368410f06bdd0b40e87263e1eefe 4a24416bcd97b1047a397a6726b80655

https://www.example.com/mp4/67383/1PxEDJP720nr2xesR2afGoTHbLp8dD3q9HqwVYU4kLw

/encrypt_url.py https://www.example.com/mp4/40987/ x/y/z/t/test.mp4 e7525184f9e5eed52e8d8d1c05ee531faaad368410f06bdd0b40e87263e1eefe 4a24416bcd97b1047a397a6726b80655

https://www.example.com/mp4/40987/1PxEDJP720nr2xesR2afGoTHbLp8dD3q9HqwVYU4kLw

can protect index.m3u8 by token?

Hello guys,

I'm using nginx-secure-token-module for token validation via 'secure_token_cloudfront'.
In my environment, I don't actually use CloudFront as my CDN. I'm trying to build a direct access solution for myself.

My config:

        location ~ ^/streaming/tokened/.* {
                        root /data/;

                        # security token
                        secure_token $token;
                        secure_token_types application/vnd.apple.mpegurl;
                        secure_token_expires_time 100d;
                        secure_token_query_token_expires_time 1h;

                        # encrypted hls
                        vod hls;
                        vod_secret_key "mukkaukk$vod_filepath";
                        vod_hls_encryption_method aes-128;

                        add_header Access-Control-Allow-Headers '*';
                        add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
                        add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
                        add_header Access-Control-Allow-Origin '*';

                        expires 100d;
                }

This work perfectly on my player (via: /streaming/tokened/test01.mp4/index.m3u8) and I can see the segment URL inserted signature automatically by secure-token-module in access log.

Here are my questions:

Can I protect "/streaming/tokened/test01.mp4/index.m3u8" by token also?
i know we can protect index.m3u8 by header checking. For complex authentication, I would like to write API to return player with signed token and index.m3u8 URL. Then the player can access index.m3u8 with token validation?

Thank you!

Can't generate a secure token on .mpd request

Hi everyone,

I can't generate a secure token on .mpd request. My configure is:

secure_token_akamai $token {
        key 73656375726aadad5746f6b656e14400809;
        acl "$secure_token_baseuri_comma*";
        param_name hdnds;
}
server {
....
secure_token $token;
secure_token_types application/vnd.apple.mpegurl video/f4m application/dash+xml text/xml;
secure_token_expires_time 100d;
secure_token_query_token_expires_time 24h;
secure_token_uri_filename_prefix index;
secure_token_avoid_cookies on;
secure_token_tokenize_segments on;
...
location / {
root /data/dash-video/;
vod dash;
vod_segment_duration 4000;
vod_bootstrap_segment_durations 3500;
vod_align_segments_to_key_frames on;
vod_dash_manifest_format segmenttemplate;
more_set_headers 'Access-Control-Allow-Headers: *';
more_set_headers 'Access-Control-Expose-Headers: Server,range,Content-Length,Content-Range';
more_set_headers 'Access-Control-Allow-Methods: GET, HEAD, OPTIONS';
more_set_headers 'Access-Control-Allow-Origin: *';
}
}

When I created request to 'http://10.0.0.10/2018/09/05/test.mp4/manifest.mpd' I got a response content .m4s url without token.
Can anybody give me a hint for solving this issue?

token propagation issue

Hi guys!

I am trying to get a local/mapped nginx-vod-module setup to run, pretty much according to your sample given here.

(cleaned) config looks like this

secure_token_akamai $token {
    key 1234;
    acl "$secure_token_baseuri*";
    param_name __hdnea__;
}


server {
    listen 6503;
    listen 6502 ssl;

    server_name  my.domain.com;

    ssl_certificate      ...
    ssl_certificate_key  ...

    vod_segments_base_url http://my.domain.com:1234;
    vod_base_url https://my.domain.com:1235;

    location /hls/ {
        vod_mode mapped;
        alias /var/hls/info/;
        vod hls;

        secure_token $token;
        secure_token_avoid_cookies on;

        secure_token_expires_time 100d;
        secure_token_query_token_expires_time 1h;
        secure_token_types application/vnd.apple.mpegurl;

        secure_token_uri_filename_prefix index;
        secure_token_uri_filename_prefix master;
        secure_token_uri_filename_prefix encryption;

        secure_token_tokenize_segments off;

        akamai_token_validate $arg___hdnea__;
        akamai_token_validate_key 1234;

        akamai_token_validate_uri_filename_prefix encryption;
        akamai_token_validate_uri_filename_prefix index;
        akamai_token_validate_uri_filename_prefix master;


        vod_secret_key "abcd";
        vod_hls_encryption_method aes-128;

        vod_align_segments_to_key_frames on;
        vod_segment_duration 2000;
        vod_live_window_duration 6000;
        vod_max_mapping_response_size 4096;
    }
}

I am trying to serve a stream with adaptive bitrates and multiple languages. A simplified version of my json looks like this

{	"playlistType": "live",
	"segmentBaseTime": 1603022304000,
	"firstClipTime": 1603022304000,
	"expirationTime": 1603042304000,
	"discontinuity": false,
	"durations": [6960000],
	"sequences": [
			{ "clips": [ { "type": "source",
						   "path": "/var/media/1.mp4",
						   "tracks": "v1-a1"
						  } ],
					"language": "ger" },
					
			{ "clips": [ { "type": "source",
						   "path": "/var/media/2.mp4",
						   "tracks": "v1-a2"
						 } ],
					"language": "eng" },

			{ "clips": [ { "type": "source",
						   "path": "/var/media/1.mp4",
						   "tracks": "v1-a1" } ],
					"language": "ger" },
					
			{ "clips": [ { "type": "source",
						   "path": "/var/media/2.mp4",
						   "tracks": "v1-a2" } ],
					"language": "eng" } ] }

Basically, I have one file per bitrate, each with multiple audio tracks. (Talking of it, maybe this confuses the server somehow?)

Requesting the master.m3u8, I retrieve a list of index m3u8s - I dont know all the details of HLS, but I can tell it contains first EXT-X-MEDIA entries pointing to playlists (matching the number of languages I have), and then #EXT-X-STREAM-INF entries - also pointing to playlists (matching the total number of streams).

My last remaining problem seems to be that #EXT-X-MEDIA playlist entries in the master file receive a token, but NOT the #EXT-X-STREAM-INF entries. This results in vlc not working and some Windows Store HLS player just playing audio.

I do not use any names based on vod_multi_uri_suffix - I tried that and it resulted in 404. My current theory is that its rather meant for mpag-dash.

Any help appreciated! If there are any syntax errors in my config files, thats because of my simplifications...

Logging decoded url

Hi all,
I was wondering about logging the decoded url, is there any way to get the decoded url part as a global variable to use in log format.

Any help is appreciated.

Incorrect appending of token with EXT-X-KEY and base64 data

Given a manifest that has these entries:

#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://expressplay_token",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,AAAARnBzc2gBAAAA7e+LqXnWSs6jyCfc1R0h7QAAAAFhYWFhYWFhYWFhYWFhYWFhAAAAEhIQYWFhYWFhYWFhYWFhYWFhYQ==",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",KEYID=0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,KEYFORMATVERSIONS="1"

The second EXT-X-KEY line ends with an equals which causes nginx-secure-token-module to append the token to the end of it creating invalid data.

Looking at the code the state machine seems to look for an = followed by a " to decide when to inject the token. Perhaps it can rather determine whether URI begins with "data:"?

Help with getting secure token module to work with secure_link

Hi, I am trying to get this to work with Nginx's secure_link module because in addition to the encrypted URI's, I want to have expired time and client IP verification.

But I cannot get it to work, this is my config:

location ~ /r/([a-zA-Z0-9_\-]+)/video.mp4$ {  
     rewrite ^/r/([a-zA-Z0-9_\-]+)/video.mp4$ /videos/$1 last;
}

location /videos/ {
     secure_token_encrypt_uri on;
     secure_token_encrypt_uri_key <...mykey...>;
     secure_token_encrypt_uri_iv 0000....s;
     secure_token_types application/vnd.apple.mpegurl;
 
     secure_link $arg_md5;
     secure_link_md5 '$uri test';
     if ($secure_link = "") { 
         return 404;
     }
     if ($secure_link = "0") {
         return 410;
     }
 }

I am always getting the 404 response. How can this be configured? Thanks.

trying to stream his but the segments are not tokenized.

Hi
I try to stream an HLS vod. The generated m3u8 file is correctly read and accepted.
However the segments in that file are not tokenized and give error 403. Been trying to find a solution but probably missing something
The error in access log
[28/Nov/2022:15:18:57 -0500] "GET /hls/brat/dvd/video_mp4/testing.mp4/index.m3u8?token=st=1669666737exp=1669667237hmac=1de505c3822995e60b58ec5f1c0044503e9fcbb235817de39982ba3665cfce28 HTTP/1.1" 200 15938 "https://cdn13.globalkink.com:8443/globalplay_brat.php?x=%27dHfrBclfwNxPTxHPTHwJ_MTtjwYg0Lj7NKHhnzFH920%27" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
[28/Nov/2022:15:18:58 -0500] "GET /hls/brat/dvd/video_mp4/testing.mp4/segment-1-v1-a1.ts HTTP/1.1" 403 186 "https://cdn13.globalkink.com:8443/globalplay_brat.php?x=%27dHfrBclfwNxPTxHPTHwJ_MTtjwYg0Lj7NKHhnzFH920%27" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"

my config in nginx

			location /hls/ {
				vod hls;
				alias /videos/;
				
				akamai_token_validate $test_token;
				akamai_token_validate_key 09903e590dcd4edac8c7b4134356770a;		
				akamai_token_validate_uri_filename_prefix encryption;
				akamai_token_validate_uri_filename_prefix index;		
							
				secure_token $secure_token;
				secure_token_content_type_m3u8 application/x-mpegURL;
				secure_token_types text/xml application/vnd.apple.mpegurl application/x-mpegURL;
				secure_token_expires_time 100d;
				secure_token_query_token_expires_time 1h;
		 					
				add_header Access-Control-Allow-Headers '*';
				add_header Access-Control-Allow-Origin '*';
				add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';

				add_header Access-Control-Expose-Headers: 'Server,range,Content-Length,Content-Range';

			}

What am I missing , why is the token not on the segment files

how to add expires/max-age to cookie instead of setting it at Expires/Cache-control header.

Hi,

We are the module nginx-secure-token-module and generating the CDN tokens as cookies.
However, the cookie set does not have any expires or max-age set, and browser interprets it as a session cookie.

Below is the header generated by the module.

Set-Cookie: hdnea=st=1614781275exp=1614867675acl=/*~hmac=c1234f5a6efb7b890ae10d3f45678ce90cc1b2345c6c3fc7bb89ebe01e23456c

We are looking for something so that we can change the Expires/Max-age in the cookie, like

Set-Cookie: hdnea=st=1614781275exp=1614867675acl=/*~hmac=c1234f5a6efb7b890ae10d3f45678ce90cc1b2345c6c3fc7bb89ebe01e23456c; max-age=3600; expires=1614867675

It seems 'secure_token_cookie_token_expires_time' is used for Expires and Cache-Control HTTP headers.

Is there some parameter to add expires/max-age to the cookie header as above instead of setting it at the Expires header level?

Can anyone help in this plz?

Thanks
Tuco

SAMPLE-AES and #EXT-X-KEY

Hello,

We have discovered that when using the Secure Token Module in combination with DRM system for SAMPLE-AES encryption, the generated output contained within #EXT-X-KEY, is prepending policy information, which complicates key retrieval.

The expected output in sub-variant should look like the following:

#EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://drmserver?assetId=014bkssd9amw9yy5",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1"

However, when secure token module is turned on for a given HLS location with "secure_token_types application/vnd.apple.mpegurl;" directive, it has appended details that are not necessary within the uri of

#EXT-X-KEY:
skd://drmserver?assetId=014bkssd9amw9yy5?Policy=<...removed for security...>&Signature=<...removed for security...>&Key-Pair-Id=<... removed for security...>

(Note: I removed sensitive information for security purposes).

Please note that

?Policy=<...removed for security...>&Signature=<...removed for security...>&Key-Pair-Id=<... removed for security...>`

is added to the URI.

We could modify the https://github.com/kaltura/nginx-secure-token-module/blob/master/ngx_http_secure_token_m3u8.c to handle SAMPLE-AES method without adding

?Policy=<...removed for security...>&Signature=<...removed for security...>&Key-Pair-Id=<... removed for security...>

detail, however, if you are able to do so then I would appreciate that very much.

When a secure token module is set to None within a 'location', the output for uri within #EXT-X-KEY does not prepend the

?Policy=<...removed for security...>&Signature=<...removed for security...>&Key-Pair-Id=<... removed for security...>

However, when secure token module is set to secure_token_types application/vnd.apple.mpegurl;, then the
?Policy=<...removed for security...>&Signature=<...removed for security...>&Key-Pair-Id=<... removed for security...> is added across all urls and there is no way to exclude propagation to #EXT-X-KEY section.
I cannot classify this as a bug or possible feature to turn it on of off, however, it definitely is not necessary for #EXT-X-KEY section uri attribute.

remote mode

Hello! I am want use remote mode in nginx-vod-stream, but encrypt url didnt work property. In master.m3u8 file links is unencrypt.

upstream hls {
  server 127.0.0.1:82;
}

server {
  # vod settings
  vod_mode remote;
  vod_upstream_location /hls;
  vod_last_modified 'Sun, 19 Nov 2000 08:52:00 GMT';
  vod_last_modified_types *;

  location ^~ /hls/ {
    internal;
    proxy_pass http://hls/;
    proxy_set_header Host $http_host;
  }

location ~* "^/stream/videoid/(.*)/" {

    secure_token_encrypt_uri on;
    secure_token_encrypt_uri_key 7a653766427466265a7933335e59646731245450426b264b30456c6735464b79;
    secure_token_encrypt_uri_iv  6c7a314532512333557235716f313051;
    secure_token_encrypt_uri_part $1;
    
    vod hls;
}
}

in master.m3u8
https://domain.ltd/stream/VideoID/un_encrypt_path/index-v1-a1.m3u8

Wrong results when used with subs_filter

Hi,

I'm using subs_filters because i need to pass some parameter accross the playlists as received in the URL.
But it seems that the secure token module doesn't take in consideration the changes made by the subs filter and appends the token at the end of the URL using ? rather than &

I think in some way my problem is related to THIS

The relevant configuration in my NGINX is the following:

secure_token_akamai $xxx_token {
                key "XXXXXXXXXXX";
                acl "$secure_token_baseuri_comma*";
                param_name "hdntl";
        }

server {
.....
.....
location / {
subs_filter_types application/vnd.apple.mpegurl;
subs_filter m3u8 m3u8$is_args$args;

secure_token $xxx_token;
secure_token_types application/vnd.apple.mpegurl;
secure_token_expires_time 100d;
secure_token_query_token_expires_time 1h;
}
}

The problem here is that if the client sends a request without parameters everything work fine, eg:

# curl -H "Host: whateverhost" http://123.123.123.123/live/stream/master.m3u8

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2890800,RESOLUTION=1280x720,CODECS="avc1.640029,mp4a.40.2"
media_0.m3u8?hdntl=st=1611224135~exp=1611310535~acl=/live/stream/*~hmac=a39f68bce27e5d62221c2e717e89137d00a1540918075486a1476eec25092d82

#EXT-X-STREAM-INF:BANDWIDTH=1680800,RESOLUTION=1024x576,CODECS="avc1.4d401f,mp4a.40.2"
media_1.m3u8?hdntl=st=1611224135~exp=1611310535~acl=/live/stream/*~hmac=a39f68bce27e5d62221c2e717e89137d00a1540918075486a1476eec25092d82

#EXT-X-STREAM-INF:BANDWIDTH=840400,RESOLUTION=853x480,CODECS="avc1.4d401e,mp4a.40.2"
media_2.m3u8?hdntl=st=1611224135~exp=1611310535~acl=/live/stream/*~hmac=a39f68bce27e5d62221c2e717e89137d00a1540918075486a1476eec25092d82

#EXT-X-STREAM-INF:BANDWIDTH=400400,RESOLUTION=640x360,CODECS="avc1.4d401e,mp4a.40.2"
media_3.m3u8?hdntl=st=1611224135~exp=1611310535~acl=/live/stream/*~hmac=a39f68bce27e5d62221c2e717e89137d00a1540918075486a1476eec25092d82

#EXT-X-STREAM-INF:BANDWIDTH=290400,RESOLUTION=427x240,CODECS="avc1.4d4015,mp4a.40.2"
media_4.m3u8?hdntl=st=1611224135~exp=1611310535~acl=/live/stream/*~hmac=a39f68bce27e5d62221c2e717e89137d00a1540918075486a1476eec25092d82

But if i send a request with a parameter this is the result:

# curl -H "Host: whateverhost" http://123.123.123.123/live/stream/master.m3u8?parameter=23123123123

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=2890800,RESOLUTION=1280x720,CODECS="avc1.640029,mp4a.40.2"
media_0.m3u8?parameter=23123123123?hdntl=st=1611224262~exp=1611310662~acl=/live/rstream/*~hmac=c006c7865d41c6556a44c9ff9122a1f347107de7544452c8300ad5676c7c31ea

#EXT-X-STREAM-INF:BANDWIDTH=1680800,RESOLUTION=1024x576,CODECS="avc1.4d401f,mp4a.40.2"
media_1.m3u8?parameter=23123123123?hdntl=st=1611224262~exp=1611310662~acl=/live/stream/*~hmac=c006c7865d41c6556a44c9ff9122a1f347107de7544452c8300ad5676c7c31ea

#EXT-X-STREAM-INF:BANDWIDTH=840400,RESOLUTION=853x480,CODECS="avc1.4d401e,mp4a.40.2"
media_2.m3u8?parameter=23123123123?hdntl=st=1611224262~exp=1611310662~acl=/live/stream/*~hmac=c006c7865d41c6556a44c9ff9122a1f347107de7544452c8300ad5676c7c31ea

#EXT-X-STREAM-INF:BANDWIDTH=400400,RESOLUTION=640x360,CODECS="avc1.4d401e,mp4a.40.2"
media_3.m3u8?parameter=23123123123?hdntl=st=1611224262~exp=1611310662~acl=/live/stream/*~hmac=c006c7865d41c6556a44c9ff9122a1f347107de7544452c8300ad5676c7c31ea

#EXT-X-STREAM-INF:BANDWIDTH=290400,RESOLUTION=427x240,CODECS="avc1.4d4015,mp4a.40.2"
media_4.m3u8?parameter=23123123123?hdntl=st=1611224262~exp=1611310662~acl=/live/stream/*~hmac=c006c7865d41c6556a44c9ff9122a1f347107de7544452c8300ad5676c7c31ea

As you can see the url contains 2 x ? while i would expect the token to be preceded by a &

Unfortunately i didn't find any way to change this behavior, neither the possibility to insert the token before the other arguments.

Anyone can help please?

Alex

SKIP token in EXT-X-KEY URI

Is there option to not add hmac token in query parameter of EXT-X-KEY URI .
This is creating problem by sending request of AES Key with each and very chunk , even though key rotation is set to 10 min,

Is there directive to not add hmac token with AES Key URL in manifest file

URI encryption with akamai token

Dear sir,
Can you give an example of combining URI encryption with token security?
When I combine these two configs, nginx gives me a urldecoder error.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.