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

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: Hostname validation using IDN.USE_STD3_ASCII_RULES and conflict resolution 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_array.h" 10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
14 #include "base/files/scoped_file.h" 15 #include "base/files/scoped_file.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
18 #include "base/metrics/statistics_recorder.h" 19 #include "base/metrics/statistics_recorder.h"
19 #include "base/prefs/pref_filter.h" 20 #include "base/prefs/pref_filter.h"
20 #include "base/prefs/pref_registry_simple.h" 21 #include "base/prefs/pref_registry_simple.h"
21 #include "base/prefs/pref_service.h" 22 #include "base/prefs/pref_service.h"
22 #include "base/prefs/pref_service_factory.h" 23 #include "base/prefs/pref_service_factory.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager( 309 scoped_ptr<net::HttpServerPropertiesManager> http_server_properties_manager(
309 new net::HttpServerPropertiesManager(pref_service_.get(), 310 new net::HttpServerPropertiesManager(pref_service_.get(),
310 kHttpServerProperties, 311 kHttpServerProperties,
311 GetNetworkTaskRunner())); 312 GetNetworkTaskRunner()));
312 http_server_properties_manager->InitializeOnNetworkThread(); 313 http_server_properties_manager->InitializeOnNetworkThread();
313 http_server_properties_manager_ = http_server_properties_manager.get(); 314 http_server_properties_manager_ = http_server_properties_manager.get();
314 context_builder.SetHttpServerProperties( 315 context_builder.SetHttpServerProperties(
315 http_server_properties_manager.Pass()); 316 http_server_properties_manager.Pass());
316 } 317 }
317 318
319 // Explicitly disable the persister for Cronet to avoid persistence of dynamic
320 // HPKP. This is a safety measure ensuring that nobody enables the persistence
321 // of HPKP by specifying transport_security_persister_path in the future.
322 context_builder.set_transport_security_persister_path(base::FilePath());
323
318 context_ = context_builder.Build().Pass(); 324 context_ = context_builder.Build().Pass();
319 325
320 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | 326 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES |
321 net::LOAD_DO_NOT_SEND_COOKIES; 327 net::LOAD_DO_NOT_SEND_COOKIES;
322 if (config->load_disable_cache) 328 if (config->load_disable_cache)
323 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 329 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
324 330
325 if (config->enable_sdch) { 331 if (config->enable_sdch) {
326 DCHECK(context_->sdch_manager()); 332 DCHECK(context_->sdch_manager());
327 sdch_owner_.reset( 333 sdch_owner_.reset(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 quic_hint.port); 374 quic_hint.port);
369 net::AlternativeService alternative_service( 375 net::AlternativeService alternative_service(
370 net::AlternateProtocol::QUIC, "", 376 net::AlternateProtocol::QUIC, "",
371 static_cast<uint16>(quic_hint.alternate_port)); 377 static_cast<uint16>(quic_hint.alternate_port));
372 context_->http_server_properties()->SetAlternativeService( 378 context_->http_server_properties()->SetAlternativeService(
373 quic_hint_host_port_pair, alternative_service, 1.0f, 379 quic_hint_host_port_pair, alternative_service, 1.0f,
374 base::Time::Max()); 380 base::Time::Max());
375 } 381 }
376 } 382 }
377 383
384 // Iterate through PKP configuration for every host.
385 for (const auto& pkp : config->pkp_list) {
386 // Convert the vector of hash strings from the config to
387 // a vector of HashValue objects.
388 net::HashValueVector hash_value_vector;
389 for (const auto& hash : pkp->pin_hashes) {
390 auto hash_value = net::HashValue(net::HASH_VALUE_SHA256);
391 bool good_hash = hash_value.FromString(*hash);
392 if (good_hash) {
393 hash_value_vector.push_back(hash_value);
394 } else {
395 LOG(WARNING) << "Unable to add hash value " << *hash;
396 }
397 }
398
399 // Add the host pinning.
400 context_->transport_security_state()->AddHPKP(
401 pkp->host, pkp->expiration_date, pkp->include_subdomains,
402 hash_value_vector, GURL::EmptyGURL());
403 }
404
378 JNIEnv* env = base::android::AttachCurrentThread(); 405 JNIEnv* env = base::android::AttachCurrentThread();
379 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj()); 406 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj());
380 Java_CronetUrlRequestContext_initNetworkThread( 407 Java_CronetUrlRequestContext_initNetworkThread(
381 env, jcronet_url_request_context.obj()); 408 env, jcronet_url_request_context.obj());
382 409
383 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 410 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
384 if (data_reduction_proxy_) 411 if (data_reduction_proxy_)
385 data_reduction_proxy_->Init(true, GetURLRequestContext()); 412 data_reduction_proxy_->Init(true, GetURLRequestContext());
386 #endif 413 #endif
387 is_context_initialized_ = true; 414 is_context_initialized_ = true;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 JNIEnv* env, 572 JNIEnv* env,
546 const JavaParamRef<jclass>& jcaller) { 573 const JavaParamRef<jclass>& jcaller) {
547 base::StatisticsRecorder::Initialize(); 574 base::StatisticsRecorder::Initialize();
548 std::vector<uint8> data; 575 std::vector<uint8> data;
549 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 576 if (!HistogramManager::GetInstance()->GetDeltas(&data))
550 return ScopedJavaLocalRef<jbyteArray>(); 577 return ScopedJavaLocalRef<jbyteArray>();
551 return base::android::ToJavaByteArray(env, &data[0], data.size()); 578 return base::android::ToJavaByteArray(env, &data[0], data.size());
552 } 579 }
553 580
554 } // namespace cronet 581 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698