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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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()); | |
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.
| |
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 write private key"; | |
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 | |
206 bool OpenSSLKeyPair::operator==(const OpenSSLKeyPair& other) const { | |
207 return EVP_PKEY_cmp(this->pkey_, other.pkey_) == 1; | |
208 } | |
209 | |
210 bool OpenSSLKeyPair::operator!=(const OpenSSLKeyPair& other) const { | |
211 return !(*this == other); | |
212 } | |
213 | |
184 #if !defined(NDEBUG) | 214 #if !defined(NDEBUG) |
185 // Print a certificate to the log, for debugging. | 215 // Print a certificate to the log, for debugging. |
186 static void PrintCert(X509* x509) { | 216 static void PrintCert(X509* x509) { |
187 BIO* temp_memory_bio = BIO_new(BIO_s_mem()); | 217 BIO* temp_memory_bio = BIO_new(BIO_s_mem()); |
188 if (!temp_memory_bio) { | 218 if (!temp_memory_bio) { |
189 LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio"; | 219 LOG_F(LS_ERROR) << "Failed to allocate temporary memory bio"; |
190 return; | 220 return; |
191 } | 221 } |
192 X509_print_ex(temp_memory_bio, x509, XN_FLAG_SEP_CPLUS_SPC, 0); | 222 X509_print_ex(temp_memory_bio, x509, XN_FLAG_SEP_CPLUS_SPC, 0); |
193 BIO_write(temp_memory_bio, "\0", 1); | 223 BIO_write(temp_memory_bio, "\0", 1); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 | 391 |
362 void OpenSSLCertificate::AddReference() const { | 392 void OpenSSLCertificate::AddReference() const { |
363 ASSERT(x509_ != NULL); | 393 ASSERT(x509_ != NULL); |
364 #if defined(OPENSSL_IS_BORINGSSL) | 394 #if defined(OPENSSL_IS_BORINGSSL) |
365 X509_up_ref(x509_); | 395 X509_up_ref(x509_); |
366 #else | 396 #else |
367 CRYPTO_add(&x509_->references, 1, CRYPTO_LOCK_X509); | 397 CRYPTO_add(&x509_->references, 1, CRYPTO_LOCK_X509); |
368 #endif | 398 #endif |
369 } | 399 } |
370 | 400 |
401 bool OpenSSLCertificate::operator==(const OpenSSLCertificate& other) const { | |
402 return X509_cmp(this->x509_, other.x509_) == 0; | |
403 } | |
404 | |
405 bool OpenSSLCertificate::operator!=(const OpenSSLCertificate& other) const { | |
406 return !(*this == other); | |
407 } | |
408 | |
371 // Documented in sslidentity.h. | 409 // Documented in sslidentity.h. |
372 int64_t OpenSSLCertificate::CertificateExpirationTime() const { | 410 int64_t OpenSSLCertificate::CertificateExpirationTime() const { |
373 ASN1_TIME* expire_time = X509_get_notAfter(x509_); | 411 ASN1_TIME* expire_time = X509_get_notAfter(x509_); |
374 bool long_format; | 412 bool long_format; |
375 | 413 |
376 if (expire_time->type == V_ASN1_UTCTIME) { | 414 if (expire_time->type == V_ASN1_UTCTIME) { |
377 long_format = false; | 415 long_format = false; |
378 } else if (expire_time->type == V_ASN1_GENERALIZEDTIME) { | 416 } else if (expire_time->type == V_ASN1_GENERALIZEDTIME) { |
379 long_format = true; | 417 long_format = true; |
380 } else { | 418 } else { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 bool OpenSSLIdentity::ConfigureIdentity(SSL_CTX* ctx) { | 506 bool OpenSSLIdentity::ConfigureIdentity(SSL_CTX* ctx) { |
469 // 1 is the documented success return code. | 507 // 1 is the documented success return code. |
470 if (SSL_CTX_use_certificate(ctx, certificate_->x509()) != 1 || | 508 if (SSL_CTX_use_certificate(ctx, certificate_->x509()) != 1 || |
471 SSL_CTX_use_PrivateKey(ctx, key_pair_->pkey()) != 1) { | 509 SSL_CTX_use_PrivateKey(ctx, key_pair_->pkey()) != 1) { |
472 LogSSLErrors("Configuring key and certificate"); | 510 LogSSLErrors("Configuring key and certificate"); |
473 return false; | 511 return false; |
474 } | 512 } |
475 return true; | 513 return true; |
476 } | 514 } |
477 | 515 |
516 std::string OpenSSLIdentity::PrivateKeyToPemString() const { | |
517 return key_pair_->PrivateKeyToPemString(); | |
518 } | |
519 | |
520 bool OpenSSLIdentity::operator==(const OpenSSLIdentity& other) const { | |
521 return *this->key_pair_ == *other.key_pair_ && | |
522 *this->certificate_ == *other.certificate_; | |
523 } | |
524 | |
525 bool OpenSSLIdentity::operator!=(const OpenSSLIdentity& other) const { | |
526 return !(*this == other); | |
527 } | |
528 | |
478 } // namespace rtc | 529 } // namespace rtc |
479 | 530 |
480 #endif // HAVE_OPENSSL_SSL_H | 531 #endif // HAVE_OPENSSL_SSL_H |
OLD | NEW |