summaryrefslogtreecommitdiff
path: root/keystore/blob.cpp
diff options
context:
space:
mode:
authorShawn Willden <swillden@google.com>2017-02-28 13:53:24 -0700
committerShawn Willden <swillden@google.com>2017-04-13 17:45:49 -0600
commitd5a24e6745eb552c137cfdbb49e09e3db5701ad1 (patch)
tree8e75c688f57291643daf80ff968acb748900cee1 /keystore/blob.cpp
parentead11aa0e1ba0c0c877b3ab80623ea8bcbaac79a (diff)
Superencrypt authentication-bound keys.
This CL causes keystore to automatically encrypt all newly-created keymaster key blobs which are authentication-bound. This appears on its face to be pointless, since the sensitive key material in the key blobs is already encrypted by the Trusted Execution Environment. It's not pointless because this adds a cryptographic dependency on the user's password, including any strengthening performed by LockSettingService... which may include the use of a separate hardware trusted module, separate from (and presumably more secure than) the TEE. A better solution is planned for the next release, but that requires changes to Gatekeeper and Keymaster. This superencryption will be removed when that work is done. Note that the encryption method used by keystore is weak. A separate CL will replace the weak method with a proper authenticated encryption. (cherry picked from commit 07aebe73053df12c21c7481a93146bd76add7fbd) Test: Manual testing. Bug: 35849499 Change-Id: I0c4910ea24b97bc8046f3d114bfb336670d03321
Diffstat (limited to 'keystore/blob.cpp')
-rw-r--r--keystore/blob.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/keystore/blob.cpp b/keystore/blob.cpp
index 7ee26f7..0e09262 100644
--- a/keystore/blob.cpp
+++ b/keystore/blob.cpp
@@ -71,12 +71,20 @@ bool Blob::isEncrypted() const {
return mBlob.flags & KEYSTORE_FLAG_ENCRYPTED;
}
+bool Blob::isSuperEncrypted() const {
+ return mBlob.flags & KEYSTORE_FLAG_SUPER_ENCRYPTED;
+}
+
+inline uint8_t setFlag(uint8_t flags, bool set, KeyStoreFlag flag) {
+ return set ? (flags | flag) : (flags & ~flag);
+}
+
void Blob::setEncrypted(bool encrypted) {
- if (encrypted) {
- mBlob.flags |= KEYSTORE_FLAG_ENCRYPTED;
- } else {
- mBlob.flags &= ~KEYSTORE_FLAG_ENCRYPTED;
- }
+ mBlob.flags = setFlag(mBlob.flags, encrypted, KEYSTORE_FLAG_ENCRYPTED);
+}
+
+void Blob::setSuperEncrypted(bool superEncrypted) {
+ mBlob.flags = setFlag(mBlob.flags, superEncrypted, KEYSTORE_FLAG_SUPER_ENCRYPTED);
}
void Blob::setFallback(bool fallback) {
@@ -90,7 +98,7 @@ void Blob::setFallback(bool fallback) {
ResponseCode Blob::writeBlob(const char* filename, AES_KEY* aes_key, State state,
Entropy* entropy) {
ALOGV("writing blob %s", filename);
- if (isEncrypted()) {
+ if (isEncrypted() || isSuperEncrypted()) {
if (state != STATE_NO_ERROR) {
ALOGD("couldn't insert encrypted blob while not unlocked");
return ResponseCode::LOCKED;
@@ -115,7 +123,7 @@ ResponseCode Blob::writeBlob(const char* filename, AES_KEY* aes_key, State state
mBlob.length = htonl(mBlob.length);
- if (isEncrypted()) {
+ if (isEncrypted() || isSuperEncrypted()) {
MD5(mBlob.digested, digestedLength, mBlob.digest);
uint8_t vector[AES_BLOCK_SIZE];
@@ -168,7 +176,7 @@ ResponseCode Blob::readBlob(const char* filename, AES_KEY* aes_key, State state)
return ResponseCode::VALUE_CORRUPTED;
}
- if (isEncrypted() && (state != STATE_NO_ERROR)) {
+ if ((isEncrypted() || isSuperEncrypted()) && (state != STATE_NO_ERROR)) {
return ResponseCode::LOCKED;
}