Skip to content

Verify webhook signatures

Ripple Custody (Vault) signs every webhook delivery, so your endpoint can confirm that a request came from your Ripple Custody (Vault) instance and that nobody changed it in transit. Signing uses Ed25519 keys and follows the asymmetric (v1a) scheme of the Standard Webhooks specification. You can verify each delivery with a public key that Ripple Custody (Vault) publishes, so no shared secret is exchanged.

Signing is on for all webhook channels from version 1.44. Verifying the signature is optional, but recommended. Signing only adds HTTP headers to each delivery: the request body is unchanged, and an endpoint that ignores the headers keeps working.

How signing works

  • Ripple Custody (Vault) holds the private signing keys. They're stored encrypted and are never exposed, including to Ripple support staff.
  • Ripple Custody (Vault) publishes the matching public keys at an unauthenticated JWKS (JSON Web Key Set) endpoint.
  • The signing key belongs to the environment, not to a channel: every webhook channel in an environment is signed with the same key. Each environment, for example your test and production environments, has its own keys, so get the keys from each environment that sends you webhooks.
  • The signature proves that a delivery came from your Ripple Custody (Vault) instance, not which domain or channel it was sent to. All domains on the instance share the signing key, so also check the domainId in the body. See step 7 of Verify a delivery.
  • Every delivery attempt, including retries and test deliveries, is signed. Ripple Custody (Vault) never sends an unsigned delivery.
  • Ripple Custody (Vault) rotates the signing key automatically once a year, with a 30-day overlap during which deliveries carry two signatures.

Signature headers

Each delivery carries three headers:

POST /your/webhook/endpoint HTTP/1.1
Content-Type: application/json
webhook-id: 7f1f6a5e-3c1d-4b8e-9d7a-2f0c9b1e4a6d
webhook-timestamp: 1793280000
webhook-signature: v1a,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4CjtXGXzpbrsYzBLXQ7STBvn7oRf2FKBWqL+mZbN0uBg==

{"domainId":"25aaec0d-e8dc-44b6-8070-9231f1ddadf0","payload":{...},"id":"...","sequenceNumber":42,"savedAt":"..."}
HeaderDescription
webhook-idUnique ID of this delivery: one event on one channel. The ID stays the same across retries and when Ripple Custody (Vault) re-sends a pending event, so you can use it to discard duplicates. It's different from the id field in the body, which all channels of a domain share.
webhook-timestampTime of this delivery attempt, in Unix seconds. Each retry gets a new timestamp and a new signature.
webhook-signatureOne or more signatures, separated by spaces. Each has the form v1a,<signature>, where the signature is a standard Base64-encoded Ed25519 signature. During a key rotation, the header carries two signatures.

The signed content is the UTF-8 string {webhook-id}.{webhook-timestamp}. followed by the exact bytes of the request body.

Get the public keys

Retrieve the public keys from the JWKS endpoint. The endpoint doesn't require authentication.

curl -X GET "${CUSTODY_API_URL}/v1/webhook-signing-keys"
{
  "keys": [
    {
      "kty": "OKP",
      "crv": "Ed25519",
      "kid": "6906b6d6-d2ad-480b-9be3-28a191726584",
      "x": "<base64url public key>",
      "whpk": "whpk_<base64 public key>",
      "use": "sig",
      "status": "active",
      "exp": 1823558400
    },
    {
      "kty": "OKP",
      "crv": "Ed25519",
      "kid": "331e90d1-c6d7-4b55-8823-00f553ef3be5",
      "x": "<base64url public key>",
      "whpk": "whpk_<base64 public key>",
      "use": "sig",
      "status": "next"
    }
  ]
}
FieldDescription
kty, crvKey type and curve. Always OKP and Ed25519.
kidKey ID, a UUID. The signature header doesn't include it, so try every key in the set.
xThe public key, Base64url-encoded without padding.
whpkThe same public key in the Standard Webhooks format: whpk_ followed by the key, standard Base64-encoded with padding. Use it with Standard Webhooks libraries and tools that take a key in that form.
useAlways sig.
statusOne of the following:
- active: the key that signs deliveries.
- next: the key that will replace it at the next rotation.
- retiring: the previous key, during the 30-day overlap after a rotation. It still signs deliveries, together with the active key.
expTime at which scheduled rotation stops publishing the key, in Unix seconds. The active and retiring keys carry it; the next key doesn't. For the active key, it's when the next key is scheduled to replace it. For the retiring key, it's the scheduled end of the 30-day overlap. exp is a schedule, not a deadline: rotation can be delayed, and the active key keeps signing after its exp until it rotates. Don't drop a key only because its exp has passed.

