File: encryptionKey_jar.out

package info (click to toggle)
derby 10.14.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 78,896 kB
  • sloc: java: 691,930; sql: 42,686; xml: 20,511; sh: 3,373; sed: 96; makefile: 60
file content (106 lines) | stat: -rw-r--r-- 5,467 bytes parent folder | download | duplicates (4)
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
ij> --
--   Licensed to the Apache Software Foundation (ASF) under one or more
--   contributor license agreements.  See the NOTICE file distributed with
--   this work for additional information regarding copyright ownership.
--   The ASF licenses this file to You under the Apache License, Version 2.0
--   (the "License"); you may not use this file except in compliance with
--   the License.  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--   Unless required by applicable law or agreed to in writing, software
--   distributed under the License is distributed on an "AS IS" BASIS,
--   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--   See the License for the specific language governing permissions and
--   limitations under the License.
--
-- Test cases to test booting of encrypted databases using encryptionKey 
-- when using jar, classpath subprotocol.
--------------------------------------------------------------------
-- Case: create encrypted database using encryptionKey, jar it up and then test 
-- using the jar protocol.
-- create encrypted database.
connect 'jdbc:derby:encdb;create=true;dataEncryption=true;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666768';
ij> create table t1(a int ) ;
0 rows inserted/updated/deleted
ij> insert into t1 values(1) ;
1 row inserted/updated/deleted
ij> insert into t1 values(2) ;
1 row inserted/updated/deleted
ij> insert into t1 values(3) ;
1 row inserted/updated/deleted
ij> insert into t1 values(4) ;
1 row inserted/updated/deleted
ij> insert into t1 values(5) ;
1 row inserted/updated/deleted
ij> connect 'jdbc:derby:encdb;shutdown=true';
ERROR 08006: Database 'encdb' shutdown.
ij> -- now create archive of encrypted database.
connect 'jdbc:derby:wombat;create=true';
ij(CONNECTION1)> create procedure CREATEARCHIVE(jarName VARCHAR(20), path VARCHAR(20), dbName VARCHAR(20))
LANGUAGE JAVA PARAMETER STYLE JAVA
NO SQL
EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.createArchive';
0 rows inserted/updated/deleted
ij(CONNECTION1)> -- archive the encdb and put in ina.jar with dbname as db1 and ina2.jar as db2.
call CREATEARCHIVE('ina.jar', 'encdb', 'db1');
0 rows inserted/updated/deleted
ij(CONNECTION1)> call CREATEARCHIVE('ina2.jar','encdb','db2');
0 rows inserted/updated/deleted
ij(CONNECTION1)> disconnect;
ij> -- now that we have the database in a jar file,
-- test using the jar protocol to connect to the db1 that is in ina.jar
-- Should pass: ( DERBY-1373)
connect 'jdbc:derby:jar:(ina.jar)db1;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666768' AS DB1;
ij(DB1)> select * from t1 order by a;
A          
-----------
1          
2          
3          
4          
5          
ij(DB1)> connect 'jdbc:derby:;shutdown=true';
ERROR XJ015: Derby system shutdown.
ij(DB1)> -- NEGATIVE CASE: Test with wrong encryption key. This should fail.
connect 'jdbc:derby:jar:(ina.jar)db1;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666760' AS DB1;
ERROR XJ040: Failed to start database 'jar:(ina.jar)db1' with class loader XXXX,  see the next exception for details.
ERROR XBCXK: The given encryption key does not match the encryption key used when creating the database. Please ensure that you are using the correct encryption key and try again. 
ij(DB1)> disconnect;
ij> -- test reading a database from a jar file and loading
-- classes etc. from the jars within the database.
-- first using the jar protocol and then the classpath option.
connect 'jdbc:derby:jar:(ina.jar)db1;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666768' AS DB1;
ij(DB1)> connect 'jdbc:derby:;shutdown=true';
ERROR XJ015: Derby system shutdown.
ij(DB1)> -- connect to database in jar file using classpath subprotocol.
-- should fail as it is not on the classpath yet.
connect 'jdbc:derby:classpath:db2;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666768' AS DB2CL;
ERROR XJ004: Database 'classpath:db2' not found.
ij(DB1)> -- create a class loader for this current thread
connect 'jdbc:derby:encdb;dataEncryption=true;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666768';
ij(CONNECTION1)> create procedure setDBContextClassLoader(JARNAME VARCHAR(20))
LANGUAGE JAVA PARAMETER STYLE JAVA
NO SQL
EXTERNAL NAME 'org.apache.derbyTesting.functionTests.tests.lang.dbjarUtil.setDBContextClassLoader';
0 rows inserted/updated/deleted
ij(CONNECTION1)> call setDBContextClassLoader('ina2.jar');
0 rows inserted/updated/deleted
ij(CONNECTION1)> disconnect;
ij> -- connect using classpath option with correct encryption key.
connect 'jdbc:derby:classpath:db2;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666768' AS DB2CL;
ij(DB2CL)> select * from t1 order by a;
A          
-----------
1          
2          
3          
4          
5          
ij(DB2CL)> connect 'jdbc:derby:;shutdown=true';
ERROR XJ015: Derby system shutdown.
ij(DB2CL)> -- try with wrong encryption key, this should fail.
connect 'jdbc:derby:classpath:db2;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=6162636465666760' AS DB2CL;
ERROR XJ040: Failed to start database 'classpath:db2' with class loader XXXX,  see the next exception for details.
ERROR XBCXK: The given encryption key does not match the encryption key used when creating the database. Please ensure that you are using the correct encryption key and try again. 
ij(DB2CL)> exit;