Skip to content

Commit a40c8cf

Browse files
authored
binder: Let apps call SecurityPolicy.checkAuthorization() by PeerUid (#12257)
This allows a server with access to PeerUid to check additional application-layer security policy *after* the call itself is authorized by the transport layer. Cross cutting application-layer checks could be done from a ServerInterceptor (RPC method level policy, say). Checks based on the substance of a request message could be done by the individual RPC method implementations themselves.
1 parent 8b46ad5 commit a40c8cf

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

binder/src/main/java/io/grpc/binder/AsyncSecurityPolicy.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,25 @@ public final Status checkAuthorization(int uid) {
6767
* authorized.
6868
*/
6969
public abstract ListenableFuture<Status> checkAuthorizationAsync(int uid);
70+
71+
/**
72+
* Decides whether the given Android UID is authorized, without providing its raw integer value.
73+
*
74+
* <p>Calling this is equivalent to calling {@link SecurityPolicy#checkAuthorization(int)}, except
75+
* the caller provides a {@link PeerUid} wrapper instead of the raw integer uid (known only to the
76+
* transport). This allows a server to check additional application-layer security policy for
77+
* itself *after* the call itself is authorized by the transport layer. Cross cutting application-
78+
* layer checks could be done from a {@link io.grpc.ServerInterceptor}. Checks based on the
79+
* substance of a request message could be done by the individual RPC method implementations
80+
* themselves.
81+
*
82+
* <p>See #checkAuthorizationAsync(int) for details on the semantics. See {@link
83+
* PeerUids#newPeerIdentifyingServerInterceptor()} for how to get a {@link PeerUid}.
84+
*
85+
* @param uid The Android UID to authenticate.
86+
* @return A gRPC {@link Status} object, with OK indicating authorized.
87+
*/
88+
public final ListenableFuture<Status> checkAuthorizationAsync(PeerUid uid) {
89+
return checkAuthorizationAsync(uid.getUid());
90+
}
7091
}

binder/src/main/java/io/grpc/binder/SecurityPolicy.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,25 @@ protected SecurityPolicy() {}
5353
* @return A gRPC {@link Status} object, with OK indicating authorized.
5454
*/
5555
public abstract Status checkAuthorization(int uid);
56+
57+
/**
58+
* Decides whether the given Android UID is authorized, without providing its raw integer value.
59+
*
60+
* <p>Calling this is equivalent to calling {@link SecurityPolicy#checkAuthorization(int)}, except
61+
* the caller provides a {@link PeerUid} wrapper instead of the raw integer uid (known only to the
62+
* transport). This allows a server to check additional application-layer security policy for
63+
* itself *after* the call itself is authorized by the transport layer. Cross cutting application-
64+
* layer checks could be done from a {@link io.grpc.ServerInterceptor}. Checks based on the
65+
* substance of a request message could be done by the individual RPC method implementations
66+
* themselves.
67+
*
68+
* <p>See #checkAuthorizationAsync(int) for details on the semantics. See {@link
69+
* PeerUids#newPeerIdentifyingServerInterceptor()} for how to get a {@link PeerUid}.
70+
*
71+
* @param uid The Android UID to authenticate.
72+
* @return A gRPC {@link Status} object, with OK indicating authorized.
73+
*/
74+
public final Status checkAuthorization(PeerUid uid) {
75+
return checkAuthorization(uid.getUid());
76+
}
5677
}

0 commit comments

Comments
 (0)