The response carries Cache-Control: public, max-age=86400, so you can cache the key set for up to 24 hours. If the endpoint returns 503 Service Unavailable, Ripple Custody (Vault) couldn't check the keys against its key store: keep the keys you hold and retry later.

You can store the public keys in either of two ways: cache them and refresh them every day, or store them until the planned rotation. For details, see Scheduled rotation.

Verify a delivery

To verify a delivery, we recommend the following procedure, before you process the event:

  1. Read the raw body. Verify the exact bytes you received, before any JSON parsing. A parsed and re-serialized body doesn't match the signature.
  2. Check the timestamp. Reject the request if webhook-timestamp is more than 5 minutes from your current time. This stops an attacker from replaying a captured delivery.
  3. Discard duplicates. If you've already processed this webhook-id in the last 24 hours, return 2xx and skip it. Retries and re-sends reuse the same ID.
  4. Build the signed content: webhook-id + . + webhook-timestamp + . + raw body.
  5. Verify the signature. For each v1a entry in webhook-signature, and each key in the key set, call a standard Ed25519 verify function with the public key, the signed content, and the decoded signature. One match is enough.
  6. If nothing matches, refresh the keys once. If your cached key set is more than 5 minutes old, fetch it again and repeat step 5. If there's still no match, reject the request.
  7. Check the domain. Parse the body and check that its domainId is the domain where you created the webhook channel. If it isn't, reject the request. Always make this check: one signing key signs the deliveries of every domain on your Ripple Custody (Vault) instance, and the signature doesn't identify the domain that a delivery was sent to. Without the check, a user who can manage webhook channels in another domain on the same instance could forward genuinely signed events from that domain to your endpoint.
  8. Acknowledge. Return 2xx only after you've stored the event durably. Your endpoint must acknowledge each delivery, whether or not it verifies the signature: the 2xx tells Ripple Custody (Vault) that the delivery succeeded. Ripple Custody (Vault) waits until each delivery succeeds or finally fails before it sends the next event, so acknowledge promptly. For how Ripple Custody (Vault) handles other responses, see HTTP status code handling.
Check your library

Many webhook libraries implement only the symmetric HMAC scheme (v1) of the Standard Webhooks specification. Ripple Custody (Vault) uses the asymmetric Ed25519 scheme (v1a). Make sure that your library supports v1a, or verify the signature yourself, as in the following examples.

The following examples implement steps 2, 4, 5, and 7. Add duplicate detection, key refresh, and error handling to suit your service.

This example uses the cryptography package.

import base64
import json
import time

from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey

TOLERANCE_SECONDS = 5 * 60


def b64url_decode(value: str) -> bytes:
    return base64.urlsafe_b64decode(value + "=" * (-len(value) % 4))


def verify_webhook(headers: dict, raw_body: bytes, jwks: dict, domain_id: str) -> bool:
    msg_id = headers["webhook-id"]
    timestamp = headers["webhook-timestamp"]

    if abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
        return False

    message = f"{msg_id}.{timestamp}.".encode() + raw_body
    signatures = [
        base64.b64decode(entry[len("v1a,"):])
        for entry in headers["webhook-signature"].split(" ")
        if entry.startswith("v1a,")
    ]
    keys = [
        Ed25519PublicKey.from_public_bytes(b64url_decode(key["x"]))
        for key in jwks["keys"]
        if key.get("use") == "sig" and key.get("crv") == "Ed25519"
    ]

    for key in keys:
        for signature in signatures:
            try:
                key.verify(signature, message)
            except InvalidSignature:
                continue
            # The signature is valid: check that the event belongs to your domain.
            return json.loads(raw_body).get("domainId") == domain_id
    return False

