You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2014/06/05 14:57:21 UTC
git commit: Fixing oauth2-jwt encryption tests with JDK6
Repository: cxf
Updated Branches:
refs/heads/master 2d0d60697 -> 90404af4e
Fixing oauth2-jwt encryption tests with JDK6
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/90404af4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/90404af4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/90404af4
Branch: refs/heads/master
Commit: 90404af4e86e252c7e8724a282eb6190fe9e273f
Parents: 2d0d606
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Thu Jun 5 13:56:44 2014 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Thu Jun 5 13:57:10 2014 +0100
----------------------------------------------------------------------
.../oauth2/jwe/JweCompactReaderWriterTest.java | 29 +++++---------------
.../oauth2/utils/crypto/CryptoUtils.java | 15 ++++++++--
2 files changed, 19 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/90404af4/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java b/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java
index 303df85..8fbedce 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/test/java/org/apache/cxf/rs/security/oauth2/jwe/JweCompactReaderWriterTest.java
@@ -36,10 +36,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
public class JweCompactReaderWriterTest extends Assert {
- private static final boolean IGNORE_TESTS;
- static {
- IGNORE_TESTS = System.getProperty("java.version").contains("1.6");
- }
private static final byte[] CONTENT_ENCRYPTION_KEY = {
(byte)177, (byte)161, (byte)244, (byte)128, 84, (byte)143, (byte)225,
115, 63, (byte)180, 3, (byte)255, 107, (byte)154, (byte)212, (byte)246,
@@ -65,29 +61,21 @@ public class JweCompactReaderWriterTest extends Assert {
@BeforeClass
public static void registerBouncyCastleIfNeeded() throws Exception {
- if (!IGNORE_TESTS) {
- try {
- // Java 8 apparently has it
- Cipher.getInstance(Algorithm.A256GCM_ALGO_JAVA);
- } catch (Throwable t) {
- // Oracle Java 7
- Security.addProvider(new BouncyCastleProvider());
- }
+ try {
+ // Java 8 apparently has it
+ Cipher.getInstance(Algorithm.A256GCM_ALGO_JAVA);
+ } catch (Throwable t) {
+ // Oracle Java 7
+ Security.addProvider(new BouncyCastleProvider());
}
}
@AfterClass
public static void unregisterBouncyCastleIfNeeded() throws Exception {
- if (!IGNORE_TESTS) {
- Security.removeProvider(BouncyCastleProvider.class.getName());
- }
+ Security.removeProvider(BouncyCastleProvider.class.getName());
}
@Test
public void testEncryptDecryptSpecExample() throws Exception {
- if (IGNORE_TESTS) {
- return;
- }
-
final String specPlainText = "The true sign of intelligence is not knowledge but imagination.";
String jweContent = encryptContent(specPlainText);
@@ -96,9 +84,6 @@ public class JweCompactReaderWriterTest extends Assert {
@Test
public void testEncryptDecryptJwsToken() throws Exception {
- if (IGNORE_TESTS) {
- return;
- }
String jweContent = encryptContent(JwsCompactReaderWriterTest.ENCODED_TOKEN_SIGNED_BY_MAC);
decrypt(jweContent, JwsCompactReaderWriterTest.ENCODED_TOKEN_SIGNED_BY_MAC);
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/90404af4/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/crypto/CryptoUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/crypto/CryptoUtils.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/crypto/CryptoUtils.java
index 350a3b2..f998bcb 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/crypto/CryptoUtils.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/utils/crypto/CryptoUtils.java
@@ -33,6 +33,7 @@ import java.security.interfaces.RSAPublicKey;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
+import java.util.logging.Logger;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
@@ -41,6 +42,7 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.CompressionUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.rs.security.oauth2.utils.Base64UrlUtility;
@@ -50,6 +52,9 @@ import org.apache.cxf.rs.security.oauth2.utils.Base64UrlUtility;
* Encryption helpers
*/
public final class CryptoUtils {
+
+ private static final Logger LOG = LogUtils.getL7dLogger(CryptoUtils.class);
+
private CryptoUtils() {
}
@@ -140,7 +145,7 @@ public final class CryptoUtils {
Constructor<?> ctr = c.getConstructor(new Class[]{int.class, byte[].class});
return (AlgorithmParameterSpec)ctr.newInstance(new Object[]{authTagLength, iv});
} catch (Throwable t) {
- throw new SecurityException(t);
+ return new IvParameterSpec(iv);
}
}
@@ -408,8 +413,12 @@ public final class CryptoUtils {
}
if (keyProps != null && keyProps.getAdditionalData() != null) {
// TODO: call updateAAD directly after switching to Java7
- Method m = Cipher.class.getMethod("updateAAD", new Class[]{byte[].class});
- m.invoke(c, new Object[]{keyProps.getAdditionalData()});
+ try {
+ Method m = Cipher.class.getMethod("updateAAD", new Class[]{byte[].class});
+ m.invoke(c, new Object[]{keyProps.getAdditionalData()});
+ } catch (NoSuchMethodException ex) {
+ LOG.fine(ex.getMessage());
+ }
}
return c;
} catch (Exception ex) {