-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8359388: Stricter checking for cipher transformations #25808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
245bf36
8d8640c
0cb4198
7d9e36b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,33 +24,63 @@ | |
|
||
/* | ||
* @test | ||
* @bug 8358159 | ||
* @summary test that the Cipher.getInstance() handles | ||
* transformations with empty mode and/or padding | ||
* @run main TestEmptyModePadding | ||
* @bug 8358159 8359388 | ||
* @summary test that the Cipher.getInstance() would reject improper | ||
* transformations with empty mode and/or padding. | ||
*/ | ||
|
||
|
||
import java.security.*; | ||
import javax.crypto.*; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.Provider; | ||
import java.security.Security; | ||
import javax.crypto.Cipher; | ||
|
||
public class TestEmptyModePadding { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please change the imports to not use wildcard imports import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import java.security.Security;
import javax.crypto.Cipher; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I can do this. |
||
|
||
public static void main(String[] args) throws Exception { | ||
Provider provider = Security.getProvider(System.getProperty("test.provider.name", "SunJCE")); | ||
Provider provider = Security.getProvider( | ||
System.getProperty("test.provider.name", "SunJCE")); | ||
|
||
System.out.println("Testing against " + provider.getName()); | ||
|
||
test("AES", provider); | ||
test("AES/ECB/PKCS5Padding", provider); | ||
test("AES//PKCS5Padding", provider); // Empty mode | ||
test("AES/CBC/", provider); // Empty padding | ||
test("AES/ /NoPadding", provider); // Mode is a space | ||
test("AES/CBC/ ", provider); // Padding is a space | ||
test("AES/ / ", provider); // Both mode and padding are spaces | ||
test("AES//", provider); // Both mode and padding are missing | ||
String[] testTransformations = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: Do you think it would be easier to read if each entry was a separate line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am ok either way, sounds like you prefer one line per entry. I can change them. |
||
// transformations w/ only 1 component, i.e. algo | ||
" ", | ||
// transformations w/ only 2 components | ||
"AES/", | ||
"AES/ ", | ||
"AES/CBC", | ||
"PBEWithHmacSHA512/224AndAES_128/", | ||
"PBEWithHmacSHA512/256AndAES_128/ ", | ||
"PBEWithHmacSHA512/224AndAES_128/CBC", | ||
// 3-component transformations w/ empty component(s) | ||
"AES//", | ||
"AES/ /", | ||
"AES// ", | ||
"AES/ / ", | ||
"AES/CBC/", "AES/CBC/ ", | ||
"AES//PKCS5Padding", "AES/ /NoPadding", | ||
"PBEWithHmacSHA512/224AndAES_128//", | ||
"PBEWithHmacSHA512/224AndAES_128/ /", | ||
"PBEWithHmacSHA512/224AndAES_128// ", | ||
"PBEWithHmacSHA512/224AndAES_128/ / ", | ||
"PBEWithHmacSHA512/256AndAES_128/CBC/", | ||
"PBEWithHmacSHA512/256AndAES_128/CBC/ ", | ||
"PBEWithHmacSHA512/256AndAES_128//PKCS5Padding", | ||
"PBEWithHmacSHA512/256AndAES_128/ /PKCS5Padding", | ||
}; | ||
|
||
for (String t : testTransformations) { | ||
test(t, provider); | ||
} | ||
} | ||
|
||
private static void test(String transformation, Provider provider) throws Exception { | ||
Cipher c = Cipher.getInstance(transformation, provider); | ||
private static void test(String t, Provider p) throws Exception { | ||
try { | ||
Cipher c = Cipher.getInstance(t, p); | ||
throw new RuntimeException("Should throw NSAE for \'" + t + "\'"); | ||
} catch (NoSuchAlgorithmException nsae) { | ||
// transformation info is already in the NSAE message | ||
System.out.println("Expected NSAE: " + nsae.getMessage()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this exception is tested. It could be by adding
test(" ", provider);
in test/jdk/javax/crypto/Cipher/TestEmptyModePadding.java on line 68There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This is covered now