Commit Graph

349 Commits

Author SHA1 Message Date
nharold
a32b8e710d Merge "Expose add/removeAddress for IpSecInterfaces" 2018-03-20 22:53:39 +00:00
Nathan Harold
e4a6258658 Expose add/removeAddress for IpSecInterfaces
When exposing the APIs, these were missed.
The outer structure is exposed, so this exposes
the addAddress and removeAddress methods.

Bug: 75234273
Test: compilation
Change-Id: I79911434f9baa660e4d8564cc59d80da4a710c42
2018-03-20 12:32:20 -07:00
Treehugger Robot
22b39848a6 Merge "Add support for auth-only transforms" 2018-03-20 18:36:04 +00:00
Benedict Wong
8c05fd7155 Merge "Added implementation for VTI add/remove address" 2018-03-19 22:05:09 +00:00
Benedict Wong
2ba4a65fe0 Add support for auth-only transforms
Kernel limitations prevent auth-only SAs from being created. Explicitly
request a null encryption algorithm instead of omitting the algorithm
to comply with the kernel requirement for ESP.

Bug: 75049573
Test: CTS tests for auth-only, crypt-only transforms added for all
combinations of (UDP, TCP, IPv4, IPv6, UDP-encap) Also added unit
tests to ensure correct triggering of NULL_CRYPT usage.
Change-Id: Ia9a5cfee9c7786412846bc039f326420f6211c08
2018-03-16 17:36:59 -07:00
Nathan Harold
e917321c4e Docstring Updates for applyTransportModeTransform
-Add anotations to usages of PolicyDirection for
 apply...() methods.
-Update the comments on DIRECTION_IN and DIRECTION_OUT
 to better reflect their current usage.
-Add a better explanation to the rekey procedure doc.
-Remove disused createTunnelInterface() stub.

Bug: 73751066
Test: make docs
Change-Id: I9f2ec864466148a18899f1e952c74a525902ccbc
2018-03-16 17:29:45 -07:00
Benedict Wong
23b86a6d99 Added implementation for VTI add/remove address
This change adds implementation details for add/remove addresses onto a
VTI.

Bug: 73675031
Test: New tests added, passing on Walleye
Change-Id: Idde9d943a5285d2c13c5c6b0f7b8a9faf718e6a5
2018-03-16 10:25:43 -07:00
Remi NGUYEN VAN
41737af07d Allow null subscriberId in NetworkStatsManager.
Use a MATCH_MOBILE_WILDCARD template to avoid filtering by
subscriberId when querying statistics from NetworkStatsService.

Bug: 74038898
Change-Id: I4b39e7031416cb33b23d89aa36ff0f774eaa942f
Fixes: 74038898
Test: runtest frameworks-net, CTS tests pass
2018-03-06 13:28:19 +09:00
Benedict Wong
e5623e2b61 Copy IpSecConfig when IpSecTransforms are created
This change prevents IpSecTransforms from being inadvertently modified
by changes to the IpSecConfig. Specifically, once the transform is
created, it takes a copy of the config, rather than a reference.

Bug: 69385347
Test: New tests added, and all test passing
Change-Id: I89b8660c175ca20aa70352dcda893434ff7fd42b
2018-02-13 23:23:13 +00:00
Nathan Harold
025aae1fc9 Require NETWORK_STACK Permission for IpSec Tunnel Mode
At least until further permissions are agreed upon,
the NETWORK_STACK permission is sufficient to ensure
that access to the tunnel mode APIs is secure, and
this permission will always be a sufficient condition.
Thus, adding NETWORK_STACK.

Bug: 66955045
Test: compilation
Change-Id: I2dc36896a52d2e71fad55041507d68ca91191ffc
2018-02-08 21:16:51 +00:00
Treehugger Robot
cbcc1d6665 Merge "Enable multiple active Ethernet interfaces" 2018-02-02 23:13:54 +00:00
Treehugger Robot
9fb04e29e5 Merge "Return non-negetive value in getMobileStats method" 2018-02-02 04:22:34 +00:00
Benedict Wong
7660370a83 Fix minor bugs with tunnel mode implementation
This change makes sure tunnel mode transforms are properly activated
upon construction, and corrects bugs with how policy selectors were being
generated for tunnel mode policies. Specifically, the source/destination could
not be empty strings, even for cases where an empty selector was desired.

