Using signatures
Overview
The data communication between the merchant web service and the ecommpay payment platform is protected by using the TLS protocol version 1.2 or later. This ensures the confidentiality of the data being transmitted, though the protocol cannot guarantee the message integrity and ensure that the message author possesses the secret key. Therefore, every message must be digitally signed by using the secret key issued by ecommpay for the merchant and known only to the merchant and the ecommpay payment platform.
Regardless of the interface that is used for working with the payment platform, digital signatures should be included in all requests, callbacks (for the requests processed within the asynchronous interaction model), and certain responses (for the requests processed within the synchronous interaction model). The responses that do not include signatures are usually the ones that contain only auxiliary information (for example, the response stating that the request has been declined due to the incorrect data) or general information without the payment or customer details (for example, the response containing the list of available banks). In other cases, signatures are included in the responses.
Thus, before you submit a request to the ecommpay payment platform, a digital signature should be generated and included in the request; after the callbacks and responses that contain signatures have been received from the payment platform, it is necessary to verify the received data by comparing the signatures to the ones generated on the merchant side. To implement the digital signature generation and verification, you can use either your own solutions or the SDK available from ecommpay. (For more information about the SDK, see Integration using SDK). The data integrity can be compromised for various reasons, but whenever such cases are detected, this data should not be considered valid.
This section describes the algorithms for the digital signature generation and the data integrity verification, including examples with the use of these algorithms and interactive forms for testing the workflows using signatures.
Signature generation
Signing algorithm
The algorithm input includes the following:
- Data to sign.
Generally, this is request body in JSON format without the
signature
parameter. - Signing key.Note: When using the Data API, you need to use the keys and tokens obtained through the Dashboard interface. (For details, see Data access model.)
For the purposes of debugging and testing your signing algorithm implementation, you are free to use any signing key. For signing requests in production environment, you are required to use your production secret key.
Depending on the algorithm implementation, its output may be either signature or signed data. Generally, the algorithm output consists of request body in JSON format with integrated signature
parameter.
The algorithm description, the example, and test form below include the most common algorithm implementation that includes request body in JSON format both as input (without the signature
parameter) and output (with the signature
parameter).
Thus, the algorithm includes the following steps:
-
Input validation Make sure the following requirements are met:
- Data conforms to the JSON format.
- Data to sign does not contain any
signature
parameter even if it is empty. - The signing key is readily available.
-
Conversion of all the strings to UTF-8 with parameters sorted in natural order. Complete the following steps:
- Encode any Boolean values as follows: replace
false
with0
, replacetrue
with1
. Mind that this rule applies only to Boolean values. If any string parameter contains"false"
or"true"
string value, the value is not replaced with0
or1
but is treated as any other string value (for example therecurring: "{type: \"U\",register: true}"
parameter doesn’t require replacingtrue
with1
). -
Convert each parameter into a string that contains the full path to the parameter (with all its parents), parameter name, and parameter value:
<parent_1>:...:<parent_n>:<parameter_name>:<parameter_value>
where parents are the object(s) and/or arrays in which the parameter is contained. Parents are ordered by embedding level starting with the topmost one. The parent names, parameter name, and parameter value are delimited by colon (:); delete any commas between “key-value” pairs and any quotation marks that delimit string values.
- Leave any empty parameter values empty. In other words, do not replace any empty values with blank space or
null
. For instance,"payment_description":""
is replaced withpayment_description:
. - Convert all the strings to UTF-8.
- Sort the strings in natural sort order and join them in a single string by using semicolon (;) as a delimiter.
- Encode any Boolean values as follows: replace
- Calculation of HMAC code by using the key and the SHA-512 hash function. Calculate the HMAC code for the string by using the SHA-512 hash function and secret key. The HMAC code must be calculated as a raw binary data.
- Encoding the HMAC code by using the Base64 scheme. Encoding the HMAC code by using the Base64 scheme to obtain the signature for the initial data.
- Adding signature. Add the
signature
parameter to the request body using the signature from the previous step as its value.
Example of data request through Data API
Suppose that you need to generate a signature for a Dashboard request in the following scenario:
- Signing key :
secret
. - Preliminary request body version where the value for the
signature
is missing:{ "token": "WKiarERJ5pcceNerpM9R5TNnyPTQMl", "interval": { "from": "2020-01-01 14:53:55", "to": "2020-01-30 13:53:59" }, "project_id": [ 183 ], "limit": 3, "offset": 0, "tz": "Asia/Singapore", "signature": "<signature that needs to be generated>" }
The task is to generate the signature; in other words, you need to compute the value for the signature
parameter and add it in the request. Complete the following steps:
- Make sure there is no
signature
parameter in your request even it is empty:{ "token": "WKiarERJ5pcceNerpM9R5TNnyPTQMl", "interval": { "from": "2020-01-01 14:53:55", "to": "2020-01-30 13:53:59" }, "project_id": [ 183 ], "limit": 3, "offset": 0, "tz": "Asia/Singapore", "signature": "<signature that needs to be generated>" }
- Convert all the strings to UTF-8 as per algorithm description:
token:WKiarERJ5pcceNerpM9R5TNnyPTQMl interval:from:2020-01-01 14:53:55 interval:to:2020-01-30 13:53:59 project_id:0:183 limit:3 offset:0 tz:Asia/Singapore
- Sort the strings in natural sort order:
interval:from:2020-01-01 14:53:55 interval:to:2020-01-30 13:53:59 limit:3 offset:0 project_id:0:183 token:WKiarERJ5pcceNerpM9R5TNnyPTQMl tz:Asia/Singapore
- Join all the strings in a single string by using semicolon (;) as a delimiter:
interval:from:2020-01-01 14:53:55;interval:to:2020-01-30 13:53:59;limit:3;offset:0;project_id:0:183;token:WKiarERJ5pcceNerpM9R5TNnyPTQMl;tz:Asia/Singapore
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
Ini3aKje6aZskajTuRS761YOzVqierlVRafZdxIz48wmVnL7yxgy9vDsp7T2/LGPGHJ/DHoKOgP7VqObJALrUA==
- Add the resulting signature in the request body:
{ "token": "WKiarERJ5pcceNerpM9R5TNnyPTQMl", "interval": { "from": "2020-01-01 14:53:55", "to": "2020-01-30 13:53:59" }, "project_id": [ 183 ], "limit": 3, "offset": 0, "tz": "Asia/Singapore", "signature": "Ini3aKje6aZskajTuRS761YOzVqierlVRafZdxIz48wmVnL7yxgy9vDsp7T2/LGPGHJ/DHoKOgP7VqObJALrUA==" }
Request signature generation form
Signature verification
Verification algorithm
The algorithm input includes the following:
- Signed data to verify.
Generally, this is a response body in JSON format with the
signature
parameter. - Verification key. It must be the same key that was previously used for signing the data to verify.
Depending on the algorithm implementation, its output may be either a generated signature or the information whether the generated signature matches the one included in the response.
The algorithm description, the example, and test form below use the most common algorithm implementation that includes response body in JSON format as input (without the signature
parameter) and output (with the signature
parameter) which is the result of signature verification.
Thus, the algorithm includes the following steps:
-
Input validation Make sure the following requirements are met:
- Data conforms to the JSON format.
- Data to sign contains a
signature
parameter with the signature value. - The signing key is readily available.
- Signature retrieval from the data to verify. Store the value of the
signature
parameter value for further reference and remove the parameter from the input data. - Generating the signature for input data:
- Conversion of all the strings to UTF-8 with parameters sorted in natural order. Complete the following steps:
- Encode any Boolean values as follows: replace
false
with0
, replacetrue
with1
. Mind that this rule applies only to Boolean values. If any string parameter contains"false"
or"true"
string value, the value is not replaced with0
or1
but is treated as any other string value (for example therecurring: "{type: \"U\",register: true}"
parameter doesn’t require replacingtrue
with1
). -
Convert each parameter into a string that contains the full path to the parameter (with all its parents), parameter name, and parameter value:
<parent_1>:...:<parent_n>:<parameter_name>:<parameter_value>
where parents are the object(s) and/or arrays in which the parameter is contained. Parents are ordered by embedding level starting with the topmost one. The parent names, parameter name, and parameter value are delimited by colon (:); delete any commas between “key-value” pairs and any quotation marks that delimit string values.
- Leave any empty parameter values empty. In other words, do not replace any empty values with blank space or
null
. For instance,"payment_description":""
is replaced withpayment_description:
. - Add index numbers to array elements starting with zero, for instance
["alpha", "beta", "gamma"]
is replaced with three strings:0:alpha
,1:beta
, and2:gamma
. - Empty arrays are totally ignored and not included in the string set used to generate the signature.
- Convert all the strings to UTF-8.
- Sort the strings in natural sort order and join them in a single string by using semicolon (;) as a delimiter.
- Encode any Boolean values as follows: replace
- Calculation of HMAC code by using the key and the SHA-512 hash function. Calculate the HMAC code for the string by using the SHA-512 hash function and secret key. The HMAC code must be calculated as a raw binary data.
- Encoding the HMAC code by using the Base64 scheme. Encoding the HMAC code by using the Base64 scheme to obtain the signature for the initial data.
- Conversion of all the strings to UTF-8 with parameters sorted in natural order. Complete the following steps:
- Signature matching Compare the generated signature with the signature stored in step 2. If the signatures match, the data are authentic and its integrity is considered confirmed; otherwise, the data is considered compromised and cannot be used for production purposes.
Example of verifying a response with operations data
Suppose that you need to verify the signature of a response in the following scenario:
- Signing key :
secret
. - The response body contains the following information:
The signature is verified as follows:
- Remove the
signature
parameter and its value from the response:{ "operations": [ { "project_id": "183", "operation_id": "9048253065548", "payment_id": "EP834a-40521580376090593", "operation_type": "cancel", "operation_status": "success", "account_number": "431422******0056", "customer_ip": "192.0.0.255", "payment_method_name": "visa", "payment_method_type": "visa", "payment_description": null, "operation_created_at": "2020-01-30T12:29:03+03:00", "operation_completed_at": "2020-01-30T12:29:04+03:00", "provider_date": null, "shipment_date": "", "mid": "3416123", "sum_initial": { "amount": 2000, "currency": "EUR" }, "sum_converted": { "amount": 2000, "currency": "EUR" }, "provider_name": "Dashboard Provider Card", "fee_currency": null, "fee_amount": 0, "arn": null, "rrn": null } ], "signature": "EksxDdDygDQ30JKsfK6QSvubpNRSj3wtLI5FzWDJuNY0nEhLXt65Y77dtKMJRcd39NegA7YK1eojA2EB1hIbnQ==" }
- Convert all the parameter string to UTF-8 according to the algorithm description:
operations:0:project_id:183 operations:0:operation_id:9048253065548 operations:0:payment_id:EP834a-40521580376090593 operations:0:operation_type:cancel operations:0:operation_status:success operations:0:account_number:431422******0056 operations:0:customer_ip:192.0.0.255 operations:0:payment_method_name:visa operations:0:payment_method_type:visa operations:0:payment_description: operations:0:operation_created_at:2020-01-30T12:29:03+03:00 operations:0:operation_completed_at:2020-01-30T12:29:04+03:00 operations:0:provider_date: operations:0:shipment_date: operations:0:mid:3416123 operations:0:sum_initial:amount:2000 operations:0:sum_initial:currency:EUR operations:0:sum_converted:currency:EUR operations:0:sum_converted:amount:2000 operations:0:provider_name:Dashboard Provider Card operations:0:fee_currency: operations:0:fee_amount:0 operations:0:arn: operations:0:rrn:
- Sort the strings in natural sort order:
operations:0:account_number:431422******0056 operations:0:arn: operations:0:customer_ip:192.0.0.255 operations:0:fee_amount:0 operations:0:fee_currency: operations:0:mid:3416123 operations:0:operation_completed_at:2020-01-30T12:29:04+03:00 operations:0:operation_created_at:2020-01-30T12:29:03+03:00 operations:0:operation_id:9048253065548 operations:0:operation_status:success operations:0:operation_type:cancel operations:0:payment_description: operations:0:payment_id:EP834a-40521580376090593 operations:0:payment_method_name:visa operations:0:payment_method_type:visa operations:0:project_id:183 operations:0:provider_date: operations:0:provider_name:Dashboard Provider Card operations:0:rrn: operations:0:shipment_date: operations:0:sum_converted:amount:2000 operations:0:sum_converted:currency:EUR operations:0:sum_initial:amount:2000 operations:0:sum_initial:currency:EUR
- Join all the strings in a single string by using semicolon (;) as a delimiter:
operations:0:account_number:431422******0056;operations:0:arn:;operations:0:customer_ip:192.0.0.255;operations:0:fee_amount:0;operations:0:fee_currency:;operations:0:mid:3416123;operations:0:operation_completed_at:2020-01-30T12:29:04+03:00;operations:0:operation_created_at:2020-01-30T12:29:03+03:00;operations:0:operation_id:9048253065548;operations:0:operation_status:success;operations:0:operation_type:cancel;operations:0:payment_description:;operations:0:payment_id:EP834a-40521580376090593;operations:0:payment_method_name:visa;operations:0:payment_method_type:visa;operations:0:project_id:183;operations:0:provider_date:;operations:0:provider_name:Dashboard Provider Card;operations:0:rrn:;operations:0:shipment_date:;operations:0:sum_converted:amount:2000;operations:0:sum_converted:currency:EUR;operations:0:sum_initial:amount:2000;operations:0:sum_initial:currency:EUR
- Calculate the HMAC code for the string by using the SHA-512 hash function and secret key, and then encode the HMAC code by using the Base64 scheme:
orpqWm+Vu7unNcob7h+jHuk+H4/M9rnX7qFZD657nECok8oKD7IkdwGye3Ag10A5zBg1Ck2DrZnvtaptNjaIkw==
- Compare the generated signature and the one included in the response.
In our case, the signatures differ which means that the response is invalid and must be ignored.
Signature verification form