forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement net/ support for Android's NetworkSecurityPolicy
NetworkSecurityPolicy allows apps to disallow cleartext requests, globally (starting from M) or by hostname (starting from N). This CL adds support for this feature in URLRequestHttpJob, and a flag on the URLRequestContext to enable it. It's off by default and only prevents requests using the "http" and "ws" schemes. Uses will be added in future CLs. BUG=474197, 473848 Review-Url: https://codereview.chromium.org/2546213003 Cr-Commit-Position: refs/heads/master@{#438661}
- Loading branch information
mgersh
authored and
Commit bot
committed
Dec 14, 2016
1 parent
8573cb8
commit d21d6d1
Showing
11 changed files
with
159 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
net/android/javatests/src/org/chromium/net/AndroidNetworkLibraryTestUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.net; | ||
|
||
import android.annotation.TargetApi; | ||
import android.os.Build; | ||
import android.security.NetworkSecurityPolicy; | ||
|
||
import org.chromium.base.annotations.CalledByNative; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Utility functions for testing features implemented in AndroidNetworkLibrary. | ||
*/ | ||
public class AndroidNetworkLibraryTestUtil { | ||
/** | ||
* Helper for tests that simulates an app disallowing cleartext traffic entirely on M and newer. | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.M) | ||
@CalledByNative | ||
private static void setUpSecurityPolicyForTesting(boolean cleartextPermitted) throws Exception { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||
Method setCleartextTrafficPermitted = NetworkSecurityPolicy.class.getDeclaredMethod( | ||
"setCleartextTrafficPermitted", boolean.class); | ||
setCleartextTrafficPermitted.invoke( | ||
NetworkSecurityPolicy.getInstance(), cleartextPermitted); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters