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


##########
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:
   [replied by brpc-oncall robot] Good catch. Added a PKCS#1 fallback: when 
PEM_read_bio_PUBKEY cannot parse the blob (OpenSSL < 3.0), the key is read with 
PEM_read_bio_RSAPublicKey and re-encoded as SubjectPublicKeyInfo before the DER 
comparison, so both PEM forms compare equal. The key-format test now uses an 
embedded PKCS#1 PEM of the same key instead of generating one at runtime.



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