浏览代码

wipe secure folder on logout

kevin 8 月之前
父节点
当前提交
2722967bff

+ 17 - 0
NexilisLite/NexilisLite/Source/FileEncryption.swift

@@ -197,5 +197,22 @@ public class FileEncryption {
         return finalData
     }
     
+    func wipeFolder() {
+        let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
+        let secureDir = documentsDirectory.appendingPathComponent("secure")
+        if FileManager.default.fileExists(atPath: secureDir.path) {
+            do {
+                let fileNames = try FileManager.default.contentsOfDirectory(atPath: secureDir.path)
+                for fileName in fileNames {
+                    let filePath = secureDir.appendingPathComponent(fileName)
+                    try FileManager.default.removeItem(atPath: secureDir.path)
+                }
+                try FileManager.default.removeItem(atPath: secureDir.path)
+                print("Secure folder deleted successfully")
+            } catch {
+                print("Error deleting secure folder")
+            }
+        }
+    }
     
 }

+ 1 - 0
NexilisLite/NexilisLite/Source/IncomingThread.swift

@@ -244,6 +244,7 @@ class IncomingThread {
                     if Utils.getForceAnonymous() {
                         viewController?.deleteAllRecordDatabase()
                         SecureUserDefaults.shared.removeValue(forKey: "device_id")
+                        FileEncryption.shared.wipeFolder()
                         Nexilis.destroyAll()
                     }
                     DispatchQueue.main.async {

+ 1 - 0
NexilisLite/NexilisLite/Source/View/Control/SettingTableViewController.swift

@@ -548,6 +548,7 @@ public class SettingTableViewController: UITableViewController, UIGestureRecogni
                             if Utils.getForceAnonymous() {
                                 self.deleteAllRecordDatabase()
                                 SecureUserDefaults.shared.removeValue(forKey: "device_id")
+                                FileEncryption.shared.wipeFolder()
                                 Nexilis.destroyAll()
                                 _ = Nexilis.write(message: CoreMessage_TMessageBank.getPostRegistration(p_pin: id))
                             }