Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: chrome/browser/extensions/api/gcd_private/privet_v3_context_getter.cc

Issue 1994353002: Update CertVerifier::Verify to use RequestParams instead (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@request_params
Patch Set: Rebased Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/ptr_util.h"
10 #include "chrome/common/chrome_content_client.h" 10 #include "chrome/common/chrome_content_client.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/cert/cert_verifier.h" 12 #include "net/cert/cert_verifier.h"
13 #include "net/cert/cert_verify_result.h" 13 #include "net/cert/cert_verify_result.h"
14 #include "net/cert/x509_certificate.h" 14 #include "net/cert/x509_certificate.h"
15 #include "net/url_request/url_request_context.h" 15 #include "net/url_request/url_request_context.h"
16 #include "net/url_request/url_request_context_builder.h" 16 #include "net/url_request/url_request_context_builder.h"
17 17
18 namespace extensions { 18 namespace extensions {
19 19
20 // Class verifies certificate by its fingerprint received using different 20 // Class verifies certificate by its fingerprint received using different
21 // 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
22 // certificate. 22 // certificate.
23 class PrivetV3ContextGetter::CertVerifier : public net::CertVerifier { 23 class PrivetV3ContextGetter::CertVerifier : public net::CertVerifier {
24 public: 24 public:
25 CertVerifier() {} 25 CertVerifier() {}
26 26
27 int Verify(net::X509Certificate* cert, 27 int Verify(const net::CertVerifier::RequestParams& params,
28 const std::string& hostname,
29 const std::string& ocsp_response,
30 int flags,
31 net::CRLSet* crl_set, 28 net::CRLSet* crl_set,
32 net::CertVerifyResult* verify_result, 29 net::CertVerifyResult* verify_result,
33 const net::CompletionCallback& callback, 30 const net::CompletionCallback& callback,
34 std::unique_ptr<Request>* out_req, 31 std::unique_ptr<Request>* out_req,
35 const net::BoundNetLog& net_log) override { 32 const net::BoundNetLog& net_log) override {
36 verify_result->Reset(); 33 verify_result->Reset();
37 verify_result->verified_cert = cert; 34 verify_result->verified_cert = params.certificate();
38 35
39 // Because no trust anchor checking is being performed, don't indicate that 36 // Because no trust anchor checking is being performed, don't indicate that
40 // it came from an OS-trusted root. 37 // it came from an OS-trusted root.
41 verify_result->is_issued_by_known_root = false; 38 verify_result->is_issued_by_known_root = false;
42 // 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
43 // it came from a supplemental trust anchor. 40 // it came from a supplemental trust anchor.
44 verify_result->is_issued_by_additional_trust_anchor = false; 41 verify_result->is_issued_by_additional_trust_anchor = false;
45 // Because no name checking is being performed, don't indicate that it the 42 // Because no name checking is being performed, don't indicate that it the
46 // common name was used. 43 // common name was used.
47 verify_result->common_name_fallback_used = false; 44 verify_result->common_name_fallback_used = false;
48 // Because the signature is not checked, do not indicate any deprecated 45 // Because the signature is not checked, do not indicate any deprecated
49 // signature algorithms were used, even if they might be present. 46 // signature algorithms were used, even if they might be present.
50 verify_result->has_md2 = false; 47 verify_result->has_md2 = false;
51 verify_result->has_md4 = false; 48 verify_result->has_md4 = false;
52 verify_result->has_md5 = false; 49 verify_result->has_md5 = false;
53 verify_result->has_sha1 = false; 50 verify_result->has_sha1 = false;
54 verify_result->has_sha1_leaf = false; 51 verify_result->has_sha1_leaf = false;
55 // Because no chain hashes calculation is being performed, keep hashes 52 // Because no chain hashes calculation is being performed, keep hashes
56 // container clean. 53 // container clean.
57 verify_result->public_key_hashes.clear(); 54 verify_result->public_key_hashes.clear();
58 55
59 verify_result->cert_status = CheckFingerprint(cert, hostname) 56 verify_result->cert_status =
60 ? 0 57 CheckFingerprint(params.certificate(), params.hostname())
61 : net::CERT_STATUS_AUTHORITY_INVALID; 58 ? 0
59 : net::CERT_STATUS_AUTHORITY_INVALID;
62 return net::IsCertStatusError(verify_result->cert_status) 60 return net::IsCertStatusError(verify_result->cert_status)
63 ? net::MapCertStatusToNetError(verify_result->cert_status) 61 ? net::MapCertStatusToNetError(verify_result->cert_status)
64 : net::OK; 62 : net::OK;
65 } 63 }
66 64
67 void AddPairedHost(const std::string& host, 65 void AddPairedHost(const std::string& host,
68 const net::SHA256HashValue& certificate_fingerprint) { 66 const net::SHA256HashValue& certificate_fingerprint) {
69 fingerprints_[host] = certificate_fingerprint; 67 fingerprints_[host] = certificate_fingerprint;
70 } 68 }
71 69
72 private: 70 private:
73 bool CheckFingerprint(net::X509Certificate* cert, 71 bool CheckFingerprint(const scoped_refptr<net::X509Certificate>& cert,
74 const std::string& hostname) const { 72 const std::string& hostname) const {
75 auto it = fingerprints_.find(hostname); 73 auto it = fingerprints_.find(hostname);
76 if (it == fingerprints_.end()) 74 if (it == fingerprints_.end())
77 return false; 75 return false;
78 76
79 return it->second == net::X509Certificate::CalculateFingerprint256( 77 return it->second == net::X509Certificate::CalculateFingerprint256(
80 cert->os_cert_handle()); 78 cert->os_cert_handle());
81 } 79 }
82 80
83 std::map<std::string, net::SHA256HashValue> fingerprints_; 81 std::map<std::string, net::SHA256HashValue> fingerprints_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 const net::SHA256HashValue& certificate_fingerprint) { 129 const net::SHA256HashValue& certificate_fingerprint) {
132 InitOnNetThread(); 130 InitOnNetThread();
133 cert_verifier_->AddPairedHost(host, certificate_fingerprint); 131 cert_verifier_->AddPairedHost(host, certificate_fingerprint);
134 } 132 }
135 133
136 PrivetV3ContextGetter::~PrivetV3ContextGetter() { 134 PrivetV3ContextGetter::~PrivetV3ContextGetter() {
137 DCHECK(net_task_runner_->BelongsToCurrentThread()); 135 DCHECK(net_task_runner_->BelongsToCurrentThread());
138 } 136 }
139 137
140 } // namespace extensions 138 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698