summaryrefslogtreecommitdiff
path: root/libfscrypt
diff options
context:
space:
mode:
authorPaul Crowley <paulcrowley@google.com>2019-10-24 22:51:20 -0700
committerPaul Crowley <paulcrowley@google.com>2019-10-28 14:37:43 -0700
commit9444d62255ca18e1ddcde9b2f02d08256bd589e1 (patch)
tree52f33ffbccde61dedf27adfb83fe32c3b59abfb7 /libfscrypt
parentf6ca2c34097e997bf0c1201f808153538368b8ea (diff)
downloadextras-9444d62255ca18e1ddcde9b2f02d08256bd589e1.tar.gz
libfscrypt: Log which version of policy we set.
Bug: 143307095 Test: check logs Change-Id: Ib8a91dc153919063bc3daf5075848a64a7e48cf8
Diffstat (limited to 'libfscrypt')
-rw-r--r--libfscrypt/fscrypt.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/libfscrypt/fscrypt.cpp b/libfscrypt/fscrypt.cpp
index c29354f3..8c578679 100644
--- a/libfscrypt/fscrypt.cpp
+++ b/libfscrypt/fscrypt.cpp
@@ -72,8 +72,6 @@ struct fscrypt_policy_v2 {
#define HEX_LOOKUP "0123456789abcdef"
-#define MAX_KEY_REF_SIZE_HEX (2 * FSCRYPT_KEY_IDENTIFIER_SIZE + 1)
-
struct ModeLookupEntry {
std::string name;
int id;
@@ -235,6 +233,16 @@ bool ParseOptionsParts(const std::string& contents_mode, const std::string& file
return true;
}
+static std::string PolicyDebugString(const EncryptionPolicy& policy) {
+ std::stringstream ss;
+ std::string ref_hex;
+ BytesToHex(policy.key_raw_ref, &ref_hex);
+ ss << ref_hex;
+ ss << " v" << policy.options.version;
+ ss << " modes " << policy.options.contents_mode << "/" << policy.options.filenames_mode;
+ return ss.str();
+}
+
bool EnsurePolicy(const EncryptionPolicy& policy, const std::string& directory) {
union {
fscrypt_policy_v1 v1;
@@ -276,11 +284,6 @@ bool EnsurePolicy(const EncryptionPolicy& policy, const std::string& directory)
return false;
}
- std::string policy_descr;
- BytesToHex(policy.key_raw_ref, &policy_descr);
- policy_descr += " modes "s + std::to_string(policy.options.contents_mode) + "/" +
- std::to_string(policy.options.filenames_mode);
-
android::base::unique_fd fd(open(directory.c_str(), O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC));
if (fd == -1) {
PLOG(ERROR) << "Failed to open directory " << directory;
@@ -302,8 +305,8 @@ bool EnsurePolicy(const EncryptionPolicy& policy, const std::string& directory)
reason = strerror(errno);
break;
}
- LOG(ERROR) << "Failed to set encryption policy of " << directory << " to " << policy_descr
- << ": " << reason;
+ LOG(ERROR) << "Failed to set encryption policy of " << directory << " to "
+ << PolicyDebugString(policy) << ": " << reason;
if (errno == ENOTEMPTY) {
log_ls(directory.c_str());
}
@@ -311,9 +314,11 @@ bool EnsurePolicy(const EncryptionPolicy& policy, const std::string& directory)
}
if (already_encrypted) {
- LOG(INFO) << "Verified that " << directory << " has the encryption policy " << policy_descr;
+ LOG(INFO) << "Verified that " << directory << " has the encryption policy "
+ << PolicyDebugString(policy);
} else {
- LOG(INFO) << "Encryption policy of " << directory << " set to " << policy_descr;
+ LOG(INFO) << "Encryption policy of " << directory << " set to "
+ << PolicyDebugString(policy);
}
return true;
}