Alibaba Cloud CDN provides the URL signing feature to protect origin servers from unauthorized downloads and access. The URL signing feature supports three signing types. This topic describes how type B signing works.

How it works

  • How a URL is signed based on type B singing
    http://DomainName/timestamp/md5hash/FileName
    Fields in a signed URL
    Field Description
    DomainName The accelerated domain name.
    timestamp The time when a signed URL is generated. The timestamp and the TTL value specify the time when a signed URL expires. The time is in UTC+8 and follows the yyyyMMddHHmm format.
    Note In most cases, the validity period of a signed URL equals the value of the TTL parameter. In some cases, the signing server also assigns a TTL value to a signed URL. Timestamp = UNIX timestamp on the signing server + TTL assigned by the signing server. Validity period of the signed URL = Timestamp + TTL assigned by Alibaba Cloud CDN.
    md5hash The string that is calculated by using the MD5 algorithm. The string must be 32 characters in length, and can contain digits and lowercase letters.
    Filename The actual URL that points to the requested resource on the origin server. The Filename field must start with a forward slash (/).
  • Authentication logic
    When an edge node receives a request, the edge node determines whether the time calculated by adding the timestamp and the TTL value in the request is earlier than the current time.
    • If the time calculated by adding the timestamp and the TTL value in the request is earlier than the current time, the edge node determines that the URL of the request expires and returns a 403 error.
    • If the time calculated by adding the timestamp and the TTL value in the request is later than the current time, a sstring is generated. Then, a md5hash value is generated based on the MD5 algorithm. The generated md5hash value is compared with the md5hash value in the request.
      • If they are the same, the request passes the authentication. The edge node returns the requested resource.
        Note If a request passes the authentication, authentication-specific parameters are removed from the URL to increase the cache hit ratio and reduce back-to-origin traffic.
        • The format of the URL that is used to generate a cache key is http://DomainName/FileName.
        • The format of the URL in the back-to-origin request is http://DomainName/FileName.
      • If they are different, the request fails the authentication. The edge node returns a 403 error.

Examples

The following example shows how to implement type B signing.
  • Sample conditions
    • A user wants to retrieve the following resource from the origin server:
      http://cdn.example.com/4/44/44c0909bcfc20a01afaf256ca99a8b8b.mp3
      Note If the URL of the requested object contains Chinese characters, you must encode the URL before you concatenate a signed URL.
    • The cryptographic key is aliyuncdnexp1234.
    • The time when the signing server generated a signed URL is 201508150800.
  • Concatenation procedure
    1. Alibaba Cloud CDN generates a signature string that is used to calculate the md5hash value.
      aliyuncdnexp1234201508150800/4/44/44c0909bcfc20a01afaf256ca99a8b8b.mp3
    2. Alibaba Cloud CDN calculates the md5hash value based on the signature string.
      md5hash = md5sum("aliyuncdnexp1234201508150800/4/44/44c0909bcfc20a01afaf256ca99a8b8b.mp3") = 9044548ef1527deadafa49a890a377f0
    3. A signed URL is generated.
      http://cdn.example.com/201508150800/9044548ef1527deadafa49a890a377f0/4/44/44c0909bcfc20a01afaf256ca99a8b8b.mp3

If a client uses a signed URL to request a resource, Alibaba Cloud CDN compares the calculated md5hash value with the md5hash value in the request. If they are the same, for example, 9044548ef1527deadafa49a890a377f0, the request passes the authentication. Otherwise, the request fails the authentication.