Skip to main content

Danamon NIK HMAC Validation and Backward-Compatible Rollout

Description

This document describes the backward-compatible rollout of authenticated NIK encryption for the Danamon ECV integration. The implementation supports the existing two-segment message and the new three-segment HMAC-protected message during migration. Invalid or unverifiable NIK values stop the call before a database call record or Genesys interaction is created.

Affected Services

  • AdminApi – validates the message format, HMAC and encrypted payload.
  • ECVDemo – stops call creation when NIK verification fails.
  • Web.App – includes the HMAC test page used for verification.

AdminApp / Web.Admin is not changed by this enhancement.

Message Formats

Legacy Format

<iv_hex>_<ciphertext_hex>

The legacy two-segment format remains available during the migration period when nikHmacRequired is set to false.

Authenticated Format

<iv_hex>_<ciphertext_hex>_<hmac_hex>
  • iv_hex: 16 bytes, represented by 32 hexadecimal characters.
  • ciphertext_hex: AES-256-CBC encrypted payload using the random IV.
  • hmac_hex: HMAC-SHA256 output, represented by 64 hexadecimal characters.

A new random 16-byte IV must be generated by the sending application for every encryption operation. The HMAC input is the raw IV bytes followed by the raw ciphertext bytes: iv || ciphertext. Hex strings and underscore separators are not included in the HMAC input.

Configuration Changes

AdminApi

Add the following settings to the existing Danamon configuration. The existing AES key is unchanged.

danamon: {
    key: "<existing AES key>",
    nikHmacRequired: false,
    nikHmacKey: process.env.DANAMON_NIK_HMAC_KEY
}

Configure the production HMAC key through the environment:

DANAMON_NIK_HMAC_KEY=<64 hexadecimal characters>
  • The HMAC key must be 32 bytes (64 hexadecimal characters).
  • The AES key and HMAC key must be different.
  • The sender and AdminApi must use the same HMAC key.
  • Do not use development fallback keys in production.

Backward-Compatible Behavior

Configuration Two Segments Valid Three Segments Invalid HMAC
nikHmacRequired = false Accepted HMAC is verified, then accepted Rejected
nikHmacRequired = true Rejected HMAC is verified, then accepted Rejected

A three-segment message is always validated with HMAC, regardless of the value of nikHmacRequired. HMAC comparison is constant-time and is completed before decryption.

Call Blocking Behavior

NIK verification is performed before the call is inserted into the database and before the Genesys interaction is created. The call is stopped and the response NIK could not be verified. is returned when:

  • The NIK value is missing or empty.
  • The segment count or hexadecimal format is invalid.
  • The HMAC does not match.
  • Decryption or payload parsing fails.
  • AdminApi cannot be reached or the verification request times out.

Technical details are written to the service logs. Typical messages are DECRYPT REQUEST ERROR in AdminApi and NIK verification failed in ECVDemo.

Client Response Contract

The HMAC enhancement does not change the existing DialEx success contract. Client applications and SDK integrations determine whether the call started from the DialEx response:

  • RoomId and InteractionId are both present: the call was created successfully.
  • Either identifier is missing: the client must treat the call as not started, stop the flow and may display the returned Message.

This response check existed before the HMAC enhancement. The new server-side behavior is that failed NIK verification now returns without call identifiers and includes the following user-safe message:

{
    "RoomId": null,
    "InteractionId": null,
    "Message": "NIK could not be verified."
}

For NIK verification failures, no database call record or Genesys interaction is created. This server-side guarantee applies regardless of how the customer UI handles the response. If a customer application or SDK does not display Message, the call is still blocked, but the user may only see a generic failure or no error feedback.

Deployment Steps

  1. Back up the current AdminApi, ECVDemo and Web.App deployments and their configuration files.
  2. Configure DANAMON_NIK_HMAC_KEY with the agreed 64-character hexadecimal key.
  3. Set nikHmacRequired to false for the transition period.
  4. Deploy AdminApi.
  5. Deploy ECVDemo.
  6. Deploy Web.App.
  7. Restart the affected services as required.
  8. Run the verification matrix below.

Verification

Test nikHmacRequired Expected Result
Valid two-segment NIK false Call is accepted.
Valid two-segment NIK true Request is rejected; no call starts.
Valid three-segment NIK false HMAC is verified and the call is accepted.
Valid three-segment NIK true HMAC is verified and the call is accepted.
Modify one character in the IV, ciphertext or HMAC false or true Request is rejected; no database call record or Genesys interaction is created.
Missing or malformed NIK false or true Request is rejected.
AdminApi unavailable false or true Verification fails closed and no call starts.

The Web.App test page WaitForAgentHmac.html can be used for positive and negative tests. For a negative test, change one hexadecimal character in the URL before opening it; changing the URL after the call has already started does not test the rejection path.

Final Migration Step

After all senders have switched to the authenticated three-segment format, set nikHmacRequired to true and restart AdminApi. Confirm that two-segment requests are rejected and valid three-segment requests continue to work.

Acceptance Criteria

The rollout is complete when valid authenticated requests are accepted, tampered or unverifiable NIK values do not create a database call record or Genesys interaction, legacy requests are accepted only while explicitly allowed, and service logs contain enough detail for troubleshooting without exposing key material.