| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // FYI - for remote reports, the timestamp will be overwritten later. | 529 // FYI - for remote reports, the timestamp will be overwritten later. |
| 530 report->set_timestamp(stats_gathering_started_); | 530 report->set_timestamp(stats_gathering_started_); |
| 531 | 531 |
| 532 report->AddInt64(StatsReport::kStatsValueNameSsrc, ssrc); | 532 report->AddInt64(StatsReport::kStatsValueNameSsrc, ssrc); |
| 533 report->AddString(StatsReport::kStatsValueNameTrackId, track_id); | 533 report->AddString(StatsReport::kStatsValueNameTrackId, track_id); |
| 534 // Add the mapping of SSRC to transport. | 534 // Add the mapping of SSRC to transport. |
| 535 report->AddId(StatsReport::kStatsValueNameTransportId, transport_id); | 535 report->AddId(StatsReport::kStatsValueNameTransportId, transport_id); |
| 536 return report; | 536 return report; |
| 537 } | 537 } |
| 538 | 538 |
| 539 StatsReport* StatsCollector::AddOneCertificateReport( | |
| 540 const rtc::SSLCertificate* cert, const StatsReport* issuer) { | |
| 541 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | |
| 542 | |
| 543 // TODO(bemasc): Move this computation to a helper class that caches these | |
| 544 // values to reduce CPU use in GetStats. This will require adding a fast | |
| 545 // SSLCertificate::Equals() method to detect certificate changes. | |
| 546 | |
| 547 std::string digest_algorithm; | |
| 548 if (!cert->GetSignatureDigestAlgorithm(&digest_algorithm)) | |
| 549 return nullptr; | |
| 550 | |
| 551 std::unique_ptr<rtc::SSLFingerprint> ssl_fingerprint( | |
| 552 rtc::SSLFingerprint::Create(digest_algorithm, cert)); | |
| 553 | |
| 554 // SSLFingerprint::Create can fail if the algorithm returned by | |
| 555 // SSLCertificate::GetSignatureDigestAlgorithm is not supported by the | |
| 556 // implementation of SSLCertificate::ComputeDigest. This currently happens | |
| 557 // with MD5- and SHA-224-signed certificates when linked to libNSS. | |
| 558 if (!ssl_fingerprint) | |
| 559 return nullptr; | |
| 560 | |
| 561 std::string fingerprint = ssl_fingerprint->GetRfc4572Fingerprint(); | |
| 562 | |
| 563 rtc::Buffer der_buffer; | |
| 564 cert->ToDER(&der_buffer); | |
| 565 std::string der_base64; | |
| 566 rtc::Base64::EncodeFromArray(der_buffer.data(), der_buffer.size(), | |
| 567 &der_base64); | |
| 568 | |
| 569 StatsReport::Id id(StatsReport::NewTypedId( | |
| 570 StatsReport::kStatsReportTypeCertificate, fingerprint)); | |
| 571 StatsReport* report = reports_.ReplaceOrAddNew(id); | |
| 572 report->set_timestamp(stats_gathering_started_); | |
| 573 report->AddString(StatsReport::kStatsValueNameFingerprint, fingerprint); | |
| 574 report->AddString(StatsReport::kStatsValueNameFingerprintAlgorithm, | |
| 575 digest_algorithm); | |
| 576 report->AddString(StatsReport::kStatsValueNameDer, der_base64); | |
| 577 if (issuer) | |
| 578 report->AddId(StatsReport::kStatsValueNameIssuerId, issuer->id()); | |
| 579 return report; | |
| 580 } | |
| 581 | |
| 582 StatsReport* StatsCollector::AddCertificateReports( | 539 StatsReport* StatsCollector::AddCertificateReports( |
| 583 const rtc::SSLCertificate* cert) { | 540 const rtc::SSLCertificate* cert) { |
| 584 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 541 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 585 // Produces a chain of StatsReports representing this certificate and the rest | |
| 586 // of its chain, and adds those reports to |reports_|. The return value is | |
| 587 // the id of the leaf report. The provided cert must be non-null, so at least | |
| 588 // one report will always be provided and the returned string will never be | |
| 589 // empty. | |
| 590 RTC_DCHECK(cert != NULL); | 542 RTC_DCHECK(cert != NULL); |
| 591 | 543 |
| 592 StatsReport* issuer = nullptr; | 544 std::unique_ptr<rtc::SSLCertificateStats> first_stats = cert->GetStats(); |
| 593 std::unique_ptr<rtc::SSLCertChain> chain = cert->GetChain(); | 545 StatsReport* first_report = nullptr; |
| 594 if (chain) { | 546 StatsReport* prev_report = nullptr; |
| 595 // This loop runs in reverse, i.e. from root to leaf, so that each | 547 for (rtc::SSLCertificateStats* stats = first_stats.get(); stats; |
| 596 // certificate's issuer's report ID is known before the child certificate's | 548 stats = stats->issuer.get()) { |
| 597 // report is generated. The root certificate does not have an issuer ID | 549 StatsReport::Id id(StatsReport::NewTypedId( |
| 598 // value. | 550 StatsReport::kStatsReportTypeCertificate, stats->fingerprint)); |
| 599 for (ptrdiff_t i = chain->GetSize() - 1; i >= 0; --i) { | 551 |
| 600 const rtc::SSLCertificate& cert_i = chain->Get(i); | 552 StatsReport* report = reports_.ReplaceOrAddNew(id); |
| 601 issuer = AddOneCertificateReport(&cert_i, issuer); | 553 report->set_timestamp(stats_gathering_started_); |
| 602 } | 554 report->AddString(StatsReport::kStatsValueNameFingerprint, |
| 555 stats->fingerprint); |
| 556 report->AddString(StatsReport::kStatsValueNameFingerprintAlgorithm, |
| 557 stats->fingerprint_algorithm); |
| 558 report->AddString(StatsReport::kStatsValueNameDer, |
| 559 stats->base64_certificate); |
| 560 if (!first_report) |
| 561 first_report = report; |
| 562 else |
| 563 prev_report->AddId(StatsReport::kStatsValueNameIssuerId, id); |
| 564 prev_report = report; |
| 603 } | 565 } |
| 604 // Add the leaf certificate. | 566 return first_report; |
| 605 return AddOneCertificateReport(cert, issuer); | |
| 606 } | 567 } |
| 607 | 568 |
| 608 StatsReport* StatsCollector::AddConnectionInfoReport( | 569 StatsReport* StatsCollector::AddConnectionInfoReport( |
| 609 const std::string& content_name, int component, int connection_id, | 570 const std::string& content_name, int component, int connection_id, |
| 610 const StatsReport::Id& channel_report_id, | 571 const StatsReport::Id& channel_report_id, |
| 611 const cricket::ConnectionInfo& info) { | 572 const cricket::ConnectionInfo& info) { |
| 612 StatsReport::Id id(StatsReport::NewCandidatePairId(content_name, component, | 573 StatsReport::Id id(StatsReport::NewCandidatePairId(content_name, component, |
| 613 connection_id)); | 574 connection_id)); |
| 614 StatsReport* report = reports_.ReplaceOrAddNew(id); | 575 StatsReport* report = reports_.ReplaceOrAddNew(id); |
| 615 report->set_timestamp(stats_gathering_started_); | 576 report->set_timestamp(stats_gathering_started_); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 StatsReport* report = entry.second; | 961 StatsReport* report = entry.second; |
| 1001 report->set_timestamp(stats_gathering_started_); | 962 report->set_timestamp(stats_gathering_started_); |
| 1002 } | 963 } |
| 1003 } | 964 } |
| 1004 | 965 |
| 1005 void StatsCollector::ClearUpdateStatsCacheForTest() { | 966 void StatsCollector::ClearUpdateStatsCacheForTest() { |
| 1006 stats_gathering_started_ = 0; | 967 stats_gathering_started_ = 0; |
| 1007 } | 968 } |
| 1008 | 969 |
| 1009 } // namespace webrtc | 970 } // namespace webrtc |
| OLD | NEW |