cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject git commit: Fixing failing JSON encryption tests with JDK 8
Date Fri, 30 May 2014 16:48:55 GMT
Repository: cxf
Updated Branches:
  refs/heads/master adf3cf437 -> 902eaae78


Fixing failing JSON encryption tests with JDK 8


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/902eaae7
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/902eaae7
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/902eaae7

Branch: refs/heads/master
Commit: 902eaae78a838e2e5aabc0a082418bd2b6b55610
Parents: adf3cf4
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri May 30 17:48:32 2014 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri May 30 17:48:48 2014 +0100

----------------------------------------------------------------------
 .../rs/security/oauth2/jwe/RSAJweEncryptor.java  |  6 +++---
 .../oauth2/jwe/JweCompactReaderWriterTest.java   |  6 +++---
 .../oauth2/utils/crypto/CryptoUtils.java         | 19 +++++++++++++++++--
 3 files changed, 23 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/902eaae7/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java
b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java
index 087d14d..6ae43b6 100644
--- a/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java
+++ b/rt/rs/security/oauth-parent/oauth2-jwt/src/main/java/org/apache/cxf/rs/security/oauth2/jwe/RSAJweEncryptor.java
@@ -33,10 +33,10 @@ public class RSAJweEncryptor extends JweEncryptor {
     public RSAJweEncryptor(RSAPublicKey publicKey, JweHeaders headers, byte[] cek, byte[]
iv) {
         this(publicKey, headers, cek, iv, DEFAULT_AUTH_TAG_LENGTH, true);
     }
-    public RSAJweEncryptor(RSAPublicKey publicKey, SecretKey secretKey, byte[] iv) {
+    public RSAJweEncryptor(RSAPublicKey publicKey, SecretKey secretKey, String secretKeyJwtAlgorithm,
+                           byte[] iv) {
         this(publicKey, 
-             new JweHeaders(Algorithm.RSA_OAEP_ALGO.getJwtName(),
-                            Algorithm.toJwtName(secretKey.getAlgorithm())), 
+             new JweHeaders(Algorithm.RSA_OAEP_ALGO.getJwtName(), secretKeyJwtAlgorithm),
              secretKey.getEncoded(), iv, DEFAULT_AUTH_TAG_LENGTH, true);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/902eaae7/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 c574e83..303df85 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
@@ -27,9 +27,9 @@ import javax.crypto.SecretKey;
 
 import org.apache.cxf.rs.security.oauth2.jws.JwsCompactReaderWriterTest;
 import org.apache.cxf.rs.security.oauth2.jwt.Algorithm;
+import org.apache.cxf.rs.security.oauth2.jwt.JwtConstants;
 import org.apache.cxf.rs.security.oauth2.utils.crypto.CryptoUtils;
 import org.bouncycastle.jce.provider.BouncyCastleProvider;
-
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -105,8 +105,8 @@ public class JweCompactReaderWriterTest extends Assert {
     
     private String encryptContent(String content) throws Exception {
         RSAPublicKey publicKey = CryptoUtils.getRSAPublicKey(RSA_MODULUS_ENCODED, RSA_PUBLIC_EXPONENT_ENCODED);
-        SecretKey key = CryptoUtils.createSecretKeySpec(CONTENT_ENCRYPTION_KEY, Algorithm.A256GCM_ALGO.getJavaName());
-        RSAJweEncryptor encryptor = new RSAJweEncryptor(publicKey, key, INIT_VECTOR);
+        SecretKey key = CryptoUtils.createSecretKeySpec(CONTENT_ENCRYPTION_KEY, "AES");
+        RSAJweEncryptor encryptor = new RSAJweEncryptor(publicKey, key, JwtConstants.A256GCM_ALGO,
INIT_VECTOR);
         return encryptor.getJweContent(content);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/902eaae7/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 fda8527..350a3b2 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
@@ -317,7 +317,8 @@ public final class CryptoUtils {
                                        String keyAlgo,
                                        Key wrapperKey,
                                        String wrapperKeyAlgo)  throws SecurityException {
-        return wrapSecretKey(new SecretKeySpec(keyBytes, keyAlgo), wrapperKey, 
+        return wrapSecretKey(new SecretKeySpec(keyBytes, convertJCECipherToSecretKeyName(keyAlgo)),

+                             wrapperKey, 
                              new KeyProperties(wrapperKeyAlgo));
     }
     
@@ -457,7 +458,7 @@ public final class CryptoUtils {
     }
     
     public static SecretKey createSecretKeySpec(byte[] bytes, String algo) {
-        return new SecretKeySpec(bytes, algo);
+        return new SecretKeySpec(bytes, convertJCECipherToSecretKeyName(algo));
     }
     
     public static byte[] decodeSequence(String encodedSequence) throws SecurityException
{
@@ -468,4 +469,18 @@ public final class CryptoUtils {
         }
     }
     
+    private static String convertJCECipherToSecretKeyName(String jceCipherName) {
+        if (jceCipherName != null) {
+            if (jceCipherName.startsWith("AES")) {
+                return "AES";
+            } else if (jceCipherName.startsWith("DESede")) {
+                return "DESede";
+            } else if (jceCipherName.startsWith("SEED")) {
+                return "SEED";
+            } else if (jceCipherName.startsWith("Camellia")) {
+                return "Camellia";
+            }
+        }
+        return null;
+    }
 }


Mime
View raw message