| 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.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
| 8 | 8 |
| 9 import org.json.JSONObject; | 9 import org.json.JSONObject; |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 private static final String CERT_USED = "quic_test.example.com.crt"; | 27 private static final String CERT_USED = "quic_test.example.com.crt"; |
| 28 private static final String[] CERTS_USED = {CERT_USED}; | 28 private static final String[] CERTS_USED = {CERT_USED}; |
| 29 private static final int DISTANT_FUTURE = Integer.MAX_VALUE; | 29 private static final int DISTANT_FUTURE = Integer.MAX_VALUE; |
| 30 private static final boolean INCLUDE_SUBDOMAINS = true; | 30 private static final boolean INCLUDE_SUBDOMAINS = true; |
| 31 private static final boolean EXCLUDE_SUBDOMAINS = false; | 31 private static final boolean EXCLUDE_SUBDOMAINS = false; |
| 32 private static final boolean KNOWN_ROOT = true; | 32 private static final boolean KNOWN_ROOT = true; |
| 33 private static final boolean UNKNOWN_ROOT = false; | 33 private static final boolean UNKNOWN_ROOT = false; |
| 34 private static final boolean ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = true; | 34 private static final boolean ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = true; |
| 35 private static final boolean DISABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = fals
e; | 35 private static final boolean DISABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS = fals
e; |
| 36 | 36 |
| 37 private CronetTestFramework mTestFramework; | 37 private CronetEngine mCronetEngine; |
| 38 private ExperimentalCronetEngine.Builder mBuilder; | 38 private ExperimentalCronetEngine.Builder mBuilder; |
| 39 private TestUrlRequestCallback mListener; | 39 private TestUrlRequestCallback mListener; |
| 40 private String mServerUrl; // https://test.example.com:6121 | 40 private String mServerUrl; // https://test.example.com:6121 |
| 41 private String mServerHost; // test.example.com | 41 private String mServerHost; // test.example.com |
| 42 private String mDomain; // example.com | 42 private String mDomain; // example.com |
| 43 | 43 |
| 44 @Override | 44 @Override |
| 45 protected void setUp() throws Exception { | 45 protected void setUp() throws Exception { |
| 46 super.setUp(); | 46 super.setUp(); |
| 47 // Start QUIC Test Server | 47 // Start QUIC Test Server |
| (...skipping 17 matching lines...) Expand all Loading... |
| 65 * | 65 * |
| 66 * @throws Exception | 66 * @throws Exception |
| 67 */ | 67 */ |
| 68 @SmallTest | 68 @SmallTest |
| 69 @Feature({"Cronet"}) | 69 @Feature({"Cronet"}) |
| 70 @OnlyRunNativeCronet | 70 @OnlyRunNativeCronet |
| 71 public void testErrorCodeIfPinDoesNotMatch() throws Exception { | 71 public void testErrorCodeIfPinDoesNotMatch() throws Exception { |
| 72 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 72 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 73 byte[] nonMatchingHash = generateSomeSha256(); | 73 byte[] nonMatchingHash = generateSomeSha256(); |
| 74 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); | 74 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); |
| 75 startCronetFramework(); | 75 startCronetEngine(); |
| 76 sendRequestAndWaitForResult(); | 76 sendRequestAndWaitForResult(); |
| 77 | 77 |
| 78 assertErrorResponse(); | 78 assertErrorResponse(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * Tests the case when the pin hash matches. The client is expected to | 82 * Tests the case when the pin hash matches. The client is expected to |
| 83 * receive the successful response with the response code 200. | 83 * receive the successful response with the response code 200. |
| 84 * | 84 * |
| 85 * @throws Exception | 85 * @throws Exception |
| 86 */ | 86 */ |
| 87 @SmallTest | 87 @SmallTest |
| 88 @Feature({"Cronet"}) | 88 @Feature({"Cronet"}) |
| 89 @OnlyRunNativeCronet | 89 @OnlyRunNativeCronet |
| 90 public void testSuccessIfPinMatches() throws Exception { | 90 public void testSuccessIfPinMatches() throws Exception { |
| 91 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 91 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 92 // Get PKP hash of the real certificate | 92 // Get PKP hash of the real certificate |
| 93 X509Certificate cert = readCertFromFileInPemFormat(CERT_USED); | 93 X509Certificate cert = readCertFromFileInPemFormat(CERT_USED); |
| 94 byte[] matchingHash = CertTestUtil.getPublicKeySha256(cert); | 94 byte[] matchingHash = CertTestUtil.getPublicKeySha256(cert); |
| 95 | 95 |
| 96 addPkpSha256(mServerHost, matchingHash, EXCLUDE_SUBDOMAINS, DISTANT_FUTU
RE); | 96 addPkpSha256(mServerHost, matchingHash, EXCLUDE_SUBDOMAINS, DISTANT_FUTU
RE); |
| 97 startCronetFramework(); | 97 startCronetEngine(); |
| 98 sendRequestAndWaitForResult(); | 98 sendRequestAndWaitForResult(); |
| 99 | 99 |
| 100 assertSuccessfulResponse(); | 100 assertSuccessfulResponse(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * Tests the case when the pin hash does not match and the client accesses t
he subdomain of | 104 * Tests the case when the pin hash does not match and the client accesses t
he subdomain of |
| 105 * the configured PKP host with includeSubdomains flag set to true. The clie
nt is | 105 * the configured PKP host with includeSubdomains flag set to true. The clie
nt is |
| 106 * expected to receive the error response. | 106 * expected to receive the error response. |
| 107 * | 107 * |
| 108 * @throws Exception | 108 * @throws Exception |
| 109 */ | 109 */ |
| 110 @SmallTest | 110 @SmallTest |
| 111 @Feature({"Cronet"}) | 111 @Feature({"Cronet"}) |
| 112 @OnlyRunNativeCronet | 112 @OnlyRunNativeCronet |
| 113 public void testIncludeSubdomainsFlagEqualTrue() throws Exception { | 113 public void testIncludeSubdomainsFlagEqualTrue() throws Exception { |
| 114 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 114 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 115 byte[] nonMatchingHash = generateSomeSha256(); | 115 byte[] nonMatchingHash = generateSomeSha256(); |
| 116 addPkpSha256(mDomain, nonMatchingHash, INCLUDE_SUBDOMAINS, DISTANT_FUTUR
E); | 116 addPkpSha256(mDomain, nonMatchingHash, INCLUDE_SUBDOMAINS, DISTANT_FUTUR
E); |
| 117 startCronetFramework(); | 117 startCronetEngine(); |
| 118 sendRequestAndWaitForResult(); | 118 sendRequestAndWaitForResult(); |
| 119 | 119 |
| 120 assertErrorResponse(); | 120 assertErrorResponse(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Tests the case when the pin hash does not match and the client accesses t
he subdomain of | 124 * Tests the case when the pin hash does not match and the client accesses t
he subdomain of |
| 125 * the configured PKP host with includeSubdomains flag set to false. The cli
ent is expected to | 125 * the configured PKP host with includeSubdomains flag set to false. The cli
ent is expected to |
| 126 * receive the successful response with the response code 200. | 126 * receive the successful response with the response code 200. |
| 127 * | 127 * |
| 128 * @throws Exception | 128 * @throws Exception |
| 129 */ | 129 */ |
| 130 @SmallTest | 130 @SmallTest |
| 131 @Feature({"Cronet"}) | 131 @Feature({"Cronet"}) |
| 132 @OnlyRunNativeCronet | 132 @OnlyRunNativeCronet |
| 133 public void testIncludeSubdomainsFlagEqualFalse() throws Exception { | 133 public void testIncludeSubdomainsFlagEqualFalse() throws Exception { |
| 134 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 134 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 135 byte[] nonMatchingHash = generateSomeSha256(); | 135 byte[] nonMatchingHash = generateSomeSha256(); |
| 136 addPkpSha256(mDomain, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_FUTUR
E); | 136 addPkpSha256(mDomain, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_FUTUR
E); |
| 137 startCronetFramework(); | 137 startCronetEngine(); |
| 138 sendRequestAndWaitForResult(); | 138 sendRequestAndWaitForResult(); |
| 139 | 139 |
| 140 assertSuccessfulResponse(); | 140 assertSuccessfulResponse(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * Tests the case when the mismatching pin is set for some host that is diff
erent from the one | 144 * Tests the case when the mismatching pin is set for some host that is diff
erent from the one |
| 145 * the client wants to access. In that case the other host pinning policy sh
ould not be applied | 145 * the client wants to access. In that case the other host pinning policy sh
ould not be applied |
| 146 * and the client is expected to receive the successful response with the re
sponse code 200. | 146 * and the client is expected to receive the successful response with the re
sponse code 200. |
| 147 * | 147 * |
| 148 * @throws Exception | 148 * @throws Exception |
| 149 */ | 149 */ |
| 150 @SmallTest | 150 @SmallTest |
| 151 @Feature({"Cronet"}) | 151 @Feature({"Cronet"}) |
| 152 @OnlyRunNativeCronet | 152 @OnlyRunNativeCronet |
| 153 public void testSuccessIfNoPinSpecified() throws Exception { | 153 public void testSuccessIfNoPinSpecified() throws Exception { |
| 154 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 154 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 155 byte[] nonMatchingHash = generateSomeSha256(); | 155 byte[] nonMatchingHash = generateSomeSha256(); |
| 156 addPkpSha256("otherhost.com", nonMatchingHash, INCLUDE_SUBDOMAINS, DISTA
NT_FUTURE); | 156 addPkpSha256("otherhost.com", nonMatchingHash, INCLUDE_SUBDOMAINS, DISTA
NT_FUTURE); |
| 157 startCronetFramework(); | 157 startCronetEngine(); |
| 158 sendRequestAndWaitForResult(); | 158 sendRequestAndWaitForResult(); |
| 159 | 159 |
| 160 assertSuccessfulResponse(); | 160 assertSuccessfulResponse(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * Tests mismatching pins that will expire in 10 seconds. The pins should be
still valid and | 164 * Tests mismatching pins that will expire in 10 seconds. The pins should be
still valid and |
| 165 * enforced during the request; thus returning PIN mismatch error. | 165 * enforced during the request; thus returning PIN mismatch error. |
| 166 * | 166 * |
| 167 * @throws Exception | 167 * @throws Exception |
| 168 */ | 168 */ |
| 169 @SmallTest | 169 @SmallTest |
| 170 @Feature({"Cronet"}) | 170 @Feature({"Cronet"}) |
| 171 @OnlyRunNativeCronet | 171 @OnlyRunNativeCronet |
| 172 public void testSoonExpiringPin() throws Exception { | 172 public void testSoonExpiringPin() throws Exception { |
| 173 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 173 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 174 final int tenSecondsAhead = 10; | 174 final int tenSecondsAhead = 10; |
| 175 byte[] nonMatchingHash = generateSomeSha256(); | 175 byte[] nonMatchingHash = generateSomeSha256(); |
| 176 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, tenSecond
sAhead); | 176 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, tenSecond
sAhead); |
| 177 startCronetFramework(); | 177 startCronetEngine(); |
| 178 sendRequestAndWaitForResult(); | 178 sendRequestAndWaitForResult(); |
| 179 | 179 |
| 180 assertErrorResponse(); | 180 assertErrorResponse(); |
| 181 } | 181 } |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * Tests mismatching pins that expired 1 second ago. Since the pins have exp
ired, they | 184 * Tests mismatching pins that expired 1 second ago. Since the pins have exp
ired, they |
| 185 * should not be enforced during the request; thus a successful response is
expected. | 185 * should not be enforced during the request; thus a successful response is
expected. |
| 186 * | 186 * |
| 187 * @throws Exception | 187 * @throws Exception |
| 188 */ | 188 */ |
| 189 @SmallTest | 189 @SmallTest |
| 190 @Feature({"Cronet"}) | 190 @Feature({"Cronet"}) |
| 191 @OnlyRunNativeCronet | 191 @OnlyRunNativeCronet |
| 192 public void testRecentlyExpiredPin() throws Exception { | 192 public void testRecentlyExpiredPin() throws Exception { |
| 193 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 193 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 194 final int oneSecondAgo = -1; | 194 final int oneSecondAgo = -1; |
| 195 byte[] nonMatchingHash = generateSomeSha256(); | 195 byte[] nonMatchingHash = generateSomeSha256(); |
| 196 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, oneSecond
Ago); | 196 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, oneSecond
Ago); |
| 197 startCronetFramework(); | 197 startCronetEngine(); |
| 198 sendRequestAndWaitForResult(); | 198 sendRequestAndWaitForResult(); |
| 199 | 199 |
| 200 assertSuccessfulResponse(); | 200 assertSuccessfulResponse(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 /** | 203 /** |
| 204 * Tests that the pinning of local trust anchors is enforced when pinning by
pass for local | 204 * Tests that the pinning of local trust anchors is enforced when pinning by
pass for local |
| 205 * trust anchors is disabled. | 205 * trust anchors is disabled. |
| 206 * | 206 * |
| 207 * @throws Exception | 207 * @throws Exception |
| 208 */ | 208 */ |
| 209 @SmallTest | 209 @SmallTest |
| 210 @Feature({"Cronet"}) | 210 @Feature({"Cronet"}) |
| 211 public void testLocalTrustAnchorPinningEnforced() throws Exception { | 211 public void testLocalTrustAnchorPinningEnforced() throws Exception { |
| 212 createCronetEngineBuilder(DISABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, UNKN
OWN_ROOT); | 212 createCronetEngineBuilder(DISABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, UNKN
OWN_ROOT); |
| 213 byte[] nonMatchingHash = generateSomeSha256(); | 213 byte[] nonMatchingHash = generateSomeSha256(); |
| 214 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); | 214 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); |
| 215 startCronetFramework(); | 215 startCronetEngine(); |
| 216 sendRequestAndWaitForResult(); | 216 sendRequestAndWaitForResult(); |
| 217 | 217 |
| 218 assertErrorResponse(); | 218 assertErrorResponse(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 /** | 221 /** |
| 222 * Tests that the pinning of local trust anchors is not enforced when pinnin
g bypass for local | 222 * Tests that the pinning of local trust anchors is not enforced when pinnin
g bypass for local |
| 223 * trust anchors is enabled. | 223 * trust anchors is enabled. |
| 224 * | 224 * |
| 225 * @throws Exception | 225 * @throws Exception |
| 226 */ | 226 */ |
| 227 @SmallTest | 227 @SmallTest |
| 228 @Feature({"Cronet"}) | 228 @Feature({"Cronet"}) |
| 229 public void testLocalTrustAnchorPinningNotEnforced() throws Exception { | 229 public void testLocalTrustAnchorPinningNotEnforced() throws Exception { |
| 230 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, UNKNO
WN_ROOT); | 230 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, UNKNO
WN_ROOT); |
| 231 byte[] nonMatchingHash = generateSomeSha256(); | 231 byte[] nonMatchingHash = generateSomeSha256(); |
| 232 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); | 232 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); |
| 233 startCronetFramework(); | 233 startCronetEngine(); |
| 234 sendRequestAndWaitForResult(); | 234 sendRequestAndWaitForResult(); |
| 235 | 235 |
| 236 assertSuccessfulResponse(); | 236 assertSuccessfulResponse(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 /** | 239 /** |
| 240 * Tests that host pinning is not persisted between multiple CronetEngine in
stances. | 240 * Tests that host pinning is not persisted between multiple CronetEngine in
stances. |
| 241 * | 241 * |
| 242 * @throws Exception | 242 * @throws Exception |
| 243 */ | 243 */ |
| 244 @SmallTest | 244 @SmallTest |
| 245 @Feature({"Cronet"}) | 245 @Feature({"Cronet"}) |
| 246 @OnlyRunNativeCronet | 246 @OnlyRunNativeCronet |
| 247 public void testPinsAreNotPersisted() throws Exception { | 247 public void testPinsAreNotPersisted() throws Exception { |
| 248 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 248 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 249 byte[] nonMatchingHash = generateSomeSha256(); | 249 byte[] nonMatchingHash = generateSomeSha256(); |
| 250 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); | 250 addPkpSha256(mServerHost, nonMatchingHash, EXCLUDE_SUBDOMAINS, DISTANT_F
UTURE); |
| 251 startCronetFramework(); | 251 startCronetEngine(); |
| 252 sendRequestAndWaitForResult(); | 252 sendRequestAndWaitForResult(); |
| 253 assertErrorResponse(); | 253 assertErrorResponse(); |
| 254 shutdownCronetEngine(); | 254 shutdownCronetEngine(); |
| 255 | 255 |
| 256 // Restart Cronet engine and try the same request again. Since the pins
are not persisted, | 256 // Restart Cronet engine and try the same request again. Since the pins
are not persisted, |
| 257 // a successful response is expected. | 257 // a successful response is expected. |
| 258 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); | 258 createCronetEngineBuilder(ENABLE_PINNING_BYPASS_FOR_LOCAL_ANCHORS, KNOWN
_ROOT); |
| 259 startCronetFramework(); | 259 startCronetEngine(); |
| 260 sendRequestAndWaitForResult(); | 260 sendRequestAndWaitForResult(); |
| 261 assertSuccessfulResponse(); | 261 assertSuccessfulResponse(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 /** | 264 /** |
| 265 * Tests that the client receives {@code InvalidArgumentException} when the
pinned host name | 265 * Tests that the client receives {@code InvalidArgumentException} when the
pinned host name |
| 266 * is invalid. | 266 * is invalid. |
| 267 * | 267 * |
| 268 * @throws Exception | 268 * @throws Exception |
| 269 */ | 269 */ |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 // Set common CronetEngine parameters | 390 // Set common CronetEngine parameters |
| 391 mBuilder = new ExperimentalCronetEngine.Builder(getContext()); | 391 mBuilder = new ExperimentalCronetEngine.Builder(getContext()); |
| 392 mBuilder.enablePublicKeyPinningBypassForLocalTrustAnchors(bypassPinningF
orLocalAnchors); | 392 mBuilder.enablePublicKeyPinningBypassForLocalTrustAnchors(bypassPinningF
orLocalAnchors); |
| 393 mBuilder.enableQuic(true); | 393 mBuilder.enableQuic(true); |
| 394 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS
erverPort(), | 394 mBuilder.addQuicHint(QuicTestServer.getServerHost(), QuicTestServer.getS
erverPort(), |
| 395 QuicTestServer.getServerPort()); | 395 QuicTestServer.getServerPort()); |
| 396 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); | 396 JSONObject hostResolverParams = CronetTestUtil.generateHostResolverRules
(); |
| 397 JSONObject experimentalOptions = new JSONObject() | 397 JSONObject experimentalOptions = new JSONObject() |
| 398 .put("HostResolverRules", hostR
esolverParams); | 398 .put("HostResolverRules", hostR
esolverParams); |
| 399 mBuilder.setExperimentalOptions(experimentalOptions.toString()); | 399 mBuilder.setExperimentalOptions(experimentalOptions.toString()); |
| 400 mBuilder.setStoragePath(CronetTestFramework.getTestStorage(getContext())
); | 400 mBuilder.setStoragePath(getTestStorage(getContext())); |
| 401 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1
000 * 1024); | 401 mBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 1
000 * 1024); |
| 402 CronetTestUtil.setMockCertVerifierForTesting( | 402 CronetTestUtil.setMockCertVerifierForTesting( |
| 403 mBuilder, MockCertVerifier.createMockCertVerifier(CERTS_USED, kn
ownRoot)); | 403 mBuilder, MockCertVerifier.createMockCertVerifier(CERTS_USED, kn
ownRoot)); |
| 404 } | 404 } |
| 405 | 405 |
| 406 private void startCronetFramework() { | 406 private void startCronetEngine() { |
| 407 mTestFramework = startCronetTestFrameworkWithUrlAndCronetEngineBuilder(n
ull, mBuilder); | 407 mCronetEngine = mBuilder.build(); |
| 408 } | 408 } |
| 409 | 409 |
| 410 private void shutdownCronetEngine() { | 410 private void shutdownCronetEngine() { |
| 411 if (mTestFramework != null && mTestFramework.mCronetEngine != null) { | 411 if (mCronetEngine != null) { |
| 412 mTestFramework.mCronetEngine.shutdown(); | 412 mCronetEngine.shutdown(); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 private byte[] generateSomeSha256() { | 416 private byte[] generateSomeSha256() { |
| 417 byte[] sha256 = new byte[32]; | 417 byte[] sha256 = new byte[32]; |
| 418 Arrays.fill(sha256, (byte) 58); | 418 Arrays.fill(sha256, (byte) 58); |
| 419 return sha256; | 419 return sha256; |
| 420 } | 420 } |
| 421 | 421 |
| 422 private void addPkpSha256( | 422 private void addPkpSha256( |
| 423 String host, byte[] pinHashValue, boolean includeSubdomain, int maxA
geInSec) { | 423 String host, byte[] pinHashValue, boolean includeSubdomain, int maxA
geInSec) { |
| 424 Set<byte[]> hashes = new HashSet<>(); | 424 Set<byte[]> hashes = new HashSet<>(); |
| 425 hashes.add(pinHashValue); | 425 hashes.add(pinHashValue); |
| 426 mBuilder.addPublicKeyPins(host, hashes, includeSubdomain, dateInFuture(m
axAgeInSec)); | 426 mBuilder.addPublicKeyPins(host, hashes, includeSubdomain, dateInFuture(m
axAgeInSec)); |
| 427 } | 427 } |
| 428 | 428 |
| 429 private void sendRequestAndWaitForResult() { | 429 private void sendRequestAndWaitForResult() { |
| 430 mListener = new TestUrlRequestCallback(); | 430 mListener = new TestUrlRequestCallback(); |
| 431 | 431 |
| 432 String quicURL = mServerUrl + "/simple.txt"; | 432 String quicURL = mServerUrl + "/simple.txt"; |
| 433 UrlRequest.Builder requestBuilder = mTestFramework.mCronetEngine.newUrlR
equestBuilder( | 433 UrlRequest.Builder requestBuilder = |
| 434 quicURL, mListener, mListener.getExecutor()); | 434 mCronetEngine.newUrlRequestBuilder(quicURL, mListener, mListener
.getExecutor()); |
| 435 requestBuilder.build().start(); | 435 requestBuilder.build().start(); |
| 436 mListener.blockForDone(); | 436 mListener.blockForDone(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 private X509Certificate readCertFromFileInPemFormat(String certFileName) thr
ows Exception { | 439 private X509Certificate readCertFromFileInPemFormat(String certFileName) thr
ows Exception { |
| 440 byte[] certDer = CertTestUtil.pemToDer(CertTestUtil.CERTS_DIRECTORY + ce
rtFileName); | 440 byte[] certDer = CertTestUtil.pemToDer(CertTestUtil.CERTS_DIRECTORY + ce
rtFileName); |
| 441 CertificateFactory certFactory = CertificateFactory.getInstance("X.509")
; | 441 CertificateFactory certFactory = CertificateFactory.getInstance("X.509")
; |
| 442 return (X509Certificate) certFactory.generateCertificate(new ByteArrayIn
putStream(certDer)); | 442 return (X509Certificate) certFactory.generateCertificate(new ByteArrayIn
putStream(certDer)); |
| 443 } | 443 } |
| 444 | 444 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 if (!shouldThrowNpe) { | 480 if (!shouldThrowNpe) { |
| 481 fail("Null pointer exception was not expected: " + ex.toString()
); | 481 fail("Null pointer exception was not expected: " + ex.toString()
); |
| 482 } | 482 } |
| 483 return; | 483 return; |
| 484 } | 484 } |
| 485 if (shouldThrowNpe) { | 485 if (shouldThrowNpe) { |
| 486 fail("NullPointerException was expected"); | 486 fail("NullPointerException was expected"); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 } | 489 } |
| OLD | NEW |