Cloud Monitor supports only the Hash-based Message Authentication Code (HMAC)-SHA1 digital signature algorithm. This topic describes how to use the HMAC-SHA1 signature algorithm.
Procedure
Prepare an active Alibaba Cloud AccessKey pair.
To generate a signature for an HTTP request, use an AccessKey pair that consists of an AccessKey ID and an AccessKey secret.
NoteYou can use an existing AccessKey pair or create a new one. Ensure the AccessKey pair is active.
Generate the signature string for the request.
The signature string for an HTTP request is generated from its method, headers, and body.
SignString = VERB + "\n" + CONTENT-MD5 + "\n" + CONTENT-TYPE + "\n" + DATE + "\n" + CanonicalizedHeaders + "\n" + CanonicalizedResourceIn the signature string,
\nis a line break escape character and+is the string concatenation operator. The other parts are defined in the following table.Name
Description
Example
VERB
The HTTP request method.
PUT, GET, POST
CONTENT-MD5
The MD5 hash of the request body.
NoteThe MD5 hash must be a string of uppercase letters and digits.
0B9BE351E56C90FED853B32524253E8B
CONTENT-TYPE
The type of the request body.
application/json
DATE
The standard timestamp header in the HTTP request.
NoteThe timestamp must follow the RFC 1123 format and use Greenwich Mean Time (GMT).
Mon, 3 Jan 2010 08:33:47 GMT
CanonicalizedHeaders
A string constructed from custom request headers that start with the
x-cmsorx-acsprefix.x-cms-api-version:0.1.0
x-cms-signature
CanonicalizedResource
A string constructed from the requested resource.
/event/custom/upload
The `CanonicalizedHeaders` and `CanonicalizedResource` strings are constructed as follows:
CanonicalizedHeaders
Convert the names of all HTTP request headers that start with the
x-cmsorx-acsprefix to lowercase.Sort all custom CMS and ACS request headers in ascending lexicographical order.
Remove any spaces from either side of the separator between the request header and the content.
Join the processed headers and their values with the
\nseparator to create the final `CanonicalizedHeaders` string.
CanonicalizedResource
Set `CanonicalizedResource` to an empty string ("").
Add the URI of the resource to `CanonicalizedResource`, such as
/event/custom/upload.If the request includes a query string (
QUERY_STRING), append a?and the query string to the end of the `CanonicalizedResource` string.The
QUERY_STRINGis a string of request parameters from the URI, sorted in lexicographical order. In this string, parameter names and values are separated by an=sign. The parameters are sorted by name in ascending lexicographical order, and then the resulting pairs are concatenated with an&symbol. The formula is as follows:QUERY_STRING = "KEY1=VALUE1" + "&" + "KEY2=VALUE2"
Generate the digital signature for the request.
The formula for the digital signature is as follows:
Signature=base16(hmac-sha1(UTF8-Encoding-Of(SignString), AccessKeySecret))Example signature:
SignString="POST" + "\n" +"0B9BE351E56C90FED853B32524253E8B" + "\n" +"application/json" + "\n" +"Tue, 11 Dec 2018 21:05:51 +0800" + "\n" +"x-cms-api-version:1.0" + "\n" +"x-cms-ip:127.0.0.1" + "\n" +"x-cms-signature:hmac-sha1" + "\n" +"/metric/custom/upload" accesskey="testkey" accessSecret="testsecret" // The signature key.Result:
1DC19ED63F755ACDE203614C8A1157EB1097E922