Chromium Code Reviews| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 return peer_certificate_ ? std::unique_ptr<SSLCertificate>( | 306 return peer_certificate_ ? std::unique_ptr<SSLCertificate>( |
| 307 peer_certificate_->GetReference()) | 307 peer_certificate_->GetReference()) |
| 308 : nullptr; | 308 : nullptr; |
| 309 } | 309 } |
| 310 | 310 |
| 311 bool OpenSSLStreamAdapter::SetPeerCertificateDigest(const std::string | 311 bool OpenSSLStreamAdapter::SetPeerCertificateDigest(const std::string |
| 312 &digest_alg, | 312 &digest_alg, |
| 313 const unsigned char* | 313 const unsigned char* |
| 314 digest_val, | 314 digest_val, |
| 315 size_t digest_len) { | 315 size_t digest_len) { |
| 316 ASSERT(!peer_certificate_); | 316 ASSERT(!certificate_verified_); |
| 317 ASSERT(peer_certificate_digest_algorithm_.size() == 0); | 317 ASSERT(!have_peer_certificate_digest()); |
| 318 ASSERT(ssl_server_name_.empty()); | 318 ASSERT(topology_ != TOPOLOGY_CLIENT_SERVER); |
|
pthatcher1
2016/07/22 18:58:27
Should we make these DCHECKS instead of crashing i
Taylor Brandstetter
2016/07/25 23:54:53
ASSERTS are still only run in debug builds. I thin
pthatcher1
2016/07/27 19:32:35
Oh, right. I got confused with CHECK. We have to
| |
| 319 size_t expected_len; | 319 size_t expected_len; |
| 320 | 320 |
| 321 if (!OpenSSLDigest::GetDigestSize(digest_alg, &expected_len)) { | 321 if (!OpenSSLDigest::GetDigestSize(digest_alg, &expected_len)) { |
| 322 LOG(LS_WARNING) << "Unknown digest algorithm: " << digest_alg; | 322 LOG(LS_WARNING) << "Unknown digest algorithm: " << digest_alg; |
| 323 return false; | 323 return false; |
| 324 } | 324 } |
| 325 if (expected_len != digest_len) | 325 if (expected_len != digest_len) { |
| 326 return false; | 326 return false; |
| 327 } | |
| 327 | 328 |
| 328 peer_certificate_digest_value_.SetData(digest_val, digest_len); | 329 peer_certificate_digest_value_.SetData(digest_val, digest_len); |
| 329 peer_certificate_digest_algorithm_ = digest_alg; | 330 peer_certificate_digest_algorithm_ = digest_alg; |
| 330 | 331 |
| 332 if (peer_certificate_) { | |
| 333 if (VerifyPeerCertificate()) { | |
|
pthatcher1
2016/07/22 18:58:27
I'd prefer some early returns:
if (!peer_certific
Taylor Brandstetter
2016/07/25 23:54:53
Done.
| |
| 334 if (state_ == SSL_CONNECTED) { | |
| 335 // Post event to unwind stack. Caller may not be expecting this event | |
| 336 // to occur synchronously. | |
| 337 PostEvent(SE_OPEN | SE_READ | SE_WRITE, 0); | |
| 338 } | |
| 339 } else { | |
| 340 Error("SetPeerCertificateDigest", -1, false); | |
| 341 return false; | |
| 342 } | |
| 343 } | |
| 331 return true; | 344 return true; |
| 332 } | 345 } |
| 333 | 346 |
| 334 std::string OpenSSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { | 347 std::string OpenSSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { |
| 335 #ifdef OPENSSL_IS_BORINGSSL | 348 #ifdef OPENSSL_IS_BORINGSSL |
| 336 const SSL_CIPHER* ssl_cipher = SSL_get_cipher_by_value(cipher_suite); | 349 const SSL_CIPHER* ssl_cipher = SSL_get_cipher_by_value(cipher_suite); |
| 337 if (!ssl_cipher) { | 350 if (!ssl_cipher) { |
| 338 return std::string(); | 351 return std::string(); |
| 339 } | 352 } |
| 340 char* cipher_name = SSL_CIPHER_get_rfc_name(ssl_cipher); | 353 char* cipher_name = SSL_CIPHER_get_rfc_name(ssl_cipher); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 | 475 |
| 463 *crypto_suite = srtp_profile->id; | 476 *crypto_suite = srtp_profile->id; |
| 464 ASSERT(!SrtpCryptoSuiteToName(*crypto_suite).empty()); | 477 ASSERT(!SrtpCryptoSuiteToName(*crypto_suite).empty()); |
| 465 return true; | 478 return true; |
| 466 #else | 479 #else |
| 467 return false; | 480 return false; |
| 468 #endif | 481 #endif |
| 469 } | 482 } |
| 470 | 483 |
| 471 int OpenSSLStreamAdapter::StartSSLWithServer(const char* server_name) { | 484 int OpenSSLStreamAdapter::StartSSLWithServer(const char* server_name) { |
| 485 if (topology_ != TOPOLOGY_UNKNOWN || state_ != SSL_NONE) { | |
| 486 // Don't allow StartSSL to be called twice. | |
| 487 return -1; | |
| 488 } | |
| 472 ASSERT(server_name != NULL && server_name[0] != '\0'); | 489 ASSERT(server_name != NULL && server_name[0] != '\0'); |
| 473 ssl_server_name_ = server_name; | 490 ssl_server_name_ = server_name; |
| 491 topology_ = TOPOLOGY_CLIENT_SERVER; | |
| 474 return StartSSL(); | 492 return StartSSL(); |
| 475 } | 493 } |
| 476 | 494 |
| 477 int OpenSSLStreamAdapter::StartSSLWithPeer() { | 495 int OpenSSLStreamAdapter::StartSSLWithPeer() { |
| 496 if (topology_ != TOPOLOGY_UNKNOWN || state_ != SSL_NONE) { | |
| 497 // Don't allow StartSSL to be called twice. | |
| 498 return -1; | |
| 499 } | |
| 478 ASSERT(ssl_server_name_.empty()); | 500 ASSERT(ssl_server_name_.empty()); |
| 501 topology_ = TOPOLOGY_PEER_TO_PEER; | |
| 479 // It is permitted to specify peer_certificate_ only later. | 502 // It is permitted to specify peer_certificate_ only later. |
| 480 return StartSSL(); | 503 return StartSSL(); |
| 481 } | 504 } |
| 482 | 505 |
| 483 void OpenSSLStreamAdapter::SetMode(SSLMode mode) { | 506 void OpenSSLStreamAdapter::SetMode(SSLMode mode) { |
| 484 ASSERT(state_ == SSL_NONE); | 507 ASSERT(state_ == SSL_NONE); |
| 485 ssl_mode_ = mode; | 508 ssl_mode_ = mode; |
| 486 } | 509 } |
| 487 | 510 |
| 488 void OpenSSLStreamAdapter::SetMaxProtocolVersion(SSLProtocolVersion version) { | 511 void OpenSSLStreamAdapter::SetMaxProtocolVersion(SSLProtocolVersion version) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 501 switch (state_) { | 524 switch (state_) { |
| 502 case SSL_NONE: | 525 case SSL_NONE: |
| 503 // pass-through in clear text | 526 // pass-through in clear text |
| 504 return StreamAdapterInterface::Write(data, data_len, written, error); | 527 return StreamAdapterInterface::Write(data, data_len, written, error); |
| 505 | 528 |
| 506 case SSL_WAIT: | 529 case SSL_WAIT: |
| 507 case SSL_CONNECTING: | 530 case SSL_CONNECTING: |
| 508 return SR_BLOCK; | 531 return SR_BLOCK; |
| 509 | 532 |
| 510 case SSL_CONNECTED: | 533 case SSL_CONNECTED: |
| 534 if (waiting_to_verify_client_cert()) { | |
| 535 return SR_BLOCK; | |
| 536 } | |
| 511 break; | 537 break; |
| 512 | 538 |
| 513 case SSL_ERROR: | 539 case SSL_ERROR: |
| 514 case SSL_CLOSED: | 540 case SSL_CLOSED: |
| 515 default: | 541 default: |
| 516 if (error) | 542 if (error) |
| 517 *error = ssl_error_code_; | 543 *error = ssl_error_code_; |
| 518 return SR_ERROR; | 544 return SR_ERROR; |
| 519 } | 545 } |
| 520 | 546 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 switch (state_) { | 586 switch (state_) { |
| 561 case SSL_NONE: | 587 case SSL_NONE: |
| 562 // pass-through in clear text | 588 // pass-through in clear text |
| 563 return StreamAdapterInterface::Read(data, data_len, read, error); | 589 return StreamAdapterInterface::Read(data, data_len, read, error); |
| 564 | 590 |
| 565 case SSL_WAIT: | 591 case SSL_WAIT: |
| 566 case SSL_CONNECTING: | 592 case SSL_CONNECTING: |
| 567 return SR_BLOCK; | 593 return SR_BLOCK; |
| 568 | 594 |
| 569 case SSL_CONNECTED: | 595 case SSL_CONNECTED: |
| 596 if (waiting_to_verify_client_cert()) { | |
| 597 return SR_BLOCK; | |
| 598 } | |
| 570 break; | 599 break; |
| 571 | 600 |
| 572 case SSL_CLOSED: | 601 case SSL_CLOSED: |
| 573 return SR_EOS; | 602 return SR_EOS; |
| 574 | 603 |
| 575 case SSL_ERROR: | 604 case SSL_ERROR: |
| 576 default: | 605 default: |
| 577 if (error) | 606 if (error) |
| 578 *error = ssl_error_code_; | 607 *error = ssl_error_code_; |
| 579 return SR_ERROR; | 608 return SR_ERROR; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 ASSERT(state_ == SSL_CLOSED || state_ == SSL_ERROR); | 691 ASSERT(state_ == SSL_CLOSED || state_ == SSL_ERROR); |
| 663 StreamAdapterInterface::Close(); | 692 StreamAdapterInterface::Close(); |
| 664 } | 693 } |
| 665 | 694 |
| 666 StreamState OpenSSLStreamAdapter::GetState() const { | 695 StreamState OpenSSLStreamAdapter::GetState() const { |
| 667 switch (state_) { | 696 switch (state_) { |
| 668 case SSL_WAIT: | 697 case SSL_WAIT: |
| 669 case SSL_CONNECTING: | 698 case SSL_CONNECTING: |
| 670 return SS_OPENING; | 699 return SS_OPENING; |
| 671 case SSL_CONNECTED: | 700 case SSL_CONNECTED: |
| 701 if (waiting_to_verify_client_cert()) { | |
| 702 return SS_OPENING; | |
| 703 } | |
| 672 return SS_OPEN; | 704 return SS_OPEN; |
| 673 default: | 705 default: |
| 674 return SS_CLOSED; | 706 return SS_CLOSED; |
| 675 }; | 707 }; |
| 676 // not reached | 708 // not reached |
| 677 } | 709 } |
| 678 | 710 |
| 679 void OpenSSLStreamAdapter::OnEvent(StreamInterface* stream, int events, | 711 void OpenSSLStreamAdapter::OnEvent(StreamInterface* stream, int events, |
| 680 int err) { | 712 int err) { |
| 681 int events_to_signal = 0; | 713 int events_to_signal = 0; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 // SE_CLOSE is the only event that uses the final parameter to OnEvent(). | 757 // SE_CLOSE is the only event that uses the final parameter to OnEvent(). |
| 726 ASSERT(signal_error == 0); | 758 ASSERT(signal_error == 0); |
| 727 signal_error = err; | 759 signal_error = err; |
| 728 } | 760 } |
| 729 if (events_to_signal) | 761 if (events_to_signal) |
| 730 StreamAdapterInterface::OnEvent(stream, events_to_signal, signal_error); | 762 StreamAdapterInterface::OnEvent(stream, events_to_signal, signal_error); |
| 731 } | 763 } |
| 732 | 764 |
| 733 int OpenSSLStreamAdapter::StartSSL() { | 765 int OpenSSLStreamAdapter::StartSSL() { |
| 734 ASSERT(state_ == SSL_NONE); | 766 ASSERT(state_ == SSL_NONE); |
| 767 ASSERT(topology_ != TOPOLOGY_UNKNOWN); | |
| 735 | 768 |
| 736 if (StreamAdapterInterface::GetState() != SS_OPEN) { | 769 if (StreamAdapterInterface::GetState() != SS_OPEN) { |
| 737 state_ = SSL_WAIT; | 770 state_ = SSL_WAIT; |
| 738 return 0; | 771 return 0; |
| 739 } | 772 } |
| 740 | 773 |
| 741 state_ = SSL_CONNECTING; | 774 state_ = SSL_CONNECTING; |
| 742 if (int err = BeginSSL()) { | 775 if (int err = BeginSSL()) { |
| 743 Error("BeginSSL", err, false); | 776 Error("BeginSSL", err, false); |
| 744 return err; | 777 return err; |
| 745 } | 778 } |
| 746 | 779 |
| 747 return 0; | 780 return 0; |
| 748 } | 781 } |
| 749 | 782 |
| 750 int OpenSSLStreamAdapter::BeginSSL() { | 783 int OpenSSLStreamAdapter::BeginSSL() { |
| 751 ASSERT(state_ == SSL_CONNECTING); | 784 ASSERT(state_ == SSL_CONNECTING); |
| 752 // The underlying stream has open. If we are in peer-to-peer mode | |
| 753 // then a peer certificate must have been specified by now. | |
| 754 ASSERT(!ssl_server_name_.empty() || | |
| 755 !peer_certificate_digest_algorithm_.empty()); | |
| 756 LOG(LS_INFO) << "BeginSSL: " | 785 LOG(LS_INFO) << "BeginSSL: " |
| 757 << (!ssl_server_name_.empty() ? ssl_server_name_ : | 786 << (topology_ == TOPOLOGY_CLIENT_SERVER ? ssl_server_name_ |
| 758 "with peer"); | 787 : "with peer"); |
| 759 | 788 |
| 760 BIO* bio = NULL; | 789 BIO* bio = NULL; |
| 761 | 790 |
| 762 // First set up the context | 791 // First set up the context |
| 763 ASSERT(ssl_ctx_ == NULL); | 792 ASSERT(ssl_ctx_ == NULL); |
| 764 ssl_ctx_ = SetupSSLContext(); | 793 ssl_ctx_ = SetupSSLContext(); |
| 765 if (!ssl_ctx_) | 794 if (!ssl_ctx_) |
| 766 return -1; | 795 return -1; |
| 767 | 796 |
| 768 bio = BIO_new_stream(static_cast<StreamInterface*>(stream())); | 797 bio = BIO_new_stream(static_cast<StreamInterface*>(stream())); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 | 847 |
| 819 // Clear the DTLS timer | 848 // Clear the DTLS timer |
| 820 Thread::Current()->Clear(this, MSG_TIMEOUT); | 849 Thread::Current()->Clear(this, MSG_TIMEOUT); |
| 821 | 850 |
| 822 int code = (role_ == SSL_CLIENT) ? SSL_connect(ssl_) : SSL_accept(ssl_); | 851 int code = (role_ == SSL_CLIENT) ? SSL_connect(ssl_) : SSL_accept(ssl_); |
| 823 int ssl_error; | 852 int ssl_error; |
| 824 switch (ssl_error = SSL_get_error(ssl_, code)) { | 853 switch (ssl_error = SSL_get_error(ssl_, code)) { |
| 825 case SSL_ERROR_NONE: | 854 case SSL_ERROR_NONE: |
| 826 LOG(LS_VERBOSE) << " -- success"; | 855 LOG(LS_VERBOSE) << " -- success"; |
| 827 | 856 |
| 828 if (!SSLPostConnectionCheck(ssl_, ssl_server_name_.c_str(), NULL, | 857 if (!SSLPostConnectionCheck()) { |
| 829 peer_certificate_digest_algorithm_)) { | |
| 830 LOG(LS_ERROR) << "TLS post connection check failed"; | 858 LOG(LS_ERROR) << "TLS post connection check failed"; |
| 831 return -1; | 859 return -1; |
| 832 } | 860 } |
| 833 | 861 |
| 834 state_ = SSL_CONNECTED; | 862 state_ = SSL_CONNECTED; |
| 835 StreamAdapterInterface::OnEvent(stream(), SE_OPEN|SE_READ|SE_WRITE, 0); | 863 if (!waiting_to_verify_client_cert()) { |
| 864 // We have everything we need to start the connection, so signal | |
| 865 // SE_OPEN. If we need a client certificate fingerprint and don't have | |
| 866 // it yet, we'll instead signal SE_OPEN in SetPeerCertificateDigest. | |
| 867 StreamAdapterInterface::OnEvent(stream(), SE_OPEN | SE_READ | SE_WRITE, | |
| 868 0); | |
| 869 } | |
| 836 break; | 870 break; |
| 837 | 871 |
| 838 case SSL_ERROR_WANT_READ: { | 872 case SSL_ERROR_WANT_READ: { |
| 839 LOG(LS_VERBOSE) << " -- error want read"; | 873 LOG(LS_VERBOSE) << " -- error want read"; |
| 840 struct timeval timeout; | 874 struct timeval timeout; |
| 841 if (DTLSv1_get_timeout(ssl_, &timeout)) { | 875 if (DTLSv1_get_timeout(ssl_, &timeout)) { |
| 842 int delay = timeout.tv_sec * 1000 + timeout.tv_usec/1000; | 876 int delay = timeout.tv_sec * 1000 + timeout.tv_usec/1000; |
| 843 | 877 |
| 844 Thread::Current()->PostDelayed(RTC_FROM_HERE, delay, this, | 878 Thread::Current()->PostDelayed(RTC_FROM_HERE, delay, this, |
| 845 MSG_TIMEOUT, 0); | 879 MSG_TIMEOUT, 0); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 if (SSL_CTX_set_tlsext_use_srtp(ctx, srtp_ciphers_.c_str())) { | 1069 if (SSL_CTX_set_tlsext_use_srtp(ctx, srtp_ciphers_.c_str())) { |
| 1036 SSL_CTX_free(ctx); | 1070 SSL_CTX_free(ctx); |
| 1037 return NULL; | 1071 return NULL; |
| 1038 } | 1072 } |
| 1039 } | 1073 } |
| 1040 #endif | 1074 #endif |
| 1041 | 1075 |
| 1042 return ctx; | 1076 return ctx; |
| 1043 } | 1077 } |
| 1044 | 1078 |
| 1045 int OpenSSLStreamAdapter::SSLVerifyCallback(int ok, X509_STORE_CTX* store) { | 1079 bool OpenSSLStreamAdapter::VerifyPeerCertificate() { |
| 1046 // Get our SSL structure from the store | 1080 if (!have_peer_certificate_digest() || !peer_certificate_) { |
| 1047 SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data( | 1081 LOG(LS_WARNING) << "Missing digest or peer certificate."; |
| 1048 store, | 1082 return false; |
| 1049 SSL_get_ex_data_X509_STORE_CTX_idx())); | |
| 1050 OpenSSLStreamAdapter* stream = | |
| 1051 reinterpret_cast<OpenSSLStreamAdapter*>(SSL_get_app_data(ssl)); | |
| 1052 | |
| 1053 if (stream->peer_certificate_digest_algorithm_.empty()) { | |
| 1054 return 0; | |
| 1055 } | |
| 1056 X509* cert = X509_STORE_CTX_get_current_cert(store); | |
| 1057 int depth = X509_STORE_CTX_get_error_depth(store); | |
| 1058 | |
| 1059 // For now We ignore the parent certificates and verify the leaf against | |
| 1060 // the digest. | |
| 1061 // | |
| 1062 // TODO(jiayl): Verify the chain is a proper chain and report the chain to | |
| 1063 // |stream->peer_certificate_|. | |
| 1064 if (depth > 0) { | |
| 1065 LOG(LS_INFO) << "Ignored chained certificate at depth " << depth; | |
| 1066 return 1; | |
| 1067 } | 1083 } |
| 1068 | 1084 |
| 1069 unsigned char digest[EVP_MAX_MD_SIZE]; | 1085 unsigned char digest[EVP_MAX_MD_SIZE]; |
| 1070 size_t digest_length; | 1086 size_t digest_length; |
| 1071 if (!OpenSSLCertificate::ComputeDigest( | 1087 if (!OpenSSLCertificate::ComputeDigest( |
| 1072 cert, | 1088 peer_certificate_->x509(), peer_certificate_digest_algorithm_, digest, |
| 1073 stream->peer_certificate_digest_algorithm_, | 1089 sizeof(digest), &digest_length)) { |
| 1074 digest, sizeof(digest), | |
| 1075 &digest_length)) { | |
| 1076 LOG(LS_WARNING) << "Failed to compute peer cert digest."; | 1090 LOG(LS_WARNING) << "Failed to compute peer cert digest."; |
| 1077 return 0; | 1091 return false; |
| 1078 } | 1092 } |
| 1079 | 1093 |
| 1080 Buffer computed_digest(digest, digest_length); | 1094 Buffer computed_digest(digest, digest_length); |
| 1081 if (computed_digest != stream->peer_certificate_digest_value_) { | 1095 if (computed_digest != peer_certificate_digest_value_) { |
| 1082 LOG(LS_WARNING) << "Rejected peer certificate due to mismatched digest."; | 1096 LOG(LS_WARNING) << "Rejected peer certificate due to mismatched digest."; |
| 1083 return 0; | 1097 return 0; |
| 1084 } | 1098 } |
| 1085 // Ignore any verification error if the digest matches, since there is no | 1099 // Ignore any verification error if the digest matches, since there is no |
| 1086 // value in checking the validity of a self-signed cert issued by untrusted | 1100 // value in checking the validity of a self-signed cert issued by untrusted |
| 1087 // sources. | 1101 // sources. |
| 1088 LOG(LS_INFO) << "Accepted peer certificate."; | 1102 LOG(LS_INFO) << "Accepted peer certificate."; |
| 1103 certificate_verified_ = true; | |
| 1104 return true; | |
| 1105 } | |
| 1106 | |
| 1107 int OpenSSLStreamAdapter::SSLVerifyCallback(int ok, X509_STORE_CTX* store) { | |
| 1108 // Get our SSL structure from the store | |
| 1109 SSL* ssl = reinterpret_cast<SSL*>( | |
| 1110 X509_STORE_CTX_get_ex_data(store, SSL_get_ex_data_X509_STORE_CTX_idx())); | |
| 1111 X509* cert = X509_STORE_CTX_get_current_cert(store); | |
| 1112 int depth = X509_STORE_CTX_get_error_depth(store); | |
| 1113 | |
| 1114 // For now we ignore the parent certificates and verify the leaf against | |
| 1115 // the digest. | |
| 1116 // | |
| 1117 // TODO(jiayl): Verify the chain is a proper chain and report the chain to | |
| 1118 // |stream->peer_certificate_|. | |
| 1119 if (depth > 0) { | |
| 1120 LOG(LS_INFO) << "Ignored chained certificate at depth " << depth; | |
| 1121 return 1; | |
| 1122 } | |
| 1123 | |
| 1124 OpenSSLStreamAdapter* stream = | |
| 1125 reinterpret_cast<OpenSSLStreamAdapter*>(SSL_get_app_data(ssl)); | |
| 1089 | 1126 |
| 1090 // Record the peer's certificate. | 1127 // Record the peer's certificate. |
| 1091 stream->peer_certificate_.reset(new OpenSSLCertificate(cert)); | 1128 stream->peer_certificate_.reset(new OpenSSLCertificate(cert)); |
| 1092 return 1; | 1129 |
| 1130 // If the peer certificate digest isn't known yet, we'll wait to verify | |
| 1131 // until it's known, and for now just return a success status. | |
| 1132 if (stream->peer_certificate_digest_algorithm_.empty()) { | |
| 1133 LOG(LS_INFO) << "Waiting to verify certificate until digest is known."; | |
| 1134 return 1; | |
| 1135 } | |
| 1136 | |
| 1137 return stream->VerifyPeerCertificate(); | |
| 1093 } | 1138 } |
| 1094 | 1139 |
| 1095 // This code is taken from the "Network Security with OpenSSL" | 1140 // This code is taken from the "Network Security with OpenSSL" |
| 1096 // sample in chapter 5 | 1141 // sample in chapter 5 |
| 1097 bool OpenSSLStreamAdapter::SSLPostConnectionCheck(SSL* ssl, | 1142 bool OpenSSLStreamAdapter::SSLPostConnectionCheck() { |
| 1098 const char* server_name, | |
| 1099 const X509* peer_cert, | |
| 1100 const std::string | |
| 1101 &peer_digest) { | |
| 1102 ASSERT(server_name != NULL); | |
| 1103 bool ok; | 1143 bool ok; |
| 1104 if (server_name[0] != '\0') { // traditional mode | 1144 if (topology_ == TOPOLOGY_CLIENT_SERVER) { |
| 1105 ok = OpenSSLAdapter::VerifyServerName(ssl, server_name, ignore_bad_cert()); | 1145 ASSERT(!ssl_server_name_.empty()); |
| 1146 ok = OpenSSLAdapter::VerifyServerName(ssl_, ssl_server_name_.c_str(), | |
| 1147 ignore_bad_cert()); | |
| 1106 | 1148 |
| 1107 if (ok) { | 1149 if (ok) { |
| 1108 ok = (SSL_get_verify_result(ssl) == X509_V_OK || | 1150 ok = (SSL_get_verify_result(ssl_) == X509_V_OK || |
| 1109 custom_verification_succeeded_); | 1151 custom_verification_succeeded_); |
| 1110 } | 1152 } |
|
pthatcher1
2016/07/22 18:58:27
We can probably just delete all of this.
| |
| 1111 } else { // peer-to-peer mode | 1153 } else { |
| 1112 ASSERT((peer_cert != NULL) || (!peer_digest.empty())); | 1154 ASSERT(topology_ == TOPOLOGY_PEER_TO_PEER); |
| 1113 // no server name validation | 1155 // no server name validation |
| 1114 ok = true; | 1156 ok = peer_certificate_ || !client_auth_enabled(); |
| 1115 } | 1157 } |
| 1116 | 1158 |
| 1117 if (!ok && ignore_bad_cert()) { | 1159 if (!ok && ignore_bad_cert()) { |
| 1118 LOG(LS_ERROR) << "SSL_get_verify_result(ssl) = " | 1160 LOG(LS_ERROR) << "SSL_get_verify_result(ssl_) = " |
| 1119 << SSL_get_verify_result(ssl); | 1161 << SSL_get_verify_result(ssl_); |
| 1120 LOG(LS_INFO) << "Other TLS post connection checks failed."; | 1162 LOG(LS_INFO) << "Other TLS post connection checks failed."; |
| 1121 ok = true; | 1163 ok = true; |
| 1122 } | 1164 } |
| 1123 | 1165 |
| 1124 return ok; | 1166 return ok; |
| 1125 } | 1167 } |
| 1126 | 1168 |
| 1127 bool OpenSSLStreamAdapter::HaveDtls() { | 1169 bool OpenSSLStreamAdapter::HaveDtls() { |
| 1128 return true; | 1170 return true; |
| 1129 } | 1171 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1219 return true; | 1261 return true; |
| 1220 } | 1262 } |
| 1221 } | 1263 } |
| 1222 | 1264 |
| 1223 return false; | 1265 return false; |
| 1224 } | 1266 } |
| 1225 | 1267 |
| 1226 } // namespace rtc | 1268 } // namespace rtc |
| 1227 | 1269 |
| 1228 #endif // HAVE_OPENSSL_SSL_H | 1270 #endif // HAVE_OPENSSL_SSL_H |
| OLD | NEW |