CTRLK

Shared components

Secure API communications

|

View as Markdown

To secure your API communications, follow the steps for both directions: from Infobip to your application, and from your application to Infobip.

From Infobip to your application

By default, Infobip will post data to your application's CallbackURL and StatusURL without any specific security scheme other than using HTTPS communications, provided your exposed URLs support HTTPS. If you wish to enhance the security of these communications, you can request Infobip to include an Authorization header to every post made toward your CallbackURL and StatusURL.

Here are the steps you need to do to be able to use an Authorization header.

Step 1 Use method to create a new number masking credential

Use the POST/voice/masking/2/credentials method to create a new number masking credential

The method will reply with a 200 OK to confirm both apiID and key values in the response's payload.
A credential composes of two key parts the user generates (apiID and key), both being alphanumerical strings (80 characters max).
Once your credentials are confirmed, any data posted to your application's CallbackURL and StatusURL will have an Authorization header whose value is computed based on your keys.
Note that number masking credentials are not application-specific. If you have multiple number masking configurations, the same apiID and key are used to build the Authorization header's content.

Step 2 Understand the Authorization header's content

Authorization headers generated by Infobip and added to POST requests to your application's CallbackURL and StatusURL are built on the following logic:

http
apiId:hashed(webhookUrl+requestBody+key)

Where:

  • webhookURL is the URL of your Callback or Status webhook
  • requestBody is the body of the message posted to your Callback or Status webhook
  • apiKey is the first part of your number masking credentials
  • key is the second part of your number masking credentials The hashing algorithm is SHA256.

This example uses the CallbackURL https://my.company.server/nmcallback and Infobip sends the following message towards that URL:

Callback body payload
1{
2 "from": "40257076838",
3 "to": "40257879513",
4 "nmCorrelationId": "7cb72e4b-cf9f-40b6-9fc4-79588d18a666",
5 "correlationId": "0f754338-1aff-4e09-a933-7d205ca7aed4"
6}

This example uses the following number masking credentials:

Number masking credentials
1{
2"apiId": "55ddccad2df62a4b615b7e3c472b2ab6",
3"key": "5da086b6a8e4424993646b8699c333ca"
4}

Infobip then adds the Authorization header that is shown as:

Complete string
55ddccad2df62a4b615b7e3c472b2ab6:hashed(https://my.company.server/nmcallback{"from":"40257076838","to":"40257879513","nmCorrelationId":"7cb72e4b-cf9f-40b6-9fc4-79588d18a666","correlationId":"0f754338-1aff-4e09-a933-7d205ca7aed4"}5da086b6a8e4424993646b8699c333ca)

The value of the header is:

Full computed Authorization header
Authorization 55ddccad2df62a4b615b7e3c472b2ab6:66c5985cf14f92e29c5647d4d9c4f12107a17507fe4ecfb3f5d4d2065e3dfab3

Step 3 Status callback particularities

When computing the Authorization header for messages sent to your Status URL, Infobip will purposely omit 3 key value pairs from the message body. The affected keys are:

  • calculatedDuration
  • currency
  • pricePerSecond

If the body of the message received from the statusURL is:

Body of original status message
1{
2 "action": "dial",
3 "from": "41793026727",
4 "to": "41793026731",
5 "transferTo": "41793026785",
6 "duration": "15",
7 "status": "answered",
8 "fileId": null,
9 "fileUrl": null,
10 "nmCorrelationId": "6ag710o6ihb23q06epc23n46ihd0nilcibb0nq9ccbq6mmsdgbp4nghefjs67vgo7200",
11 "inboundDuration": 15,
12 "calculatedDuration": 15,
13 "pricePerSecond": 0.0,
14 "currency": "EUR",
15 "ringingTime": "2018-01-01 12:00:00",
16 "answeredTime": "2018-01-01 12:00:10",
17 "correlationId": "0f754338-1aff-4e09-a933-7d205ca7aed4",
18 "inboundDuration": "30"
19}

What this means is that the Authorization header takes only the following elements into account:

Body payload used for computing the Authorization header
1{
2 "action": "dial",
3 "from": "41793026727",
4 "to": "41793026731",
5 "transferTo": "41793026785",
6 "duration": "15",
7 "status": "answered",
8 "fileId": null,
9 "fileUrl": null,
10 "nmCorrelationId": "6ag710o6ihb23q06epc23n46ihd0nilcibb0nq9ccbq6mmsdgbp4nghefjs67vgo7200",
11 "inboundDuration":15,
12 "ringingTime": "2018-01-01 12:00:00",
13 "answeredTime": "2018-01-01 12:00:10",
14 "correlationId": "0f754338-1aff-4e09-a933-7d205ca7aed4",
15 "inboundDuration": "30"
16}

Step 4 Validating incoming messages to your application's Callback and Status URLs

When you receive a message from Infobip to your Callback or StatusURLs, you need to apply the same logic as explained from Steps 2 and 3 to compute what should be the expected Authorization value and compare it to the one you will receive in the message. If the values match, you can be sure that this message was sent by Infobip and is safe.

NOTE

When concatenating your webhookURL, body and key and before hashing that concatenated string, make sure to strip off any potential new line characters from the body. New lines would not appear when string concatenation and hashing is performed by your application code, but can happen in debugging phase if you copy/paste the body content manually in text editors.

From your application to Infobip

Although not a specific feature in number masking, if you wish to add an extra layer of security to HTTP requests your application sends to Infobip, you can generate a specific API Key that will be limited to predefined IP addresses. The IP address(es) are the fixed address(es) behind your application. On the API Key Management page of the Infobip web interface, you can easily create an API key and assign your IPs:

Was this page helpful?