Testing

Local Development and Testing

For local development, you can use Ngrok to create a secure tunnel to your local environment:

  1. Download Ngrok from the official website for your operating system

  2. Extract and navigate to the Ngrok directory in your terminal

  3. Run the command: ./ngrok http PORT_NUMBER

    • Replace PORT_NUMBER with your local server port (e.g., 8080 for default Spring Boot applications)

  4. Copy the generated Ngrok URL to use as your webhook endpoint

Security: Signature Verification

Every webhook request includes an X-RR-Signature header to verify authenticity. This signature is generated using the endpoint's secret key and the payload.

Verification Process

  1. The signature is provided as a hexadecimal string in the X-RR-Signature header

  2. Generate your own signature using the received payload and your secret key

  3. Compare the generated signature with the received signature

  4. If they match, the payload is verified as coming from Rocket Referral

Implementation Examples

Java Implementation

javaCopyimport javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.HexFormat;

public String signedPayload(String message, String key) 
    throws NoSuchAlgorithmException, InvalidKeyException {
    Mac hmacSHA256 = Mac.getInstance("HmacSHA256");
    SecretKeySpec secretKeySpec = new SecretKeySpec(
        key.getBytes(StandardCharsets.UTF_8),
        "HmacSHA256"
    );
    hmacSHA256.init(secretKeySpec);
    return HexFormat.of().formatHex(
        hmacSHA256.doFinal(message.getBytes(StandardCharsets.UTF_8))
    );
}

JavaScript Implementation

javascriptCopyconst crypto = require('crypto');

function signed_payload(clientKey, msg) {
    const key = new Buffer(clientKey, 'hex');
    return crypto.createHmac('sha256', key)
        .update(msg)
        .digest('hex');
}

Last updated