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

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 1407263010: [Cronet] Public key pinning for Java API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small comment fixes Created 5 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/cronet/android/cronet_url_request_context_adapter.h" 5 #include "components/cronet/android/cronet_url_request_context_adapter.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h"
12 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
13 #include "base/files/scoped_file.h" 14 #include "base/files/scoped_file.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
16 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
17 #include "base/prefs/pref_filter.h" 18 #include "base/prefs/pref_filter.h"
18 #include "base/prefs/pref_registry_simple.h" 19 #include "base/prefs/pref_registry_simple.h"
19 #include "base/prefs/pref_service.h" 20 #include "base/prefs/pref_service.h"
20 #include "base/prefs/pref_service_factory.h" 21 #include "base/prefs/pref_service_factory.h"
21 #include "base/single_thread_task_runner.h" 22 #include "base/single_thread_task_runner.h"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( 306 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager(
306 new net::HttpServerPropertiesManager(pref_service_.get(), 307 new net::HttpServerPropertiesManager(pref_service_.get(),
307 kHttpServerProperties, 308 kHttpServerProperties,
308 GetNetworkTaskRunner())); 309 GetNetworkTaskRunner()));
309 http_server_properties_manager->InitializeOnNetworkThread(); 310 http_server_properties_manager->InitializeOnNetworkThread();
310 http_server_properties_manager_ = http_server_properties_manager.get(); 311 http_server_properties_manager_ = http_server_properties_manager.get();
311 context_builder.SetHttpServerProperties( 312 context_builder.SetHttpServerProperties(
312 http_server_properties_manager.Pass()); 313 http_server_properties_manager.Pass());
313 } 314 }
314 315
316 // Explicitly disable the persister for Cronet to avoid persistence
317 // of dynamic HPKP. This is a safety measure in case if somebody will
318 // enable the persistence by specifying transport_security_persister_path
319 // in the future.
320 #if DCHECK_IS_ON()
mef 2015/11/06 18:02:17 DCHECK_IS_ON() in debug, but not in the release. W
kapishnikov 2015/11/06 19:45:08 The intention was to execute it in debug mode only
321 context_builder.set_transport_security_persister_path(base::FilePath());
322 #endif
323
315 context_ = context_builder.Build().Pass(); 324 context_ = context_builder.Build().Pass();
316 325
317 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | 326 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
318 net::LOAD_DO_NOT_SEND_COOKIES; 327 net::LOAD_DO_NOT_SEND_COOKIES;
319 if (config->load_disable_cache) 328 if (config->load_disable_cache)
320 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 329 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
321 330
322 if (config->enable_sdch) { 331 if (config->enable_sdch) {
323 DCHECK(context_->sdch_manager()); 332 DCHECK(context_->sdch_manager());
324 sdch_owner_.reset( 333 sdch_owner_.reset(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 quic_hint.port); 374 quic_hint.port);
366 net::AlternativeService alternative_service( 375 net::AlternativeService alternative_service(
367 net::AlternateProtocol::QUIC, "", 376 net::AlternateProtocol::QUIC, "",
368 static_cast<uint16>(quic_hint.alternate_port)); 377 static_cast<uint16>(quic_hint.alternate_port));
369 context_->http_server_properties()->SetAlternativeService( 378 context_->http_server_properties()->SetAlternativeService(
370 quic_hint_host_port_pair, alternative_service, 1.0f, 379 quic_hint_host_port_pair, alternative_service, 1.0f,
371 base::Time::Max()); 380 base::Time::Max());
372 } 381 }
373 } 382 }
374 383
384 // Iterate through HPKP configuration for every host.
385 for (auto hpkp_itr = config->hpkp_list.begin();
386 hpkp_itr != config->hpkp_list.end(); ++hpkp_itr) {
387 const URLRequestContextConfig::Hpkp& hpkp = **hpkp_itr;
388
389 // Convert the vector of hash strings from the config to
390 // a vector of HashValue objects.
391 net::HashValueVector hash_value_vector;
392 for (const auto& hash : hpkp.pin_hashes) {
393 auto hash_value = net::HashValue(net::HASH_VALUE_SHA256);
394 bool good_hash = hash_value.FromString(*hash);
395 if (good_hash) {
396 hash_value_vector.push_back(hash_value);
397 } else {
398 LOG(WARNING) << "Unable to add hash value " << *hash;
399 }
400 }
401
mef 2015/11/06 18:02:17 maybe add DCHECK here that context->transport_secu
kapishnikov 2015/11/06 19:45:08 Yes, the problem is that there is no accessor. We
402 // Add the host pinning.
403 context_->transport_security_state()->AddHPKP(
404 hpkp.host, hpkp.expiration_date, hpkp.include_subdomains,
405 hash_value_vector, GURL());
mef 2015/11/06 18:02:17 GURL() -> GURL::EmptyGURL();
kapishnikov 2015/11/06 19:45:09 Done.
406 }
407
375 JNIEnv* env = base::android::AttachCurrentThread(); 408 JNIEnv* env = base::android::AttachCurrentThread();
376 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj()); 409 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj());
377 Java_CronetUrlRequestContext_initNetworkThread( 410 Java_CronetUrlRequestContext_initNetworkThread(
378 env, jcronet_url_request_context.obj()); 411 env, jcronet_url_request_context.obj());
379 412
380 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 413 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
381 if (data_reduction_proxy_) 414 if (data_reduction_proxy_)
382 data_reduction_proxy_->Init(true, GetURLRequestContext()); 415 data_reduction_proxy_->Init(true, GetURLRequestContext());
383 #endif 416 #endif
384 is_context_initialized_ = true; 417 is_context_initialized_ = true;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 static jint SetMinLogLevel(JNIEnv* env, 565 static jint SetMinLogLevel(JNIEnv* env,
533 const JavaParamRef<jclass>& jcaller, 566 const JavaParamRef<jclass>& jcaller,
534 jint jlog_level) { 567 jint jlog_level) {
535 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); 568 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel());
536 // MinLogLevel is global, shared by all URLRequestContexts. 569 // MinLogLevel is global, shared by all URLRequestContexts.
537 logging::SetMinLogLevel(static_cast<int>(jlog_level)); 570 logging::SetMinLogLevel(static_cast<int>(jlog_level));
538 return old_log_level; 571 return old_log_level;
539 } 572 }
540 573
541 } // namespace cronet 574 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698