Skip to content

Comments

Implement HMAC-based authentication fields in RegisterTMRequest with backward compatibility#10

Draft
Copilot wants to merge 4 commits into2.x_25_10_17_04from
copilot/extend-hmac-authentication
Draft

Implement HMAC-based authentication fields in RegisterTMRequest with backward compatibility#10
Copilot wants to merge 4 commits into2.x_25_10_17_04from
copilot/extend-hmac-authentication

Conversation

Copy link

Copilot AI commented Oct 17, 2025

Overview

This PR implements HMAC-based authentication for the RegisterTMRequest message by extending it with dedicated authentication fields, while ensuring full backward compatibility with older client and server versions.

Problem

Previously, HMAC authentication data (access key, digest, timestamp, auth version) was only stored in the extraData field as a string. This approach has limitations:

  • Authentication data is mixed with other metadata
  • Requires string parsing to extract individual fields
  • Less efficient for serialization and validation
  • Difficult to handle in strongly-typed systems

Solution

Added four dedicated fields to RegisterTMRequest:

  • accessKey (String): Access key for authentication
  • digest (String): HMAC digest generated from request data
  • timestamp (Long): Timestamp when the request was created
  • authVersion (String): Authentication algorithm version (e.g., "V4")

Implementation Details

1. Core Protocol Extensions

  • Added fields to RegisterTMRequest with standard getters/setters
  • Maintains existing constructors and behavior
  • Fields are optional (nullable) for backward compatibility

2. Codec Changes (Seata Serializer)

  • Extended RegisterTMRequestCodec to encode/decode new fields
  • Encoding: Writes new fields after base fields using length-prefixed format
  • Decoding: Checks buffer size before reading each field, gracefully handles missing data
  • Old messages without HMAC fields decode successfully with null values

3. Protobuf Serializer Updates

  • Extended .proto definition with new fields (IDs 2-5)
  • Updated RegisterTMRequestConvertor to handle field conversion
  • Empty/zero values are properly handled for backward compatibility

4. Client Integration

  • Updated TmNettyRemotingClient.getPoolKeyFunction() to populate HMAC fields
  • Automatically generates digest, sets timestamp, and retrieves auth version
  • Maintains existing extraData functionality for legacy support

Backward Compatibility

The implementation ensures seamless interoperability across versions:

Client Version Server Version Behavior
Old (no HMAC fields) Old ✅ Works - Basic authentication only
Old (no HMAC fields) New ✅ Works - Server handles null HMAC fields
New (with HMAC) Old ✅ Works - Old server ignores extra data
New (with HMAC) New ✅ Works - Full HMAC authentication

Key compatibility mechanisms:

  • Codec checks remaining buffer size before reading each HMAC field
  • Missing fields result in null values, not errors
  • Proto3 handles optional fields with default values
  • Existing extraData field continues to work for legacy clients

Testing

Added comprehensive tests covering:

  • Full encode/decode cycle with HMAC fields
  • Backward compatibility with old messages (without HMAC fields)
  • Protobuf conversion with and without HMAC fields
  • Null value handling
  • All 15 new and existing tests pass

Test files:

  • RegisterTMRequestSerializerTest: Tests for Seata codec
  • RegisterTMRequestConvertorTest: Tests for Protobuf convertor

Changes Summary

  • 8 files modified
  • 463 lines added (mostly tests and documentation)
  • No breaking changes to existing APIs
  • Follows existing patterns from RegisterRMRequest

Documentation

Added HMAC_AUTHENTICATION_IMPLEMENTATION.md documenting:

  • Design decisions
  • Backward compatibility strategy
  • Version compatibility matrix
  • Testing approach

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • httpbin.org
  • registry.npmmirror.com
    • Triggering command: npm install (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/fescar/fescar org.codehaus.plexus.classworlds.launcher.Launcher clean install -DskipTests -T 4 -q (dns block)
  • repository.apache.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.11/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.11/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.11 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.11/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/fescar/fescar org.codehaus.plexus.classworlds.launcher.Launcher test -pl core -Dtest=RegisterTMRequestTest -q (dns block)
  • seata.io
  • www.apache.org

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

基于RegisterTMRequest消息字段扩展实现基于HMAC的鉴权,需要保证编解码高低版本兼容。


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits October 17, 2025 14:31
Co-authored-by: slievrly <8758457+slievrly@users.noreply.github.com>
…patibility

Co-authored-by: slievrly <8758457+slievrly@users.noreply.github.com>
…nd documentation

Co-authored-by: slievrly <8758457+slievrly@users.noreply.github.com>
Copilot AI changed the title [WIP] Add HMAC-based authentication for RegisterTMRequest Implement HMAC-based authentication fields in RegisterTMRequest with backward compatibility Oct 17, 2025
Copilot AI requested a review from slievrly October 17, 2025 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants