Copilot commented on code in PR #3779:
URL: https://github.com/apache/brpc/pull/3779#discussion_r4715045404


##########
src/brpc/policy/mysql/mysql_auth_scramble.cpp:
##########
@@ -38,6 +39,32 @@ bool Sha256Bytes(const unsigned char* data, size_t len, 
unsigned char out[32]) {
         && digest_len == 32;
 }
 
+// Parses a PEM-encoded public key and returns its DER encoding, or an empty
+// string when |pem| is not a parseable public key.
+std::string PublicKeyDer(const butil::StringPiece& pem) {
+    if (pem.empty()) {
+        return std::string();
+    }
+    BIO* bio = BIO_new_mem_buf(pem.data(), static_cast<int>(pem.size()));
+    if (bio == nullptr) {
+        return std::string();
+    }
+    EVP_PKEY* pkey = PEM_read_bio_PUBKEY(bio, nullptr, nullptr, nullptr);
+    BIO_free(bio);
+    if (pkey == nullptr) {

Review Comment:
   `PEM_read_bio_PUBKEY` parses SubjectPublicKeyInfo (`BEGIN PUBLIC KEY`) but 
not PKCS#1 `BEGIN RSA PUBLIC KEY`. Therefore the advertised PKCS#1-versus-SPKI 
equivalence fails: `PublicKeyDer` returns empty for a valid PKCS#1 key, so the 
new `Pkcs1AndSpkiEncodingsOfSameKeyMatch` case (and real callers using that 
encoding) is rejected. Add a PKCS#1 parsing fallback and normalize it to an 
`EVP_PKEY` before DER comparison.



-- 
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