db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r365785 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/reference/ engine/org/apache/derby/impl/services/jce/ engine/org/apache/derby/loc/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/fu...
Date Wed, 04 Jan 2006 00:48:42 GMT
Author: djd
Date: Tue Jan  3 16:48:38 2006
New Revision: 365785

URL: http://svn.apache.org/viewcvs?rev=365785&view=rev
Log:
DERBY-746 Fix NullPointerException on passing an invalid format as encryptionKey on a JDBC
URL
* JCECipherFactory.boot() now checks the output from the fromHexString-method and throws an
exception if it is invalid.
* Added 2 new SQLStates and messages (only English)
* Added 2 new test cases (invalid char in encryption key and encryption key of with odd length).
* Updated master file. 
Patch contributed by Kristian Waagan (Kristian.Waagan@Sun.com)

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jce/JCECipherFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/encryptionKey.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/encryptionKey.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java?rev=365785&r1=365784&r2=365785&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/SQLState.java Tue Jan
 3 16:48:38 2006
@@ -222,6 +222,9 @@
     String ENCRYPTION_BAD_JCE           = "XBCXJ.S";
     String ENCRYPTION_BAD_EXTERNAL_KEY  = "XBCXK.S";
     String ENCRYPTION_UNABLE_KEY_VERIFICATION  = "XBCXL.S";
+    String ENCRYPTION_INVALID_EXKEY_LENGTH          = "XBCXM.S";
+    String ENCRYPTION_ILLEGAL_EXKEY_CHARS           = "XBCXN.S";
+        
 	/*
 	** Cache Service
 	*/

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jce/JCECipherFactory.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jce/JCECipherFactory.java?rev=365785&r1=365784&r2=365785&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jce/JCECipherFactory.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jce/JCECipherFactory.java
Tue Jan  3 16:48:38 2006
@@ -546,6 +546,14 @@
 					throw StandardException.newException(SQLState.SERVICE_WRONG_BOOT_PASSWORD);
 
 				generatedKey = org.apache.derby.iapi.util.StringUtil.fromHexString(externalKey, 0, externalKey.length());
+                if (generatedKey == null) {
+                    throw StandardException.newException(
+                        // If length is even, we assume invalid character(s),
+                        // based on how 'fromHexString' behaves.
+                        externalKey.length() % 2 == 0 
+                            ? SQLState.ENCRYPTION_ILLEGAL_EXKEY_CHARS
+                            : SQLState.ENCRYPTION_INVALID_EXKEY_LENGTH);
+                }
 
 			} else {
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties?rev=365785&r1=365784&r2=365785&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages_en.properties Tue Jan  3
16:48:38 2006
@@ -83,6 +83,8 @@
 XBCXJ.S=The application is using a version of the Java Cryptography Extension (JCE) earlier
than 1.2.1.  Please upgrade to JCE 1.2.1 and try the operation again.    
 XBCXK.S=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. 
 XBCXL.S=The verification process for the encryption key was not successful. This could have
been caused by an error when accessing the appropriate file to do the verification process.
 See next exception for details.  
+XBCXM.S=The length of the external encryption key must be an even number.
+XBCXN.S=The external encryption key contains one or more illegal characters. Allowed characters
for a hexedecimal number are 0-9, a-f and A-F.
 
 #../java/com/ibm/db2j/impl/BasicServices/CacheService/Generic/messages.properties
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/encryptionKey.out
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/encryptionKey.out?rev=365785&r1=365784&r2=365785&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/encryptionKey.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/encryptionKey.out
Tue Jan  3 16:48:38 2006
@@ -13,7 +13,10 @@
 --	   with right key
 --	   with wrong key
 --	   with right key
--- 	   test restoreFrom 
+--	   test restoreFrom
+-- Case 4: use invalid key when trying to create
+--     key length not even
+--     key contains invalid character(s)
 --	   
 ------------------------------------------------------------------------------------
 -- case1:	give external encryptionKey instead of bootpassword
@@ -113,4 +116,15 @@
 --------------------------------
 1          |a                   
 ij(CONNECTION6)> disconnect;
+ij> -- case 4 : invalid keys
+-- key length not even
+connect 'jdbc:derby:encddbdb_invkey;create=true;dataEncryption=true;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=123456789';
+ERROR XJ041: Failed to create database 'encddbdb_invkey', see the next exception for details.
+ERROR XBM01: Startup failed due to an exception. See next exception for details. 
+ERROR XBCXM: The length of the external encryption key must be an even number.
+ij> -- key contains illegal character(s)
+connect 'jdbc:derby:encddbdb_invkey;create=true;dataEncryption=true;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=616263646566676869616263646565XY';
+ERROR XJ041: Failed to create database 'encddbdb_invkey', see the next exception for details.
+ERROR XBM01: Startup failed due to an exception. See next exception for details. 
+ERROR XBCXN: The external encryption key contains one or more illegal characters. Allowed
characters for a hexedecimal number are 0-9, a-f and A-F.
 ij> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/encryptionKey.sql
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/encryptionKey.sql?rev=365785&r1=365784&r2=365785&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/encryptionKey.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/encryptionKey.sql
Tue Jan  3 16:48:38 2006
@@ -13,7 +13,10 @@
 --	   with right key
 --	   with wrong key
 --	   with right key
--- 	   test restoreFrom 
+--	   test restoreFrom
+-- Case 4: use invalid key when trying to create
+--     key length not even
+--     key contains invalid character(s)
 --	   
 ------------------------------------------------------------------------------------
 -- case1:	give external encryptionKey instead of bootpassword
@@ -83,3 +86,11 @@
 connect 'jdbc:derby:encdb;restoreFrom=extinout/mybackup2/encdb;dataEncryption=true;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=61626364656667686961626364656568';
 select * from t1;
 disconnect;
+
+-- case 4 : invalid keys
+-- key length not even
+connect 'jdbc:derby:encddbdb_invkey;create=true;dataEncryption=true;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=123456789';
+
+-- key contains illegal character(s)
+connect 'jdbc:derby:encddbdb_invkey;create=true;dataEncryption=true;encryptionAlgorithm=DES/CBC/NoPadding;encryptionKey=616263646566676869616263646565XY';
+



Mime
View raw message