2 # codec.test developed by Stephen Lombardo (Zetetic LLC)
3 # sjlombardo at zetetic dot net
6 # Copyright (c) 2009, ZETETIC LLC
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of the ZETETIC LLC nor the
17 # names of its contributors may be used to endorse or promote products
18 # derived from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
21 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 # DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
24 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 # This file implements regression tests for SQLite library. The
32 # focus of this script is testing code cipher features.
34 # NOTE: tester.tcl has overridden the definition of sqlite3 to
35 # automatically pass in a key value. Thus tests in this file
36 # should explicitly close and open db with sqlite_orig in order
37 # to bypass default key assignment.
40 file delete -force test.db
41 file delete -force test2.db
42 file delete -force test3.db
43 file delete -force test4.db
45 set testdir [file dirname $argv0]
46 source $testdir/tester.tcl
48 # If the library is not compiled with has_codec support then
49 # skip all tests in this file.
50 if {![sqlite_orig -has-codec]} {
55 proc setup {file key} {
57 execsql "PRAGMA key=$key;"
60 INSERT INTO t1 VALUES ('test1', 'test2');
65 # The database is initially empty.
66 # set an hex key create some basic data
67 # create table and insert operations should work
68 # close database, open it again with the same
69 # hex key. verify that the table is readable
70 # and the data just inserted is visible
71 setup test.db "\"x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836481'\""
72 do_test will-open-with-correct-raw-key {
73 sqlite_orig db test.db
75 PRAGMA key = "x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836481'";
76 SELECT name FROM sqlite_master WHERE type='table';
81 file delete -force test.db
83 # set an encryption key (non-hex) and create some basic data
84 # create table and insert operations should work
85 # close database, open it again with the same
86 # key. verify that the table is readable
87 # and the data just inserted is visible
88 setup test.db "'testkey'"
89 do_test will-open-with-correct-derived-key {
91 sqlite_orig db test.db
93 PRAGMA key = 'testkey';
94 SELECT name FROM sqlite_master WHERE type='table';
99 file delete -force test.db
101 # open the database and try to read from it without
102 # providing a passphrase. verify that the
103 # an error is returned from the library
104 setup test.db "'testkey'"
105 do_test wont-open-without-key {
106 sqlite_orig db test.db
108 SELECT name FROM sqlite_master WHERE type='table';
110 } {1 {file is encrypted or is not a database}}
112 file delete -force test.db
114 # open the database and try to set an invalid
115 # passphrase. verify that an error is returned
116 # and that data couldn't be read
117 setup test.db "'testkey'"
118 do_test wont-open-with-invalid-derived-key {
119 sqlite_orig db test.db
121 PRAGMA key = 'testkey2';
122 SELECT name FROM sqlite_master WHERE type='table';
124 } {1 {file is encrypted or is not a database}}
126 file delete -force test.db
128 # open the database and try to set an invalid
129 # hex key. verify that an error is returned
130 # and that data couldn't be read
131 setup test.db "'testkey'"
132 do_test wont-open-with-invalid-raw-key {
133 sqlite_orig db test.db
135 PRAGMA key = "x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836480'";
136 SELECT name FROM sqlite_master WHERE type='table';
138 } {1 {file is encrypted or is not a database}}
140 file delete -force test.db
142 # test a large number of inserts in a transaction to a memory database
143 do_test memory-database {
144 sqlite_orig db :memory:
146 PRAGMA key = 'testkey3';
148 CREATE TABLE t2(a,b);
150 for {set i 1} {$i<=25000} {incr i} {
151 set r [expr {int(rand()*500000)}]
152 execsql "INSERT INTO t2 VALUES($i,$r);"
156 SELECT count(*) FROM t2;
158 SELECT count(*) FROM t2;
163 # test a large number of inserts in a transaction for multiple pages
164 do_test multi-page-database {
165 sqlite_orig db test.db
167 PRAGMA key = 'testkey';
168 CREATE TABLE t2(a,b);
171 for {set i 1} {$i<=25000} {incr i} {
172 set r [expr {int(rand()*500000)}]
173 execsql "INSERT INTO t2 VALUES($i,$r);"
177 SELECT count(*) FROM t2;
181 file delete -force test.db
183 # test a rekey operation as the first op on a database
184 # then test that now the new key opens the database
185 # now close database re-open with new key
186 setup test.db "'testkey'"
187 do_test rekey-as-first-operation {
188 sqlite_orig db test.db
190 PRAGMA key = 'testkey';
191 PRAGMA rekey = 'testkeynew';
195 sqlite_orig db test.db
197 PRAGMA key = 'testkeynew';
198 SELECT name FROM sqlite_master WHERE type='table';
202 file delete -force test.db
204 # attach an encrypted database
205 # where both database have the same
207 setup test.db "'testkey'"
208 do_test attach-database-with-same-key {
209 sqlite_orig db2 test2.db
212 PRAGMA key = 'testkey';
213 CREATE TABLE t2(a,b);
214 INSERT INTO t2 VALUES ('test1', 'test2');
218 SELECT count(*) FROM t2;
219 ATTACH 'test.db' AS db;
220 SELECT count(*) FROM db.t1;
225 file delete -force test.db
226 file delete -force test2.db
228 # attach an encrypted database
229 # where databases have different keys
230 setup test.db "'testkey'"
231 do_test attach-database-with-different-keys {
232 sqlite_orig db2 test2.db
235 PRAGMA key = 'testkey2';
236 CREATE TABLE t2(a,b);
237 INSERT INTO t2 VALUES ('test1', 'test2');
241 ATTACH 'test.db' AS db KEY 'testkey';
242 SELECT count(*) FROM db.t1;
243 SELECT count(*) FROM t2;
248 file delete -force test.db
249 file delete -force test2.db
251 # test locking across multiple handles
252 setup test.db "'testkey'"
253 do_test locking-across-multiple-handles-start {
254 sqlite_orig db test.db
257 PRAGMA key = 'testkey';
259 INSERT INTO t1 VALUES(1,2);
262 sqlite_orig dba test.db
264 PRAGMA key = 'testkey';
265 SELECT count(*) FROM t1;
268 } {1 {database is locked}}
270 do_test locking-accross-multiple-handles-finish {
276 SELECT count(*) FROM t1;
281 file delete -force test.db
284 setup test.db "'testkey'"
285 do_test alter-schema {
286 sqlite_orig db test.db
288 PRAGMA key = 'testkey';
289 ALTER TABLE t1 ADD COLUMN c;
290 INSERT INTO t1 VALUES (1,2,3);
291 INSERT INTO t1 VALUES (1,2,4);
292 CREATE TABLE t1a (a);
293 INSERT INTO t1a VALUES ('teststring');
297 sqlite_orig db test.db
299 PRAGMA key = 'testkey';
300 SELECT count(*) FROM t1 WHERE a IS NOT NULL;
301 SELECT count(*) FROM t1 WHERE c IS NOT NULL;
307 file delete -force test.db
309 # test alterations of KDF iterations and ciphers
311 setup test.db "'testkey'"
312 do_test non-standard-kdf-and-ciphers {
313 sqlite_orig db test.db
315 PRAGMA key = 'testkey';
316 PRAGMA rekey_kdf_iter = 1000;
317 PRAGMA rekey_cipher = 'aes-256-cfb';
318 PRAGMA rekey = 'testkey2';
319 INSERT INTO t1 VALUES (1,2);
323 sqlite_orig db test.db
325 PRAGMA key = 'testkey2';
326 PRAGMA kdf_iter = 1000;
327 PRAGMA cipher = 'aes-256-cfb';
328 SELECT count(*) FROM t1;
333 file delete -force test.db
335 # test alterations of CIPHER from CBC Mode requiring
336 # IV to ECB mode that does not
337 setup test.db "'testkey'"
338 do_test rekey-from-cbc-to-ecb-no-iv {
339 sqlite_orig db test.db
341 PRAGMA key = 'testkey';
345 for {set i 1} {$i<=1000} {incr i} {
346 set r [expr {int(rand()*500000)}]
347 execsql "INSERT INTO t1 VALUES($i,$r);"
352 PRAGMA rekey_kdf_iter = 1000;
353 PRAGMA rekey_cipher = 'aes-128-ecb';
354 PRAGMA rekey = 'testkey';
358 sqlite_orig db test.db
360 PRAGMA key = 'testkey';
361 PRAGMA kdf_iter = 1000;
362 PRAGMA cipher = 'aes-128-ecb';
363 SELECT count(*) FROM t1;
368 file delete -force test.db
370 # test alterations of CIPHER from ECB Mode (no IV) to CBC Mode
371 do_test rekey-from-ecb-to-cbc-with-iv {
372 sqlite_orig db test.db
374 PRAGMA key = 'testkey';
375 PRAGMA cipher = 'aes-256-ecb';
376 CREATE table t1(a,b);
380 for {set i 1} {$i<=1000} {incr i} {
381 set r [expr {int(rand()*500000)}]
382 execsql "INSERT INTO t1 VALUES($i,$r);"
387 PRAGMA rekey_cipher = 'aes-256-cbc';
388 PRAGMA rekey = 'testkey';
392 sqlite_orig db test.db
394 PRAGMA key = 'testkey';
395 SELECT count(*) FROM t1;
400 file delete -force test.db
402 # create an unencrypted database, attach a new encrypted volume
403 # copy data between, verify the encypted database is good afterwards
404 do_test unencryped-attach {
405 sqlite_orig db test.db
408 CREATE TABLE t1(a,b);
412 for {set i 1} {$i<=1000} {incr i} {
413 set r [expr {int(rand()*500000)}]
414 execsql "INSERT INTO t1 VALUES($i,$r);"
419 ATTACH DATABASE 'test2.db' AS db2 KEY 'testkey';
420 CREATE TABLE db2.t1(a,b);
421 INSERT INTO db2.t1 SELECT * FROM t1;
425 sqlite_orig db2 test2.db
427 PRAGMA key='testkey';
428 SELECT count(*) FROM t1;
432 file delete -force test.db
433 file delete -force test2.db
435 # create an unencrypted database, attach a new encrypted volume
436 # using a raw key copy data between, verify the encypted
437 # database is good afterwards
438 do_test unencryped-attach-raw-key {
439 sqlite_orig db test.db
442 CREATE TABLE t1(a,b);
446 for {set i 1} {$i<=1000} {incr i} {
447 set r [expr {int(rand()*500000)}]
448 execsql "INSERT INTO t1 VALUES($i,$r);"
453 ATTACH DATABASE 'test2.db' AS db2 KEY "x'10483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836481'";
454 CREATE TABLE db2.t1(a,b);
455 INSERT INTO db2.t1 SELECT * FROM t1;
459 sqlite_orig db2 test2.db
461 PRAGMA key="x'10483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836481'";
462 SELECT count(*) FROM t1;
466 file delete -force test.db
467 file delete -force test2.db
469 # create an encrypted database, attach an unencrypted volume
470 # copy data between, verify the unencypted database is good afterwards
471 do_test encryped-attach-unencrypted {
472 sqlite_orig db test.db
475 CREATE TABLE t1(a,b);
478 sqlite_orig db2 test2.db
480 PRAGMA key='testkey';
481 CREATE TABLE t1(a,b);
485 for {set i 1} {$i<=1000} {incr i} {
486 set r [expr {int(rand()*500000)}]
487 execsql "INSERT INTO t1 VALUES($i,$r);" db2
492 ATTACH DATABASE 'test.db' AS test KEY '';
493 INSERT INTO test.t1 SELECT * FROM t1;
494 DETACH DATABASE test;
498 SELECT count(*) FROM t1;
503 file delete -force test.db
504 file delete -force test2.db
506 # create an unencrypted database, attach an unencrypted volume
507 # copy data between, verify the unencypted database is good afterwards
508 do_test unencryped-attach-unencrypted {
509 sqlite_orig db test.db
512 CREATE TABLE t1(a,b);
515 sqlite_orig db2 test2.db
517 CREATE TABLE t1(a,b);
521 for {set i 1} {$i<=1000} {incr i} {
522 set r [expr {int(rand()*500000)}]
523 execsql "INSERT INTO t1 VALUES($i,$r);" db2
528 ATTACH DATABASE 'test.db' AS test;
529 INSERT INTO test.t1 SELECT * FROM t1;
530 DETACH DATABASE test;
534 SELECT count(*) FROM t1;
539 file delete -force test.db
540 file delete -force test2.db
542 # 1. create a database with a custom page size,
543 # 2. create table and insert operations should work
544 # 3. close database, open it again with the same
546 # 4. verify that the table is readable
547 # and the data just inserted is visible
548 do_test custom-pagesize {
549 sqlite_orig db test.db
552 PRAGMA key = 'testkey';
553 PRAGMA cipher_page_size = 4096;
554 CREATE table t1(a,b);
558 for {set i 1} {$i<=1000} {incr i} {
559 set r [expr {int(rand()*500000)}]
560 execsql "INSERT INTO t1 VALUES($i,'value $r');"
568 sqlite_orig db test.db
571 PRAGMA key = 'testkey';
572 PRAGMA cipher_page_size = 4096;
573 SELECT count(*) FROM t1;
579 # open the database with the default page size
580 ## and verfiy that it is not readable
581 do_test custom-pagesize-must-match {
582 sqlite_orig db test.db
584 PRAGMA key = 'testkey';
585 SELECT name FROM sqlite_master WHERE type='table';
587 } {1 {file is encrypted or is not a database}}
589 file delete -force test.db
591 # 1. create a database and insert a bunch of data, close the database
592 # 2. seek to the middle of a database page and write some junk
593 # 3. Open the database and verify that the database is no longer readable
594 do_test hmac-tamper-resistence {
595 sqlite_orig db test.db
598 PRAGMA key = 'testkey';
599 CREATE table t1(a,b);
603 for {set i 1} {$i<=1000} {incr i} {
604 set r [expr {int(rand()*500000)}]
605 execsql "INSERT INTO t1 VALUES($i,'value $r');"
614 # write some junk into the middle of the page
615 hexio_write test.db 2560 00
617 sqlite_orig db test.db
620 PRAGMA key = 'testkey';
621 SELECT count(*) FROM t1;
624 } {1 {database disk image is malformed}}
626 file delete -force test.db
628 # 1. create a database and insert a bunch of data, close the database
629 # 2. seek to the middle of a database page and write some junk
630 # 3. Open the database and verify that the database is still readable
631 do_test nohmac-not-tamper-resistent {
632 sqlite_orig db test.db
635 PRAGMA key = 'testkey';
636 PRAGMA cipher_use_hmac = OFF;
637 PRAGMA cipher_page_size = 1024;
638 CREATE table t1(a,b);
642 for {set i 1} {$i<=1000} {incr i} {
643 set r [expr {int(rand()*500000)}]
644 execsql "INSERT INTO t1 VALUES($i,'value $r');"
653 # write some junk into the middle of the page
654 hexio_write test.db 2560 00
656 sqlite_orig db test.db
659 PRAGMA key = 'testkey';
660 PRAGMA cipher_use_hmac = OFF;
661 PRAGMA cipher_page_size = 1024;
662 SELECT count(*) FROM t1;
667 file delete -force test.db
669 # open a 1.1.8 database using the new code, HMAC disabled
670 do_test open-1.1.8-database {
671 sqlite_orig db sqlcipher-1.1.8-testkey.db
673 PRAGMA key = 'testkey';
674 PRAGMA cipher_use_hmac = OFF;
675 SELECT count(*) FROM t1;
678 } {4 1 1 one one 1 2 one two}
682 # open a 1.1.8 database without hmac, then copy the data
683 do_test attach-and-copy-1.1.8 {
684 sqlite_orig db sqlcipher-1.1.8-testkey.db
687 PRAGMA key = 'testkey';
688 PRAGMA cipher_use_hmac = OFF;
689 ATTACH DATABASE 'test.db' AS db2 KEY 'testkey-hmac';
690 CREATE TABLE db2.t1(a,b);
691 INSERT INTO db2.t1 SELECT * FROM main.t1;
696 sqlite_orig db test.db
698 PRAGMA key = 'testkey-hmac';
699 SELECT count(*) FROM t1;
702 } {4 1 1 one one 1 2 one two}
704 file delete -force test.db
706 # open a standard database, then attach a new
707 # database with completely different options.
708 # copy data between them, and verify that the
709 # new database can be opened with the proper data
710 do_test attached-database-pragmas {
711 sqlite_orig db test.db
714 PRAGMA key = 'testkey';
715 CREATE TABLE t1(a,b);
719 for {set i 1} {$i<=1000} {incr i} {
720 set r [expr {int(rand()*500000)}]
721 execsql "INSERT INTO t1 VALUES($i,'value $r');"
726 ATTACH DATABASE 'test2.db' AS db2 KEY 'testkey2';
727 PRAGMA db2.cipher_page_size = 4096;
728 PRAGMA db2.cipher = 'aes-128-cbc';
729 PRAGMA db2.kdf_iter = 1000;
730 PRAGMA db2.cipher_use_hmac = OFF;
731 CREATE TABLE db2.t1(a,b);
732 INSERT INTO db2.t1 SELECT * FROM main.t1;
737 sqlite_orig db test2.db
739 PRAGMA key = 'testkey2';
740 PRAGMA cipher_page_size = 4096;
741 PRAGMA cipher = 'aes-128-cbc';
742 PRAGMA kdf_iter = 1000;
743 PRAGMA cipher_use_hmac = OFF;
744 SELECT count(*) FROM t1;
748 file delete -force test.db
749 file delete -force test2.db
751 # use the sqlcipher_export function
752 # on a non-existent database. Verify
753 # the error gets through.
754 do_test export-error {
755 sqlite_orig db test.db
758 PRAGMA key = 'testkey';
759 CREATE TABLE t1(a,b);
760 SELECT sqlcipher_export('nodb');
762 } {1 {unknown database nodb}}
764 file delete -force test.db
766 # use the sqlcipher_export function
767 # to copy a complicated database.
768 # tests autoincrement fields,
769 # indexes, views, and triggers,
770 # tables and virtual tables
771 do_test export-database {
772 sqlite_orig db test.db
775 PRAGMA key = 'testkey';
776 CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
777 CREATE UNIQUE INDEX b_idx ON t1(b);
778 CREATE INDEX c_idx ON t1(c);
780 CREATE TABLE t2(b,c);
781 CREATE TRIGGER t2_after_insert AFTER INSERT ON t2
783 INSERT INTO t1(b,c) VALUES (new.b, new.c);
789 CREATE VIRTUAL TABLE fts USING fts3(a,b);
792 -- start with one known value
793 INSERT INTO t2 VALUES(1000000,'value 1000000');
796 for {set i 1} {$i<=999} {incr i} {
797 set r [expr {int(rand()*500000)}]
798 execsql "INSERT INTO t2 VALUES($i,'value $r');"
802 INSERT INTO fts SELECT b,c FROM t1;
805 ATTACH DATABASE 'test2.db' AS db2 KEY 'testkey2';
806 PRAGMA db2.cipher_page_size = 4096;
808 SELECT sqlcipher_export('db2');
814 sqlite_orig db test2.db
816 PRAGMA key = 'testkey2';
817 PRAGMA cipher_page_size = 4096;
818 SELECT count(*) FROM t1;
819 SELECT count(*) FROM v1;
820 SELECT count(*) FROM sqlite_sequence;
821 SELECT seq FROM sqlite_sequence WHERE name = 't1';
822 INSERT INTO t2 VALUES(10001, 'value 938383');
823 SELECT count(*) FROM t1; -- verify the trigger worked
824 SELECT seq FROM sqlite_sequence WHERE name = 't1'; -- verify that autoincrement worked
825 SELECT a FROM fts WHERE b MATCH '1000000';
827 } {1000 1000 1 1000 1001 1001 1000000}
829 file copy -force test.db test-debug.db
830 file copy -force test2.db test2-debug.db
831 file delete -force test.db
832 file delete -force test2.db
834 # 1. create a database with WAL journal mode
835 # 2. create table and insert operations should work
836 # 3. close database, open it again
837 # 4. verify that the table is present, readable, and that
838 # the journal mode is WAL
839 do_test journal-mode-wal {
840 sqlite_orig db test.db
843 PRAGMA key = 'testkey';
844 PRAGMA journal_mode = WAL;
845 CREATE table t1(a,b);
849 for {set i 1} {$i<=1000} {incr i} {
850 set r [expr {int(rand()*500000)}]
851 execsql "INSERT INTO t1 VALUES($i,'value $r');"
859 sqlite_orig db test.db
862 PRAGMA key = 'testkey';
863 SELECT count(*) FROM t1;
869 file delete -force test.db
871 # Test rekey as first operation on an empty database. should be a no-op
872 do_test rekey-as-first-op {
873 sqlite_orig db test.db
876 PRAGMA rekey = 'testkey';
877 CREATE table t1(a,b);
881 for {set i 1} {$i<=100} {incr i} {
882 set r [expr {int(rand()*500000)}]
883 execsql "INSERT INTO t1 VALUES($i,'value $r');"
891 sqlite_orig db test.db
894 PRAGMA rekey = 'testkey';
895 SELECT count(*) FROM t1;
900 file delete -force test.db
902 # Test rekey as first operation follwed by key
903 do_test rekey-then-key-as-first-ops {
904 sqlite_orig db test.db
907 PRAGMA rekey = '1234';
908 PRAGMA key = 'testkey';
909 CREATE table t1(a,b);
913 for {set i 1} {$i<=100} {incr i} {
914 set r [expr {int(rand()*500000)}]
915 execsql "INSERT INTO t1 VALUES($i,'value $r');"
923 sqlite_orig db test.db
926 PRAGMA rekey = '4321';
927 PRAGMA key = 'testkey';
928 SELECT count(*) FROM t1;
933 file delete -force test.db
935 setup test.db "'testkey'"
936 do_test multiple-key-calls-safe-1 {
937 sqlite_orig db test.db
939 PRAGMA key = 'testkey';
940 PRAGMA cache_size = 0;
941 SELECT name FROM sqlite_master WHERE type='table';
945 do_test multiple-key-calls-safe-2 {
947 PRAGMA key = 'wrong key';
948 SELECT name FROM sqlite_master WHERE type='table';
950 } {1 {file is encrypted or is not a database}}
952 do_test multiple-key-calls-safe-3 {
954 PRAGMA key = 'testkey';
955 SELECT name FROM sqlite_master WHERE type='table';
960 file delete -force test.db
962 # 1. create a database with a custom hmac kdf iteration count,
963 # 2. create table and insert operations should work
964 # 3. close database, open it again with the same
965 # key and hmac kdf iteration count
966 # 4. verify that the table is readable
967 # and the data just inserted is visible
968 do_test custom-hmac-kdf-iter {
969 sqlite_orig db test.db
972 PRAGMA key = 'testkey';
973 PRAGMA fast_kdf_iter = 10;
974 CREATE table t1(a,b);
978 for {set i 1} {$i<=1000} {incr i} {
979 set r [expr {int(rand()*500000)}]
980 execsql "INSERT INTO t1 VALUES($i,'value $r');"
988 sqlite_orig db test.db
991 PRAGMA key = 'testkey';
992 PRAGMA fast_kdf_iter = 10;
993 SELECT count(*) FROM t1;
999 # open the database with the default hmac
1000 # kdf iteration count
1001 # to verify that it is not readable
1002 do_test custom-hmac-kdf-iter-must-match {
1003 sqlite_orig db test.db
1005 PRAGMA key = 'testkey';
1006 SELECT name FROM sqlite_master WHERE type='table';
1008 } {1 {file is encrypted or is not a database}}
1010 file delete -force test.db
1012 # open the database and turn on auto_vacuum
1013 # then insert a bunch of data, delete it
1014 # and verify that the file has become smaller
1015 # but can still be opened with the proper
1017 do_test auto-vacuum {
1018 sqlite_orig db test.db
1022 PRAGMA key = 'testkey';
1023 PRAGMA auto_vacuum=FULL;
1024 CREATE table t1(a,b);
1028 for {set i 1} {$i<=10000} {incr i} {
1029 set r [expr {int(rand()*500000)}]
1030 execsql "INSERT INTO t1 VALUES($i,'value $r');"
1033 lappend rc [execsql {
1035 SELECT count(*) FROM t1;
1038 # grab current size of file
1039 set sz [file size test.db]
1041 # delete some records, and verify
1042 # autovacuum removes them
1044 DELETE FROM t1 WHERE rowid > 5000;
1049 # grab new file size, post
1051 set sz2 [file size test.db]
1053 # verify that the new size is
1054 # smaller than the old size
1055 if {$sz > $sz2} { lappend rc true }
1057 sqlite_orig db test.db
1059 lappend rc [execsql {
1060 PRAGMA key = 'testkey';
1061 SELECT count(*) FROM t1;
1066 file delete -force test.db
1068 # open the database then insert a bunch of data.
1069 # then delete it and run a manual vacuum
1070 # verify that the file has become smaller
1071 # but can still be opened with the proper
1074 sqlite_orig db test.db
1078 PRAGMA key = 'testkey';
1079 CREATE table t1(a,b);
1083 for {set i 1} {$i<=10000} {incr i} {
1084 set r [expr {int(rand()*500000)}]
1085 execsql "INSERT INTO t1 VALUES($i,'value $r');"
1088 lappend rc [execsql {
1090 SELECT count(*) FROM t1;
1093 # grab current size of file
1094 set sz [file size test.db]
1097 DELETE FROM t1 WHERE rowid > 5000;
1102 # grab new file size, post
1104 set sz2 [file size test.db]
1106 # verify that the new size is
1107 # smaller than the old size
1108 if {$sz > $sz2} { lappend rc true }
1110 sqlite_orig db test.db
1111 lappend rc [execsql {
1112 PRAGMA key = 'testkey';
1113 SELECT count(*) FROM t1;