Skip to content

[DRAFT][mysql] Clean-room mysql_native_password scramble (Stage 1a of #2093 takeover)#3310

Draft
rajvarun77 wants to merge 1 commit into
apache:masterfrom
rajvarun77:mysql-auth-hash-clean-room
Draft

[DRAFT][mysql] Clean-room mysql_native_password scramble (Stage 1a of #2093 takeover)#3310
rajvarun77 wants to merge 1 commit into
apache:masterfrom
rajvarun77:mysql-auth-hash-clean-room

Conversation

@rajvarun77
Copy link
Copy Markdown

Draft / WIP — not for review yet. Posted now so the staged plan announced on dev@brpc.apache.org and at #2093 (comment) has a concrete first commit to point at.

What

Adds src/brpc/policy/mysql_auth_hash.{h,cpp} implementing the mysql_native_password (a.k.a. mysql41) authentication scramble:

scramble = SHA1(password) XOR SHA1( salt || SHA1( SHA1(password) ) )

Plus test/brpc_mysql_auth_hash_unittest.cpp with two known-answer vectors, an empty-password check, a bad-salt-length check, a determinism check, and a salt-diversity check.

Why this exists as a standalone commit

The original MySQL PR #2093 by @yanglimingcn bundled an mysql_auth_hash.cpp lifted directly from MySQL Connector/C++ — which is GPLv2 (with the FOSS exception). @wwbmmm flagged this as unmergeable at #2093 (discussion). Replacing that file with a clean-room implementation is on the critical path for any MySQL work landing in brpc, so it's the first stage of the takeover plan.

This file is implemented from MySQL's public protocol documentation only — no GPL source consulted. It uses butil::SHA1HashBytes (BSD-licensed Chromium SHA-1 already in butil/), so it adds zero new third-party dependencies.

Where this fits in the larger plan

The full staged delivery announced on dev@:

Stage Scope This PR
1a Clean-room mysql_auth_hash (this PR) You are here. Leaf utility, no callers yet.
1b Text protocol (COM_QUERY, result-set parsing, authenticator wiring, MysqlChannel etc.) Follows; will use this commit
2 Transactions (MysqlTransaction)
3 Prepared statements + Socket::_fd_version ABA mapping
4 caching_sha2_password + TLS (beyond #2093 scope)

This is intentionally a small leaf utility — it does not yet wire into MysqlAuthenticator. That wiring lands in Stage 1b. Opening as Draft because the function has no production caller in this PR; it ships only with the unit test exercising it. Maintainers may prefer to wait until 1b before reviewing, which is fine.

Refs

CC: @wwbmmm @yanglimingcn @chenBright

Test plan

  • Unit tests added (brpc_mysql_auth_hash_unittest.cpp) — 6 cases, includes two SHA-1-derived known answer vectors
  • GitHub Actions CI passes (pending after push)
  • Integration with real MySQL server — deferred to Stage 1b once authenticator is wired

Adds src/brpc/policy/mysql_auth_hash.{h,cpp} implementing the
mysql_native_password ("mysql41") authentication scramble used during
MySQL client connection handshake:

    scramble = SHA1(password) XOR SHA1( salt || SHA1( SHA1(password) ) )

Implemented from MySQL's public protocol documentation only; not
derived from any GPL source. The previous in-tree implementation
proposed in PR apache#2093 was copied from MySQL Connector/C++ (GPLv2 with
FOSS exception) and was flagged as unmergeable by @wwbmmm at
apache#2093 (comment) .

Uses butil::SHA1HashBytes (BSD-licensed Chromium SHA-1 already
present in butil), so no new third-party dependency is introduced.

This is Stage 1a of the staged delivery plan announced on
dev@brpc.apache.org and at
apache#2093 (comment) .
It is intentionally a leaf utility: subsequent stages will wire it
into MysqlAuthenticator and the MySQL protocol policy.

Includes a gtest unittest (brpc_mysql_auth_hash_unittest.cpp) with
two known answer vectors plus empty-password, bad-salt-length,
determinism, and salt-diversity checks.

Refs: apache#209, apache#2093
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.

1 participant