Bug: 72457770
Test: GTS tests run
Change-Id: I9a9f64c34b07883a02a5c996614f958486d214fc
2018-01-31 01:16:53 +00:00
Chenbo Feng
905f034c57 Return non-negetive value in getMobileStats method
The current implementation of getMobileRxBytes and all the similiar
method adds up the return values for multiple calls to getRxBytes so if
all of them return UNSUPPORTED for any reason, getMobileRxBytes() would
return a value such as -3. This behavior is not compliance with the cts
TrafficStatsTest which always assume getMobileRxBytes to return a
non-negetive value. The method now will check tha stats get from
getRxBytes method and add them up only if the stats is valid.

Bug: 72473294
Test: run cts -m CtsNetTestCases -t android.net.cts.TrafficStatsTest
Change-Id: I656970ebc8f6506cf17c4353ad46c0178bb65cfd
2018-01-29 12:19:26 -08:00
Pavel Maltsev
50ec1f33c6 Enable multiple active Ethernet interfaces
- add Ethernet interface configurations to config.xml; no vendors can
specify network capabilities (in particular they can mark network as
restricted which make sense for embedded applications + static IP
configuration)
- extend EthernetManager to support multiple interfaces, use interface
name as an identificator
- extend IpConfigStore to store IP configuration based on string
identifier (e.g. ethernet name)

Test: runtest -x frameworks/base/services/tests/servicestests/ -c com.android.server.net.IpConfigStoreTest
Change-Id: Ic1e70003f2380ca8edb4469d6b34e27c5e8cf059
2018-01-29 10:11:05 -08:00
Nathan Harold
b559164017 Move Keepalive out of IpSecTransform.Builder
The lifecycle of Keepalive offloading is, unfortunately
different from that of an IpSecTransform. Because starting
a keepalive is fundamentally asynchronous, and isn't valid
until after a transform exists, it will now be a separate
optional procedure that may succeed or fail. It remains
linked with a Transform by the need for a Transform to exist
in order to initiate a Keepalive.

Bug: 38350389
Test: compilation
Change-Id: Ia76fccee41f86d694dff436043293d0c0762c041
2018-01-24 19:32:04 -08:00
Benedict Wong
8bc907311b Add TunnelInterface API and KernelResourceRecords
This change adds one KernelResourceRecord type (TunnelInterfaceRecord),
and adds methods for the creation of TunnelInterfaces, as well as the
application of Transforms to the given TunnelInterfaces

As part of the generation of ikeys/okeys, a ReserveKeyTracker manages a
java bitset to avoid collisions and reserve/release keys.

Bug: 63588681
Test: Compiles, CTS, unit tests all pass on AOSP_marlin
Change-Id: I9e9b6455e27073acd4491eae666aa966b3b10e0f
2018-01-24 07:24:27 +00:00
Benedict Wong
6b3456b253 Merge "Add xfrm mark in IpSecConfig" 2018-01-24 05:53:29 +00:00
Treehugger Robot
bd268b204c Merge changes from topic "bpfStats"
* changes:
  Use /proc/net/dev to get stats summary
  Add bpf support for NetworkStatsFactory
  Add BPF support for NetworkStatsService
2018-01-24 04:08:29 +00:00
Benedict Wong
03e732a299 Expose applyTunnelModeTransform as a system API
Simple change to expose systemAPI for applyTunnelModeTransform

Bug: 36033193
Test: All CTS, unit tests passing
Change-Id: I2d857c048bc0dc80c3949387f946b1f5adf0527e
2018-01-23 23:25:54 +00:00
Lorenzo Colitti
f1b197b23b Support passing a template to NetworkStatsManager queries.
Currently, NetworkStatsManager queries and callbacks only allow
selecting network traffic based on network identifiers:
networkType, subscriptionId and networkId.  The code ends up
converting these into a template under the hood.

Now that templates can express more fine-grained queries (e.g.,
select only roaming traffic, or select only traffic that's not
on the default network) add a hidden method to pass in a
template. This should have no security implications, as all the
access controls are performed in NetworkStatsService.

Bug: 35142602
Test: android.app.usage.cts.NetworkUsageStatsTest passes
Change-Id: Iab4afa26b34544299d2a9c501c1b0feb470e90a9
Merged-In: Iab4afa26b34544299d2a9c501c1b0feb470e90a9
2018-01-23 18:38:48 +09:00
Lorenzo Colitti
75ec1aed18 Add metered, roaming, and defaultNetwork info to NetworkTemplate.
This will allow data usage clients to query for and receive
callbacks on data usage matching these conditions.

