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;