OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/prefs/pref_service.h" | |
9 #include "chrome/browser/browser_process.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/profiles/profile_manager.h" | |
12 #include "chrome/common/pref_names.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 #include "net/base/cert_verify_proc.h" | |
15 #include "net/base/multi_threaded_cert_verifier.h" | |
16 #include "net/base/net_errors.h" | |
17 | |
18 namespace policy { | |
19 | |
20 namespace { | |
21 | |
22 void TaintProfile(void* profile_ptr) { | |
23 Profile* profile = reinterpret_cast<Profile*>(profile_ptr); | |
24 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) | |
25 return; | |
26 profile->GetPrefs()->SetBoolean(prefs::kUsedPolicyCertificatesOnce, true); | |
27 } | |
28 | |
29 void MaybeTaintProfile(const net::CertVerifyResult& verify_result, | |
30 void* profile) { | |
31 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
32 if (verify_result.is_issued_by_additional_trust_anchor) { | |
33 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
34 base::Bind(&TaintProfile, profile)); | |
Ryan Sleevi
2013/03/25 21:09:53
I have no clue if this is (thread) safe, but it su
Joao da Silva
2013/03/31 19:22:14
I'm not sure what it is that you're unsure about h
Ryan Sleevi
2013/04/02 19:16:06
It was concern about profile deletion, yes. If the
| |
35 } | |
36 } | |
37 | |
38 void CallbackWrapper(void* profile, | |
39 const net::CertVerifyResult* verify_result, | |
40 const net::CompletionCallback& callback, | |
41 int error) { | |
42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
43 if (error == net::OK) | |
44 MaybeTaintProfile(*verify_result, profile); | |
45 if (!callback.is_null()) | |
46 callback.Run(error); | |
Ryan Sleevi
2013/03/25 21:09:53
nit: naming could be better
nit: Isn't an error to
Joao da Silva
2013/03/31 19:22:14
Renamed to |original_callback|.
| |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 PolicyCertVerifier::PolicyCertVerifier( | |
52 void* profile, | |
53 net::CertTrustAnchorProvider* trust_anchor_provider) | |
54 : profile_(profile) { | |
55 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
56 net::MultiThreadedCertVerifier* verifier = | |
57 new net::MultiThreadedCertVerifier(net::CertVerifyProc::CreateDefault()); | |
Ryan Sleevi
2013/03/25 21:09:53
Because you added the bool to the SSLInfo, I think
Ryan Sleevi
2013/03/25 23:55:32
I'm an idiot who hadn't had his coffee. Ignore thi
| |
58 verifier->SetCertTrustAnchorProvider(trust_anchor_provider); | |
59 delegate_.reset(verifier); | |
60 } | |
61 | |
62 PolicyCertVerifier::~PolicyCertVerifier() { | |
63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
64 } | |
65 | |
66 int PolicyCertVerifier::Verify(net::X509Certificate* cert, | |
67 const std::string& hostname, | |
68 int flags, | |
69 net::CRLSet* crl_set, | |
70 net::CertVerifyResult* verify_result, | |
71 const net::CompletionCallback& callback, | |
72 RequestHandle* out_req, | |
73 const net::BoundNetLog& net_log) { | |
74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
75 net::CompletionCallback wrapped_callback = | |
76 base::Bind(&CallbackWrapper, profile_, verify_result, callback); | |
77 int error = delegate_->Verify(cert, hostname, flags, crl_set, verify_result, | |
78 wrapped_callback, out_req, net_log); | |
79 if (error == net::OK) | |
80 MaybeTaintProfile(*verify_result, profile_); | |
81 return error; | |
82 } | |
83 | |
84 void PolicyCertVerifier::CancelRequest(RequestHandle req) { | |
85 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
86 delegate_->CancelRequest(req); | |
87 } | |
88 | |
89 } // namespace policy | |
OLD | NEW |