ios: fix: storing passphrase makes in available in NSE, do not allow empty current passphrase, reset files count after deletion (#1125)

This commit is contained in:
Evgeny Poberezkin
2022-09-25 20:53:32 +01:00
committed by GitHub
parent 4dde46a646
commit 83b77748b6
4 changed files with 9 additions and 2 deletions

View File

@@ -87,6 +87,7 @@ struct DatabaseEncryptionView: View {
}
}
.disabled(
(m.chatDbEncrypted == true && currentKey == "") ||
currentKey == newKey ||
newKey != confirmNewKey ||
newKey == "" ||
@@ -184,6 +185,7 @@ struct DatabaseEncryptionView: View {
message: Text("Instant push notifications will be hidden!\n") + storeSecurelyDanger(),
primaryButton: .destructive(Text("Remove")) {
if removeDatabaseKey() {
logger.debug("passphrase removed from keychain")
setUseKeychain(false)
storedKey = false
} else {

View File

@@ -337,6 +337,7 @@ struct DatabaseView: View {
_ = removeDatabaseKey()
storeDBPassphraseGroupDefault.set(true)
await operationEnded(.chatDeleted)
appFilesCountAndSize = directoryFileCountAndSize(getAppFilesDirectory())
} catch let error {
await operationEnded(.error(title: "Error deleting database", error: responseError(error)))
}

View File

@@ -159,7 +159,10 @@ func startChat() -> DBMigrationResult? {
hs_init(0, nil)
if chatStarted { return .ok }
let (_, dbStatus) = chatMigrateInit()
if dbStatus != .ok { return dbStatus }
if dbStatus != .ok {
resetChatCtrl()
return dbStatus
}
if let user = apiGetActiveUser() {
logger.debug("active user \(String(describing: user))")
do {

View File

@@ -19,14 +19,15 @@ public func getChatCtrl(_ useKey: String? = nil) -> chat_ctrl {
public func chatMigrateInit(_ useKey: String? = nil) -> (Bool, DBMigrationResult) {
if let res = migrationResult { return res }
logger.debug("chatMigrateInit \(storeDBPassphraseGroupDefault.get())")
let dbPath = getAppDatabasePath().path
var dbKey = ""
let useKeychain = storeDBPassphraseGroupDefault.get()
logger.debug("chatMigrateInit uses keychain: \(useKeychain)")
if let key = useKey {
dbKey = key
} else if useKeychain {
if !hasDatabase() {
logger.debug("chatMigrateInit generating a random DB key")
dbKey = randomDatabasePassword()
initialRandomDBPassphraseGroupDefault.set(true)
} else if let key = getDatabaseKey() {