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 updates to Jose code to support detached payloads
Date Tue, 13 Jan 2015 22:30:53 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes a0c55ab2c -> eb2631677


Minor updates to Jose code to support detached payloads


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

Branch: refs/heads/3.0.x-fixes
Commit: eb2631677175e90b55640156fd253a9e7434a467
Parents: a0c55ab
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jan 13 22:28:31 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jan 13 22:30:32 2015 +0000

----------------------------------------------------------------------
 .../cxf/rs/security/jose/jwk/JsonWebKey.java    |  2 +-
 .../security/jose/jws/JwsCompactConsumer.java   | 21 ++++++++++++++------
 .../security/jose/jws/JwsCompactProducer.java   | 12 +++++++----
 3 files changed, 24 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/eb263167/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
index 8566dea..e723ef3 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jwk/JsonWebKey.java
@@ -55,7 +55,7 @@ public class JsonWebKey extends JsonMapObject {
     public static final String EC_CURVE = "crv";
     public static final String EC_CURVE_P256 = "P-256";
     public static final String EC_CURVE_P384 = "P-384";
-    public static final String EC_CURVE_P512 = "P-512";
+    public static final String EC_CURVE_P521 = "P-521";
     public static final String EC_X_COORDINATE = "x";
     public static final String EC_Y_COORDINATE = "y";
     public static final String EC_PRIVATE_KEY = "d";

http://git-wip-us.apache.org/repos/asf/cxf/blob/eb263167/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
index 105d895..3ab2841 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactConsumer.java
@@ -32,11 +32,14 @@ public class JwsCompactConsumer {
     private String encodedSequence;
     private String encodedSignature;
     private String headersJson;
-    private String jwsPayload;
+    private String decodedJwsPayload;
     public JwsCompactConsumer(String encodedJws) {
         this(encodedJws, null);
     }
     public JwsCompactConsumer(String encodedJws, JoseHeadersReader r) {
+        this(encodedJws, null, r);
+    }
+    public JwsCompactConsumer(String encodedJws, String encodedDetachedPayload, JoseHeadersReader
r) {
         if (r != null) {
             this.reader = r;
         }
@@ -53,10 +56,16 @@ public class JwsCompactConsumer {
         } else {
             encodedSignature = parts[2];
         }
+        String encodedJwsPayload = parts[1];
+        if (encodedDetachedPayload != null) {
+            if (StringUtils.isEmpty(encodedJwsPayload)) {
+                throw new SecurityException("Invalid JWS Compact sequence");
+            }
+            encodedJwsPayload = encodedDetachedPayload;
+        }
+        encodedSequence = parts[0] + "." + encodedJwsPayload;
         headersJson = JoseUtils.decodeToString(parts[0]);
-        jwsPayload = JoseUtils.decodeToString(parts[1]);
-        encodedSequence = parts[0] + "." + parts[1];
-        
+        decodedJwsPayload = JoseUtils.decodeToString(encodedJwsPayload);
     }
     public String getUnsignedEncodedSequence() {
         return encodedSequence;
@@ -68,10 +77,10 @@ public class JwsCompactConsumer {
         return headersJson;
     }
     public String getDecodedJwsPayload() {
-        return jwsPayload;
+        return decodedJwsPayload;
     }
     public byte[] getDecodedJwsPayloadBytes() {
-        return StringUtils.toBytesUTF8(jwsPayload);
+        return StringUtils.toBytesUTF8(decodedJwsPayload);
     }
     public byte[] getDecodedSignature() {
         return encodedSignature.isEmpty() ? new byte[]{} : JoseUtils.decode(encodedSignature);

http://git-wip-us.apache.org/repos/asf/cxf/blob/eb263167/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactProducer.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactProducer.java
b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactProducer.java
index b8aee4a..53fdf7a 100644
--- a/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactProducer.java
+++ b/rt/rs/security/jose/src/main/java/org/apache/cxf/rs/security/jose/jws/JwsCompactProducer.java
@@ -54,24 +54,28 @@ public class JwsCompactProducer {
         return headers;
     }
     public String getUnsignedEncodedJws() {
+        return getUnsignedEncodedJws(false);
+    }
+    private String getUnsignedEncodedJws(boolean detached) {
         checkAlgorithm();
         if (plainRep == null) {
             plainRep = Base64UrlUtility.encode(writer.headersToJson(getJoseHeaders())) 
                 + "." 
-                + Base64UrlUtility.encode(plainJwsPayload);
+                + (detached ? "" : Base64UrlUtility.encode(plainJwsPayload));
         }
         return plainRep;
     }
-    
     public String getSignedEncodedJws() {
+        return getSignedEncodedJws(false);
+    }
+    public String getSignedEncodedJws(boolean detached) {
         checkAlgorithm();
         boolean noSignature = StringUtils.isEmpty(signature);
         if (noSignature && !isPlainText()) {
             throw new IllegalStateException("Signature is not available");
         }
-        return getUnsignedEncodedJws() + "." + (noSignature ? "" : signature);
+        return getUnsignedEncodedJws(detached) + "." + (noSignature ? "" : signature);
     }
-    
     public String signWith(JsonWebKey jwk) {
         return signWith(JwsUtils.getSignatureProvider(jwk, headers.getAlgorithm()));
     }


Mime
View raw message