Bug: 35142602
Test: atest FrameworksNetTests
Change-Id: I4d985a2734eeab7ee454c09cc2098b6b3c671c23
Merged-In: I4d985a2734eeab7ee454c09cc2098b6b3c671c23
2018-01-23 18:38:48 +09:00
Lorenzo Colitti
0ba426b8a1 Add the defaultNetwork element to the netstats.proto.
This is in its own commit because AOSP has diverged from internal
master.

Bug: 35142602
Test: builds, boots
Change-Id: I75fc85b961bc919e3d6c2adce6d6861c6f2c8379
Merged-In: I75fc85b961bc919e3d6c2adce6d6861c6f2c8379
2018-01-23 18:38:48 +09:00
Lorenzo Colitti
92a946d09f Add getDefaultNetwork to the NetworkStats public API.
This allows an app using the public API to know whether the
traffic in a particular bucket was on the default network
(i.e., the network was selected by the system), or not (i.e.,
the network was selected by the app).

Bug: 35142602
Test: builds, boots
Test: added coverage to NetworkUsageStatsTest CTS test, still passes
Change-Id: I9f6669908fa119743b9c0aa0c31a03e5ebafa7db
Merged-In: I9f6669908fa119743b9c0aa0c31a03e5ebafa7db
2018-01-23 18:28:07 +09:00
Chenbo Feng
75a1efb3f5 Use /proc/net/dev to get stats summary
If the qtaguid proc file is no longer exist, the device is running new
eBPF module to do traffic accounting. So the NetworkStatsFactory need to
use the proc/net/dev interface to get the per interface traffic stats
summary. Also, adding a test to verify the helper function work properly

Bug: 30950746
Test: run NetworkStatsFactoryTest
Change-Id: Ia36808bf02f1637dd41a3e7c50917b91b1a77524
2018-01-23 00:35:02 -08:00
Chenbo Feng
adfda6945d Add bpf support for NetworkStatsFactory
Add the native method used to read the detail information of network
stats from bpf maps. The native method of NetworkStatsFactory should
choose the correct implementation to get the stats detail depending on
the kernel version. Currently the bpf result is printed as a reference
and the actual behavior of NetworkStatsFactory should not change.

Test: NetworkStatsFactory related cts test should not fail.
Bug: 30950746
Change-Id: I4715a23559b5b2306bd556cea0431f0ed172a993
2018-01-23 00:34:53 -08:00
Lorenzo Colitti
ebb1d92eb8 Merge "Remove obsolete NetworkStats.Entry constructor." 2018-01-23 00:15:15 +00:00
Benedict Wong
da6956a702 Merge "Rename create/delete transform methods" 2018-01-22 17:57:15 +00:00
Lorenzo Colitti
9ab3929812 Remove obsolete NetworkStats.Entry constructor.
The only caller is telephony code, and it's being fixed in this
topic.

Bug: 35142602
Test: builds, boots
Change-Id: Ia77a1c2c297037f311c2355610c206cd8e3192c4
2018-01-21 23:01:35 +09:00
nharold
a82dbcb3c7 Merge "Add Tunnel Interface APIs to IpSecManager" 2018-01-19 19:43:17 +00:00
Benedict Wong
0fff56eae5 Rename create/delete transform methods
CreateTransportModeTransform and DeleteTransportModeTransform are both
agnostic as far as which mode of transform it creates/deletes. As such,
to facilitate the implementation of tunnel mode, this patch renames them
to CreateTransform and DeleteTransform, along with all test names.

Bug: 63588681
Test: frameworks/base unit tests and CTS tests run, passed
Change-Id: I1f015eb7ad0e85fca966658a9402485ca2b44091
2018-01-19 10:43:01 -08:00
Lorenzo Colitti
ab7807a5bb Track and persist in stats whether traffic is on the default network.
This change adds the defaultNetwork to the ident based on current
system networking state, and persists that value to flash.

Bug: 35142602
Test: runtest frameworks-net
Test: downloaded files using default/non-default networks while watching dumpsys netstats
Change-Id: Id8776d149b2977548a9eb455ad4926af55e25aba
2018-01-19 19:49:16 +09:00
Lorenzo Colitti
3e85855083 Add the default network to NetworkStats and NetworkStatsCollection.
This allows us to maintain NetworkStats entries that track
whether the traffic was on the default network.

