From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11930 invoked by alias); 15 Jun 2006 23:17:38 -0000 Received: (qmail 11921 invoked by uid 22791); 15 Jun 2006 23:17:37 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 15 Jun 2006 23:17:35 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k5FNHXT7017297 for ; Thu, 15 Jun 2006 19:17:33 -0400 Received: from pobox.toronto.redhat.com (pobox.toronto.redhat.com [172.16.14.4]) by int-mx1.corp.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k5FNHXQY015666 for ; Thu, 15 Jun 2006 19:17:33 -0400 Received: from [127.0.0.1] (sebastian-int.corp.redhat.com [172.16.52.221]) by pobox.toronto.redhat.com (8.12.8/8.12.8) with ESMTP id k5FNHWve018458 for ; Thu, 15 Jun 2006 19:17:32 -0400 Message-ID: <4491E9E6.3080009@redhat.com> Date: Thu, 15 Jun 2006 23:17:00 -0000 From: Vivek Lakshmanan User-Agent: Thunderbird 1.5.0.2 (X11/20060501) MIME-Version: 1.0 To: mauve-patches@sources.redhat.com Subject: FYI: Check for correct exceptions for TestOfCipherEngineInit Content-Type: multipart/mixed; boundary="------------090101090109070403060505" X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2006/txt/msg00420.txt.bz2 This is a multi-part message in MIME format. --------------090101090109070403060505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 463 The following _already committed_ updates the testInitWithParameterSpec test with a check for the correct exception expected. Also provides more comments for the logic involved in this test case. Thanks, Vivek 2006-06-15 Vivek Lakshmanan * gnu/testlet/gnu/javax/crypto/jce/TestOfCipherEngineInit.java (testInitWithParameterSpec): More comments and look for InvalidAlgorithmParameterException instead of InvalidKeyException. --------------090101090109070403060505 Content-Type: text/x-patch; name="mauve-TestOfCipherEngineInit.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mauve-TestOfCipherEngineInit.patch" Content-length: 4665 Index: gnu/testlet/gnu/javax/crypto/jce/TestOfCipherEngineInit.java =================================================================== RCS file: /cvs/mauve/mauve/gnu/testlet/gnu/javax/crypto/jce/TestOfCipherEngineInit.java,v retrieving revision 1.2 diff -u -r1.2 TestOfCipherEngineInit.java --- gnu/testlet/gnu/javax/crypto/jce/TestOfCipherEngineInit.java 15 Jun 2006 16:55:36 -0000 1.2 +++ gnu/testlet/gnu/javax/crypto/jce/TestOfCipherEngineInit.java 15 Jun 2006 23:02:05 -0000 @@ -28,6 +28,7 @@ import gnu.testlet.TestHarness; import gnu.testlet.Testlet; +import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.Key; import java.security.SecureRandom; @@ -165,13 +166,15 @@ // If param is null, and the cipher needs algorithm parameters to // function then init should create random/default parameters provided // the cipher is in ENCRYPT or WRAP mode, if in DECRYPT or UNWRAP mode - // the function must throw an InvalidKeyException. + // the function must throw an InvalidAlgorithmParameterException. // Extrapolation: If algorithm does not require additional params // then none should be created? private void testInitWithParameterSpec(TestHarness harness) { try { + // This cipher does not need extra algorithm parameters like + // an IV to be provided so it should not generate one. cipher = Cipher.getInstance("DESede/ECB/NoPadding"); String input = "Does this work ?"; @@ -184,6 +187,7 @@ byte[] ciphertext = cipher.doFinal(plaintext); iv = null; + // No need for an IV so none should be generated in decrypt mode either. cipher.init(Cipher.DECRYPT_MODE, key, (AlgorithmParameterSpec) null); iv = cipher.getIV(); harness.check( @@ -192,6 +196,7 @@ byte[] plaintext2 = cipher.doFinal(ciphertext); String recovered = new String(plaintext2); + // Encryption and decryption should still work. harness.check(input.equals(recovered), "Original and recovered texts MUST be equal"); } @@ -206,6 +211,8 @@ cipher = Cipher.getInstance("DESede/CBC/NoPadding"); String input = "Does this work ?"; + // null param for CBC should result in random algorithm params being + // generated cipher.init(Cipher.ENCRYPT_MODE, key, (AlgorithmParameterSpec) null); iv = cipher.getIV(); harness.check( @@ -220,21 +227,25 @@ AlgorithmParameterSpec backupAlg = cipher.getParameters().getParameterSpec( BlockCipherParameterSpec.class); - try { + // Should not be able to init a DECRYPT cipher for CBC without + // params. cipher.init(Cipher.DECRYPT_MODE, key, (AlgorithmParameterSpec) null); harness.fail("(Decrypting - NULL AlgorithmParameterSpec) init of CBC with NULL IV NOT possible"); } catch (Exception e) { + // The exception must be InvalidAlgorithmParameterException String type = e.getClass().getName(); harness.check( - type.equals(InvalidKeyException.class.getName()), + type.equals(InvalidAlgorithmParameterException.class.getName()), "(Decrypting - NULL AlgorithmParameterSpec) CBC init with NULL IV MUST throw exception"); } try { + // Now use a proper algorithm parameter and test init. + // This should pass!! cipher.init(Cipher.DECRYPT_MODE, key, backupAlg); } catch (Exception e) @@ -245,9 +256,9 @@ iv = cipher.getIV(); harness.check( iv != null, - "(Decrypting - Valid AlgorithmParameterSpec) cipher.getIV() for CBC init with NULL params MUST NOT return null"); + "(Decrypting - Valid AlgorithmParameterSpec) cipher.getIV() for CBC init with valid params MUST NOT return null"); harness.check(iv.length == 8, - "(Decrypting - NULL AlgorithmParameterSpec) IV length for CBC should be 8"); + "(Decrypting - Valid AlgorithmParameterSpec) IV length for CBC should be 8"); byte[] plaintext2 = cipher.doFinal(ciphertext); String recovered = new String(plaintext2); @@ -264,7 +275,7 @@ } - //TODO: Add tests for WRAP and UNWRAP too. + // TODO: Add tests for WRAP and UNWRAP too. } --------------090101090109070403060505--