Set encrypted flag when appropriate

"generate" and "put" were not setting the encrypted flag in the blob
written to disk. Add setting the flag whenever appropriate for these
functions.

Additinally, the master key should always be encrypted.

Bug: 11113056
Change-Id: Ibf8f2ad4d5de0732dcc25e1005ad4751683e3b80
diff --git a/keystore/keystore.cpp b/keystore/keystore.cpp
index 336a15b..7366c34 100644
--- a/keystore/keystore.cpp
+++ b/keystore/keystore.cpp
@@ -421,7 +421,11 @@
         mBlob.version = CURRENT_BLOB_VERSION;
         mBlob.type = uint8_t(type);
 
-        mBlob.flags = KEYSTORE_FLAG_NONE;
+        if (type == TYPE_MASTER_KEY) {
+            mBlob.flags = KEYSTORE_FLAG_ENCRYPTED;
+        } else {
+            mBlob.flags = KEYSTORE_FLAG_NONE;
+        }
     }
 
     Blob(blob b) {
@@ -1492,6 +1496,8 @@
         String8 filename(mKeyStore->getKeyNameForUidWithDir(name8, targetUid));
 
         Blob keyBlob(item, itemLength, NULL, 0, ::TYPE_GENERIC);
+        keyBlob.setEncrypted(flags & KEYSTORE_FLAG_ENCRYPTED);
+
         return mKeyStore->put(filename.string(), &keyBlob, callingUid);
     }
 
@@ -1848,6 +1854,7 @@
         Blob keyBlob(data, dataLength, NULL, 0, TYPE_KEY_PAIR);
         free(data);
 
+        keyBlob.setEncrypted(flags & KEYSTORE_FLAG_ENCRYPTED);
         keyBlob.setFallback(isFallback);
 
         return mKeyStore->put(filename.string(), &keyBlob, callingUid);