At the moment, the stats collection code always passes in
DEFAULT_NETWORK_NO. However, this value is a no-op, since it is
not persisted to disk. Only the ident, the uid/set/tag, and the
packet/byte/operation counters are persisted.

A future change will add defaultNetwork to the ident and start
persisting it.

Bug: 35142602
Test: runtest frameworks-net
Change-Id: Ifa291c62c0fa389b88e5561086a29dcd7cee2253
2018-01-19 19:49:16 +09:00
Lorenzo Colitti
28d1a529d5 Pass all default networks to NetworkStatsService
This will allow NetworkStatsService to treat traffic on these
networks differently from traffic where the app selects a network
that is not the default.

Bug: 35142602
Test: runtest frameworks-net
Change-Id: I5ea9d200d9fb153490c6108bb9390bf152f297da
2018-01-19 16:40:10 +09:00
Di Lu
3fef704896 Add xfrm mark in IpSecConfig
Bug: 63589600
Test: runtest frameworks-net
Change-Id: I2d38d781b8b31d8bf39fd4e9a7e31509f15a9e16
2018-01-18 15:23:56 -08:00
Nathan Harold
67e7673adf Add Tunnel Interface APIs to IpSecManager
Add a new interface and a new management object,
IpSecTunnelInterface to the IpSecManager surface.
This object will be used to control IPsec tunnels.

-Add IpSecTunnelInterface object
-Add methods to create and use an IpSecTunnelInterface
-Update the IpSecTransform builder to create Tunnel
 mode IpSecTransform objects (usable with an IpSecTunnel)

Bug: 36033193
Test: compilation
Change-Id: Ib6948b12c15c93674234dc36288058ae44435b90
2018-01-17 16:14:17 -08:00
Nathan Harold
0d483b76f3 IpSec - API Tweak for removeTransportModeTransform
Because IpSecTransforms are now unidirectional,
and because the only mechanism for removing Transforms
removes it from both directions, the API can no longer
use the Transform parameter to meaningfully validate
that the caller had applied a transform. Since that
functionality was as-yet unimplemented and is now
infeasible, the transform parameter is removed.

Bug: 72079356
Test: cts - IpSecManagerTest; runtest frameworks-net
Change-Id: If19b0d34bdc6daf31a40d6d62bff326dcbca08c0
2018-01-17 01:11:46 -08:00
Nathan Harold
3167625a15 Prevent Closure of Underlying Socket FDs
The version of applyTransportModeTransform() and
removeTransportModeTransform() that accepted
Socket and DatagramSocket were closing the underlying
FDs upon return. It's unclear whether this is due to
a behavior change elsewhere in ParcelFileDescriptor,
but either way, converting to using getFileDescriptor$
and then calling dup() explicitly rather than relying
on ParcelFileDescriptor seems like a better idea anyway.

Bug: 72047396
Test: CTS - IpSecManagerTest.testCreateTransform()
Change-Id: Ia2f02564e1289f25bf113dbb861fcfd2240537a7
2018-01-16 21:30:20 -08:00
Nathan Harold
5a19b9500d Make Transforms Unidirectional
Convert the IpSecTransform from being a bi-directional
pair of SAs to a unidirectional single SA. This CL
also removes the concept of "direction from SAs meaning
that a IpSecTransform may now be applied to a socket
in either direction.

-Make transforms unidirectional
-Add Convert allocateSpi() to use destination rather
 than direction and remote address
-Remove directionality from builders for IpSecTransform
-Change applyTransportModeTransform() to take a
 direction in which to apply the transform object.
-Additional minor naming updates
-Restrict IpSecConfig to only print keys on eng builds
-Move DIRECTION constants to IpSecManager
-Add sourceAddress parameter to IpSecTransform to provide
 additional guarantees about the source address of data;
 (explicit failure rather than implicit failure).
-Move SPI to the build() method of IpSecTransform

Bug: 71717213
Test: runtest frameworks-net, CTS - IpSecManagerTest
Change-Id: I0824b37f443f4b8c62536d9801238c63ed8f2a1c
2018-01-16 11:08:31 -08:00
Benedict Wong
53e5d21924 Merge "Add validation to IpSecConfig algorithm setters" 2018-01-09 18:18:28 +00:00
Benedict Wong
70867e55f7 Add validation to IpSecConfig algorithm setters
Adds checks to ensure that users can only set the correct types of
algorithms for the Authentication, Encryption and Authenticated
Encryption algorithms.

