OLD | NEW |
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 | 180 |
181 void OpenSSLKeyPair::AddReference() { | 181 void OpenSSLKeyPair::AddReference() { |
182 #if defined(OPENSSL_IS_BORINGSSL) | 182 #if defined(OPENSSL_IS_BORINGSSL) |
183 EVP_PKEY_up_ref(pkey_); | 183 EVP_PKEY_up_ref(pkey_); |
184 #else | 184 #else |
185 CRYPTO_add(&pkey_->references, 1, CRYPTO_LOCK_EVP_PKEY); | 185 CRYPTO_add(&pkey_->references, 1, CRYPTO_LOCK_EVP_PKEY); |
186 #endif | 186 #endif |
187 } | 187 } |
188 | 188 |
189 #ifdef _DEBUG | 189 #if !defined(NDEBUG) |
190 // Print a certificate to the log, for debugging. | 190 // Print a certificate to the log, for debugging. |
191 static void PrintCert(X509* x509) { | 191 static void PrintCert(X509* x509) { |
192 BIO* temp_memory_bio = BIO_new(BIO_s_mem()); | 192 BIO* temp_memory_bio = BIO_new(BIO_s_mem()); |
193 if (!temp_memory_bio) { | 193 if (!temp_memory_bio) { |
194 LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio"; | 194 LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio"; |
195 return; | 195 return; |
196 } | 196 } |
197 X509_print_ex(temp_memory_bio, x509, XN_FLAG_SEP_CPLUS_SPC, 0); | 197 X509_print_ex(temp_memory_bio, x509, XN_FLAG_SEP_CPLUS_SPC, 0); |
198 BIO_write(temp_memory_bio, "\0", 1); | 198 BIO_write(temp_memory_bio, "\0", 1); |
199 char* buffer; | 199 char* buffer; |
200 BIO_get_mem_data(temp_memory_bio, &buffer); | 200 BIO_get_mem_data(temp_memory_bio, &buffer); |
201 LOG(LS_VERBOSE) << buffer; | 201 LOG(LS_VERBOSE) << buffer; |
202 BIO_free(temp_memory_bio); | 202 BIO_free(temp_memory_bio); |
203 } | 203 } |
204 #endif | 204 #endif |
205 | 205 |
206 OpenSSLCertificate* OpenSSLCertificate::Generate( | 206 OpenSSLCertificate* OpenSSLCertificate::Generate( |
207 OpenSSLKeyPair* key_pair, const SSLIdentityParams& params) { | 207 OpenSSLKeyPair* key_pair, const SSLIdentityParams& params) { |
208 SSLIdentityParams actual_params(params); | 208 SSLIdentityParams actual_params(params); |
209 if (actual_params.common_name.empty()) { | 209 if (actual_params.common_name.empty()) { |
210 // Use a random string, arbitrarily 8chars long. | 210 // Use a random string, arbitrarily 8chars long. |
211 actual_params.common_name = CreateRandomString(8); | 211 actual_params.common_name = CreateRandomString(8); |
212 } | 212 } |
213 X509* x509 = MakeCertificate(key_pair->pkey(), actual_params); | 213 X509* x509 = MakeCertificate(key_pair->pkey(), actual_params); |
214 if (!x509) { | 214 if (!x509) { |
215 LogSSLErrors("Generating certificate"); | 215 LogSSLErrors("Generating certificate"); |
216 return NULL; | 216 return NULL; |
217 } | 217 } |
218 #ifdef _DEBUG | 218 #if !defined(NDEBUG) |
219 PrintCert(x509); | 219 PrintCert(x509); |
220 #endif | 220 #endif |
221 OpenSSLCertificate* ret = new OpenSSLCertificate(x509); | 221 OpenSSLCertificate* ret = new OpenSSLCertificate(x509); |
222 X509_free(x509); | 222 X509_free(x509); |
223 return ret; | 223 return ret; |
224 } | 224 } |
225 | 225 |
226 OpenSSLCertificate* OpenSSLCertificate::FromPEMString( | 226 OpenSSLCertificate* OpenSSLCertificate::FromPEMString( |
227 const std::string& pem_string) { | 227 const std::string& pem_string) { |
228 BIO* bio = BIO_new_mem_buf(const_cast<char*>(pem_string.c_str()), -1); | 228 BIO* bio = BIO_new_mem_buf(const_cast<char*>(pem_string.c_str()), -1); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 SSL_CTX_use_PrivateKey(ctx, key_pair_->pkey()) != 1) { | 455 SSL_CTX_use_PrivateKey(ctx, key_pair_->pkey()) != 1) { |
456 LogSSLErrors("Configuring key and certificate"); | 456 LogSSLErrors("Configuring key and certificate"); |
457 return false; | 457 return false; |
458 } | 458 } |
459 return true; | 459 return true; |
460 } | 460 } |
461 | 461 |
462 } // namespace rtc | 462 } // namespace rtc |
463 | 463 |
464 #endif // HAVE_OPENSSL_SSL_H | 464 #endif // HAVE_OPENSSL_SSL_H |
OLD | NEW |