ApsaraDB for MongoDB performs identity authentication on each access request. Therefore, both the HTTP request and HTTPS request must contain signature information. ApsaraDB for MongoDB performs symmetric encryption to verify the request sender by using Access Key ID and Access Key Secret. The Access Key ID and Access Key Secret are officially issued to visitors by Alibaba Cloud (visitors can apply for and manage them at Alibaba Cloud’s official website). The Access Key ID indicates the identity of the visitor. The Access Key Secret is the secret key used to encrypt and verify the signature string on the server. It must be kept confidential and only be available to Alibaba Cloud and the user. The following method is used to sign the access request:
Use request parameters to construct a canonicalized query string.
The request parameters are ordered alphabetically by the parameter names (this includes the “public request parameters” and custom parameters for the given request interfaces described in this document, but not the Signature parameter mentioned in “public request parameters”).
Note: When a request is submitted using the GET method, the request parameters are the same as those included in the parameter section of the request URI. That is, the section of the URI following the question mark (?) and connected by the and sign (&).
The name and value of each request parameter are encoded. URL encoding using the UTF-8 character set is required. URL encoding rules are as follows:
a. Upper case letters from A to Z, lowercase letters from a to z, integers from 0 to 9, and other characters including the en dashes (-), underlines (_), periods (.), and tildes (~) are not encoded.
b. Other characters are encoded in
%XYformat, with XY representing the characters’ ASCII code in hexadecimal notation. For example, double quotation marks (“) are encoded as %22.
c. Extended UTF-8 characters are encoded in
%XY%ZA…format.iv. It must be noted that an English space ( ) is encoded as %20, rather than the plus sign (+).
NOTE: Generally, libraries that support URL encoding (for example, java.net.URLEncoder of Java) are all encoded according to the rules for the “application/x-www-form-urlencoded” MIME-type. You can use this encoding method directly by replacing the plus sign (+) with %20 and the asterisk (*) with %2A in the encoded string, and change %7E back to the tilde (~) to conform to the preceding encoding rules.
Connect the encoded parameter names and values with the equal sign (=).
Then, sort the parameter name and value pairs connected by equal signs in alphabetical order, and connect them with the & symbol to produce the Canonicalized Query String.
Use the canonicalized query string to construct the string for signature calculation according to the following rules:
HTTPMethod + “&” +
percentEncode(“/”) + ”&” +
Here, HTTPMethod is the HTTP method used for request submission. For example, GET. percentEncode(“/“) is the coded value for the character
/according to the URL encoding rules described in 1.b, namely,
%2F. The percentEncode(CanonicalizedQueryString) is the Canonicalized Query String (constructed in Step 1) that is encoded according to the URL encoding rules described in 1.b.
According to RFC2104 definitions, use the preceding signature string to calculate the signature’s HMAC value.
NOTE: When calculating the signature, the Key is your Access Key Secret appended with the and sign (&) (ASCII:38). The SHA1 hashing algorithm is used.
According to Base64 encoding rules, encode the preceding HMAC value into a string to obtain the signature value.
Add the obtained signature value as the
Signatureparameter to the request parameters to complete the request signing process.
Note: When the obtained signature value is submitted to the ApsaraDB for RDS server as the final request parameter value, the value is URL encoded like other parameters according to RFC3986 rules. DescribeDBInstances is used as an example. The request URL prior to signing is as follows:
The StringToSign is:
Assume that the Access Key ID parameter value is testid, the Access Key Secret parameter value is testsecret, the key used for HMAC calculation is
testsecret&and the calculated signature value is:
The signed request URL is (with the Signature parameter added):