You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2012/10/30 16:19:21 UTC

svn commit: r1403735 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/jdbc/EmbedConnection.java testing/org/apache/derbyTesting/functionTests/tests/store/DecryptDatabaseTest.java

Author: rhillegas
Date: Tue Oct 30 15:19:21 2012
New Revision: 1403735

URL: http://svn.apache.org/viewvc?rev=1403735&view=rev
Log:
DERBY-5970: Prevent user from setting the decryptDatabase attribute to anything other than true.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/DecryptDatabaseTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=1403735&r1=1403734&r2=1403735&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Tue Oct 30 15:19:21 2012
@@ -770,9 +770,11 @@ public class EmbedConnection implements 
      * @return {@code true} if a boot will perform a cryptographic operation on
      *      the database.
      */
-    private boolean isCryptoBoot(Properties p) {
+    private boolean isCryptoBoot(Properties p)
+        throws SQLException
+    {
         return (isTrue(p, Attribute.DATA_ENCRYPTION) ||
-                isTrue(p, Attribute.DECRYPT_DATABASE) ||
+                vetTrue(p, Attribute.DECRYPT_DATABASE) ||
                 isSet(p, Attribute.NEW_BOOT_PASSWORD) ||
                 isSet(p, Attribute.NEW_CRYPTO_EXTERNAL_KEY));
 	}
@@ -849,6 +851,22 @@ public class EmbedConnection implements 
         return Boolean.valueOf(p.getProperty(attribute)).booleanValue();
     }
 
+    /**
+     * Returns true if the attribute exists and is set to true.
+     * Raises an exception if the attribute exists and is set to something else.
+     */
+    private static boolean vetTrue(Properties p, String attribute)
+        throws SQLException
+    {
+        String  value = p.getProperty( attribute );
+        if ( value == null ) { return false; }
+
+        if ( Boolean.valueOf( value ).booleanValue() ) { return true; }
+
+        throw newSQLException
+            ( SQLState.INVALID_ATTRIBUTE, attribute, value, Boolean.TRUE.toString() );
+    }
+
     private String getReplicationOperation(Properties p) 
         throws StandardException {
 
@@ -3168,15 +3186,18 @@ public class EmbedConnection implements 
         return Util.getExceptionFactory();
     }
 
-	protected SQLException newSQLException(String messageId) {
+	protected static SQLException newSQLException(String messageId) {
 		return Util.generateCsSQLException(messageId);
 	}
-	protected SQLException newSQLException(String messageId, Object arg1) {
+	protected static SQLException newSQLException(String messageId, Object arg1) {
 		return Util.generateCsSQLException(messageId, arg1);
 	}
-	protected SQLException newSQLException(String messageId, Object arg1, Object arg2) {
+	protected static SQLException newSQLException(String messageId, Object arg1, Object arg2) {
 		return Util.generateCsSQLException(messageId, arg1, arg2);
 	}
+	protected static SQLException newSQLException(String messageId, Object arg1, Object arg2, Object arg3) {
+		return Util.generateCsSQLException(messageId, arg1, arg2, arg3);
+	}
 
 	/////////////////////////////////////////////////////////////////////////
 	//

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/DecryptDatabaseTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/DecryptDatabaseTest.java?rev=1403735&r1=1403734&r2=1403735&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/DecryptDatabaseTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/DecryptDatabaseTest.java Tue Oct 30 15:19:21 2012
@@ -148,6 +148,15 @@ public class DecryptDatabaseTest
         } catch (SQLException sqle) {
             assertSQLState("XBM06", sqle);
         }
+        
+        // Bad setting for decryptDatabase
+        try {
+            connect( false, BOOTPW, "decryptDatabase=fred" );
+            fail( "bad decryptDatabase setting not detected" );
+        } catch (SQLException sqle) {
+            assertSQLState("XJ05B", sqle);
+        }
+
         connect(false, BOOTPW, null);
     }