We moved this page to our Documentation Portal. You can find the latest updates here. |
Question
How can I use URL Signing (Advanced Settings) For HTTP Pull CDN resource?
Answer
Protect your files from unauthorized access with a key and optionally an expiration time. Enabling this option provides an entry field to enter a secret key to securely sign any direct URI (Uniform Resource Indicator) link to all files/resources under this URL. Upon CDN resource creation/edit, enable "Advanced Settings".
- Enable URL Signing – tick this checkbox to enable it
- URL Signing Key – input the key, which will be used for URL signing
The URL signing key is similar to a password and can contain a minimum of 6 to a maximum of 32 characters.
Below are examples of a signed URL in one of the following formats:
Query string format
http://example.com/filename?secure=DMF1ucDxtqgxwYQ&expires=1546300800&ip=1.2.3.4
Path format
http://example.com/secure=DMF1ucDxtqgxwYQ&expires=1546300800&ip=1.2.3.4/filename
The secure token is formed using the following format:
<expires><path><key><ip>
- <expires> : The expiration of the URL. This is in Unix timestamp format. This is optional.
- <path>: The file path or file directory **note: for HLS, it is better to put path instead of .m3u8 file, so that all the chunk of the hls will be authenticated as well.
- <key>: The URL signing key. Size of the key is between 6 characters to 32 characters.
- <IP>: The IP that allow to access. This is optional and only one IP allowed when generating the hash key each time.
For generating the hash key, kindly download the attached script in Ruby, Python, PHP or Java. You may run it with the following command to generate signed URL:
Ruby: ruby UrlSigning.rb -f path -s https -r example.com -p images/photo.png -k abc123 -e 1546300800 -i 1.2.3.4 Python: python UrlSigning.py -f path -s https -r example.com -p images/photo.png -k abc123 -e 1546300800 -i 1.2.3.4
Python3:
python3 UrlSigning3.py -f path -s https -r example.com -p images/photo.png -k abc123 -e 1546300800 -i 1.2.3.4 PHP: php UrlSigning.php -f path -s https -r example.com -p images/photo.png -k abc123s -e 1546300800 -i 1.2.3.4
Java:
javac UrlSigning.java
java UrlSigning -f path -s https -r example.com -p images/photo.png -k abc123 -e 1546300800 -i 1.2.3.4
Available options:
-f: format, path or querystring, default = querystring
-s: scheme for resource URL, http or https, default = http
-r: resource hostname (compulsory)
-p: file path of the resource, default = /
-k: URL signing key (compulsory)
-e: expiration of the URL (optional)
-i: IP that allow to access (optional)