To prevent malicious downloads and theft of site resources, you can configure a Referer blacklist or whitelist to identify and filter visitors. You can also use URL signing to better protect resources on your origin server. This topic describes the URL signing feature, how the feature works, how to configure the feature, and the usage notes.
Use URL signing
In the ApsaraVideo Live console, you can use the default URL signing settings or configure your custom URL signing settings.
Default authentication: The default authentication type is Type A. For more information, see Live URL generator.
Custom authentication: If you do not want to use the default authentication, you can configure the URL signing settings. For more information, see Configure URL signing.
ImportantYou can configure the primary and secondary keys in the ApsaraVideo Live console. The primary and secondary keys are equally effective. The secondary key is used to ensure a smooth switchover.
If you change the primary key, all generated streaming URLs that use the original primary key immediately become invalid. If you switch from the primary key to the secondary key, the generated streaming URLs that use the original primary key remain valid for a period of time. This ensures a smooth switchover.
You can use code to construct a signed URL.
Construct an unsigned streaming URL based on the AppName and StreamName fields in an ingest URL. Example:
rtmp:/DomainName/AppName/StreamName
.Then, generate a signed streaming URL by using an authentication algorithm in your code. For more information about the authentication algorithm, see Construct a signed URL. For more information about the sample code that is used to generate a signed URL, see URL signing examples.
Construct a signed URL
Signed URLs are supported by third-party stream ingest tools and players on PCs and mobile devices. A signed URL consists of an ingest URL or a streaming URL and an access token
. Example:
rtmp://DomainName/AppName/StreamName?auth_key=timestamp-rand-uid-md5hash
Signed URL | Description |
| The ingest URL or streaming URL. For more information, see Generate ingest and streaming URLs. |
| The access token, which includes the timestamp, rand, uid, and md5hash fields. |
timestamp | The time when the signed URL expires, which is determined by the time when the signed URL is generated and the specified validity period. The value is a UNIX timestamp. Unit: seconds.
|
rand | A random number, which is typically set to 0. If you want to generate a different URL each time, we recommend that you use a UUID as the random number. The value cannot contain hyphens (-). Example: |
uid | An additional parameter, which is not used. It is typically set to 0. |
md5hash | The string that is calculated by using the MD5 algorithm. The string is 32 characters in length and contains digits and lowercase letters.
Note No matter you use the ApsaraVideo Live console to generate a signed URL or use code to construct a signed URL, the |
How URL signing works
After URL signing is enabled, the server verifies a request by performing the following operations:
The server checks whether the timestamp in the request is earlier than the current time.
If the timestamp is earlier than the current time, the server considers that the signed URL expires and returns HTTP status code 403.
If the timestamp is later than the current time, the server constructs a string by using the following sstring formula.
The server uses the MD5 algorithm to calculate the hash value of the string and then compares the hash value with that contained in the request.
If the two values are the same, the authentication is successful. The server returns the live stream.
If the two values are different, the authentication fails. The server returns HTTP status code 403.
The hash value is calculated based on the following formulas:
sstring = "URI-timestamp-rand-uid-PrivateKey"
HashValue = md5sum(sstring)
Example
Assumption:
You request the
rtmp://demo.aliyundoc.com/video/standard****
object by using req_auth.You set the cryptographic key to aliyunliveexp1234, which is the primary key or secondary key configured in the ApsaraVideo Live console.
The time when the signed URL is generated is 16:49:57 on May 28, 2021 (UTC+8).
In the ApsaraVideo Live console, the validity period of the signed URL is set to 40 minutes.
You set both the rand and uid fields to 0.
Result:
The calculated UNIX timestamp of the signed URL is 1622194197, which is 17:29:57 on May 28, 2021 (UTC+8).
The server constructs a signature string that is used to calculate the hash value.
/video/standard-1622194197-0-0-aliyunliveexp1234
The server calculates the hash value based on the signature string.
HashValue = md5sum("/video/standard-1622194197-0-0-aliyunliveexp1234") = 5552ff52b5e4e20387c6dc18afce****
The URL of the request is
rtmp://demo.aliyundoc.com/video/standard****?auth_key=1622194197-0-0-5552ff52b5e4e20387c6dc18afce****
.NoteThe auth_key field indicates the access token that is included in the signed URL.
The calculated hash value is
md5hash = 5552ff52b5e4e20387c6dc18afce****
, which is the same as that contained in the request. In this case, the authentication is successful.
Usage notes
By default, URL signing is enabled. We recommend that you keep this feature enabled to prevent your content from being pirated. If you want to disable URL signing, make sure that you understand the risks of unauthorized use of your resources and agree to the Disclaimer for Disabling URL Signing on the URL Signing page in the ApsaraVideo Live console.
You must manually set the auth_key field. ApsaraVideo Live provides no API operation for calculating the value of the auth_key field.
After you enable URL signing, you must add the auth_key field to the ingest and streaming URLs. Otherwise, live streams cannot be played. You cannot sign only the ingest URL or the streaming URL. You must sign them both.
Signed URLs remain valid before their expiration timestamp. You can access a signed URL anytime before it expires. ApsaraVideo Live does not support one-time signed URLs.
The value of the auth_key field is the MD5 value of the URI without the queryString fields. For more information, see the preceding section about setting URL signing parameters. The URIs of both the ingest and streaming URLs are AppName/StreamName. If the ingest URL is not confidential, we recommend that you set an expiration timestamp as near as possible. This prevents malicious access to the streaming URL.
For ingest and streaming URLs in the Real-Time Messaging Protocol (RTMP), FLV, and Real-Time Streaming (RTS) formats, requests are authenticated only when stream ingest or streaming begins. Ongoing stream ingest or streaming is not interrupted if the signed URL expires during the process.
For streaming URLs in the M3U8 format, requests are authenticated at the beginning of streaming and during streaming. Ongoing streaming is interrupted if the signed URL expires during the process.