Snap for 4484469 from f62c26562f150109d9498488ffb9798e4e2a84d8 to pi-release
Change-Id: I382b60bef0752eeb6bbb2d9db555ff7f81d1fdf2
This commit is contained in:
@@ -21,6 +21,7 @@ import android.os.Build;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.util.HexDump;
|
import com.android.internal.util.HexDump;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
@@ -34,6 +35,8 @@ import java.util.Arrays;
|
|||||||
* Internet Protocol</a>
|
* Internet Protocol</a>
|
||||||
*/
|
*/
|
||||||
public final class IpSecAlgorithm implements Parcelable {
|
public final class IpSecAlgorithm implements Parcelable {
|
||||||
|
private static final String TAG = "IpSecAlgorithm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AES-CBC Encryption/Ciphering Algorithm.
|
* AES-CBC Encryption/Ciphering Algorithm.
|
||||||
*
|
*
|
||||||
@@ -45,6 +48,7 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
* MD5 HMAC Authentication/Integrity Algorithm. <b>This algorithm is not recommended for use in
|
* MD5 HMAC Authentication/Integrity Algorithm. <b>This algorithm is not recommended for use in
|
||||||
* new applications and is provided for legacy compatibility with 3gpp infrastructure.</b>
|
* new applications and is provided for legacy compatibility with 3gpp infrastructure.</b>
|
||||||
*
|
*
|
||||||
|
* <p>Keys for this algorithm must be 128 bits in length.
|
||||||
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 128.
|
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 128.
|
||||||
*/
|
*/
|
||||||
public static final String AUTH_HMAC_MD5 = "hmac(md5)";
|
public static final String AUTH_HMAC_MD5 = "hmac(md5)";
|
||||||
@@ -53,6 +57,7 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
* SHA1 HMAC Authentication/Integrity Algorithm. <b>This algorithm is not recommended for use in
|
* SHA1 HMAC Authentication/Integrity Algorithm. <b>This algorithm is not recommended for use in
|
||||||
* new applications and is provided for legacy compatibility with 3gpp infrastructure.</b>
|
* new applications and is provided for legacy compatibility with 3gpp infrastructure.</b>
|
||||||
*
|
*
|
||||||
|
* <p>Keys for this algorithm must be 160 bits in length.
|
||||||
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 160.
|
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 160.
|
||||||
*/
|
*/
|
||||||
public static final String AUTH_HMAC_SHA1 = "hmac(sha1)";
|
public static final String AUTH_HMAC_SHA1 = "hmac(sha1)";
|
||||||
@@ -60,6 +65,7 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* SHA256 HMAC Authentication/Integrity Algorithm.
|
* SHA256 HMAC Authentication/Integrity Algorithm.
|
||||||
*
|
*
|
||||||
|
* <p>Keys for this algorithm must be 256 bits in length.
|
||||||
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 256.
|
* <p>Valid truncation lengths are multiples of 8 bits from 96 to (default) 256.
|
||||||
*/
|
*/
|
||||||
public static final String AUTH_HMAC_SHA256 = "hmac(sha256)";
|
public static final String AUTH_HMAC_SHA256 = "hmac(sha256)";
|
||||||
@@ -67,6 +73,7 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* SHA384 HMAC Authentication/Integrity Algorithm.
|
* SHA384 HMAC Authentication/Integrity Algorithm.
|
||||||
*
|
*
|
||||||
|
* <p>Keys for this algorithm must be 384 bits in length.
|
||||||
* <p>Valid truncation lengths are multiples of 8 bits from 192 to (default) 384.
|
* <p>Valid truncation lengths are multiples of 8 bits from 192 to (default) 384.
|
||||||
*/
|
*/
|
||||||
public static final String AUTH_HMAC_SHA384 = "hmac(sha384)";
|
public static final String AUTH_HMAC_SHA384 = "hmac(sha384)";
|
||||||
@@ -74,6 +81,7 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
/**
|
/**
|
||||||
* SHA512 HMAC Authentication/Integrity Algorithm.
|
* SHA512 HMAC Authentication/Integrity Algorithm.
|
||||||
*
|
*
|
||||||
|
* <p>Keys for this algorithm must be 512 bits in length.
|
||||||
* <p>Valid truncation lengths are multiples of 8 bits from 256 to (default) 512.
|
* <p>Valid truncation lengths are multiples of 8 bits from 256 to (default) 512.
|
||||||
*/
|
*/
|
||||||
public static final String AUTH_HMAC_SHA512 = "hmac(sha512)";
|
public static final String AUTH_HMAC_SHA512 = "hmac(sha512)";
|
||||||
@@ -130,12 +138,10 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
* @param truncLenBits number of bits of output hash to use.
|
* @param truncLenBits number of bits of output hash to use.
|
||||||
*/
|
*/
|
||||||
public IpSecAlgorithm(@AlgorithmName String algorithm, @NonNull byte[] key, int truncLenBits) {
|
public IpSecAlgorithm(@AlgorithmName String algorithm, @NonNull byte[] key, int truncLenBits) {
|
||||||
if (!isTruncationLengthValid(algorithm, truncLenBits)) {
|
|
||||||
throw new IllegalArgumentException("Unknown algorithm or invalid length");
|
|
||||||
}
|
|
||||||
mName = algorithm;
|
mName = algorithm;
|
||||||
mKey = key.clone();
|
mKey = key.clone();
|
||||||
mTruncLenBits = Math.min(truncLenBits, key.length * 8);
|
mTruncLenBits = truncLenBits;
|
||||||
|
checkValidOrThrow(mName, mKey.length * 8, mTruncLenBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the algorithm name */
|
/** Get the algorithm name */
|
||||||
@@ -169,7 +175,11 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
public static final Parcelable.Creator<IpSecAlgorithm> CREATOR =
|
public static final Parcelable.Creator<IpSecAlgorithm> CREATOR =
|
||||||
new Parcelable.Creator<IpSecAlgorithm>() {
|
new Parcelable.Creator<IpSecAlgorithm>() {
|
||||||
public IpSecAlgorithm createFromParcel(Parcel in) {
|
public IpSecAlgorithm createFromParcel(Parcel in) {
|
||||||
return new IpSecAlgorithm(in);
|
final String name = in.readString();
|
||||||
|
final byte[] key = in.createByteArray();
|
||||||
|
final int truncLenBits = in.readInt();
|
||||||
|
|
||||||
|
return new IpSecAlgorithm(name, key, truncLenBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IpSecAlgorithm[] newArray(int size) {
|
public IpSecAlgorithm[] newArray(int size) {
|
||||||
@@ -177,30 +187,47 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private IpSecAlgorithm(Parcel in) {
|
private static void checkValidOrThrow(String name, int keyLen, int truncLen) {
|
||||||
mName = in.readString();
|
boolean isValidLen = true;
|
||||||
mKey = in.createByteArray();
|
boolean isValidTruncLen = true;
|
||||||
mTruncLenBits = in.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isTruncationLengthValid(String algo, int truncLenBits) {
|
switch(name) {
|
||||||
switch (algo) {
|
|
||||||
case CRYPT_AES_CBC:
|
case CRYPT_AES_CBC:
|
||||||
return (truncLenBits == 128 || truncLenBits == 192 || truncLenBits == 256);
|
isValidLen = keyLen == 128 || keyLen == 192 || keyLen == 256;
|
||||||
|
break;
|
||||||
case AUTH_HMAC_MD5:
|
case AUTH_HMAC_MD5:
|
||||||
return (truncLenBits >= 96 && truncLenBits <= 128);
|
isValidLen = keyLen == 128;
|
||||||
|
isValidTruncLen = truncLen >= 96 && truncLen <= 128;
|
||||||
|
break;
|
||||||
case AUTH_HMAC_SHA1:
|
case AUTH_HMAC_SHA1:
|
||||||
return (truncLenBits >= 96 && truncLenBits <= 160);
|
isValidLen = keyLen == 160;
|
||||||
|
isValidTruncLen = truncLen >= 96 && truncLen <= 160;
|
||||||
|
break;
|
||||||
case AUTH_HMAC_SHA256:
|
case AUTH_HMAC_SHA256:
|
||||||
return (truncLenBits >= 96 && truncLenBits <= 256);
|
isValidLen = keyLen == 256;
|
||||||
|
isValidTruncLen = truncLen >= 96 && truncLen <= 256;
|
||||||
|
break;
|
||||||
case AUTH_HMAC_SHA384:
|
case AUTH_HMAC_SHA384:
|
||||||
return (truncLenBits >= 192 && truncLenBits <= 384);
|
isValidLen = keyLen == 384;
|
||||||
|
isValidTruncLen = truncLen >= 192 && truncLen <= 384;
|
||||||
|
break;
|
||||||
case AUTH_HMAC_SHA512:
|
case AUTH_HMAC_SHA512:
|
||||||
return (truncLenBits >= 256 && truncLenBits <= 512);
|
isValidLen = keyLen == 512;
|
||||||
|
isValidTruncLen = truncLen >= 256 && truncLen <= 512;
|
||||||
|
break;
|
||||||
case AUTH_CRYPT_AES_GCM:
|
case AUTH_CRYPT_AES_GCM:
|
||||||
return (truncLenBits == 64 || truncLenBits == 96 || truncLenBits == 128);
|
// The keying material for GCM is a key plus a 32-bit salt
|
||||||
|
isValidLen = keyLen == 128 + 32 || keyLen == 192 + 32 || keyLen == 256 + 32;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
throw new IllegalArgumentException("Couldn't find an algorithm: " + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidLen) {
|
||||||
|
throw new IllegalArgumentException("Invalid key material keyLength: " + keyLen);
|
||||||
|
}
|
||||||
|
if (!isValidTruncLen) {
|
||||||
|
throw new IllegalArgumentException("Invalid truncation keyLength: " + truncLen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,8 +244,9 @@ public final class IpSecAlgorithm implements Parcelable {
|
|||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** package */
|
/** @hide */
|
||||||
static boolean equals(IpSecAlgorithm lhs, IpSecAlgorithm rhs) {
|
@VisibleForTesting
|
||||||
|
public static boolean equals(IpSecAlgorithm lhs, IpSecAlgorithm rhs) {
|
||||||
if (lhs == null || rhs == null) return (lhs == rhs);
|
if (lhs == null || rhs == null) return (lhs == rhs);
|
||||||
return (lhs.mName.equals(rhs.mName)
|
return (lhs.mName.equals(rhs.mName)
|
||||||
&& Arrays.equals(lhs.mKey, rhs.mKey)
|
&& Arrays.equals(lhs.mKey, rhs.mKey)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import android.annotation.RequiresPermission;
|
import android.annotation.RequiresPermission;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.app.DownloadManager;
|
import android.app.DownloadManager;
|
||||||
import android.app.backup.BackupManager;
|
import android.app.backup.BackupManager;
|
||||||
@@ -30,6 +31,8 @@ import com.android.server.NetworkManagementSocketTagger;
|
|||||||
|
|
||||||
import dalvik.system.SocketTagger;
|
import dalvik.system.SocketTagger;
|
||||||
|
|
||||||
|
import java.io.FileDescriptor;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
@@ -263,15 +266,26 @@ public class TrafficStats {
|
|||||||
NetworkManagementSocketTagger.setThreadSocketStatsUid(uid);
|
NetworkManagementSocketTagger.setThreadSocketStatsUid(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set specific UID to use when accounting {@link Socket} traffic
|
||||||
|
* originating from the current thread as the calling UID. Designed for use
|
||||||
|
* when another application is performing operations on your behalf.
|
||||||
|
* <p>
|
||||||
|
* Changes only take effect during subsequent calls to
|
||||||
|
* {@link #tagSocket(Socket)}.
|
||||||
|
*/
|
||||||
|
public static void setThreadStatsUidSelf() {
|
||||||
|
setThreadStatsUid(android.os.Process.myUid());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear any active UID set to account {@link Socket} traffic originating
|
* Clear any active UID set to account {@link Socket} traffic originating
|
||||||
* from the current thread.
|
* from the current thread.
|
||||||
*
|
*
|
||||||
* @see #setThreadStatsUid(int)
|
* @see #setThreadStatsUid(int)
|
||||||
* @hide
|
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
|
@SuppressLint("Doclava125")
|
||||||
public static void clearThreadStatsUid() {
|
public static void clearThreadStatsUid() {
|
||||||
NetworkManagementSocketTagger.setThreadSocketStatsUid(-1);
|
NetworkManagementSocketTagger.setThreadSocketStatsUid(-1);
|
||||||
}
|
}
|
||||||
@@ -315,6 +329,27 @@ public class TrafficStats {
|
|||||||
SocketTagger.get().untag(socket);
|
SocketTagger.get().untag(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag the given {@link FileDescriptor} socket with any statistics
|
||||||
|
* parameters active for the current thread. Subsequent calls always replace
|
||||||
|
* any existing parameters. When finished, call
|
||||||
|
* {@link #untagFileDescriptor(FileDescriptor)} to remove statistics
|
||||||
|
* parameters.
|
||||||
|
*
|
||||||
|
* @see #setThreadStatsTag(int)
|
||||||
|
*/
|
||||||
|
public static void tagFileDescriptor(FileDescriptor fd) throws IOException {
|
||||||
|
SocketTagger.get().tag(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove any statistics parameters from the given {@link FileDescriptor}
|
||||||
|
* socket.
|
||||||
|
*/
|
||||||
|
public static void untagFileDescriptor(FileDescriptor fd) throws IOException {
|
||||||
|
SocketTagger.get().untag(fd);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start profiling data usage for current UID. Only one profiling session
|
* Start profiling data usage for current UID. Only one profiling session
|
||||||
* can be active at a time.
|
* can be active at a time.
|
||||||
|
|||||||
Reference in New Issue
Block a user