DO NOT MERGE Enable properties in ext4enc
(cherry-picked from 4e7274551c
)
Enables OwnerInfo and pattern suppression
Bug: 18151196
Change-Id: I46144e16cb00319deeb5492ab82c67f5dd43d6d3
This commit is contained in:
parent
c78c71b171
commit
368d79459e
3 changed files with 38 additions and 8 deletions
|
@ -46,14 +46,6 @@ namespace {
|
||||||
uint32_t size;
|
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 {
|
namespace tag {
|
||||||
const char* magic = "magic";
|
const char* magic = "magic";
|
||||||
const char* major_version = "major_version";
|
const char* major_version = "major_version";
|
||||||
|
@ -440,3 +432,28 @@ int e4crypt_get_password_type(const char* path)
|
||||||
return GetPropsOrAltProps(path).GetChild(properties::key)
|
return GetPropsOrAltProps(path).GetChild(properties::key)
|
||||||
.Get<int>(tag::crypt_type, CRYPT_TYPE_DEFAULT);
|
.Get<int>(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<std::string>(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;
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stddef.h>
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
@ -12,5 +13,9 @@ int e4crypt_check_passwd(const char* path, const char* password);
|
||||||
int e4crypt_get_password_type(const char* path);
|
int e4crypt_get_password_type(const char* path);
|
||||||
const char* e4crypt_get_password(const char* path);
|
const char* e4crypt_get_password(const char* path);
|
||||||
int e4crypt_restart(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
|
__END_DECLS
|
||||||
|
|
|
@ -3491,6 +3491,10 @@ static int persist_count_keys(const char *fieldname)
|
||||||
/* Return the value of the specified field. */
|
/* Return the value of the specified field. */
|
||||||
int cryptfs_getfield(const char *fieldname, char *value, int len)
|
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];
|
char temp_value[PROPERTY_VALUE_MAX];
|
||||||
/* CRYPTO_GETFIELD_OK is success,
|
/* CRYPTO_GETFIELD_OK is success,
|
||||||
* CRYPTO_GETFIELD_ERROR_NO_FIELD is value not set,
|
* CRYPTO_GETFIELD_ERROR_NO_FIELD is value not set,
|
||||||
|
@ -3552,6 +3556,10 @@ out:
|
||||||
/* Set the value of the specified field. */
|
/* Set the value of the specified field. */
|
||||||
int cryptfs_setfield(const char *fieldname, const char *value)
|
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];
|
char encrypted_state[PROPERTY_VALUE_MAX];
|
||||||
/* 0 is success, negative values are error */
|
/* 0 is success, negative values are error */
|
||||||
int rc = CRYPTO_SETFIELD_ERROR_OTHER;
|
int rc = CRYPTO_SETFIELD_ERROR_OTHER;
|
||||||
|
|
Loading…
Reference in a new issue