OSDN Git Service

Add secdiscard command for secure deletion of files
authorRubin Xu <rubinxu@google.com>
Thu, 27 Apr 2017 19:43:10 +0000 (20:43 +0100)
committerRubin Xu <rubinxu@google.com>
Tue, 16 May 2017 11:44:02 +0000 (12:44 +0100)
This is used by LockSettingsService to delete sensitive credential files.

Bug: 34600579
Test: manual - change device lock under synthetic password, verify
      old data on disk is erased.

Change-Id: I5e11b559ad8818bd2ad2b321d67d21477aab7555

CryptCommandListener.cpp
Ext4Crypt.cpp
Ext4Crypt.h
KeyStorage.cpp
KeyStorage.h

index 5c2ac84..779338f 100644 (file)
@@ -427,6 +427,11 @@ int CryptCommandListener::CryptfsCmd::runCommand(SocketClient *cli,
         return sendGenericOkFailOnBool(cli,
                 e4crypt_destroy_user_storage(parseNull(argv[2]), atoi(argv[3]), atoi(argv[4])));
 
+    } else if (subcommand == "secdiscard") {
+        if (!check_argc(cli, subcommand, argc, 3, "<path>")) return 0;
+        return sendGenericOkFailOnBool(cli,
+                e4crypt_secdiscard(parseNull(argv[2])));
+
     } else {
         dumpArgs(argc, argv, -1);
         cli->sendMsg(ResponseCode::CommandSyntaxError, "Unknown cryptfs subcommand", false);
index dd8922c..c3e0cc3 100644 (file)
@@ -686,3 +686,7 @@ bool e4crypt_destroy_user_storage(const char* volume_uuid, userid_t user_id, int
 
     return res;
 }
+
+bool e4crypt_secdiscard(const char* path) {
+    return android::vold::runSecdiscardSingle(std::string(path));
+}
index 2dcc197..e90167b 100644 (file)
@@ -38,4 +38,5 @@ bool e4crypt_lock_user_key(userid_t user_id);
 bool e4crypt_prepare_user_storage(const char* volume_uuid, userid_t user_id, int serial, int flags);
 bool e4crypt_destroy_user_storage(const char* volume_uuid, userid_t user_id, int flags);
 
+bool e4crypt_secdiscard(const char* path);
 __END_DECLS
index ddecbb8..b4f85f4 100644 (file)
@@ -512,6 +512,16 @@ static bool runSecdiscard(const std::string& dir) {
     return true;
 }
 
+bool runSecdiscardSingle(const std::string& file) {
+    if (ForkExecvp(
+            std::vector<std::string>{kSecdiscardPath, "--",
+                file}) != 0) {
+        LOG(ERROR) << "secdiscard failed";
+        return false;
+    }
+    return true;
+}
+
 static bool recursiveDeleteKey(const std::string& dir) {
     if (ForkExecvp(std::vector<std::string>{kRmPath, "-rf", dir}) != 0) {
         LOG(ERROR) << "recursive delete failed";
index 6186d19..63345f4 100644 (file)
@@ -61,6 +61,7 @@ bool retrieveKey(const std::string& dir, const KeyAuthentication& auth, std::str
 // Securely destroy the key stored in the named directory and delete the directory.
 bool destroyKey(const std::string& dir);
 
+bool runSecdiscardSingle(const std::string& file);
 }  // namespace vold
 }  // namespace android