wwbmmm opened a new pull request, #3779:
URL: https://github.com/apache/brpc/pull/3779

   ### What problem does this PR solve?
   
   Issue Number: resolve
   
   Problem Summary:
   On a plain-TCP connection using caching_sha2_password, when the server 
answers the fast scramble with AuthMoreData 0x04 (perform_full_authentication), 
the client automatically requests the server's RSA public key in-band and 
encrypts (password || NUL) XOR salt with it. The key is not authenticated and 
there was no way to pin it (no equivalent of libmysqlclient's 
--get-server-public-key / --server-public-key-path), so the password could be 
recovered by whoever supplied that key.
   
   ### What is changed and the side effects?
   
   Changed:
   - `MysqlAuthenticator` gains `set_server_public_key(pem)`: the server public 
key can be pinned out of band (PEM, obtained from a trusted channel). The 
pinned key is carried to the connection phase through the existing 
per-connection auth context.
   - On a non-TLS connection, the 0x04 full-authentication branch now fails 
immediately, without asking for the server key, when no key is pinned. The RPC 
error text and the error log tell the operator to use TLS or pin the key.
   - When a key is pinned, the PEM received from the server is parsed and 
compared (as DER, so encoding variations do not matter) with the pinned key 
before the password is encrypted; a mismatch fails the authentication and no 
ciphertext is sent.
   - The TLS/secure-transport branch and the caching_sha2 fast-auth path are 
unchanged.
   - Docs (docs/cn/mysql_client.md) and test/README_mysql_auth.md updated.
   
   Side effects:
   - Performance effects: none outside the authentication exchange (one PEM 
parse for the pinned-key comparison).
   
   - Breaking backward compatibility: caching_sha2_password full authentication 
over a non-TLS connection now requires a pinned key. Users hitting that path 
must switch to TLS or call `MysqlAuthenticator::set_server_public_key()`.
   
   Tests:
   - New `test/brpc_mysql_full_auth_unittest.cpp` drives a real brpc mysql 
Channel against a fake MySQL server: 0x04 without a pinned key fails before 
requesting the key; a mismatched key fails without sending the password; the 
matching pinned key succeeds and the server recovers the password from the 
RSA-OAEP ciphertext; the secure-transport branch still sends the password in 
the clear.
   - Added `ServerPublicKeyMatches` cases to 
`test/brpc_mysql_auth_scramble_unittest.cpp` (same key, PKCS#1 vs 
SubjectPublicKeyInfo encodings, invalid input).
   - Ran `cmake -S . -B build -DBUILD_UNIT_TESTS=ON -DDOWNLOAD_GTEST=OFF 
-DBRPC_SYSTEM_GTEST_SOURCE_DIR=/usr/src/googletest`, `make -j6`, and the mysql 
unit tests: brpc_mysql_full_auth_unittest (4 passed), 
brpc_mysql_auth_handshake_unittest (28), brpc_mysql_auth_packet_unittest (27), 
brpc_mysql_auth_scramble_unittest (38), brpc_mysql_reply_parse_unittest (36). 
Integration tests skip without a live mysqld.
   
   ---
   ### Check List:
   - Please make sure your changes are compilable.
   - When providing us with a new feature, it is best to add related tests.
   - Please follow [Contributor Covenant Code of 
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
   
   ---
   🤖 This PR was automatically created by brpc-oncall


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to