cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6996] Fixing a JWK RSA modulus representation
Date Fri, 05 Aug 2016 12:03:53 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 503567af6 -> babffd73a


[CXF-6996] Fixing a JWK RSA modulus representation


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

Branch: refs/heads/3.1.x-fixes
Commit: babffd73a73b4443c3654717639f684f50a56478
Parents: 503567a
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Aug 5 12:56:40 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Aug 5 13:03:36 2016 +0100

----------------------------------------------------------------------
 .../apache/cxf/rs/security/jose/jwk/JwkUtils.java   |  7 ++++++-
 .../cxf/rs/security/jose/jwk/JwkUtilsTest.java      | 16 ++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/babffd73/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
index e5c93c5..4248663 100644
--- a/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
+++ b/rt/rs/security/jose-parent/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JwkUtils.java
@@ -488,7 +488,12 @@ public final class JwkUtils {
             }
             jwk.setAlgorithm(algo);
         }
-        String encodedModulus = Base64UrlUtility.encode(modulus.toByteArray());
+        byte[] modulusBytes = modulus.toByteArray();
+        int extraBytesLength = modulusBytes.length - modulus.bitLength() / 8;
+        if (extraBytesLength > 0) {
+            modulusBytes = Arrays.copyOfRange(modulusBytes, extraBytesLength, modulusBytes.length);
+        }
+        String encodedModulus = Base64UrlUtility.encode(modulusBytes);
         jwk.setProperty(JsonWebKey.RSA_MODULUS, encodedModulus);
         return jwk;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/babffd73/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwk/JwkUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwk/JwkUtilsTest.java
b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwk/JwkUtilsTest.java
index 3f62f4f..b71b6f7 100644
--- a/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwk/JwkUtilsTest.java
+++ b/rt/rs/security/jose-parent/jose/src/test/java/org/apache/cxf/rs/security/jose/jwk/JwkUtilsTest.java
@@ -18,6 +18,10 @@
  */
 package org.apache.cxf.rs.security.jose.jwk;
 
+import java.security.interfaces.RSAPublicKey;
+
+import org.apache.cxf.rs.security.jose.common.JoseUtils;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -61,6 +65,18 @@ public class JwkUtilsTest extends Assert {
         + "\"k\": \"NGbwp1rC4n85A1SaNxoHow\""
         + "}";
     @Test
+    public void testRsaKeyModulus() throws Exception {
+        JsonWebKey jwk = JwkUtils.readJwkKey(RSA_KEY);
+        String modulus = jwk.getStringProperty(JsonWebKey.RSA_MODULUS);
+        assertEquals(256, JoseUtils.decode(modulus).length);
+        
+        RSAPublicKey pk = JwkUtils.toRSAPublicKey(jwk);
+        JsonWebKey jwk2 = JwkUtils.fromRSAPublicKey(pk, jwk.getAlgorithm());
+        String modulus2 = jwk2.getStringProperty(JsonWebKey.RSA_MODULUS);
+        assertEquals(256, JoseUtils.decode(modulus2).length);
+        assertEquals(modulus2, modulus);
+    }
+    @Test
     public void testRsaKeyThumbprint() throws Exception {
         String thumbprint = JwkUtils.getThumbprint(RSA_KEY);
         assertEquals("NzbLsXh8uDCcd-6MNwXF4W_7noWXFZAfHkxZsRGC9Xs", thumbprint);


Mime
View raw message