added skip to test for encryption if not running unlimited strength java

pull/124/merge
Justin Richer 2012-07-30 14:47:02 -04:00
parent 92e779257d
commit f9dd9df7cd
3 changed files with 16 additions and 7 deletions

View File

@ -71,10 +71,10 @@ public class RsaEncrypter extends AbstractJweEncrypter {
if(jwe.getHeader().getAlgorithm().equals("RSA1_5")){ if(jwe.getHeader().getAlgorithm().equals("RSA1_5")){
Cipher cipher = Cipher.getInstance("RSA"); Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, publicKey); cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encryptedKey = cipher.doFinal(contentMasterKey); byte[] encryptedKey = cipher.doFinal(contentMasterKey);
return encryptedKey; return encryptedKey;
} else { } else {
throw new IllegalArgumentException(jwe.getHeader().getAlgorithm() + " is not a supported algorithm"); throw new IllegalArgumentException(jwe.getHeader().getAlgorithm() + " is not a supported algorithm");

View File

@ -16,10 +16,13 @@ import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import org.easymock.internal.matchers.GreaterThan;
import org.junit.After; import org.junit.After;
import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -43,7 +46,10 @@ public class RsaEncrypterDecrypterTest {
String jwePlaintextString = new String("Why couldn't the bike move? It was two tired."); String jwePlaintextString = new String("Why couldn't the bike move? It was two tired.");
@Before @Before
public void setUp(){ public void setUp() throws NoSuchAlgorithmException{
Assume.assumeTrue(Cipher.getMaxAllowedKeyLength("AES") > 128); // if we're capped at 128 bits then we can't run these tests
} }
@After @After
@ -52,6 +58,9 @@ public class RsaEncrypterDecrypterTest {
@Test @Test
public void encryptDecryptTest() throws JsonIOException, JsonSyntaxException, IOException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException { public void encryptDecryptTest() throws JsonIOException, JsonSyntaxException, IOException, NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException, InvalidKeySpecException {
//
//read in header and plaintext from files //read in header and plaintext from files
JsonParser parser = new JsonParser(); JsonParser parser = new JsonParser();
JsonObject jweHeaderObject = parser.parse(new BufferedReader(new InputStreamReader(jweHeaderUrl.openStream()))).getAsJsonObject(); JsonObject jweHeaderObject = parser.parse(new BufferedReader(new InputStreamReader(jweHeaderUrl.openStream()))).getAsJsonObject();
@ -59,7 +68,7 @@ public class RsaEncrypterDecrypterTest {
Jwe jwe = new Jwe(new JweHeader(jweHeaderObject), null, jwePlaintextString.getBytes(), null); Jwe jwe = new Jwe(new JweHeader(jweHeaderObject), null, jwePlaintextString.getBytes(), null);
//generate key pair. this will be passed in from the user //generate key pair. this will be passed in from the user
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(512); keyGen.initialize(4096);
KeyPair pair = keyGen.generateKeyPair(); KeyPair pair = keyGen.generateKeyPair();
PublicKey publicKey = pair.getPublic(); PublicKey publicKey = pair.getPublic();
PrivateKey privateKey = pair.getPrivate(); PrivateKey privateKey = pair.getPrivate();

View File

@ -1 +1 @@
{"alg":"RSA1_5","enc":"A256CBC","int":"HS384","iv":"AxY8DCtDaGlsbGljb3RoZQ","kdf":"CS256"} {"alg":"RSA1_5","enc":"A256CBC","int":"HS256","iv":"AxY8DCtDaGlsbGljb3RoZQ","kdf":"CS256"}