Skip to content

Commit 3bd6262

Browse files
committed
refactor sqlcipher tests into separate files
1 parent f615ede commit 3bd6262

9 files changed

Lines changed: 3289 additions & 2985 deletions

test/crypto.test

Lines changed: 0 additions & 2985 deletions
This file was deleted.

test/sqlcipher-compatibility.test

Lines changed: 1233 additions & 0 deletions
Large diffs are not rendered by default.

test/sqlcipher-core.test

Lines changed: 714 additions & 0 deletions
Large diffs are not rendered by default.

test/sqlcipher-plaintext-header.test

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

test/sqlcipher-pragmas.test

Lines changed: 379 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,379 @@
1+
# SQLCipher
2+
# codec.test developed by Stephen Lombardo (Zetetic LLC)
3+
# sjlombardo at zetetic dot net
4+
# http://zetetic.net
5+
#
6+
# Copyright (c) 2018, ZETETIC LLC
7+
# Redistribution and use in source and binary forms, with or without
8+
# modification, are permitted provided that the following conditions are met:
9+
# * Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
# * Redistributions in binary form must reproduce the above copyright
12+
# notice, this list of conditions and the following disclaimer in the
13+
# documentation and/or other materials provided with the distribution.
14+
# * Neither the name of the ZETETIC LLC nor the
15+
# names of its contributors may be used to endorse or promote products
16+
# derived from this software without specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
19+
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
22+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
# This file implements regression tests for SQLite library. The
30+
# focus of this script is testing code cipher features.
31+
#
32+
# NOTE: tester.tcl has overridden the definition of sqlite3 to
33+
# automatically pass in a key value. Thus tests in this file
34+
# should explicitly close and open db with sqlite_orig in order
35+
# to bypass default key assignment.
36+
37+
set testdir [file dirname $argv0]
38+
source $testdir/tester.tcl
39+
source $testdir/sqlcipher.tcl
40+
41+
# verify the pragma cipher_version
42+
# returns the currently configured
43+
# sqlcipher version
44+
do_test verify-pragma-cipher-version {
45+
sqlite_orig db test.db
46+
execsql {
47+
PRAGMA cipher_version;
48+
}
49+
} {3.4.2}
50+
db close
51+
file delete -force test.db
52+
53+
# verify the pragma cipher_use_hmac
54+
# is set to true be default
55+
do_test verify-pragma-cipher-use-hmac-default {
56+
sqlite_orig db test.db
57+
execsql {
58+
PRAGMA key = 'test';
59+
PRAGMA cipher_use_hmac;
60+
}
61+
} {1}
62+
db close
63+
file delete -force test.db
64+
65+
# verify the pragma cipher_use_hmac
66+
# reports the flag turned off
67+
do_test verify-pragma-cipher-use-hmac-off {
68+
sqlite_orig db test.db
69+
execsql {
70+
PRAGMA key = 'test';
71+
PRAGMA cipher_use_hmac = off;
72+
PRAGMA cipher_use_hmac;
73+
}
74+
} {0}
75+
db close
76+
file delete -force test.db
77+
78+
# verify the pragma default_cipher_use_hmac
79+
# is set to true by default
80+
do_test verify-pragma-cipher-default-use-hmac-default {
81+
sqlite_orig db test.db
82+
execsql {
83+
PRAGMA cipher_default_use_hmac;
84+
}
85+
} {1}
86+
db close
87+
file delete -force test.db
88+
89+
# verify the pragma default_cipher_use_hmac
90+
# reports the flag turned off
91+
do_test verify-pragma-cipher-default-use-hmac-off {
92+
sqlite_orig db test.db
93+
execsql {
94+
PRAGMA cipher_default_use_hmac = off;
95+
PRAGMA cipher_default_use_hmac;
96+
-- Be sure to turn cipher_default_use_hmac
97+
-- back on or it will break later tests
98+
-- (it's a global flag)
99+
PRAGMA cipher_default_use_hmac = ON;
100+
}
101+
} {0}
102+
db close
103+
file delete -force test.db
104+
105+
# verify the pragma default_cipher_kdf_iter
106+
# is set to 256000 by default
107+
do_test verify-pragma-cipher-default-kdf-iter-default {
108+
sqlite_orig db test.db
109+
execsql {
110+
PRAGMA cipher_default_kdf_iter;
111+
}
112+
} {256000}
113+
db close
114+
file delete -force test.db
115+
116+
117+
# verify the pragma default_cipher_kdf_ter
118+
# reports changes
119+
do_test verify-pragma-cipher-default-use-hmac-off {
120+
sqlite_orig db test.db
121+
execsql {
122+
PRAGMA cipher_default_kdf_iter = 1000;
123+
PRAGMA cipher_default_kdf_iter;
124+
PRAGMA cipher_default_kdf_iter = 256000;
125+
}
126+
} {1000}
127+
db close
128+
file delete -force test.db
129+
130+
# verify the pragma kdf_iter
131+
# reports the default value
132+
do_test verify-pragma-kdf-iter-reports-default {
133+
sqlite_orig db test.db
134+
execsql {
135+
PRAGMA key = 'test';
136+
PRAGMA kdf_iter;
137+
}
138+
} {256000}
139+
db close
140+
file delete -force test.db
141+
142+
# verify the pragma kdf_iter
143+
# reports value changed
144+
do_test verify-pragma-kdf-iter-reports-value-changed {
145+
sqlite_orig db test.db
146+
execsql {
147+
PRAGMA key = 'test';
148+
PRAGMA kdf_iter = 8000;
149+
PRAGMA kdf_iter;
150+
}
151+
} {8000}
152+
db close
153+
file delete -force test.db
154+
155+
# verify the pragma fast_kdf_iter
156+
# reports the default value
157+
do_test verify-pragma-fast-kdf-iter-reports-default {
158+
sqlite_orig db test.db
159+
execsql {
160+
PRAGMA key = 'test';
161+
PRAGMA fast_kdf_iter;
162+
}
163+
} {2}
164+
db close
165+
file delete -force test.db
166+
167+
# verify the pragma fast_kdf_iter
168+
# reports value changed
169+
do_test verify-pragma-kdf-iter-reports-value-changed {
170+
sqlite_orig db test.db
171+
execsql {
172+
PRAGMA key = 'test';
173+
PRAGMA fast_kdf_iter = 4000;
174+
PRAGMA fast_kdf_iter;
175+
}
176+
} {4000}
177+
db close
178+
file delete -force test.db
179+
180+
# verify the pragma cipher_page_size
181+
# reports default value
182+
do_test verify-pragma-cipher-page-size-default {
183+
sqlite_orig db test.db
184+
execsql {
185+
PRAGMA key = 'test';
186+
PRAGMA cipher_page_size;
187+
}
188+
} {4096}
189+
db close
190+
file delete -force test.db
191+
192+
# verify the pragma cipher_page_size
193+
# reports change in value
194+
do_test verify-pragma-cipher-page-size-changed {
195+
sqlite_orig db test.db
196+
execsql {
197+
PRAGMA key = 'test';
198+
PRAGMA cipher_page_size = 8192;
199+
PRAGMA cipher_page_size;
200+
}
201+
} {8192}
202+
db close
203+
file delete -force test.db
204+
205+
# verify setting cipher_store_pass before key
206+
# does not cause segfault
207+
do_test verify-cipher-store-pass-before-key-does-not-segfault {
208+
sqlite_orig db test.db
209+
execsql {
210+
PRAGMA cipher_store_pass = 1;
211+
PRAGMA key = 'test';
212+
}
213+
} {}
214+
db close
215+
file delete -force test.db
216+
217+
# verify the pragma cipher
218+
# reports the default value
219+
if_built_with_openssl verify-pragma-cipher-default {
220+
sqlite_orig db test.db
221+
execsql {
222+
PRAGMA key = 'test';
223+
PRAGMA cipher;
224+
}
225+
} {AES-256-CBC}
226+
db close
227+
file delete -force test.db
228+
229+
# verify the pragma cipher_hmac_salt_mask reports default
230+
do_test verify-pragma-hmac-salt-mask-reports-default {
231+
sqlite_orig db test.db
232+
execsql {
233+
PRAGMA key = 'test';
234+
PRAGMA cipher_hmac_salt_mask;
235+
}
236+
} {3a}
237+
db close
238+
file delete -force test.db
239+
240+
# verify the pragma cipher_hmac_salt_mask reports
241+
# reports value changed
242+
do_test verify-pragma-hmac-salt-mask-reports-value-changed {
243+
sqlite_orig db test.db
244+
execsql {
245+
PRAGMA key = 'test';
246+
PRAGMA cipher_hmac_salt_mask = "x'11'";
247+
PRAGMA cipher_hmac_salt_mask;
248+
}
249+
} {11}
250+
db close
251+
file delete -force test.db
252+
253+
# verify the pragma cipher_hmac_pgno reports default
254+
do_test verify-pragma-hmac-pgno-reports-default {
255+
sqlite_orig db test.db
256+
execsql {
257+
PRAGMA key = 'test';
258+
PRAGMA cipher_hmac_pgno;
259+
}
260+
} {le}
261+
db close
262+
file delete -force test.db
263+
264+
# verify the pragma cipher_hmac_pgno
265+
# reports value changed
266+
do_test verify-pragma-hmac-pgno-reports-value-changed {
267+
sqlite_orig db test.db
268+
execsql {
269+
PRAGMA key = 'test';
270+
PRAGMA cipher_hmac_pgno = be;
271+
PRAGMA cipher_hmac_pgno;
272+
PRAGMA cipher_hmac_pgno = native;
273+
PRAGMA cipher_hmac_pgno;
274+
PRAGMA cipher_hmac_pgno = le;
275+
PRAGMA cipher_hmac_pgno;
276+
}
277+
} {be native le}
278+
db close
279+
file delete -force test.db
280+
281+
# verify the pragma cipher_hmac_algorithm works properly
282+
do_test verify-pragma-cipher-hmac-algorithm-reports-default {
283+
sqlite_orig db test.db
284+
execsql {
285+
PRAGMA key = 'test';
286+
PRAGMA cipher_hmac_algorithm;
287+
}
288+
} {HMAC_SHA512}
289+
db close
290+
file delete -force test.db
291+
292+
do_test verify-pragma-cipher-hmac-algorithm-reports-value-changed {
293+
sqlite_orig db test.db
294+
execsql {
295+
PRAGMA key = 'test';
296+
PRAGMA cipher_hmac_algorithm = HMAC_SHA1;
297+
PRAGMA cipher_hmac_algorithm;
298+
}
299+
} {HMAC_SHA1}
300+
db close
301+
file delete -force test.db
302+
303+
do_test verify-pragma-cipher-default-hmac-algorithm {
304+
sqlite_orig db test.db
305+
execsql {
306+
PRAGMA cipher_default_hmac_algorithm;
307+
PRAGMA cipher_default_hmac_algorithm = HMAC_SHA1;
308+
PRAGMA cipher_default_hmac_algorithm;
309+
PRAGMA cipher_default_hmac_algorithm = HMAC_SHA512;
310+
}
311+
} {HMAC_SHA512 HMAC_SHA1}
312+
db close
313+
file delete -force test.db
314+
315+
# verify the pragma cipher_kdf_algorithm works properly
316+
do_test verify-pragma-cipher-kdf-algorithm-reports-default {
317+
sqlite_orig db test.db
318+
execsql {
319+
PRAGMA key = 'test';
320+
PRAGMA cipher_kdf_algorithm;
321+
}
322+
} {PBKDF2_HMAC_SHA512}
323+
db close
324+
file delete -force test.db
325+
326+
do_test verify-pragma-cipher-kdf-algorithm-reports-value-changed {
327+
sqlite_orig db test.db
328+
execsql {
329+
PRAGMA key = 'test';
330+
PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;
331+
PRAGMA cipher_kdf_algorithm;
332+
}
333+
} {PBKDF2_HMAC_SHA1}
334+
db close
335+
file delete -force test.db
336+
337+
do_test verify-pragma-cipher-default-kdf-algorithm {
338+
sqlite_orig db test.db
339+
execsql {
340+
PRAGMA cipher_default_kdf_algorithm;
341+
PRAGMA cipher_default_kdf_algorithm = PBKDF2_HMAC_SHA1;
342+
PRAGMA cipher_default_kdf_algorithm;
343+
PRAGMA cipher_default_kdf_algorithm = PBKDF2_HMAC_SHA512;
344+
}
345+
} {PBKDF2_HMAC_SHA512 PBKDF2_HMAC_SHA1}
346+
db close
347+
file delete -force test.db
348+
349+
if_built_with_openssl verify-default-cipher {
350+
sqlite_orig db test.db
351+
execsql {
352+
PRAGMA key='test';
353+
PRAGMA cipher;
354+
}
355+
} {AES-256-CBC}
356+
db close
357+
file delete -force test.db
358+
359+
if_built_with_libtomcrypt verify-default-cipher {
360+
sqlite_orig db test.db
361+
execsql {
362+
PRAGMA key='test';
363+
PRAGMA cipher;
364+
}
365+
} {aes-256-cbc}
366+
db close
367+
file delete -force test.db
368+
369+
if_built_with_commoncrypto verify-default-cipher {
370+
sqlite_orig db test.db
371+
execsql {
372+
PRAGMA key='test';
373+
PRAGMA cipher;
374+
}
375+
} {aes-256-cbc}
376+
db close
377+
file delete -force test.db
378+
379+
finish_test

0 commit comments

Comments
 (0)