Bug: 65223935
Test: Added tests in IpSecConfigTest, and passed on aosp_marlin-eng
Change-Id: I462c77d9eb5710b8d03a48866453649d3b6fc6bf
2018-01-04 16:56:40 -08:00
Nathan Harold
5e8544685d IpSec Invalidate the Resource IDs on close()
To facilitate error checking we should invalidate
the resource IDs of all objects when we close() them.
Today, the resource ID is invalidated on the Transform
object but not on the SPI or Encap Socket. This CL
unifies the behavior.

Bug: 70641274
Test: cts - IpSecManagerTest
Change-Id: I28caec3e913902c748c6a50b4ef742ccef8b1b09
2018-01-04 15:28:29 -08:00
Chenbo Feng
aa7ba31c8e Use NetworkStatsService to get stats for apps
Move the native implementation of TrafficStats to NetworkStatsService
and apps need to get the NetworkStatsService binder interface from
system_server in order to get the network usage stats since boot. This
implementation can hide the detail of retrieving network traffic
information from apps and the NetworkStatsService can choose which
methoed it use to get the data depending on the kernel version of the
device.

Bug: 30950746
Test: CtsNetTestCases -t android.net.cts.TrafficStatsTest
Change-Id: I53bbefd19aa0b783b9b4b42ea4d76db3e9ec07a3
2017-12-19 19:57:44 -08:00
Benedict Wong
083faee14a [ipsec-qtaguid] Tag sockets upon creation of encap sockets
Added calls to tag encap sockets to that of the UID for which the encap
socket is being created on behalf of. This ensures that all data
accounting generated for the UDP-encap-ESP socket is correctly billed to
the right UID.

Bug: 62994731
Test: New tests added to IpSecServiceTest.java, passing
Change-Id: I15365ea9c982fd7b4e3cdeff314ddfba2289c86e
2017-12-18 19:46:06 +00:00
Jeff Sharkey
1fb74318cf [CHERRY-PICK] API for apps to tag sockets with their own UID.
This enables app A to create a socket, pass it to app B, and have
app B accept blame for the traffic performed on that socket.

Also adds helpful public APIs for tagging raw FileDescriptor sockets
instead of making developers go through shady SocketImpl wrappers.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AppSecurityTests#testAppFailAccessPrivateData
Bug: 63932076
Change-Id: I08925c843974675fc82e4080cec2eaab9ab7cd41
Merged-In: I08925c843974675fc82e4080cec2eaab9ab7cd41
(cherry picked from commit 4e164f9e94)
2017-12-18 19:44:40 +00:00
Jonathan Basseri
20e96c55d5 Use consistent naming for allocating SPI.
Throughout the IPsec code (API, system server, netd) we use "reserve"
SPI and "allocate" SPI interchangeably. This renames to use "allocate"
everywhere for self-consistency and consistency with the kernel
(ALLOCSPI).

In javadoc, I am leaving the word "reserve" in several places because it
is still an accurate description of how the method behaves.

Bug: 69128142
Test: TreeHugger should be enough
Change-Id: I8ea603b4612303b0393beef04032671fa53d2106
2017-12-12 13:50:35 -08:00
nharold
f0dd03e114 Merge "Validate IpSecAlgorithm Length"
am: 68b81299d2

Change-Id: I23f7612c119e67f9a1647568aeefde38a365f8da
2017-12-05 02:28:10 +00:00
Nathan Harold
eb1d489332 Validate IpSecAlgorithm Length
Improve the Validation of IpSecAlgorithm by
explicitly checking the length in addition to
the truncation length (previously an oversight).
In addition, we now check the lengths during
un-parceling, which will catch someone maliciously
manually building a parcel and passing it, bypassing
the checks in the constructor.

Bug: 68780091
Test: runtest -x IpSecAlgorithmTest.java
Change-Id: I8172762617264d34f47d5144336464510f07a701
2017-12-04 15:12:14 -08:00
Jonathan Basseri
f96bfee165 Merge "Javadoc cleanup of IpSecManager API."
am: d09d106ec0

Change-Id: Iaf206b0980d3bed14fe6b8318d2073577212b460
2017-11-22 01:51:46 +00:00
Jonathan Basseri
2725a233c9 Javadoc cleanup of IpSecManager API.
This changes only comments and annotations, which results
in minor API changes.

Bug: 63777932
Test: `make update-api` and visually inspect generated HTML.
Change-Id: I7a7a9244eade6cc55aca17a47e0a838cd6f84cc9
2017-11-20 10:49:59 -08:00