This documentation provides a comprehensive overview of the SMS Verification Processor, a high-performance middleware designed to route and secure SMS-based data flows.
The SMS Verification Processor is a Kafka-driven microservice responsible for securely processing incoming SMS messages and forwarding them to service-specific APIs based on detected keywords. It ensures message integrity and authenticity through HMAC-SHA512 Authorization headers.
<KEYWORD> and <ENCRYPTED_PAYLOAD>.Messages arrive in Kafka with the following structure:
Raw SMS Body:
SERVICE1 zkwaA2SDGRUxVuERKJiG/qmpzTbcHNENEBD3RGTS9cU=
Kafka JSON Object:
JSON
{
"mobileNumber": "09171234567",
"message": "SERVICE1 zkwaA2SDGRUxVuERKJiG/qmpzTbcHNENEBD3RGTS9cU=",
"receivedDate": "2025-01-15 16:46:21",
"traceId": "169878025",
"shortCode": "37888"
}
The processor strips the keyword and forwards the following to the downstream API:
JSON
{
"mobileNumber": "09171234567",
"keyword": "SERVICE1",
"message": "zkwaA2SDGRUxVuERKJiG/qmpzTbcHNENEBD3RGTS9cU=",
"traceId": "169878025"
}
The service uses a custom HMAC scheme:
Authorization: HmacSHA512 ::
To validate a request, the digest must be calculated using the following logic:
String Construction: Concatenate using a space ( ) as a delimiter.
" " + apiKey + " " + nonce + " " + payloadJson + " "
Hashing:
$$digest = Base64(HMAC_SHA512(digestString, apiSecret))$$
JavaScript
import axios from "axios";
import { createHmac } from "crypto";
const getDigest = (apiKey, apiSecret, nonce, payload) => {
const delimiter = " ";
const digestString = `${delimiter}${apiKey}${delimiter}${nonce}${delimiter}${payload}${delimiter}`;
return createHmac("sha512", apiSecret)
.update(digestString)
.digest("base64");
};
const getAuthorizationHeader = (apiKey, apiSecret, payload) => {
const nonce = Date.now().toString();
const digest = getDigest(apiKey, apiSecret, nonce, JSON.stringify(payload));
return `HmacSHA512 ${apiKey}:${nonce}:${digest}`;
};
| Variable | Description |
|---|---|
KAFKA_BROKERS | List of Kafka brokers (e.g., localhost:9092) |
KAFKA_CONSUME_TOPIC | Inbound SMS topic |
KAFKA_ERROR_TOPIC | Topic for failed processing attempts |
SERVICE1_API_URL | Destination for SERVICE1 keyword |
SERVICE1_API_KEY | API Key for HMAC generation |
Deploy the processor using the following command:
Bash
docker run --network=prod_network \
-e KAFKA_BROKERS=kafka:9092 \
-e KAFKA_CONSUME_TOPIC=sms-inbound \
-e KAFKA_ERROR_TOPIC=sms-error-log \
-e SERVICE1_API_URL=http://api.service.com/v1/verify \
-e SERVICE1_API_KEY=your-api-key \
-e SERVICE1_API_SECRET=your-api-secret \
sms-verification-processor:latest
If a message cannot be processed, it is routed to the KAFKA_ERROR_TOPIC with one of the following schemas:
Content type
Image
Digest
sha256:0d30c8723…
Size
50 MB
Last updated
over 1 year ago
docker pull anavpdel/sms-verification-processor