FBE for Pixel 2
Includes various minor fixes for building in Android 8 trees with r23+ tag
Update FBE extended header in libtar to version 2 and include the entire
ext4_encryption_policy structure now after translating the policy.
See this post for more details:
https://plus.google.com/u/1/+DeesTroy/posts/i33ygUi7tiu
Change-Id: I2af981e51f459b17fcd895fb8c2d3f6c8200e24b
diff --git a/libtar/append.c b/libtar/append.c
index 8896764..66e3aa1 100644
--- a/libtar/append.c
+++ b/libtar/append.c
@@ -131,27 +131,39 @@
#ifdef HAVE_EXT4_CRYPT
if (TH_ISDIR(t) && t->options & TAR_STORE_EXT4_POL)
{
- if (t->th_buf.e4crypt_policy != NULL)
+ if (t->th_buf.eep != NULL)
{
- free(t->th_buf.e4crypt_policy);
- t->th_buf.e4crypt_policy = NULL;
+ free(t->th_buf.eep);
+ t->th_buf.eep = NULL;
}
- char e4crypt_policy[EXT4_KEY_DESCRIPTOR_SIZE];
- if (e4crypt_policy_get(realname, e4crypt_policy, EXT4_KEY_DESCRIPTOR_SIZE, 0))
+ t->th_buf.eep = (struct ext4_encryption_policy*)malloc(sizeof(struct ext4_encryption_policy));
+ if (!t->th_buf.eep) {
+ printf("malloc ext4_encryption_policy\n");
+ return -1;
+ }
+ if (e4crypt_policy_get_struct(realname, t->th_buf.eep))
{
char tar_policy[EXT4_KEY_DESCRIPTOR_SIZE];
memset(tar_policy, 0, sizeof(tar_policy));
- char policy_hex[EXT4_KEY_DESCRIPTOR_HEX];
- policy_to_hex(e4crypt_policy, policy_hex);
- if (lookup_ref_key(e4crypt_policy, &tar_policy)) {
+ char policy_hex[EXT4_KEY_DESCRIPTOR_SIZE_HEX];
+ policy_to_hex(t->th_buf.eep->master_key_descriptor, policy_hex);
+ if (lookup_ref_key(t->th_buf.eep->master_key_descriptor, &tar_policy[0])) {
printf("found policy '%s' - '%s' - '%s'\n", realname, tar_policy, policy_hex);
- t->th_buf.e4crypt_policy = strdup(tar_policy);
+ memcpy(t->th_buf.eep->master_key_descriptor, tar_policy, EXT4_KEY_DESCRIPTOR_SIZE);
} else {
printf("failed to lookup tar policy for '%s' - '%s'\n", realname, policy_hex);
+ free(t->th_buf.eep);
+ t->th_buf.eep = NULL;
return -1;
}
- } // else no policy found, but this is not an error as not all dirs will have a policy
+ }
+ else
+ {
+ // no policy found, but this is not an error as not all dirs will have a policy
+ free(t->th_buf.eep);
+ t->th_buf.eep = NULL;
+ }
}
#endif