blob: cdd6584e9b35ca2581143589be3254bd96b971a6 [file] [log] [blame]
Victor Hsieh20fe1f62019-09-30 13:36:21 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.security;
18
19import android.annotation.NonNull;
20import android.annotation.RequiresPermission;
21import android.annotation.SystemService;
22import android.content.Context;
23import android.os.RemoteException;
24
25import java.security.cert.CertificateEncodingException;
26import java.security.cert.X509Certificate;
27
28/**
29 * This class provides access to file integrity related operations.
30 */
31@SystemService(Context.FILE_INTEGRITY_SERVICE)
32public final class FileIntegrityManager {
33 @NonNull private final IFileIntegrityService mService;
34
35 /** @hide */
36 public FileIntegrityManager(@NonNull IFileIntegrityService service) {
37 mService = service;
38 }
39
40 /**
41 * Returns true if APK Verity is supported on the device. When supported, an APK can be
42 * installed with a fs-verity signature (if verified with trusted App Source Certificate) for
43 * continuous on-access verification.
44 */
45 public boolean isApkVeritySupported() {
46 try {
47 // Go through the service just to avoid exposing the vendor controlled system property
48 // to all apps.
49 return mService.isApkVeritySupported();
50 } catch (RemoteException e) {
51 throw e.rethrowFromSystemServer();
52 }
53 }
54
55 /**
56 * Returns whether the given certificate can be used to prove app's install source. Always
57 * return false if the feature is not supported.
58 *
59 * <p>A store can use this API to decide if a signature file needs to be downloaded. Also, if a
60 * store has shipped different certificates before (e.g. with stronger and weaker key), it can
61 * also use this API to download the best signature on the running device.
62 *
63 * @return whether the certificate is trusted in the system
64 */
65 @RequiresPermission(anyOf = {
66 android.Manifest.permission.INSTALL_PACKAGES,
67 android.Manifest.permission.REQUEST_INSTALL_PACKAGES
68 })
69 public boolean isAppSourceCertificateTrusted(@NonNull X509Certificate certificate)
70 throws CertificateEncodingException {
71 try {
72 return mService.isAppSourceCertificateTrusted(certificate.getEncoded());
73 } catch (RemoteException e) {
74 throw e.rethrowFromSystemServer();
75 }
76 }
77}