Paul Crowley | f71ace3 | 2016-06-02 11:01:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
| 17 | #ifndef ANDROID_VOLD_KEYUTIL_H |
| 18 | #define ANDROID_VOLD_KEYUTIL_H |
| 19 | |
Pavel Grafov | e2e2d30 | 2017-08-01 17:15:53 +0100 | [diff] [blame] | 20 | #include "KeyBuffer.h" |
Paul Crowley | 26a5388 | 2017-10-26 11:16:39 -0700 | [diff] [blame] | 21 | #include "KeyStorage.h" |
Pavel Grafov | e2e2d30 | 2017-08-01 17:15:53 +0100 | [diff] [blame] | 22 | |
Paul Crowley | 77df7f2 | 2020-01-23 15:29:30 -0800 | [diff] [blame] | 23 | #include <fscrypt/fscrypt.h> |
| 24 | |
Pavel Grafov | e2e2d30 | 2017-08-01 17:15:53 +0100 | [diff] [blame] | 25 | #include <memory> |
Paul Crowley | 14c8c07 | 2018-09-18 13:30:21 -0700 | [diff] [blame] | 26 | #include <string> |
Paul Crowley | f71ace3 | 2016-06-02 11:01:19 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace vold { |
| 30 | |
Paul Crowley | 77df7f2 | 2020-01-23 15:29:30 -0800 | [diff] [blame] | 31 | using namespace android::fscrypt; |
| 32 | |
Pavel Grafov | e2e2d30 | 2017-08-01 17:15:53 +0100 | [diff] [blame] | 33 | bool randomKey(KeyBuffer* key); |
Eric Biggers | f3dc420 | 2019-09-30 13:05:58 -0700 | [diff] [blame] | 34 | |
| 35 | bool isFsKeyringSupported(void); |
| 36 | |
Paul Crowley | 77df7f2 | 2020-01-23 15:29:30 -0800 | [diff] [blame] | 37 | // Install a file-based encryption key to the kernel, for use by encrypted files |
| 38 | // on the specified filesystem using the specified encryption policy version. |
| 39 | // |
| 40 | // For v1 policies, we use FS_IOC_ADD_ENCRYPTION_KEY if the kernel supports it. |
| 41 | // Otherwise we add the key to the legacy global session keyring. |
| 42 | // |
| 43 | // For v2 policies, we always use FS_IOC_ADD_ENCRYPTION_KEY; it's the only way |
| 44 | // the kernel supports. |
| 45 | // |
| 46 | // Returns %true on success, %false on failure. On success also sets *policy |
| 47 | // to the EncryptionPolicy used to refer to this key. |
| 48 | bool installKey(const std::string& mountpoint, const EncryptionOptions& options, |
| 49 | const KeyBuffer& key, EncryptionPolicy* policy); |
| 50 | |
| 51 | // Evict a file-based encryption key from the kernel. |
| 52 | // |
| 53 | // We use FS_IOC_REMOVE_ENCRYPTION_KEY if the kernel supports it. Otherwise we |
| 54 | // remove the key from the legacy global session keyring. |
| 55 | // |
| 56 | // In the latter case, the caller is responsible for dropping caches. |
| 57 | bool evictKey(const std::string& mountpoint, const EncryptionPolicy& policy); |
| 58 | |
| 59 | bool retrieveKey(bool create_if_absent, const KeyAuthentication& key_authentication, |
| 60 | const std::string& key_path, const std::string& tmp_path, KeyBuffer* key, |
| 61 | bool keepOld = true); |
Paul Crowley | f71ace3 | 2016-06-02 11:01:19 -0700 | [diff] [blame] | 62 | |
| 63 | } // namespace vold |
| 64 | } // namespace android |
| 65 | |
| 66 | #endif |