| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.net.http.HttpResponseCache; | 9 import android.net.http.HttpResponseCache; |
| 10 import android.support.annotation.IntDef; | 10 import android.support.annotation.IntDef; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 mExpirationDate = expirationDate; | 95 mExpirationDate = expirationDate; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[
0-9\\.]*$"); | 99 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[
0-9\\.]*$"); |
| 100 | 100 |
| 101 // Private fields are simply storage of configuration for the resulting
CronetEngine. | 101 // Private fields are simply storage of configuration for the resulting
CronetEngine. |
| 102 // See setters below for verbose descriptions. | 102 // See setters below for verbose descriptions. |
| 103 private final Context mContext; | 103 private final Context mContext; |
| 104 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); | 104 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); |
| 105 private final List<Pkp> mPkps = new LinkedList<>(); | 105 private final List<Pkp> mPkps = new LinkedList<Pkp>(); |
| 106 private boolean mPublicKeyPinningBypassForLocalTrustAnchorsEnabled; | |
| 107 private String mUserAgent; | 106 private String mUserAgent; |
| 108 private String mStoragePath; | 107 private String mStoragePath; |
| 109 private boolean mLegacyModeEnabled; | 108 private boolean mLegacyModeEnabled; |
| 110 private LibraryLoader mLibraryLoader; | 109 private LibraryLoader mLibraryLoader; |
| 111 private String mLibraryName; | 110 private String mLibraryName; |
| 112 private boolean mQuicEnabled; | 111 private boolean mQuicEnabled; |
| 113 private boolean mHttp2Enabled; | 112 private boolean mHttp2Enabled; |
| 114 private boolean mSdchEnabled; | 113 private boolean mSdchEnabled; |
| 115 private String mDataReductionProxyKey; | 114 private String mDataReductionProxyKey; |
| 116 private String mDataReductionProxyPrimaryProxy; | 115 private String mDataReductionProxyPrimaryProxy; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 129 */ | 128 */ |
| 130 public Builder(Context context) { | 129 public Builder(Context context) { |
| 131 mContext = context; | 130 mContext = context; |
| 132 setLibraryName("cronet"); | 131 setLibraryName("cronet"); |
| 133 enableLegacyMode(false); | 132 enableLegacyMode(false); |
| 134 enableQUIC(false); | 133 enableQUIC(false); |
| 135 enableHTTP2(true); | 134 enableHTTP2(true); |
| 136 enableSDCH(false); | 135 enableSDCH(false); |
| 137 enableHttpCache(HTTP_CACHE_DISABLED, 0); | 136 enableHttpCache(HTTP_CACHE_DISABLED, 0); |
| 138 enableNetworkQualityEstimator(false); | 137 enableNetworkQualityEstimator(false); |
| 139 enablePublicKeyPinningBypassForLocalTrustAnchors(true); | |
| 140 } | 138 } |
| 141 | 139 |
| 142 /** | 140 /** |
| 143 * Constructs a User-Agent string including application name and version
, | 141 * Constructs a User-Agent string including application name and version
, |
| 144 * system build version, model and id, and Cronet version. | 142 * system build version, model and id, and Cronet version. |
| 145 * | 143 * |
| 146 * @return User-Agent string. | 144 * @return User-Agent string. |
| 147 */ | 145 */ |
| 148 public String getDefaultUserAgent() { | 146 public String getDefaultUserAgent() { |
| 149 return UserAgent.from(mContext); | 147 return UserAgent.from(mContext); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 537 |
| 540 /** | 538 /** |
| 541 * Returns list of public key pins. | 539 * Returns list of public key pins. |
| 542 * @return list of public key pins. | 540 * @return list of public key pins. |
| 543 */ | 541 */ |
| 544 List<Pkp> publicKeyPins() { | 542 List<Pkp> publicKeyPins() { |
| 545 return mPkps; | 543 return mPkps; |
| 546 } | 544 } |
| 547 | 545 |
| 548 /** | 546 /** |
| 549 * Enables or disables public key pinning bypass for local trust anchors
. Disabling the | |
| 550 * bypass for local trust anchors is highly discouraged since it may pro
hibit the app | |
| 551 * from communicating with the pinned hosts. E.g., a user may want to se
nd all traffic | |
| 552 * through an SSL enabled proxy by changing the device proxy settings an
d adding the | |
| 553 * proxy certificate to the list of local trust anchor. Disabling the by
pass will most | |
| 554 * likly prevent the app from sending any traffic to the pinned hosts. F
or more | |
| 555 * information see 'How does key pinning interact with local proxies and
filters?' at | |
| 556 * https://www.chromium.org/Home/chromium-security/security-faq | |
| 557 * | |
| 558 * @param value {@code true} to enable the bypass, {@code false} to disa
ble. | |
| 559 * @return the builder to facilitate chaining. | |
| 560 */ | |
| 561 public Builder enablePublicKeyPinningBypassForLocalTrustAnchors(boolean
value) { | |
| 562 mPublicKeyPinningBypassForLocalTrustAnchorsEnabled = value; | |
| 563 return this; | |
| 564 } | |
| 565 | |
| 566 boolean publicKeyPinningBypassForLocalTrustAnchorsEnabled() { | |
| 567 return mPublicKeyPinningBypassForLocalTrustAnchorsEnabled; | |
| 568 } | |
| 569 | |
| 570 /** | |
| 571 * Checks whether a given string represents a valid host name for PKP an
d converts it | 547 * Checks whether a given string represents a valid host name for PKP an
d converts it |
| 572 * to ASCII Compatible Encoding representation according to RFC 1122, RF
C 1123 and | 548 * to ASCII Compatible Encoding representation according to RFC 1122, RF
C 1123 and |
| 573 * RFC 3490. This method is more restrictive than required by RFC 7469.
Thus, a host | 549 * RFC 3490. This method is more restrictive than required by RFC 7469.
Thus, a host |
| 574 * that contains digits and the dot character only is considered invalid
. | 550 * that contains digits and the dot character only is considered invalid
. |
| 575 * | 551 * |
| 576 * Note: Currently Cronet doesn't have native implementation of host nam
e validation that | 552 * Note: Currently Cronet doesn't have native implementation of host nam
e validation that |
| 577 * can be used. There is code that parses a provided URL but doesn
't ensure its | 553 * can be used. There is code that parses a provided URL but doesn
't ensure its |
| 578 * correctness. The implementation relies on {@code getaddrinfo} f
unction. | 554 * correctness. The implementation relies on {@code getaddrinfo} f
unction. |
| 579 * | 555 * |
| 580 * @param hostName host name to check and convert. | 556 * @param hostName host name to check and convert. |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 * @hide as it's a prototype. | 1147 * @hide as it's a prototype. |
| 1172 */ | 1148 */ |
| 1173 public interface RequestFinishedListener { | 1149 public interface RequestFinishedListener { |
| 1174 /** | 1150 /** |
| 1175 * Invoked with request info. | 1151 * Invoked with request info. |
| 1176 * @param requestInfo {@link UrlRequestInfo} for finished request. | 1152 * @param requestInfo {@link UrlRequestInfo} for finished request. |
| 1177 */ | 1153 */ |
| 1178 void onRequestFinished(UrlRequestInfo requestInfo); | 1154 void onRequestFinished(UrlRequestInfo requestInfo); |
| 1179 } | 1155 } |
| 1180 } | 1156 } |
| OLD | NEW |