cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: Minor update to OAuth2 CryptoUtils
Date Tue, 20 May 2014 10:10:27 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 0dcfa2fb5 -> 5bd695d0d


Minor update to OAuth2 CryptoUtils


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

Branch: refs/heads/master
Commit: 5bd695d0df1535a1859a72db1fd85922873f02a4
Parents: 0dcfa2f
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue May 20 11:10:12 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue May 20 11:10:12 2014 +0100

----------------------------------------------------------------------
 .../oauth2/utils/crypto/CryptoUtils.java        | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5bd695d0/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 410b56e..afc2345 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
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.rs.security.oauth2.utils.crypto;
 
+import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 import java.math.BigInteger;
 import java.security.Key;
@@ -36,8 +37,10 @@ import java.security.spec.RSAPublicKeySpec;
 import javax.crypto.Cipher;
 import javax.crypto.KeyGenerator;
 import javax.crypto.SecretKey;
+import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.util.CompressionUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.rs.security.oauth2.utils.Base64UrlUtility;
@@ -112,6 +115,28 @@ public final class CryptoUtils {
         }
     }
      
+    public static AlgorithmParameterSpec getContentEncryptionCipherSpec(int authTagLength,
byte[] iv) {
+        // this can be overridden if needed
+        if (authTagLength > 0) {
+            return CryptoUtils.getGCMParameterSpec(authTagLength, iv);
+        } else if (iv.length > 0) {
+            return new IvParameterSpec(iv);
+        } else {
+            return null;
+        }
+    }
+    
+    public static AlgorithmParameterSpec getGCMParameterSpec(int authTagLength, byte[] iv)
{
+        try {
+            // In case Java 6 compiler is used
+            Class<?> c = ClassLoaderUtils.loadClass("javax.crypto.spec.GCMParameterSpec",
CryptoUtils.class);
+            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);
+        }
+    }
+    
     public static byte[] signData(byte[] data, PrivateKey key, String signAlgo) {
         return signData(data, key, signAlgo, null, null);
     }


Mime
View raw message