summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaquille Johnson <ssjohnson@google.com>2023-12-19 19:45:32 +0000
committerShaquille Johnson <ssjohnson@google.com>2023-12-21 18:30:50 +0000
commit52b8c9321b728b7b113e4116569e25ab0c96d497 (patch)
tree192b7ee613c061d3129ccadcc4ad04a103e9d4fa
parent0ac69e8ba364303e392e733d8addd9b3acb43978 (diff)
downloadsecurity-52b8c9321b728b7b113e4116569e25ab0c96d497.tar.gz
When wal flag not enabled set db back to default
When a database is set once it will still maintain that setting even if on the next connection it is not specified. Any databases that set the wal flag will need to turn the database back to its default when the flag is disabled or there will be an error in the access of the database. Bug: 314419678 Test: atest keystore2_test && atest legacykeystore_test Change-Id: I008f2d2f6ac055704b721cdd451fc8bdfe448832
-rw-r--r--keystore2/aconfig/flags.aconfig2
-rw-r--r--keystore2/legacykeystore/lib.rs6
-rw-r--r--keystore2/src/database.rs13
3 files changed, 9 insertions, 12 deletions
diff --git a/keystore2/aconfig/flags.aconfig b/keystore2/aconfig/flags.aconfig
index 7bdb0074..133c4abe 100644
--- a/keystore2/aconfig/flags.aconfig
+++ b/keystore2/aconfig/flags.aconfig
@@ -1,7 +1,7 @@
package: "android.security.keystore2"
flag {
- name: "wal_db_journalmode_v2"
+ name: "wal_db_journalmode_v3"
namespace: "hardware_backed_security"
description: "This flag controls changing journalmode to wal"
bug: "191777960"
diff --git a/keystore2/legacykeystore/lib.rs b/keystore2/legacykeystore/lib.rs
index a665405e..f7a81983 100644
--- a/keystore2/legacykeystore/lib.rs
+++ b/keystore2/legacykeystore/lib.rs
@@ -46,12 +46,6 @@ impl DB {
conn: Connection::open(db_file).context("Failed to initialize SQLite connection.")?,
};
- if keystore2_flags::wal_db_journalmode_v2() {
- // Update journal mode to WAL
- db.conn
- .pragma_update(None, "journal_mode", "WAL")
- .context("Failed to connect in WAL mode for persistent db")?;
- }
db.init_tables().context("Trying to initialize legacy keystore db.")?;
Ok(db)
}
diff --git a/keystore2/src/database.rs b/keystore2/src/database.rs
index 93de4844..15ceed60 100644
--- a/keystore2/src/database.rs
+++ b/keystore2/src/database.rs
@@ -1014,6 +1014,14 @@ impl KeystoreDB {
let mut persistent_path_str = "file:".to_owned();
persistent_path_str.push_str(&persistent_path.to_string_lossy());
+ // Connect to database in specific mode
+ let persistent_path_mode = if keystore2_flags::wal_db_journalmode_v3() {
+ "?journal_mode=WAL".to_owned()
+ } else {
+ "?journal_mode=DELETE".to_owned()
+ };
+ persistent_path_str.push_str(&persistent_path_mode);
+
Ok(persistent_path_str)
}
@@ -1036,11 +1044,6 @@ impl KeystoreDB {
break;
}
- if keystore2_flags::wal_db_journalmode_v2() {
- // Update journal mode to WAL
- conn.pragma_update(None, "journal_mode", "WAL")
- .context("Failed to connect in WAL mode for persistent db")?;
- }
// Drop the cache size from default (2M) to 0.5M
conn.execute("PRAGMA persistent.cache_size = -500;", params![])
.context("Failed to decrease cache size for persistent db")?;