OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromeos/policy/policy_cert_verifier.h" | 5 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | |
9 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
10 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
11 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
12 #include "net/cert/cert_verify_proc.h" | 11 #include "net/cert/cert_verify_proc.h" |
13 #include "net/cert/multi_threaded_cert_verifier.h" | 12 #include "net/cert/multi_threaded_cert_verifier.h" |
14 | 13 |
15 namespace policy { | 14 namespace policy { |
16 | 15 |
17 namespace { | 16 PolicyCertVerifier::PolicyCertVerifier() |
18 | 17 : weak_ptr_factory_(this), weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { |
19 void MaybeSignalAnchorUse(int error, | |
20 const base::Closure& anchor_used_callback, | |
21 const net::CertVerifyResult& verify_result) { | |
22 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
23 if (error != net::OK || !verify_result.is_issued_by_additional_trust_anchor || | |
24 anchor_used_callback.is_null()) { | |
25 return; | |
26 } | |
27 anchor_used_callback.Run(); | |
28 } | |
29 | |
30 void CompleteAndSignalAnchorUse( | |
31 const base::Closure& anchor_used_callback, | |
32 const net::CompletionCallback& completion_callback, | |
33 const net::CertVerifyResult* verify_result, | |
34 int error) { | |
35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
36 MaybeSignalAnchorUse(error, anchor_used_callback, *verify_result); | |
37 if (!completion_callback.is_null()) | |
38 completion_callback.Run(error); | |
39 } | |
40 | |
41 } // namespace | |
42 | |
43 PolicyCertVerifier::PolicyCertVerifier( | |
44 const base::Closure& anchor_used_callback) | |
45 : anchor_used_callback_(anchor_used_callback) { | |
46 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 18 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
19 anchor_used_callback_list_.reset(new base::CallbackList<void()>()); | |
47 } | 20 } |
48 | 21 |
49 PolicyCertVerifier::~PolicyCertVerifier() { | 22 PolicyCertVerifier::~PolicyCertVerifier() { |
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 23 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
24 DCHECK(!anchor_used_callback_list_); | |
25 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); | |
51 } | 26 } |
52 | 27 |
53 void PolicyCertVerifier::InitializeOnIOThread() { | 28 void PolicyCertVerifier::InitializeOnIOThread() { |
54 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 29 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
55 scoped_refptr<net::CertVerifyProc> verify_proc = | 30 scoped_refptr<net::CertVerifyProc> verify_proc = |
56 net::CertVerifyProc::CreateDefault(); | 31 net::CertVerifyProc::CreateDefault(); |
57 if (!verify_proc->SupportsAdditionalTrustAnchors()) { | 32 if (!verify_proc->SupportsAdditionalTrustAnchors()) { |
58 LOG(WARNING) | 33 LOG(WARNING) |
59 << "Additional trust anchors not supported in the current platform!"; | 34 << "Additional trust anchors not supported in the current platform!"; |
60 } | 35 } |
61 net::MultiThreadedCertVerifier* verifier = | 36 net::MultiThreadedCertVerifier* verifier = |
62 new net::MultiThreadedCertVerifier(verify_proc.get()); | 37 new net::MultiThreadedCertVerifier(verify_proc.get()); |
63 verifier->SetCertTrustAnchorProvider(this); | 38 verifier->SetCertTrustAnchorProvider(this); |
64 delegate_.reset(verifier); | 39 delegate_.reset(verifier); |
65 } | 40 } |
66 | 41 |
42 void PolicyCertVerifier::ShutdownOnUIThread() { | |
43 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
44 anchor_used_callback_list_.reset(); | |
45 weak_ptr_factory_.InvalidateWeakPtrs(); | |
46 } | |
47 | |
48 scoped_ptr<base::CallbackList<void()>::Subscription> | |
49 PolicyCertVerifier::RegisterAnchorUsedCallback(const base::Closure& cb) { | |
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
51 if (anchor_used_callback_list_) | |
52 return anchor_used_callback_list_->Add(cb); | |
53 return scoped_ptr<base::CallbackList<void()>::Subscription>(); | |
54 } | |
55 | |
67 void PolicyCertVerifier::SetTrustAnchors( | 56 void PolicyCertVerifier::SetTrustAnchors( |
68 const net::CertificateList& trust_anchors) { | 57 const net::CertificateList& trust_anchors) { |
69 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
70 trust_anchors_ = trust_anchors; | 59 trust_anchors_ = trust_anchors; |
71 } | 60 } |
72 | 61 |
73 int PolicyCertVerifier::Verify( | 62 int PolicyCertVerifier::Verify( |
74 net::X509Certificate* cert, | 63 net::X509Certificate* cert, |
75 const std::string& hostname, | 64 const std::string& hostname, |
76 int flags, | 65 int flags, |
77 net::CRLSet* crl_set, | 66 net::CRLSet* crl_set, |
78 net::CertVerifyResult* verify_result, | 67 net::CertVerifyResult* verify_result, |
79 const net::CompletionCallback& completion_callback, | 68 const net::CompletionCallback& completion_callback, |
80 RequestHandle* out_req, | 69 RequestHandle* out_req, |
81 const net::BoundNetLog& net_log) { | 70 const net::BoundNetLog& net_log) { |
82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
83 DCHECK(delegate_); | 72 DCHECK(delegate_); |
84 net::CompletionCallback wrapped_callback = | 73 net::CompletionCallback wrapped_callback = |
85 base::Bind(&CompleteAndSignalAnchorUse, | 74 base::Bind(&PolicyCertVerifier::CompleteAndSignalAnchorUse, |
86 anchor_used_callback_, | |
87 completion_callback, | 75 completion_callback, |
88 verify_result); | 76 verify_result, |
77 weak_ptr_factory_.GetWeakPtr()); | |
Joao da Silva
2013/10/16 12:44:58
can't do, this is on IO. Use |weak_ptr_| here
pneubeck (no reviews)
2013/10/22 18:47:41
doh. Of course. That was the original intention wh
| |
89 int error = delegate_->Verify(cert, hostname, flags, crl_set, verify_result, | 78 int error = delegate_->Verify(cert, hostname, flags, crl_set, verify_result, |
90 wrapped_callback, out_req, net_log); | 79 wrapped_callback, out_req, net_log); |
91 MaybeSignalAnchorUse(error, anchor_used_callback_, *verify_result); | 80 MaybeSignalAnchorUse(error, *verify_result, weak_ptr_factory_.GetWeakPtr()); |
Joao da Silva
2013/10/16 12:44:58
Same here, use |weak_ptr_|
pneubeck (no reviews)
2013/10/22 18:47:41
Done.
| |
92 return error; | 81 return error; |
93 } | 82 } |
94 | 83 |
95 void PolicyCertVerifier::CancelRequest(RequestHandle req) { | 84 void PolicyCertVerifier::CancelRequest(RequestHandle req) { |
96 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 85 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
97 delegate_->CancelRequest(req); | 86 delegate_->CancelRequest(req); |
98 } | 87 } |
99 | 88 |
100 const net::CertificateList& PolicyCertVerifier::GetAdditionalTrustAnchors() { | 89 const net::CertificateList& PolicyCertVerifier::GetAdditionalTrustAnchors() { |
101 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 90 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
102 return trust_anchors_; | 91 return trust_anchors_; |
103 } | 92 } |
104 | 93 |
94 void PolicyCertVerifier::RunCallback() { | |
Joao da Silva
2013/10/16 12:44:58
rename to NotifyOnUI
pneubeck (no reviews)
2013/10/22 18:47:41
Done.
| |
95 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
96 anchor_used_callback_list_->Notify(); | |
97 } | |
98 | |
99 // static | |
100 void PolicyCertVerifier::MaybeSignalAnchorUse( | |
101 int error, | |
102 const net::CertVerifyResult& verify_result, | |
103 const base::WeakPtr<PolicyCertVerifier>& weak_ptr) { | |
104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
105 if (error != net::OK || !verify_result.is_issued_by_additional_trust_anchor) | |
106 return; | |
107 | |
108 content::BrowserThread::PostTask( | |
109 content::BrowserThread::UI, | |
110 FROM_HERE, | |
111 base::Bind(&PolicyCertVerifier::RunCallback, weak_ptr)); | |
112 } | |
113 | |
114 // static | |
115 void PolicyCertVerifier::CompleteAndSignalAnchorUse( | |
116 const net::CompletionCallback& completion_callback, | |
117 const net::CertVerifyResult* verify_result, | |
118 const base::WeakPtr<PolicyCertVerifier>& weak_ptr, | |
119 int error) { | |
120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
121 MaybeSignalAnchorUse(error, *verify_result, weak_ptr); | |
122 if (!completion_callback.is_null()) | |
123 completion_callback.Run(error); | |
124 } | |
125 | |
105 } // namespace policy | 126 } // namespace policy |
OLD | NEW |