summaryrefslogtreecommitdiffstats
path: root/mysql-test/main/func_encrypt.test
blob: 306939ef2ac85162ab4a2e1161cd5f90865936f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
-- source include/have_des.inc
#double warning for view protocol 
--source include/no_view_protocol.inc

--disable_warnings
drop table if exists t1;
--enable_warnings

create table t1 (x blob);
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('a','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','a'));
insert into t1 values (des_encrypt('ab','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','ab'));
insert into t1 values (des_encrypt('abc','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abc'));
insert into t1 values (des_encrypt('abcd','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcd'));
insert into t1 values (des_encrypt('abcde','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcde'));
insert into t1 values (des_encrypt('abcdef','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcdef'));
insert into t1 values (des_encrypt('abcdefg','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcdefg'));
insert into t1 values (des_encrypt('abcdefgh','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcdefgh'));
insert into t1 values (des_encrypt('abcdefghi','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcdefghi'));
insert into t1 values (des_encrypt('abcdefghij','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcdefghij'));
insert into t1 values (des_encrypt('abcdefghijk','The quick red fox jumped over the lazy brown dog'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','abcdefghijk'));
insert into t1 values (des_encrypt('The quick red fox jumped over the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('quick red fox jumped over the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('red fox jumped over the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('fox jumped over the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('jumped over the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('over the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('brown dog','sabakala'));
insert into t1 values (des_encrypt('dog','sabakala'));
insert into t1 values (des_encrypt('dog!','sabakala'));
insert into t1 values (des_encrypt('dog!!','sabakala'));
insert into t1 values (des_encrypt('dog!!!','sabakala'));
insert into t1 values (des_encrypt('dog!!!!','sabakala'));
insert into t1 values (des_encrypt('dog!!!!!','sabakala'));
insert into t1 values (des_encrypt('jumped over the lazy brown dog','sabakala'));
insert into t1 values (des_encrypt('jumped over the lazy brown dog','sabakala'));
select hex(x), hex(des_decrypt(x,'sabakala')) from t1;
select des_decrypt(x,'sabakala') as s from t1 having s like '%dog%';
drop table t1;

#
# Test default keys
#
select hex(des_encrypt("hello")),des_decrypt(des_encrypt("hello"));
select des_decrypt(des_encrypt("hello",4));
select des_decrypt(des_encrypt("hello",'test'),'test');
select hex(des_encrypt("hello")),hex(des_encrypt("hello",5)),hex(des_encrypt("hello",'default_password'));
select des_decrypt(des_encrypt("hello"),'default_password');
select des_decrypt(des_encrypt("hello",4),'password4');

# Test use of invalid parameters
select des_encrypt("hello",10);
select des_encrypt(NULL);
select des_encrypt(NULL, 10);
select des_encrypt(NULL, NULL);
select des_encrypt(10, NULL);
select des_encrypt("hello", NULL);

select des_decrypt("hello",10);
select des_decrypt(NULL);
select des_decrypt(NULL, 10);
select des_decrypt(NULL, NULL);
select des_decrypt(10, NULL);
select des_decrypt("hello", NULL);


# Test flush
SET @a=des_decrypt(des_encrypt("hello"));
flush des_key_file;
select @a = des_decrypt(des_encrypt("hello"));

# Test usage of wrong password
select hex("hello");
select hex(des_decrypt(des_encrypt("hello",4),'password2'));
select hex(des_decrypt(des_encrypt("hello","hidden")));

explain extended select des_decrypt(des_encrypt("hello",4),'password2'), des_decrypt(des_encrypt("hello","hidden"));

# End of 4.1 tests

--echo #
--echo # Start of 10.1 tests
--echo #

--echo #
--echo # MDEV-8369 Unexpected impossible WHERE for a condition on a ZEROFILL field
--echo #
CREATE TABLE t1 (a INT(6) ZEROFILL);
INSERT INTO t1 VALUES (1),(2);
# This should not propagate a=1 into DES_ENCRYPT
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE a=1 AND DES_ENCRYPT('test',a)=_latin1 'abc' COLLATE latin1_bin;
DROP TABLE t1;

--echo #
--echo # End of 10.1 tests
--echo #

--echo #
--echo # Start of 10.2 tests
--echo #

--echo #
--echo # MDEV-10134 Add full support for DEFAULT
--echo #

CREATE TABLE t1 (
  a VARCHAR(30),
  b BLOB DEFAULT DES_ENCRYPT(a, 'passwd'),
  c TEXT DEFAULT DES_DECRYPT(b, 'passwd')
);
--disable_warnings
SHOW CREATE TABLE t1;
--enable_warnings
INSERT INTO t1 (a) VALUES ('test');
SELECT c FROM t1;
DROP TABLE t1;

--echo #
--echo # End of 10.2 tests
--echo #