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

Side by Side Diff: webrtc/base/opensslidentity.cc

Issue 1898383003: RTCCertificate serialization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Verifying expiration time of clone 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 174 }
175 175
176 void OpenSSLKeyPair::AddReference() { 176 void OpenSSLKeyPair::AddReference() {
177 #if defined(OPENSSL_IS_BORINGSSL) 177 #if defined(OPENSSL_IS_BORINGSSL)
178 EVP_PKEY_up_ref(pkey_); 178 EVP_PKEY_up_ref(pkey_);
179 #else 179 #else
180 CRYPTO_add(&pkey_->references, 1, CRYPTO_LOCK_EVP_PKEY); 180 CRYPTO_add(&pkey_->references, 1, CRYPTO_LOCK_EVP_PKEY);
181 #endif 181 #endif
182 } 182 }
183 183
184 std::string OpenSSLKeyPair::PrivateKeyToPemString() const {
185 BIO* temp_memory_bio = BIO_new(BIO_s_mem());
186 if (!temp_memory_bio) {
187 LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio";
188 RTC_NOTREACHED();
189 return "";
190 }
191 if (!PEM_write_bio_PrivateKey(
192 temp_memory_bio, pkey_, nullptr, nullptr, 0, nullptr, nullptr)) {
193 LOG_F(LS_ERROR) << "Failed to read private key";
nisse-webrtc 2016/04/22 11:38:25 s/read/write/ in error message.
hbos 2016/04/22 13:19:29 Done.
194 BIO_free(temp_memory_bio);
195 RTC_NOTREACHED();
196 return "";
197 }
198 BIO_write(temp_memory_bio, "\0", 1);
199 char* buffer;
200 BIO_get_mem_data(temp_memory_bio, &buffer);
201 std::string priv_key_str = buffer;
202 BIO_free(temp_memory_bio);
203 return priv_key_str;
204 }
205
184 #if !defined(NDEBUG) 206 #if !defined(NDEBUG)
185 // Print a certificate to the log, for debugging. 207 // Print a certificate to the log, for debugging.
186 static void PrintCert(X509* x509) { 208 static void PrintCert(X509* x509) {
187 BIO* temp_memory_bio = BIO_new(BIO_s_mem()); 209 BIO* temp_memory_bio = BIO_new(BIO_s_mem());
188 if (!temp_memory_bio) { 210 if (!temp_memory_bio) {
189 LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio"; 211 LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio";
190 return; 212 return;
191 } 213 }
192 X509_print_ex(temp_memory_bio, x509, XN_FLAG_SEP_CPLUS_SPC, 0); 214 X509_print_ex(temp_memory_bio, x509, XN_FLAG_SEP_CPLUS_SPC, 0);
193 BIO_write(temp_memory_bio, "\0", 1); 215 BIO_write(temp_memory_bio, "\0", 1);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 bool OpenSSLIdentity::ConfigureIdentity(SSL_CTX* ctx) { 490 bool OpenSSLIdentity::ConfigureIdentity(SSL_CTX* ctx) {
469 // 1 is the documented success return code. 491 // 1 is the documented success return code.
470 if (SSL_CTX_use_certificate(ctx, certificate_->x509()) != 1 || 492 if (SSL_CTX_use_certificate(ctx, certificate_->x509()) != 1 ||
471 SSL_CTX_use_PrivateKey(ctx, key_pair_->pkey()) != 1) { 493 SSL_CTX_use_PrivateKey(ctx, key_pair_->pkey()) != 1) {
472 LogSSLErrors("Configuring key and certificate"); 494 LogSSLErrors("Configuring key and certificate");
473 return false; 495 return false;
474 } 496 }
475 return true; 497 return true;
476 } 498 }
477 499
500 std::string OpenSSLIdentity::PrivateKeyToPemString() const {
501 return key_pair_->PrivateKeyToPemString();
502 }
503
478 } // namespace rtc 504 } // namespace rtc
479 505
480 #endif // HAVE_OPENSSL_SSL_H 506 #endif // HAVE_OPENSSL_SSL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698