Skip to content

Commit 1976970

Browse files
committed
Fix additional-trust-anchors
1 parent a03aa3a commit 1976970

File tree

3 files changed

+13
-38
lines changed

3 files changed

+13
-38
lines changed

BUILD.gn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ nw_chrome_browser_sources = [
117117
"src/browser/nw_chrome_browser_hooks.h",
118118
"src/browser/nw_extensions_browser_hooks.cc",
119119
"src/browser/nw_extensions_browser_hooks.h",
120-
"src/policy_cert_verifier.cc",
121-
"src/policy_cert_verifier.h",
120+
#"src/policy_cert_verifier.cc",
121+
#"src/policy_cert_verifier.h",
122122
"src/nw_content_verifier_delegate.cc",
123123
"src/nw_content_verifier_delegate.h",
124124
]

src/browser/nw_chrome_browser_hooks.cc

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
#include "content/nw/src/common/shell_switches.h"
3535
#include "content/public/browser/browser_thread.h"
3636
#include "content/public/browser/child_process_security_policy.h"
37+
#include "content/public/browser/network_service_instance.h"
3738
#include "content/public/browser/render_frame_host.h"
3839
#include "content/public/browser/render_process_host.h"
40+
#include "content/public/browser/storage_partition.h"
3941
#include "content/public/browser/web_contents.h"
4042
#include "content/public/common/result_codes.h"
4143

@@ -58,6 +60,7 @@
5860
#include "sql/meta_table.h"
5961
#include "sql/transaction.h"
6062
#include "storage/common/database/database_identifier.h"
63+
#include "services/network/network_service.h"
6164

6265
#if defined(OS_WIN)
6366
#define _USE_MATH_DEFINES
@@ -188,32 +191,16 @@ bool GetDirUserData(base::FilePath *user_data_dir) {
188191
return base::PathService::Get(chrome::DIR_USER_DATA, user_data_dir);
189192
}
190193

191-
#if 0
192-
void SetTrustAnchorsOnIOThread(const scoped_refptr<net::URLRequestContextGetter>& url_request_getter,
193-
IOThread* io_thread,
194-
const net::CertificateList& trust_anchors) {
195-
PolicyCertVerifier* verifier =
196-
(PolicyCertVerifier*)io_thread->globals()->system_request_context->cert_verifier();
197-
verifier->SetTrustAnchors(trust_anchors);
198-
#if 1
199-
net::URLRequestContext* url_request_context =
200-
url_request_getter->GetURLRequestContext();
201-
PolicyCertVerifier* verifier2 = (PolicyCertVerifier*)url_request_context->cert_verifier();
202-
verifier2->SetTrustAnchors(trust_anchors);
203-
#endif
204-
}
205-
206194
void SetTrustAnchors(net::CertificateList& trust_anchors) {
207195
// LOG(INFO)
208196
// << "Added " << trust_anchors.size() << " certificates to trust anchors.";
197+
#if 0
209198
Profile* profile = ProfileManager::GetActiveUserProfile();
210-
net::URLRequestContextGetter* url_request_context_getter = profile->GetRequestContext();
211-
base::PostTaskWithTraits(FROM_HERE,
212-
{content::BrowserThread::IO},
213-
base::BindOnce(SetTrustAnchorsOnIOThread, base::WrapRefCounted(url_request_context_getter),
214-
g_browser_process->io_thread(), trust_anchors));
215-
}
199+
content::StoragePartition* storage_partition =
200+
content::BrowserContext::GetDefaultStoragePartition(profile);
216201
#endif
202+
content::GetNetworkService()->SetAdditionalTrustAnchors(trust_anchors);
203+
}
217204

218205
void SetAppIcon(gfx::Image &icon) {
219206
g_app_icon = icon;
@@ -389,13 +376,7 @@ void MainPartsPreMainMessageLoopRunHook() {
389376
trust_anchors.insert(trust_anchors.end(), loaded.begin(), loaded.end());
390377
}
391378
if (!trust_anchors.empty()) {
392-
#if !defined(OS_MACOSX)
393-
//SetTrustAnchors(trust_anchors);
394-
#else
395-
net::TestRootCerts* certs = net::TestRootCerts::GetInstance();
396-
for (size_t i = 0; i < trust_anchors.size(); i++)
397-
certs->Add(trust_anchors[i].get());
398-
#endif
379+
SetTrustAnchors(trust_anchors);
399380
}
400381
}
401382
}

src/policy_cert_verifier.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "base/logging.h"
88
#include "base/memory/ptr_util.h"
9-
#include "chrome/browser/browser_process.h"
109
#include "content/public/browser/browser_thread.h"
1110
#include "net/base/net_errors.h"
1211
#include "net/cert/caching_cert_verifier.h"
@@ -20,7 +19,6 @@ namespace {
2019
void MaybeSignalAnchorUse(int error,
2120
const base::Closure& anchor_used_callback,
2221
const net::CertVerifyResult& verify_result) {
23-
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
2422
if (error != net::OK || !verify_result.is_issued_by_additional_trust_anchor ||
2523
anchor_used_callback.is_null()) {
2624
return;
@@ -33,7 +31,6 @@ void CompleteAndSignalAnchorUse(
3331
net::CompletionOnceCallback completion_callback,
3432
const net::CertVerifyResult* verify_result,
3533
int error) {
36-
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
3734
MaybeSignalAnchorUse(error, anchor_used_callback, *verify_result);
3835
std::move(completion_callback).Run(error);
3936
}
@@ -53,16 +50,15 @@ net::CertVerifier::Config ExtendTrustAnchors(
5350
PolicyCertVerifier::PolicyCertVerifier(
5451
const base::Closure& anchor_used_callback)
5552
: anchor_used_callback_(anchor_used_callback) {
53+
LOG(WARNING) << "===> PolicyCertVerifier::PolicyCertVerifier";
5654
//DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
5755
}
5856

5957
PolicyCertVerifier::~PolicyCertVerifier() {
60-
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
6158
}
6259

6360
void PolicyCertVerifier::InitializeOnIOThread(
6461
const scoped_refptr<net::CertVerifyProc>& verify_proc) {
65-
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
6662
if (!verify_proc->SupportsAdditionalTrustAnchors()) {
6763
LOG(WARNING)
6864
<< "Additional trust anchors not supported on the current platform!";
@@ -74,7 +70,7 @@ void PolicyCertVerifier::InitializeOnIOThread(
7470

7571
void PolicyCertVerifier::SetTrustAnchors(
7672
const net::CertificateList& trust_anchors) {
77-
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
73+
LOG(WARNING) << "===> PolicyCertVerifier::SetTrustAnchors";
7874
if (trust_anchors == trust_anchors_)
7975
return;
8076
trust_anchors_ = trust_anchors;
@@ -89,7 +85,6 @@ int PolicyCertVerifier::Verify(
8985
net::CompletionOnceCallback completion_callback,
9086
std::unique_ptr<Request>* out_req,
9187
const net::NetLogWithSource& net_log) {
92-
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
9388
DCHECK(delegate_);
9489
net::CompletionOnceCallback wrapped_callback =
9590
base::BindOnce(&CompleteAndSignalAnchorUse,
@@ -104,7 +99,6 @@ int PolicyCertVerifier::Verify(
10499
}
105100

106101
void PolicyCertVerifier::SetConfig(const Config& config) {
107-
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
108102
orig_config_ = config;
109103
delegate_->SetConfig(ExtendTrustAnchors(orig_config_, trust_anchors_));
110104
}

0 commit comments

Comments
 (0)