Skip to content

Commit 07ca482

Browse files
committed
disable memory security feature by default; once it is turned on it can't be turned off
1 parent 7b54c31 commit 07ca482

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/crypto_impl.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static volatile int default_page_size = 4096;
5151
static volatile int default_plaintext_header_sz = 0;
5252
static volatile int default_hmac_algorithm = SQLCIPHER_HMAC_SHA512;
5353
static volatile int default_kdf_algorithm = SQLCIPHER_PBKDF2_HMAC_SHA512;
54-
static volatile int mem_security_on = 1;
54+
static volatile int mem_security_on = 0;
5555
static volatile int mem_security_initialized = 0;
5656
static volatile int mem_security_activated = 0;
5757
static volatile unsigned int sqlcipher_activate_count = 0;
@@ -836,8 +836,11 @@ int sqlcipher_get_default_pagesize() {
836836
}
837837

838838
void sqlcipher_set_mem_security(int on) {
839-
mem_security_on = on;
840-
mem_security_activated = 0;
839+
/* memory security can only be enabled, not disabled */
840+
if(on) {
841+
mem_security_on = on;
842+
mem_security_activated = 0;
843+
}
841844
}
842845

843846
int sqlcipher_get_mem_security() {

test/sqlcipher-core.test

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -730,20 +730,20 @@ db close
730730
file delete -force test.db
731731

732732
# verify memory security behavior
733-
# initially should report ON
734-
# then disable, check that it is off
735-
# turn it back on, then check.
733+
# initially should report OFF
734+
# then enable, check that it is ON
735+
# try to turn if off, but verify that it
736+
# can't be unset.
736737
do_test verify-memory-security {
737738
sqlite_orig db test.db
738739
execsql {
739-
PRAGMA cipher_memory_security;
740-
PRAGMA cipher_memory_security = OFF;
741740
PRAGMA cipher_memory_security;
742741
PRAGMA cipher_memory_security = ON;
743742
PRAGMA cipher_memory_security;
744-
743+
PRAGMA cipher_memory_security = OFF;
744+
PRAGMA cipher_memory_security;
745745
}
746-
} {1 0 1}
746+
} {0 1 1}
747747
db close
748748
file delete -force test.db
749749

0 commit comments

Comments
 (0)