diff options
author | Eric Biggers <ebiggers@google.com> | 2018-10-29 17:19:39 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-10-29 17:19:39 +0000 |
commit | b27fec0d91b6a33776e831f2c898ab5a71e07340 (patch) | |
tree | 2c0adbb1f50eb882ee4d5cf2af9ebdd7ab1afbc0 | |
parent | 67f1b299ade36c4b419d15fd1d63e1dfb5b222f2 (diff) | |
parent | b0ff883fb6f32b3dee1eddb5ee64fa739b19e974 (diff) | |
download | extras-b27fec0d91b6a33776e831f2c898ab5a71e07340.tar.gz |
Merge changes from topic "e4crypt_to_fscrypt"
* changes:
libfscrypt: get the fscrypt kernel API declarations from linux/fs.h
Refactor "ext4 encryption" code into libfscrypt
-rw-r--r-- | ext4_utils/Android.bp | 6 | ||||
-rw-r--r-- | libfscrypt/Android.bp | 17 | ||||
-rw-r--r-- | libfscrypt/MODULE_LICENSE_APACHE2 | 0 | ||||
-rw-r--r-- | libfscrypt/NOTICE | 190 | ||||
-rw-r--r-- | libfscrypt/fscrypt.cpp (renamed from ext4_utils/ext4_crypt.cpp) | 123 | ||||
-rw-r--r-- | libfscrypt/fscrypt_init_extensions.cpp (renamed from ext4_utils/ext4_crypt_init_extensions.cpp) | 19 | ||||
-rw-r--r-- | libfscrypt/include/fscrypt/fscrypt.h (renamed from ext4_utils/include/ext4_utils/ext4_crypt.h) | 16 | ||||
-rw-r--r-- | libfscrypt/include/fscrypt/fscrypt_init_extensions.h (renamed from ext4_utils/include/ext4_utils/ext4_crypt_init_extensions.h) | 10 |
8 files changed, 278 insertions, 103 deletions
diff --git a/ext4_utils/Android.bp b/ext4_utils/Android.bp index ead4d4d9..5b57575e 100644 --- a/ext4_utils/Android.bp +++ b/ext4_utils/Android.bp @@ -30,14 +30,8 @@ cc_library { }, android: { - srcs: [ - "ext4_crypt.cpp", - "ext4_crypt_init_extensions.cpp", - ], shared_libs: [ "libbase", - "libkeyutils", - "liblogwrap", "libselinux", ], diff --git a/libfscrypt/Android.bp b/libfscrypt/Android.bp new file mode 100644 index 00000000..cca38235 --- /dev/null +++ b/libfscrypt/Android.bp @@ -0,0 +1,17 @@ +// Copyright 2018 The Android Open Source Project + +cc_library { + name: "libfscrypt", + recovery_available: true, + srcs: [ + "fscrypt.cpp", + "fscrypt_init_extensions.cpp", + ], + export_include_dirs: ["include"], + shared_libs: [ + "libbase", + "libcutils", + "libkeyutils", + "liblogwrap", + ], +} diff --git a/libfscrypt/MODULE_LICENSE_APACHE2 b/libfscrypt/MODULE_LICENSE_APACHE2 new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/libfscrypt/MODULE_LICENSE_APACHE2 diff --git a/libfscrypt/NOTICE b/libfscrypt/NOTICE new file mode 100644 index 00000000..8530865d --- /dev/null +++ b/libfscrypt/NOTICE @@ -0,0 +1,190 @@ + + Copyright (c) 2015, The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + diff --git a/ext4_utils/ext4_crypt.cpp b/libfscrypt/fscrypt.cpp index 36fe11f7..bf611887 100644 --- a/ext4_utils/ext4_crypt.cpp +++ b/libfscrypt/fscrypt.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "ext4_utils/ext4_crypt.h" +#include "fscrypt/fscrypt.h" #include <array> @@ -22,9 +22,10 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <linux/fs.h> #include <string.h> -#include <sys/syscall.h> #include <sys/stat.h> +#include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> @@ -34,41 +35,15 @@ #include <logwrap/logwrap.h> #include <utils/misc.h> -#define XATTR_NAME_ENCRYPTION_POLICY "encryption.policy" -#define EXT4_KEYREF_DELIMITER ((char)'.') - -// ext4enc:TODO Include structure from somewhere sensible -// MUST be in sync with ext4_crypto.c in kernel -#define EXT4_KEY_DESCRIPTOR_SIZE 8 -#define EXT4_KEY_DESCRIPTOR_SIZE_HEX 17 - -struct ext4_encryption_policy { - uint8_t version; - uint8_t contents_encryption_mode; - uint8_t filenames_encryption_mode; - uint8_t flags; - uint8_t master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE]; -} __attribute__((__packed__)); - -#define EXT4_ENCRYPTION_MODE_AES_256_XTS 1 -#define EXT4_ENCRYPTION_MODE_AES_256_CTS 4 -#define EXT4_ENCRYPTION_MODE_AES_256_HEH 126 -#define EXT4_ENCRYPTION_MODE_PRIVATE 127 - -#define EXT4_POLICY_FLAGS_PAD_4 0x00 -#define EXT4_POLICY_FLAGS_PAD_8 0x01 -#define EXT4_POLICY_FLAGS_PAD_16 0x02 -#define EXT4_POLICY_FLAGS_PAD_32 0x03 -#define EXT4_POLICY_FLAGS_PAD_MASK 0x03 -#define EXT4_POLICY_FLAGS_VALID 0x03 +#define FS_KEY_DESCRIPTOR_SIZE_HEX (2 * FS_KEY_DESCRIPTOR_SIZE + 1) -// ext4enc:TODO Get value from somewhere sensible -#define EXT4_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct ext4_encryption_policy) -#define EXT4_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct ext4_encryption_policy) +/* modes not supported by upstream kernel, so not in <linux/fs.h> */ +#define FS_ENCRYPTION_MODE_AES_256_HEH 126 +#define FS_ENCRYPTION_MODE_PRIVATE 127 #define HEX_LOOKUP "0123456789abcdef" -bool e4crypt_is_native() { +bool fscrypt_is_native() { char value[PROPERTY_VALUE_MAX]; property_get("ro.crypto.type", value, "none"); return !strcmp(value, "file"); @@ -96,11 +71,11 @@ static void log_ls(const char* dirname) { } static void policy_to_hex(const char* policy, char* hex) { - for (size_t i = 0, j = 0; i < EXT4_KEY_DESCRIPTOR_SIZE; i++) { + for (size_t i = 0, j = 0; i < FS_KEY_DESCRIPTOR_SIZE; i++) { hex[j++] = HEX_LOOKUP[(policy[i] & 0xF0) >> 4]; hex[j++] = HEX_LOOKUP[policy[i] & 0x0F]; } - hex[EXT4_KEY_DESCRIPTOR_SIZE_HEX - 1] = '\0'; + hex[FS_KEY_DESCRIPTOR_SIZE_HEX - 1] = '\0'; } static bool is_dir_empty(const char *dirname, bool *is_empty) @@ -133,27 +108,27 @@ static bool is_dir_empty(const char *dirname, bool *is_empty) return true; } -static uint8_t e4crypt_get_policy_flags(int filenames_encryption_mode) { - if (filenames_encryption_mode == EXT4_ENCRYPTION_MODE_AES_256_CTS) { +static uint8_t fscrypt_get_policy_flags(int filenames_encryption_mode) { + if (filenames_encryption_mode == FS_ENCRYPTION_MODE_AES_256_CTS) { // Use legacy padding with our original filenames encryption mode. - return EXT4_POLICY_FLAGS_PAD_4; + return FS_POLICY_FLAGS_PAD_4; } // With a new mode we can use the better padding flag without breaking existing devices: pad // filenames with zeroes to the next 16-byte boundary. This is more secure (helps hide the // length of filenames) and makes the inputs evenly divisible into blocks which is more // efficient for encryption and decryption. - return EXT4_POLICY_FLAGS_PAD_16; + return FS_POLICY_FLAGS_PAD_16; } -static bool e4crypt_policy_set(const char *directory, const char *policy, +static bool fscrypt_policy_set(const char *directory, const char *policy, size_t policy_length, int contents_encryption_mode, int filenames_encryption_mode) { - if (policy_length != EXT4_KEY_DESCRIPTOR_SIZE) { + if (policy_length != FS_KEY_DESCRIPTOR_SIZE) { LOG(ERROR) << "Policy wrong length: " << policy_length; return false; } - char policy_hex[EXT4_KEY_DESCRIPTOR_SIZE_HEX]; + char policy_hex[FS_KEY_DESCRIPTOR_SIZE_HEX]; policy_to_hex(policy, policy_hex); int fd = open(directory, O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC); @@ -162,13 +137,13 @@ static bool e4crypt_policy_set(const char *directory, const char *policy, return false; } - ext4_encryption_policy eep; - eep.version = 0; - eep.contents_encryption_mode = contents_encryption_mode; - eep.filenames_encryption_mode = filenames_encryption_mode; - eep.flags = e4crypt_get_policy_flags(filenames_encryption_mode); - memcpy(eep.master_key_descriptor, policy, EXT4_KEY_DESCRIPTOR_SIZE); - if (ioctl(fd, EXT4_IOC_SET_ENCRYPTION_POLICY, &eep)) { + fscrypt_policy fp; + fp.version = 0; + fp.contents_encryption_mode = contents_encryption_mode; + fp.filenames_encryption_mode = filenames_encryption_mode; + fp.flags = fscrypt_get_policy_flags(filenames_encryption_mode); + memcpy(fp.master_key_descriptor, policy, FS_KEY_DESCRIPTOR_SIZE); + if (ioctl(fd, FS_IOC_SET_ENCRYPTION_POLICY, &fp)) { PLOG(ERROR) << "Failed to set encryption policy for " << directory << " to " << policy_hex << " modes " << contents_encryption_mode << "/" << filenames_encryption_mode; close(fd); @@ -181,11 +156,11 @@ static bool e4crypt_policy_set(const char *directory, const char *policy, return true; } -static bool e4crypt_policy_get(const char *directory, char *policy, +static bool fscrypt_policy_get(const char *directory, char *policy, size_t policy_length, int contents_encryption_mode, int filenames_encryption_mode) { - if (policy_length != EXT4_KEY_DESCRIPTOR_SIZE) { + if (policy_length != FS_KEY_DESCRIPTOR_SIZE) { LOG(ERROR) << "Policy wrong length: " << policy_length; return false; } @@ -196,9 +171,9 @@ static bool e4crypt_policy_get(const char *directory, char *policy, return false; } - ext4_encryption_policy eep; - memset(&eep, 0, sizeof(ext4_encryption_policy)); - if (ioctl(fd, EXT4_IOC_GET_ENCRYPTION_POLICY, &eep) != 0) { + fscrypt_policy fp; + memset(&fp, 0, sizeof(fscrypt_policy)); + if (ioctl(fd, FS_IOC_GET_ENCRYPTION_POLICY, &fp) != 0) { PLOG(ERROR) << "Failed to get encryption policy for " << directory; close(fd); log_ls(directory); @@ -206,37 +181,37 @@ static bool e4crypt_policy_get(const char *directory, char *policy, } close(fd); - if ((eep.version != 0) - || (eep.contents_encryption_mode != contents_encryption_mode) - || (eep.filenames_encryption_mode != filenames_encryption_mode) - || (eep.flags != - e4crypt_get_policy_flags(filenames_encryption_mode))) { + if ((fp.version != 0) + || (fp.contents_encryption_mode != contents_encryption_mode) + || (fp.filenames_encryption_mode != filenames_encryption_mode) + || (fp.flags != + fscrypt_get_policy_flags(filenames_encryption_mode))) { LOG(ERROR) << "Failed to find matching encryption policy for " << directory; return false; } - memcpy(policy, eep.master_key_descriptor, EXT4_KEY_DESCRIPTOR_SIZE); + memcpy(policy, fp.master_key_descriptor, FS_KEY_DESCRIPTOR_SIZE); return true; } -static bool e4crypt_policy_check(const char *directory, const char *policy, +static bool fscrypt_policy_check(const char *directory, const char *policy, size_t policy_length, int contents_encryption_mode, int filenames_encryption_mode) { - if (policy_length != EXT4_KEY_DESCRIPTOR_SIZE) { + if (policy_length != FS_KEY_DESCRIPTOR_SIZE) { LOG(ERROR) << "Policy wrong length: " << policy_length; return false; } - char existing_policy[EXT4_KEY_DESCRIPTOR_SIZE]; - if (!e4crypt_policy_get(directory, existing_policy, EXT4_KEY_DESCRIPTOR_SIZE, + char existing_policy[FS_KEY_DESCRIPTOR_SIZE]; + if (!fscrypt_policy_get(directory, existing_policy, FS_KEY_DESCRIPTOR_SIZE, contents_encryption_mode, filenames_encryption_mode)) return false; - char existing_policy_hex[EXT4_KEY_DESCRIPTOR_SIZE_HEX]; + char existing_policy_hex[FS_KEY_DESCRIPTOR_SIZE_HEX]; policy_to_hex(existing_policy, existing_policy_hex); - if (memcmp(policy, existing_policy, EXT4_KEY_DESCRIPTOR_SIZE) != 0) { - char policy_hex[EXT4_KEY_DESCRIPTOR_SIZE_HEX]; + if (memcmp(policy, existing_policy, FS_KEY_DESCRIPTOR_SIZE) != 0) { + char policy_hex[FS_KEY_DESCRIPTOR_SIZE_HEX]; policy_to_hex(policy, policy_hex); LOG(ERROR) << "Found policy " << existing_policy_hex << " at " << directory << " which doesn't match expected value " << policy_hex; @@ -248,7 +223,7 @@ static bool e4crypt_policy_check(const char *directory, const char *policy, return true; } -int e4crypt_policy_ensure(const char *directory, const char *policy, +int fscrypt_policy_ensure(const char *directory, const char *policy, size_t policy_length, const char *contents_encryption_mode, const char *filenames_encryption_mode) { @@ -257,9 +232,9 @@ int e4crypt_policy_ensure(const char *directory, const char *policy, if (!strcmp(contents_encryption_mode, "software") || !strcmp(contents_encryption_mode, "aes-256-xts")) { - contents_mode = EXT4_ENCRYPTION_MODE_AES_256_XTS; + contents_mode = FS_ENCRYPTION_MODE_AES_256_XTS; } else if (!strcmp(contents_encryption_mode, "ice")) { - contents_mode = EXT4_ENCRYPTION_MODE_PRIVATE; + contents_mode = FS_ENCRYPTION_MODE_PRIVATE; } else { LOG(ERROR) << "Invalid file contents encryption mode: " << contents_encryption_mode; @@ -267,9 +242,9 @@ int e4crypt_policy_ensure(const char *directory, const char *policy, } if (!strcmp(filenames_encryption_mode, "aes-256-cts")) { - filenames_mode = EXT4_ENCRYPTION_MODE_AES_256_CTS; + filenames_mode = FS_ENCRYPTION_MODE_AES_256_CTS; } else if (!strcmp(filenames_encryption_mode, "aes-256-heh")) { - filenames_mode = EXT4_ENCRYPTION_MODE_AES_256_HEH; + filenames_mode = FS_ENCRYPTION_MODE_AES_256_HEH; } else { LOG(ERROR) << "Invalid file names encryption mode: " << filenames_encryption_mode; @@ -279,10 +254,10 @@ int e4crypt_policy_ensure(const char *directory, const char *policy, bool is_empty; if (!is_dir_empty(directory, &is_empty)) return -1; if (is_empty) { - if (!e4crypt_policy_set(directory, policy, policy_length, + if (!fscrypt_policy_set(directory, policy, policy_length, contents_mode, filenames_mode)) return -1; } else { - if (!e4crypt_policy_check(directory, policy, policy_length, + if (!fscrypt_policy_check(directory, policy, policy_length, contents_mode, filenames_mode)) return -1; } return 0; diff --git a/ext4_utils/ext4_crypt_init_extensions.cpp b/libfscrypt/fscrypt_init_extensions.cpp index 728949e5..af50a0f8 100644 --- a/ext4_utils/ext4_crypt_init_extensions.cpp +++ b/libfscrypt/fscrypt_init_extensions.cpp @@ -14,7 +14,8 @@ * limitations under the License. */ -#include "ext4_utils/ext4_crypt_init_extensions.h" +#include "fscrypt/fscrypt.h" +#include "fscrypt/fscrypt_init_extensions.h" #include <dirent.h> #include <errno.h> @@ -34,17 +35,15 @@ #include <keyutils.h> #include <logwrap/logwrap.h> -#include "ext4_utils/ext4_crypt.h" - -#define TAG "ext4_utils" +#define TAG "fscrypt" static const std::string arbitrary_sequence_number = "42"; static int set_system_de_policy_on(char const* dir); -int e4crypt_install_keyring() +int fscrypt_install_keyring() { - key_serial_t device_keyring = add_key("keyring", "e4crypt", 0, 0, + key_serial_t device_keyring = add_key("keyring", "fscrypt", 0, 0, KEY_SPEC_SESSION_KEYRING); if (device_keyring == -1) { @@ -57,7 +56,7 @@ int e4crypt_install_keyring() return 0; } -int e4crypt_set_directory_policy(const char* dir) +int fscrypt_set_directory_policy(const char* dir) { if (!dir || strncmp(dir, "/data/", 6)) { return 0; @@ -101,14 +100,14 @@ int e4crypt_set_directory_policy(const char* dir) } static int set_system_de_policy_on(char const* dir) { - std::string ref_filename = std::string("/data") + e4crypt_key_ref; + std::string ref_filename = std::string("/data") + fscrypt_key_ref; std::string policy; if (!android::base::ReadFileToString(ref_filename, &policy)) { LOG(ERROR) << "Unable to read system policy to set on " << dir; return -1; } - auto type_filename = std::string("/data") + e4crypt_key_mode; + auto type_filename = std::string("/data") + fscrypt_key_mode; std::string modestring; if (!android::base::ReadFileToString(type_filename, &modestring)) { LOG(ERROR) << "Cannot read mode"; @@ -122,7 +121,7 @@ static int set_system_de_policy_on(char const* dir) { } LOG(INFO) << "Setting policy on " << dir; - int result = e4crypt_policy_ensure(dir, policy.c_str(), policy.length(), + int result = fscrypt_policy_ensure(dir, policy.c_str(), policy.length(), modes[0].c_str(), modes.size() >= 2 ? modes[1].c_str() : "aes-256-cts"); diff --git a/ext4_utils/include/ext4_utils/ext4_crypt.h b/libfscrypt/include/fscrypt/fscrypt.h index d410ccfd..8a68b935 100644 --- a/ext4_utils/include/ext4_utils/ext4_crypt.h +++ b/libfscrypt/include/fscrypt/fscrypt.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef _EXT4_CRYPT_H_ -#define _EXT4_CRYPT_H_ +#ifndef _FSCRYPT_H_ +#define _FSCRYPT_H_ #include <sys/cdefs.h> #include <stdbool.h> @@ -23,17 +23,17 @@ __BEGIN_DECLS -bool e4crypt_is_native(); +bool fscrypt_is_native(); -int e4crypt_policy_ensure(const char *directory, const char *policy, +int fscrypt_policy_ensure(const char *directory, const char *policy, size_t policy_length, const char *contents_encryption_mode, const char *filenames_encryption_mode); -static const char* e4crypt_unencrypted_folder = "/unencrypted"; -static const char* e4crypt_key_ref = "/unencrypted/ref"; -static const char* e4crypt_key_mode = "/unencrypted/mode"; +static const char* fscrypt_unencrypted_folder = "/unencrypted"; +static const char* fscrypt_key_ref = "/unencrypted/ref"; +static const char* fscrypt_key_mode = "/unencrypted/mode"; __END_DECLS -#endif // _EXT4_CRYPT_H_ +#endif // _FSCRYPT_H_ diff --git a/ext4_utils/include/ext4_utils/ext4_crypt_init_extensions.h b/libfscrypt/include/fscrypt/fscrypt_init_extensions.h index f14d4a99..2b6c46e1 100644 --- a/ext4_utils/include/ext4_utils/ext4_crypt_init_extensions.h +++ b/libfscrypt/include/fscrypt/fscrypt_init_extensions.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef _EXT4_CRYPT_INIT_EXTENSIONS_H_ -#define _EXT4_CRYPT_INIT_EXTENSIONS_H_ +#ifndef _FSCRYPT_INIT_EXTENSIONS_H_ +#define _FSCRYPT_INIT_EXTENSIONS_H_ #include <sys/cdefs.h> #include <stdbool.h> @@ -25,9 +25,9 @@ __BEGIN_DECLS // These functions assume they are being called from init // They will not operate properly outside of init -int e4crypt_install_keyring(); -int e4crypt_set_directory_policy(const char* path); +int fscrypt_install_keyring(); +int fscrypt_set_directory_policy(const char* path); __END_DECLS -#endif // _EXT4_CRYPT_INIT_EXTENSIONS_H_ +#endif // _FSCRYPT_INIT_EXTENSIONS_H_ |