Class Signatures
java.lang.Object
com.fortemate.dicechess.runtime.Signatures
HMAC-SHA256 signing and verification for the DiceChess webhook delivery protocol.
The signed payload is timestamp + "." + body, hex-encoded. A delivery is accepted
only if its timestamp falls within REPLAY_WINDOW_SECONDS of the verifier's clock,
and the comparison is constant-time to avoid leaking the secret through timing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDomain separation prefix prepended to the raw body when computing a version-2 activation response proof.static final longThe signature is only accepted within this many seconds of the current time, either side. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringactivationProof(String secret, String rawBody) Computes the lowercase-hex HMAC-SHA256 response proof for a version-2 verification challenge.static StringComputes the hex-encoded HMAC-SHA256 signature for a delivery.static booleanverify(WebhookKeys keys, long timestampEpochSeconds, String body, String signature, long nowEpochSeconds) Verifies a delivery's signature and freshness against configured active and/or pending keys.static booleanverify(String secret, long timestampEpochSeconds, String body, String signature, long nowEpochSeconds) Verifies a delivery's signature and freshness against a single secret.
-
Field Details
-
REPLAY_WINDOW_SECONDS
public static final long REPLAY_WINDOW_SECONDSThe signature is only accepted within this many seconds of the current time, either side.- See Also:
-
ACTIVATION_PROOF_PREFIX
Domain separation prefix prepended to the raw body when computing a version-2 activation response proof.- See Also:
-
-
Method Details
-
sign
Computes the hex-encoded HMAC-SHA256 signature for a delivery.- Parameters:
secret- the webhook secret issued by the platformtimestampEpochSeconds- the delivery timestamp, Unix epoch secondsbody- the raw request body, exactly as transmitted- Returns:
- the lowercase hex signature
-
activationProof
Computes the lowercase-hex HMAC-SHA256 response proof for a version-2 verification challenge.- Parameters:
secret- the pending webhook secret issued by the platformrawBody- the exact raw request body received from the platform- Returns:
- the lowercase hex proof string
-
verify
public static boolean verify(String secret, long timestampEpochSeconds, String body, String signature, long nowEpochSeconds) Verifies a delivery's signature and freshness against a single secret.- Parameters:
secret- the webhook secret issued by the platformtimestampEpochSeconds- the delivery's claimed timestamp, Unix epoch secondsbody- the raw request body, exactly as receivedsignature- the hex signature supplied with the deliverynowEpochSeconds- the verifier's current time, Unix epoch seconds- Returns:
trueif the timestamp is withinREPLAY_WINDOW_SECONDSand the signature matches
-
verify
public static boolean verify(WebhookKeys keys, long timestampEpochSeconds, String body, String signature, long nowEpochSeconds) Verifies a delivery's signature and freshness against configured active and/or pending keys.When both keys are configured, both signatures are evaluated using constant-time comparisons without early return to eliminate timing oracles.
- Parameters:
keys- the active and/or pending webhook keystimestampEpochSeconds- the delivery's claimed timestamp, Unix epoch secondsbody- the raw request body, exactly as receivedsignature- the hex signature supplied with the deliverynowEpochSeconds- the verifier's current time, Unix epoch seconds- Returns:
trueif the timestamp is withinREPLAY_WINDOW_SECONDSand either key matches the signature
-