Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Unified Diff: webrtc/base/opensslidentity.cc

Issue 1898383003: RTCCertificate serialization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Handle PEM_write_bio_PrivateKey failure Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/base/opensslidentity.cc
diff --git a/webrtc/base/opensslidentity.cc b/webrtc/base/opensslidentity.cc
index 9c2112e157c0dc71099b57a764c58c4e48d4c28b..d86974569c40f58948a811e840871d410cc9f3ad 100644
--- a/webrtc/base/opensslidentity.cc
+++ b/webrtc/base/opensslidentity.cc
@@ -181,6 +181,28 @@ void OpenSSLKeyPair::AddReference() {
#endif
}
+std::string OpenSSLKeyPair::PrivateKeyToPemString() const {
+ BIO* temp_memory_bio = BIO_new(BIO_s_mem());
+ if (!temp_memory_bio) {
+ LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio";
+ RTC_NOTREACHED();
+ return "";
+ }
+ if (!PEM_write_bio_PrivateKey(
+ temp_memory_bio, pkey_, nullptr, nullptr, 0, nullptr, nullptr)) {
+ LOG_F(LS_ERROR) << "Failed to read private key";
+ BIO_free(temp_memory_bio);
+ RTC_NOTREACHED();
+ return "";
+ }
+ BIO_write(temp_memory_bio, "\0", 1);
+ char* buffer;
+ BIO_get_mem_data(temp_memory_bio, &buffer);
+ std::string priv_key_str = buffer;
+ BIO_free(temp_memory_bio);
+ return priv_key_str;
+}
+
#if !defined(NDEBUG)
// Print a certificate to the log, for debugging.
static void PrintCert(X509* x509) {
@@ -475,6 +497,10 @@ bool OpenSSLIdentity::ConfigureIdentity(SSL_CTX* ctx) {
return true;
}
+std::string OpenSSLIdentity::PrivateKeyToPemString() const {
+ return key_pair_->PrivateKeyToPemString();
+}
+
} // namespace rtc
#endif // HAVE_OPENSSL_SSL_H

Powered by Google App Engine
This is Rietveld 408576698