Index: webrtc/base/opensslidentity.cc |
diff --git a/webrtc/base/opensslidentity.cc b/webrtc/base/opensslidentity.cc |
index 9c2112e157c0dc71099b57a764c58c4e48d4c28b..8b35a70250797980900e38b23c794075da4dd716 100644 |
--- a/webrtc/base/opensslidentity.cc |
+++ b/webrtc/base/opensslidentity.cc |
@@ -181,6 +181,36 @@ void OpenSSLKeyPair::AddReference() { |
#endif |
} |
+std::string OpenSSLKeyPair::PrivateKeyToPemString() const { |
+ BIO* temp_memory_bio = BIO_new(BIO_s_mem()); |
nisse-webrtc
2016/04/22 13:44:07
I was a bit confused by the name if this class; I
hbos
2016/04/25 14:23:23
Hmm, confusing indeed.
The previously existing SS
nisse-webrtc
2016/04/27 08:05:46
The private key always (are there any exceptions?)
hbos
2016/04/27 09:00:44
Oh good, then the private key -> key pair makes se
nisse-webrtc
2016/04/27 09:08:57
Yes. More or less by definition, a certificate con
hbos
2016/04/27 10:12:08
Acknowledged.
|
+ 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 write 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; |
+} |
+ |
+bool OpenSSLKeyPair::operator==(const OpenSSLKeyPair& other) const { |
+ return EVP_PKEY_cmp(this->pkey_, other.pkey_) == 1; |
+} |
+ |
+bool OpenSSLKeyPair::operator!=(const OpenSSLKeyPair& other) const { |
+ return !(*this == other); |
+} |
+ |
#if !defined(NDEBUG) |
// Print a certificate to the log, for debugging. |
static void PrintCert(X509* x509) { |
@@ -368,6 +398,14 @@ void OpenSSLCertificate::AddReference() const { |
#endif |
} |
+bool OpenSSLCertificate::operator==(const OpenSSLCertificate& other) const { |
+ return X509_cmp(this->x509_, other.x509_) == 0; |
+} |
+ |
+bool OpenSSLCertificate::operator!=(const OpenSSLCertificate& other) const { |
+ return !(*this == other); |
+} |
+ |
// Documented in sslidentity.h. |
int64_t OpenSSLCertificate::CertificateExpirationTime() const { |
ASN1_TIME* expire_time = X509_get_notAfter(x509_); |
@@ -475,6 +513,19 @@ bool OpenSSLIdentity::ConfigureIdentity(SSL_CTX* ctx) { |
return true; |
} |
+std::string OpenSSLIdentity::PrivateKeyToPemString() const { |
+ return key_pair_->PrivateKeyToPemString(); |
+} |
+ |
+bool OpenSSLIdentity::operator==(const OpenSSLIdentity& other) const { |
+ return *this->key_pair_ == *other.key_pair_ && |
+ *this->certificate_ == *other.certificate_; |
+} |
+ |
+bool OpenSSLIdentity::operator!=(const OpenSSLIdentity& other) const { |
+ return !(*this == other); |
+} |
+ |
} // namespace rtc |
#endif // HAVE_OPENSSL_SSL_H |