| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/gcd_private/privet_v3_context_getter.h" | 5 #include "chrome/browser/extensions/api/gcd_private/privet_v3_context_getter.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "chrome/common/chrome_content_client.h" | 10 #include "chrome/common/chrome_content_client.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "net/cert/cert_verifier.h" | 12 #include "net/cert/cert_verifier.h" |
| 12 #include "net/cert/cert_verify_result.h" | 13 #include "net/cert/cert_verify_result.h" |
| 13 #include "net/cert/x509_certificate.h" | 14 #include "net/cert/x509_certificate.h" |
| 14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_context_builder.h" | 16 #include "net/url_request/url_request_context_builder.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 // Class verifies certificate by its fingerprint received using different | 20 // Class verifies certificate by its fingerprint received using different |
| 20 // channel. It's the only know information about device with self-signed | 21 // channel. It's the only know information about device with self-signed |
| 21 // certificate. | 22 // certificate. |
| 22 class PrivetV3ContextGetter::CertVerifier : public net::CertVerifier { | 23 class PrivetV3ContextGetter::CertVerifier : public net::CertVerifier { |
| 23 public: | 24 public: |
| 24 CertVerifier() {} | 25 CertVerifier() {} |
| 25 | 26 |
| 26 int Verify(net::X509Certificate* cert, | 27 int Verify(net::X509Certificate* cert, |
| 27 const std::string& hostname, | 28 const std::string& hostname, |
| 28 const std::string& ocsp_response, | 29 const std::string& ocsp_response, |
| 29 int flags, | 30 int flags, |
| 30 net::CRLSet* crl_set, | 31 net::CRLSet* crl_set, |
| 31 net::CertVerifyResult* verify_result, | 32 net::CertVerifyResult* verify_result, |
| 32 const net::CompletionCallback& callback, | 33 const net::CompletionCallback& callback, |
| 33 scoped_ptr<Request>* out_req, | 34 std::unique_ptr<Request>* out_req, |
| 34 const net::BoundNetLog& net_log) override { | 35 const net::BoundNetLog& net_log) override { |
| 35 verify_result->Reset(); | 36 verify_result->Reset(); |
| 36 verify_result->verified_cert = cert; | 37 verify_result->verified_cert = cert; |
| 37 | 38 |
| 38 // Because no trust anchor checking is being performed, don't indicate that | 39 // Because no trust anchor checking is being performed, don't indicate that |
| 39 // it came from an OS-trusted root. | 40 // it came from an OS-trusted root. |
| 40 verify_result->is_issued_by_known_root = false; | 41 verify_result->is_issued_by_known_root = false; |
| 41 // Because no trust anchor checking is being performed, don't indicate that | 42 // Because no trust anchor checking is being performed, don't indicate that |
| 42 // it came from a supplemental trust anchor. | 43 // it came from a supplemental trust anchor. |
| 43 verify_result->is_issued_by_additional_trust_anchor = false; | 44 verify_result->is_issued_by_additional_trust_anchor = false; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 102 |
| 102 void PrivetV3ContextGetter::InitOnNetThread() { | 103 void PrivetV3ContextGetter::InitOnNetThread() { |
| 103 DCHECK(net_task_runner_->BelongsToCurrentThread()); | 104 DCHECK(net_task_runner_->BelongsToCurrentThread()); |
| 104 if (!context_) { | 105 if (!context_) { |
| 105 net::URLRequestContextBuilder builder; | 106 net::URLRequestContextBuilder builder; |
| 106 | 107 |
| 107 builder.set_proxy_service(net::ProxyService::CreateDirect()); | 108 builder.set_proxy_service(net::ProxyService::CreateDirect()); |
| 108 builder.SetSpdyAndQuicEnabled(false, false); | 109 builder.SetSpdyAndQuicEnabled(false, false); |
| 109 builder.DisableHttpCache(); | 110 builder.DisableHttpCache(); |
| 110 cert_verifier_ = new CertVerifier(); | 111 cert_verifier_ = new CertVerifier(); |
| 111 builder.SetCertVerifier(make_scoped_ptr(cert_verifier_)); | 112 builder.SetCertVerifier(base::WrapUnique(cert_verifier_)); |
| 112 builder.set_user_agent(::GetUserAgent()); | 113 builder.set_user_agent(::GetUserAgent()); |
| 113 context_ = builder.Build(); | 114 context_ = builder.Build(); |
| 114 } | 115 } |
| 115 } | 116 } |
| 116 | 117 |
| 117 void PrivetV3ContextGetter::AddPairedHost( | 118 void PrivetV3ContextGetter::AddPairedHost( |
| 118 const std::string& host, | 119 const std::string& host, |
| 119 const net::SHA256HashValue& certificate_fingerprint, | 120 const net::SHA256HashValue& certificate_fingerprint, |
| 120 const base::Closure& callback) { | 121 const base::Closure& callback) { |
| 121 net_task_runner_->PostTaskAndReply( | 122 net_task_runner_->PostTaskAndReply( |
| 122 FROM_HERE, | 123 FROM_HERE, |
| 123 base::Bind(&PrivetV3ContextGetter::AddPairedHostOnNetThread, | 124 base::Bind(&PrivetV3ContextGetter::AddPairedHostOnNetThread, |
| 124 weak_ptr_factory_.GetWeakPtr(), host, certificate_fingerprint), | 125 weak_ptr_factory_.GetWeakPtr(), host, certificate_fingerprint), |
| 125 callback); | 126 callback); |
| 126 } | 127 } |
| 127 | 128 |
| 128 void PrivetV3ContextGetter::AddPairedHostOnNetThread( | 129 void PrivetV3ContextGetter::AddPairedHostOnNetThread( |
| 129 const std::string& host, | 130 const std::string& host, |
| 130 const net::SHA256HashValue& certificate_fingerprint) { | 131 const net::SHA256HashValue& certificate_fingerprint) { |
| 131 InitOnNetThread(); | 132 InitOnNetThread(); |
| 132 cert_verifier_->AddPairedHost(host, certificate_fingerprint); | 133 cert_verifier_->AddPairedHost(host, certificate_fingerprint); |
| 133 } | 134 } |
| 134 | 135 |
| 135 PrivetV3ContextGetter::~PrivetV3ContextGetter() { | 136 PrivetV3ContextGetter::~PrivetV3ContextGetter() { |
| 136 DCHECK(net_task_runner_->BelongsToCurrentThread()); | 137 DCHECK(net_task_runner_->BelongsToCurrentThread()); |
| 137 } | 138 } |
| 138 | 139 |
| 139 } // namespace extensions | 140 } // namespace extensions |
| OLD | NEW |