Class DingTalkCallbackCrypto
java.lang.Object
io.agentscope.extensions.channel.dingtalk.DingTalkCallbackCrypto
Implements DingTalk's HTTP-callback request verification and optional body decryption for robot
message reception. See the DingTalk docs on verifying
robot requests and callback
body encryption.
Inputs:
appSecret— the enterprise-internal app secret. Used as the HMAC key for request signature verification: each callback carriestimestampandsignheaders, wheresign = Base64(HmacSHA256(appSecret, timestamp + "\n" + appSecret))and the timestamp is a millisecond epoch DingTalk requires to be no older than one hour; timestamps ahead of local time are tolerated only within a clock-skew allowance.aesKey— optional 43-character base64 (no padding). When the robot is configured with encryption, the callback body is a{"encrypt": ...}envelope instead of plain JSON, and this key (decoded with an appended"="to 32 bytes, its first 16 bytes also used as the CBC IV) decrypts it. May benullfor robots configured without encryption.
Instances are immutable and thread-safe; verify(java.lang.String, java.lang.String) and decrypt(java.lang.String) may be invoked
concurrently from multiple request threads.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDecrypts theencryptbody field and returns the inner JSON payload as a UTF-8 string.booleanReturns whether this channel is configured with anaesKey(encrypted callbacks).booleanVerifies thetimestamp/signrequest headers of a callback: the timestamp must be a millisecond epoch no older thanMAX_TIMESTAMP_AGE_MSand no further ahead of local time thanMAX_FUTURE_TIMESTAMP_MS, andsignmust equalBase64(HmacSHA256(appSecret, timestamp + "\n" + appSecret)).
-
Constructor Details
-
DingTalkCallbackCrypto
-
-
Method Details
-
verify
Verifies thetimestamp/signrequest headers of a callback: the timestamp must be a millisecond epoch no older thanMAX_TIMESTAMP_AGE_MSand no further ahead of local time thanMAX_FUTURE_TIMESTAMP_MS, andsignmust equalBase64(HmacSHA256(appSecret, timestamp + "\n" + appSecret)). -
decrypt
Decrypts theencryptbody field and returns the inner JSON payload as a UTF-8 string.DingTalk plaintext layout after AES-CBC decrypt + PKCS#7 unpad:
| 16 bytes random | 4 bytes msg_len (big-endian) | msg (msg_len bytes) | optional trailing bytes |
Trailing bytes beyond
msg_len(present in DingTalk's event-callback variant of this envelope, which appends a receive id) are not part of the message and are ignored. -
hasAesKey
public boolean hasAesKey()Returns whether this channel is configured with anaesKey(encrypted callbacks).
-