Package 

Class SecurityPolicies


  • @CheckReturnValue() 
    public final class SecurityPolicies
    
                        

    Static factory methods for creating standard security policies.

    • Method Detail

      • hasSignature

        @ExperimentalApi(value = https://github.com/grpc/grpc-java/issues/8022) static SecurityPolicy hasSignature(PackageManager packageManager, String packageName, Signature requiredSignature)

        Creates a SecurityPolicy which checks if the package signaturematches {@code requiredSignature}.

        Parameters:
        packageName - the package name of the allowed package.
        requiredSignature - the allowed signature of the allowed package.
      • hasSignatureSha256Hash

        @ExperimentalApi(value = https://github.com/grpc/grpc-java/issues/8022) static SecurityPolicy hasSignatureSha256Hash(PackageManager packageManager, String packageName, Array<byte> requiredSignatureSha256Hash)

        Creates SecurityPolicy which checks if the SHA-256 hash of the package signaturematches {@code requiredSignatureSha256Hash}.

        Parameters:
        packageName - the package name of the allowed package.
        requiredSignatureSha256Hash - the SHA-256 digest of the signature of the allowed package.
      • oneOfSignatures

        @ExperimentalApi(value = https://github.com/grpc/grpc-java/issues/8022) static SecurityPolicy oneOfSignatures(PackageManager packageManager, String packageName, Collection<Signature> requiredSignatures)

        Creates a SecurityPolicy which checks if the package signaturematches any of {@code requiredSignatures}.

        Parameters:
        packageName - the package name of the allowed package.
        requiredSignatures - the allowed signatures of the allowed package.
      • oneOfSignatureSha256Hash

         static SecurityPolicy oneOfSignatureSha256Hash(PackageManager packageManager, String packageName, List<Array<byte>> requiredSignatureSha256Hashes)

        Creates SecurityPolicy which checks if the SHA-256 hash of the package signaturematches any of {@code requiredSignatureSha256Hashes}.

        Parameters:
        packageName - the package name of the allowed package.
        requiredSignatureSha256Hashes - the SHA-256 digests of the signatures of the allowedpackage.
      • allOf

         static SecurityPolicy allOf(Array<SecurityPolicy> securityPolicies)

        Creates a SecurityPolicy that allows access if and only if *all* of the specified {@code securityPolicies} allow access.

        Parameters:
        securityPolicies - the security policies that all must allow access.
      • anyOf

         static SecurityPolicy anyOf(Array<SecurityPolicy> securityPolicies)

        Creates a SecurityPolicy that allows access if *any* of the specified {@code * securityPolicies} allow access.

        Policies will be checked in the order that they are passed. If a policy allows access,subsequent policies will not be checked.

        If all policies deny access, the io.grpc.Status returned by {@code * checkAuthorization} will included the concatenated descriptions of the failed policies andattach any additional causes as suppressed throwables. The status code will be that of thefirst failed policy.

        Parameters:
        securityPolicies - the security policies that will be checked.
      • hasPermissions

         static SecurityPolicy hasPermissions(PackageManager packageManager, ImmutableSet<String> permissions)

        Creates a SecurityPolicy which checks if the caller has all of the given permissionsfrom {@code permissions}.

        The gRPC framework assumes that a SecurityPolicy's verdict for a given peer UID willnot change over the lifetime of any process with that UID. But Android runtime permissions canbe granted or revoked by the user at any time and so using the hasPermissionsSecurityPolicy comes with certain special responsibilities.

        In particular, callers must ensure that the *subjects* of the returned SecurityPolicy hold all required {@code permissions} *before* making use of it. Androidkills an app's processes when it loses any permission but the same isn't true when a permissionis granted. And so without special care, a hasPermissions denial could incorrectlypersist even if the subject is later granted all required {@code permissions}.

        A server using hasPermissions must, as part of its RPC API contract, requireclients to request and receive all {@code permissions} before making a call. This is in linewith official Android guidance to request and confirm receipt of runtime permissions beforeusing them.

        A client, on the other hand, should only use hasPermissions policies that requireinstall-time permissions which cannot change.

        Parameters:
        permissions - all permissions that the calling package needs to have