From 368d79459e8d30474dd5cbc414623c1e2f78ee98 Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Wed, 15 Apr 2015 14:12:00 -0700 Subject: [PATCH] DO NOT MERGE Enable properties in ext4enc (cherry-picked from 4e7274551c93e1c064648409f52ca430da647050) Enables OwnerInfo and pattern suppression Bug: 18151196 Change-Id: I46144e16cb00319deeb5492ab82c67f5dd43d6d3 --- Ext4Crypt.cpp | 33 +++++++++++++++++++++++++-------- Ext4Crypt.h | 5 +++++ cryptfs.c | 8 ++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Ext4Crypt.cpp b/Ext4Crypt.cpp index 0c7b351..0f6af6b 100644 --- a/Ext4Crypt.cpp +++ b/Ext4Crypt.cpp @@ -46,14 +46,6 @@ namespace { uint32_t size; }; - // ext4enc:TODO Get from somewhere good - struct ext4_encryption_policy { - char version; - char contents_encryption_mode; - char filenames_encryption_mode; - char master_key_descriptor[EXT4_KEY_DESCRIPTOR_SIZE]; - } __attribute__((__packed__)); - namespace tag { const char* magic = "magic"; const char* major_version = "major_version"; @@ -440,3 +432,28 @@ int e4crypt_get_password_type(const char* path) return GetPropsOrAltProps(path).GetChild(properties::key) .Get(tag::crypt_type, CRYPT_TYPE_DEFAULT); } + +int e4crypt_get_field(const char* path, const char* fieldname, + char* value, size_t len) +{ + auto v = GetPropsOrAltProps(path).GetChild(properties::props) + .Get(fieldname); + + if (v == "") { + return CRYPTO_GETFIELD_ERROR_NO_FIELD; + } + + if (v.length() >= len) { + return CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL; + } + + strlcpy(value, v.c_str(), len); + return 0; +} + +int e4crypt_set_field(const char* path, const char* fieldname, + const char* value) +{ + return GetPropsOrAltProps(path).GetChild(properties::props) + .Set(fieldname, std::string(value)) ? 0 : -1; +} diff --git a/Ext4Crypt.h b/Ext4Crypt.h index 301639d..68e0fb2 100644 --- a/Ext4Crypt.h +++ b/Ext4Crypt.h @@ -1,3 +1,4 @@ +#include #include __BEGIN_DECLS @@ -12,5 +13,9 @@ int e4crypt_check_passwd(const char* path, const char* password); int e4crypt_get_password_type(const char* path); const char* e4crypt_get_password(const char* path); int e4crypt_restart(const char* path); +int e4crypt_get_field(const char* path, const char* fieldname, + char* value, size_t len); +int e4crypt_set_field(const char* path, const char* fieldname, + const char* value); __END_DECLS diff --git a/cryptfs.c b/cryptfs.c index 1ab587c..47b19a6 100644 --- a/cryptfs.c +++ b/cryptfs.c @@ -3491,6 +3491,10 @@ static int persist_count_keys(const char *fieldname) /* Return the value of the specified field. */ int cryptfs_getfield(const char *fieldname, char *value, int len) { + if (e4crypt_crypto_complete(DATA_MNT_POINT) == 0) { + return e4crypt_get_field(DATA_MNT_POINT, fieldname, value, len); + } + char temp_value[PROPERTY_VALUE_MAX]; /* CRYPTO_GETFIELD_OK is success, * CRYPTO_GETFIELD_ERROR_NO_FIELD is value not set, @@ -3552,6 +3556,10 @@ out: /* Set the value of the specified field. */ int cryptfs_setfield(const char *fieldname, const char *value) { + if (e4crypt_crypto_complete(DATA_MNT_POINT) == 0) { + return e4crypt_set_field(DATA_MNT_POINT, fieldname, value); + } + char encrypted_state[PROPERTY_VALUE_MAX]; /* 0 is success, negative values are error */ int rc = CRYPTO_SETFIELD_ERROR_OTHER;