cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Minor update to jwe utils
Date Fri, 14 Aug 2015 16:07:43 GMT
Repository: cxf
Updated Branches:
  refs/heads/master fa612d157 -> a3b70f3a4


Minor update to jwe utils


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

Branch: refs/heads/master
Commit: a3b70f3a4319215eb06603b43809cba365c4cd1c
Parents: fa612d1
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Aug 14 17:07:28 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Aug 14 17:07:28 2015 +0100

----------------------------------------------------------------------
 .../jwe/EcdhAesWrapKeyEncryptionAlgorithm.java  |  6 ++++
 .../cxf/rs/security/jose/jwe/JweUtils.java      | 29 ++++++++++++--------
 2 files changed, 23 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a3b70f3a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java
index 524a135..2c19541 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/EcdhAesWrapKeyEncryptionAlgorithm.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import org.apache.cxf.rs.security.jose.jwa.AlgorithmUtils;
 import org.apache.cxf.rs.security.jose.jwa.KeyAlgorithm;
 import org.apache.cxf.rs.security.jose.jwe.EcdhDirectKeyJweEncryption.EcdhHelper;
+import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
 
 public class EcdhAesWrapKeyEncryptionAlgorithm implements KeyEncryptionProvider {
     
@@ -39,6 +40,11 @@ public class EcdhAesWrapKeyEncryptionAlgorithm implements KeyEncryptionProvider
     private EcdhHelper helper;
     
     public EcdhAesWrapKeyEncryptionAlgorithm(ECPublicKey peerPublicKey,
+                                             KeyAlgorithm keyAlgo) {
+        //TODO: figure out the curve *name* given ECPublicKey
+        this(peerPublicKey, JsonWebKey.EC_CURVE_P256, null, null, keyAlgo);
+    }
+    public EcdhAesWrapKeyEncryptionAlgorithm(ECPublicKey peerPublicKey,
                                              String curve,
                                              KeyAlgorithm keyAlgo) {
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/a3b70f3a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweUtils.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweUtils.java
index 735f0c0..984d15b 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweUtils.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwe/JweUtils.java
@@ -20,6 +20,7 @@ package org.apache.cxf.rs.security.jose.jwe;
 
 import java.nio.ByteBuffer;
 import java.security.PrivateKey;
+import java.security.PublicKey;
 import java.security.cert.X509Certificate;
 import java.security.interfaces.ECPrivateKey;
 import java.security.interfaces.ECPublicKey;
@@ -66,13 +67,13 @@ public final class JweUtils {
     private JweUtils() {
         
     }
-    public static String encrypt(RSAPublicKey key, KeyAlgorithm keyAlgo, ContentAlgorithm
contentAlgo, 
+    public static String encrypt(PublicKey key, KeyAlgorithm keyAlgo, ContentAlgorithm contentAlgo,

                                  byte[] content) {
         return encrypt(key, keyAlgo, contentAlgo, content, null);
     }
-    public static String encrypt(RSAPublicKey key, KeyAlgorithm keyAlgo, 
+    public static String encrypt(PublicKey key, KeyAlgorithm keyAlgo, 
                                  ContentAlgorithm contentAlgo, byte[] content, String ct)
{
-        KeyEncryptionProvider keyEncryptionProvider = getRSAKeyEncryptionProvider(key, keyAlgo);
+        KeyEncryptionProvider keyEncryptionProvider = getPublicKeyEncryptionProvider(key,
keyAlgo);
         return encrypt(keyEncryptionProvider, contentAlgo, content, ct);
     }
     public static String encrypt(SecretKey key, KeyAlgorithm keyAlgo, ContentAlgorithm contentAlgo,

@@ -136,7 +137,7 @@ public final class JweUtils {
         KeyEncryptionProvider keyEncryptionProvider = null;
         KeyType keyType = jwk.getKeyType();
         if (KeyType.RSA == keyType) {
-            keyEncryptionProvider = getRSAKeyEncryptionProvider(JwkUtils.toRSAPublicKey(jwk,
true), 
+            keyEncryptionProvider = getPublicKeyEncryptionProvider(JwkUtils.toRSAPublicKey(jwk,
true), 
                                                                  keyAlgo);
         } else if (KeyType.OCTET == keyType) {
             keyEncryptionProvider = getSecretKeyEncryptionAlgorithm(JwkUtils.toSecretKey(jwk),

@@ -148,8 +149,12 @@ public final class JweUtils {
         }
         return keyEncryptionProvider;
     }
-    public static KeyEncryptionProvider getRSAKeyEncryptionProvider(RSAPublicKey key, KeyAlgorithm
algo) {
-        return new RSAKeyEncryptionAlgorithm(key, algo);
+    public static KeyEncryptionProvider getPublicKeyEncryptionProvider(PublicKey key, KeyAlgorithm
algo) {
+        if (key instanceof PublicKey) {
+            return new RSAKeyEncryptionAlgorithm((RSAPublicKey)key, algo);
+        } else {
+            return new EcdhAesWrapKeyEncryptionAlgorithm((ECPublicKey)key, algo);
+        }
     }
     public static KeyEncryptionProvider getSecretKeyEncryptionAlgorithm(SecretKey key, KeyAlgorithm
algo) {
         if (AlgorithmUtils.isAesKeyWrap(algo.getJwaName())) {
@@ -305,8 +310,8 @@ public final class JweUtils {
                 }
             }
         } else {
-            keyEncryptionProvider = getRSAKeyEncryptionProvider(
-                (RSAPublicKey)KeyManagementUtils.loadPublicKey(m, props), 
+            keyEncryptionProvider = getPublicKeyEncryptionProvider(
+                KeyManagementUtils.loadPublicKey(m, props), 
                 keyAlgo);
             if (reportPublicKey) {
                 headers.setX509Chain(KeyManagementUtils.loadAndEncodeX509CertificateOrChain(m,
props));
@@ -365,15 +370,15 @@ public final class JweUtils {
         return createJweDecryptionProvider(keyDecryptionProvider, ctDecryptionKey, 
                                            getContentAlgo(contentEncryptionAlgo));
     }
-    public static JweEncryptionProvider createJweEncryptionProvider(RSAPublicKey key,
+    public static JweEncryptionProvider createJweEncryptionProvider(PublicKey key,
                                                                     KeyAlgorithm keyAlgo,
                                                                     ContentAlgorithm contentEncryptionAlgo,
                                                                     String compression) {
-        KeyEncryptionProvider keyEncryptionProvider = getRSAKeyEncryptionProvider(key, keyAlgo);
+        KeyEncryptionProvider keyEncryptionProvider = getPublicKeyEncryptionProvider(key,
keyAlgo);
         return createJweEncryptionProvider(keyEncryptionProvider, contentEncryptionAlgo,
compression);
     }
-    public static JweEncryptionProvider createJweEncryptionProvider(RSAPublicKey key, JweHeaders
headers) {
-        KeyEncryptionProvider keyEncryptionProvider = getRSAKeyEncryptionProvider(key, 
+    public static JweEncryptionProvider createJweEncryptionProvider(PublicKey key, JweHeaders
headers) {
+        KeyEncryptionProvider keyEncryptionProvider = getPublicKeyEncryptionProvider(key,

                                                            headers.getKeyEncryptionAlgorithm());
         return createJweEncryptionProvider(keyEncryptionProvider, headers);
     }


Mime
View raw message