Commit Graph

46 Commits

Author SHA1 Message Date
marvinliu 80f1cbf6c4
binder: add hasPermissions security policy and test 2022-05-02 10:15:22 -07:00
Sergii Tkachenko b3d4607a62
binder, xds: address minor linter fixes (#9130) 2022-04-29 09:42:15 -07:00
Marvin Liu fdd9ab4f96 adding a security policy that allows access if and only if all given security policies allow access. this contributes to b/221149437 and is similar to cl/442582915 2022-04-28 15:48:23 -07:00
Marvin Liu 40973aedbe usage of ErrorProne CheckReturnValue 2022-04-28 13:02:43 -07:00
John Cormie fba4ae496a
binder: Work around an Android Intent bug (#9061)
Where filterEquals() can be inconsistent with filterHashCode().

Fixes #9045
2022-04-06 07:37:00 -07:00
Eric Anderson 3c2c357efa binder: Use Ticker for durations
Ticker is powered by System.nanoTime() which is CLOCK_MONOTONIC.
TimeProvider is powered by System.currentTimeMillis() which is
CLOCK_REALTIME. For durations, the monotonic clock is appropriate, not
the wall time which can jump around.
2022-04-06 07:16:21 -07:00
John Cormie 2bf0a1f271
binder: Dispatch transact() calls on an Executor when FLAG_ONEWAY would not be respected. (#8987)
Fixes #8914
2022-03-16 23:19:06 -07:00
John Cormie abd1642371
New streams before transportReady() are not guaranteed to work (#8955)
Update javadoc to mention this previously-unwritten rule.

Update earlyServerClose_serverFailure_withClientCancelOnListenerClosed to obey it.

Update BinderTransport to fail sooner if this rule is broken.
2022-03-03 08:03:07 -08:00
John Cormie 128324540f
binder: Fix a ServiceConnection leak (#8861)
Closes #8726
2022-01-24 19:54:21 -08:00
ZHANG Dapeng d1e0be6919
all: fix various gradle build warnings 2022-01-18 10:18:16 -08:00
markb74 d853414ba3
Update javadoc for AndroidComponentAddress. (#8725)
Be more explicit that "packagename" is the application package name.
2022-01-18 09:22:59 -08:00
John Cormie 25531d6257
binder: Invoke onTransportReady() in a round-robin fashion. (#8835)
Also call onTransportReady() only if isReady() still holds by the time
we get to a given Inbound. This dramatically reduces timeouts and
improves throughput when flow control has kicked in.

This approach is still not completely fair since each ongoing call might
consume a different amount of window on its turn, but because of the way
Outbound#writeMessageData() and BlockPool already work, everyone gets to
send at least 16kb.
2022-01-14 14:06:14 -08:00
Eric Anderson d44de5069d
Bump to Gradle 6.9 and update plugins
These changes make the build compatible with Gradle 7, except for
Android which requires plugin updates.

I removed animalsniffer from binder because it did nothing (as there
were no signatures) and it was failing after setting toolVersion. It
failed because animalsniffer is only compatible with java plugin. After
this change I put the withId(animalsniffer) loading inside the
withId(java) to avoid a plugin ordering failure. That made it safe again
for binder to load animalsniffer, but it is still best to remove the
plugin from binder as it is misleading.

I did not upgrade Android plugin versions as newer versions (even 3.6)
require dealing with androidx (#8421).
2022-01-07 09:54:50 -08:00
Grant Oakley e28145ab6a
Enclose all operations using obtained Parcels in try-finally blocks that will recycle the Parcel in the case that any exception is thrown. (#8733) 2021-12-08 14:39:42 -08:00
John Cormie 27b03c66a6
Send empty shutdown flags to avoid a binder memory leak (#8728) 2021-11-30 16:00:43 -08:00
markb74 746501dff6
binder: SecurityPolicy updates (take 2). (#8637)
The previous attempt at this CL relied on guava's Hashing class which
is still in beta. This update compares Signature objects directly instead
of SHA256 hashs, removing the need for the Hashing class.

Add additional comments to the security policy class, to mention that
implementing new policies requires significant care.

With that in mind, add security policies to check the peer app's
signature, so people can create cross-app communication without
having to implement their own policy.

Finally, add the UntrustedSecurityPolicies class, since that's
inevitably a policy which is sometimes needed.
2021-11-01 18:57:30 +01:00
markb74 14eb3b265f
Support BinderChannelBuilder.forTarget. (#8633)
Allows this class to be used with custom name resolvers.
2021-11-01 14:01:56 +01:00
Eric Anderson ee395e0e43 Revert "binder: SecurityPolicy updates. (#8632)"
This reverts commit 997592192b.

Hashing is a Beta API in Guava, so we can't use it as-is.
2021-10-28 13:18:14 -07:00
markb74 997592192b
binder: SecurityPolicy updates. (#8632)
Add additional comments to the security policy class, to mention that implementing new policies requires significant care.

Also add security policies which check the Sha256 of a peer apps's signature, so people can do trusted cross-app communication without having to implement their own policy.

Finally, add the UntrustedSecurityPolicies class, since that's inevitably a policy you sometimes need as well.
2021-10-28 11:30:43 +02:00
markb74 9266174812
Fix code & javadoc warnings in the binder package. (#8588)
Note: I didn't fix all javadoc warnings mentioned in #8585, since
they're not generated with a modern java version, and the fix feels
worse than the warning.

Specifically, {@link X.Y} generates a warning if only X is imported,
and {@link Z} generates a warning if Z is declared later in the class.

In particular, attempting to fix the first issue by importing X.Y results
in a code-readability warning suggesting I shouldn't do that.
2021-10-09 12:27:01 +02:00
markb74 0d25d8f7d6
Publish binder in releases. (#8585) 2021-10-08 12:03:44 +02:00
ZHANG Dapeng 2e84b0f20a
android: bump min Android SDK version to 19 (#8583)
As Google Play Service [discontinued updates for Jelly Bean (API levels 16, 17 & 18)](https://android-developers.googleblog.com/2021/07/google-play-services-discontinuing-jelly-bean.html).
2021-10-06 10:02:32 -07:00
markb74 fcc7b9694e
Add LifecycleOnDestroyHelper to support shutdown of channel/server on Android lifecycle changes (#8568) 2021-09-29 20:04:47 +02:00
John Cormie 3ff23d3684
Synchronize access to acknowledgedOutgoingBytes/transmitWindowFull. (#8547)
Fixes #8536
2021-09-22 12:19:48 -07:00
John Cormie 46dbac3eb6
Make manifest usable with android_instrumentation_test()s in google3 (#8545) 2021-09-22 11:53:16 -07:00
markb74 e244065b0c
Fix flakey security policy tests. (#8550)
Using ShadowProcess to set the processes uID doesn't help since SecurityPolicies class fetches the ID in a static initializer, and it may have already been loaded.

Instead, just rely on whatever the uID is already, and ensure the other UIDs we test with are offset from that first value.
2021-09-22 19:19:10 +02:00
Eric Anderson 7942f35c47 binder: Disable flaky SecurityPolicy tests
Not using `@Ignore` because the tests can probably run successfully
under Bazel.

See #8391
2021-08-06 12:20:39 -07:00
ZHANG Dapeng 1833587597
binder: fix binder build (#8366)
The binder module fail to compile because in #8355, the class BinderClientTransportTest was not refactored correspondingly.
2021-08-02 15:54:55 -07:00
ZHANG Dapeng 860e97d12a
all: API refactoring in preparation to support retry stats (#8355)
Rebased PR #8343 into the first commit of this PR, then (the 2nd commit) reverted the part for metric recording of retry attempts. The PR as a whole is mechanical refactoring. No behavior change (except that some of the old code path when tracer is created is moved into the new method `streamCreated()`).

The API change is documented in go/grpc-stats-api-change-for-retry-java
2021-07-31 18:33:02 -07:00
markb74 5e18ff208a
Run binderchannel android tests. (#8306) 2021-07-14 13:10:28 +02:00
markb74 eb802cf6b1
Add an asAndroidAppUri() method to AndroidComponentAddress. (#8312)
This returns the address as an "android-app://" uri, which can be
used with AndroidAppNameResolverProvider.
2021-07-14 11:01:07 +02:00
Eric Anderson dd2a422193 binder: Remove unused import 2021-07-08 09:48:43 -05:00
markb74 d4ecc7cdb4
More exposed APIs to support internal transition. (#8303)
All maked with Internal to make it clear these APIs shouldn't
be used normally.
2021-07-05 13:12:49 +02:00
John Cormie 380f26fd8d
Inform the server of the client's deadline using the standard header. (#8286) 2021-07-02 18:31:50 +02:00
markb74 06d34925f9
binder: Updates to support migrations to this API from internal versions. (#8299) 2021-07-02 12:53:47 +02:00
John Cormie 66faf105dd
Fix BinderSecurityTests that would always pass due to empty 'methods' map (#8287) 2021-06-25 22:15:08 +02:00
John Cormie c092d94255
Update AndroidComponentAddress to wrap a binding Intent. (#8275)
By considering this Intent's action, data, type, identity and categories
we align gRPC/Binder's addressing with Android's natural equivalence
relation for "cached" IBinders.
2021-06-24 13:38:06 +02:00
Eric Anderson 5642e01243
Replace failOnVersionConflict() with custom requireUpperBoundDeps
failOnVersionConflict has never been good for us. It is equivalent to
Maven dependencyConvergence which we discourage our users to use because
it is too tempermental and _creates_ version skew issues over time.
However, we had no real alternative for determining if our deps would be
misinterpeted by Maven.

failOnVersionConflict has been a constant drain and makes it really hard
to do seemingly-trivial upgrades. As evidenced by protobuf/build.gradle
in this change, it also caused _us_ to introduce a version downgrade.

This introduces our own custom requireUpperBoundDeps implementation so
that we can get back to simple dependency upgrades _and_ increase our
confidence in a consistent dependency tree.
2021-06-11 14:01:18 -07:00
markb74 b846ae79bb
Allow SecurityPolicy definitions. (#8254)
Internally this was package visible to retain strict control
over the available policies. However, that kind of strict control
doesn't work with the open-source version, since users will want
to create their own policies. There's at least google-specific
policy internally.
2021-06-11 18:02:36 +02:00
markb74 0c723f7ca9
binder: Server and Channel Builders for BinderChannel. (#8218)
binder: Server and Channel Builders for BinderChannel.

Also adds 3 additional tests.
2021-06-07 19:39:20 +02:00
markb74 1cd925c3dd
Remove InternalMetadataHelper. (#8209)
This class wasn't really necessary.
2021-06-02 11:03:29 +02:00
markb74 f88d362bc7
Fix the use of scheduler pools in BinderServer. (#8210)
Switch to using scheduled pools in BinderServer.
2021-05-27 13:37:22 +02:00
markb74 8e18c11bbd
binder: BinderTransport implementation. (#8031)
This is the first major code drop for binderchannel, containing the transport class and its internals.
2021-05-26 14:54:32 +02:00
Chengyuan Zhang f33658a6d7
Migrate away from Jcenter (#8111)
Replaces jcenter with mavenCentral.
2021-04-22 15:59:36 -07:00
markb74 9fc32f1bc9
binder: Add LeakSafeOneWayBinder and tests. (#8021)
Another util class, this one with tests which need to run on
an Android emulator.
2021-03-31 17:39:10 +01:00
markb74 c6d48f7cb1
binder: Some basic binderchannel util code (#7796)
This just adds the ServiceBinding class and
BindServiceFlags, internal utils.

Most binderchannel code relies heavily on Java8 features,
so I'm keeping that requirement, since grpc-java plans to
require Java8 eventually anyway.
2021-03-24 15:40:11 -07:00