Bug 28104 - Cipher.init(...) does not check if the passed parameters are valid
Summary: Cipher.init(...) does not check if the passed parameters are valid
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: crypto (show other bugs)
Version: 0.92
: P3 normal
Target Milestone: ---
Assignee: Casey Marshall
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-20 18:30 UTC by Matt Wringe
Modified: 2006-08-02 21:31 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Mauve test case to check if passed IV are valid or not (1.23 KB, patch)
2006-06-21 15:14 UTC, Matt Wringe
Details | Diff
Checks that the IvParameterSpec contains a valid length IV (427 bytes, patch)
2006-06-21 15:19 UTC, Matt Wringe
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Wringe 2006-06-20 18:30:53 UTC
Cipher.init(...) does not check if the passed parameters are valid or not.

For example:

        int blocksize = 8;     
        byte[] iv = new byte[blocksize -1];
        encrypt = Cipher.getInstance("DES/CBC/PKCS5Padding", "GNU-CRYPTO");
        encrypt.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));

According to the javadocs, a InvalidAlgorithmParameterException should be thrown as the IV is too short. This is also the behaviour of BouncyCastle.
Comment 1 Matt Wringe 2006-06-21 15:14:36 UTC
Created attachment 11719 [details]
Mauve test case to check if passed IV are valid or not

Adds a testInitWithIVParameterSpec test to the mauve TestOfCipherEngineInit test. This test checks to make sure that only valid IV are being accepted.
Comment 2 Matt Wringe 2006-06-21 15:19:39 UTC
Created attachment 11720 [details]
Checks that the IvParameterSpec contains a valid length IV

Adds a simple test to the CipherAdapter that will throw a InvalidAlgorithmParameterException if the IV size does not match the block size of the cipher.
Comment 3 Raif S. Naffah 2006-08-02 10:17:40 UTC
hello Matt,

does your following patch fixes this PR?

2006-07-14  Matt Wringe  <mwringe@redhat.com>

	* gnu/javax/crypto/jce/cipher/CipherAdapter.java 
	(engineInit): Throw InvalidAlgorithmParameterException
	for invalid IVParameterSpec IV length.

if yes i'd like to close this PR.


cheers;
rsn
Comment 4 Matt Wringe 2006-08-02 13:11:53 UTC
A patch for this bug has already been committed. 

If there are no objections, this bug should now be closed.
Comment 5 Raif S. Naffah 2006-08-02 21:31:34 UTC
i'm closing this PR.  it was fixed as of this ChangeLog entry:

2006-07-14  Matt Wringe  <mwringe@redhat.com>