Key rotation

Scheduled rotation

Ripple Custody (Vault) rotates the signing key automatically once a year:

  1. The next key is published well in advance: from the previous rotation, or from the start for a new instance.
  2. At rotation, the next key becomes the active key, and Ripple Custody (Vault) publishes a new next key.
  3. For 30 days, the previous key stays in the key set with the status retiring, and each delivery carries two signatures, one from the previous key and one from the new key.
  4. After 30 days, the previous key stops signing and is removed from the key set.

Store the public keys in either of the following ways:

  • Cache the keys and refresh them every day. Fetch the key set, cache it for up to 24 hours as the Cache-Control header indicates, then fetch it again. Your endpoint picks up each new key automatically, and you don't need to take any action at rotation. This option also picks up an emergency rotation within a day.
  • Store the keys until the planned rotation. Fetch the key set once, and use the active key's expiration time (exp) to schedule the next fetch, or to add the next key by hand, before the 30-day overlap ends. Rotation can happen later than exp, so remove an old key only once it's no longer in the key set, not when its exp passes. You then fetch the key set about once a year. With this option, you don't pick up an emergency rotation until you fetch the key set again.

Emergency rotation

If a signing key is compromised, the operator of your instance revokes it: Ripple for SaaS, or your platform team on-premises. The revoked key is removed from the key set immediately, the next key starts signing at once, and there's no 30-day overlap.

Your endpoint keeps trusting the revoked key until it refreshes the key set. Clients that respect the 24-hour cache lifetime stop trusting it within a day. If you're told about an emergency rotation, refresh the key set right away, and remove any key that you configured by hand.

Configure signing on-premises

On-premises, the signing keys are stored encrypted under a master key. Configure the master key in your Helm values file:

ValueDescription
kms.autoGenerateIf true, Ripple Custody (Vault) generates the master key. Default: true.
kms.masterThe master key, set inline.
kms.existingSecret.name, kms.existingSecret.keyThe name of an existing Kubernetes Secret that holds the master key, and the key within that Secret. If you set an existing Secret, it takes precedence over the other options.

You can't change the rotation period (12 months) or the overlap (30 days).

Signing uses a software KMS (KMS soft), not an HSM or a KMS Connect sidecar. For an air-gapped installation, make its image available in your private registry, like the other Ripple Custody (Vault) images.

Revoke a signing key on-premises

On-premises, you revoke a key through the Helm chart:

  1. Add the kid of the compromised key to the webhookSigning.revokedKids list in your values file.
  2. Run helm upgrade.

At startup, Ripple Custody (Vault) removes every listed key. If the active key is listed, the next key becomes active and Ripple Custody (Vault) creates a new next key.

If you suspect that the key store itself is compromised, treat the master key that encrypts the signing keys as compromised too. Replace the master-key Secret, and list both the active and the next key in webhookSigning.revokedKids. Ripple Custody (Vault) then creates a new key that has never been published and makes it active immediately, so notify your webhook consumers to refresh their key sets.

Delivery behavior

  • If Ripple Custody (Vault) can't sign a delivery, for example because the signing service is temporarily unavailable, the delivery stays PENDING and is retried once signing is available again. These attempts don't count toward maxRetries. A separate process makes them, so these deliveries can arrive out of order, after events that were created later.
  • While signing is unavailable, Test a webhook channel returns 503 Service Unavailable.
  • For HTTPS webhook URLs, Ripple Custody (Vault) uses TLS 1.2 or 1.3, validates the server certificate against the standard trust store, and verifies the hostname. You can't add a custom certificate authority to the trust store, as for other Ripple Custody (Vault) components, so your endpoint's certificate must chain to a publicly trusted certificate authority.