From f278725568d481fb135d988261309a332dce2bb7 Mon Sep 17 00:00:00 2001
From: sgrampone <30872877+sgrampone@users.noreply.github.com>
Date: Thu, 18 Jun 2020 11:03:22 -0300
Subject: [PATCH 01/10] Change version to 16.11.0 (#18)
---
GeneXusCryptography/pom.xml | 2 +-
GeneXusFtps/pom.xml | 2 +-
GeneXusJWT/pom.xml | 2 +-
GeneXusSftp/pom.xml | 2 +-
GeneXusXmlSignature/pom.xml | 2 +-
SecurityAPICommons/pom.xml | 2 +-
pom.xml | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/GeneXusCryptography/pom.xml b/GeneXusCryptography/pom.xml
index f41023b..39c31f5 100644
--- a/GeneXusCryptography/pom.xml
+++ b/GeneXusCryptography/pom.xml
@@ -7,7 +7,7 @@
com.genexus
SecurityAPIParent
- 1.0.0.3
+ 16.11.0
diff --git a/GeneXusFtps/pom.xml b/GeneXusFtps/pom.xml
index ea2500f..eeb6dd4 100644
--- a/GeneXusFtps/pom.xml
+++ b/GeneXusFtps/pom.xml
@@ -8,7 +8,7 @@
com.genexus
SecurityAPIParent
- 1.0.0.3
+ 16.11.0
diff --git a/GeneXusJWT/pom.xml b/GeneXusJWT/pom.xml
index 9b29790..4671d0c 100644
--- a/GeneXusJWT/pom.xml
+++ b/GeneXusJWT/pom.xml
@@ -7,7 +7,7 @@
com.genexus
SecurityAPIParent
- 1.0.0.3
+ 16.11.0
diff --git a/GeneXusSftp/pom.xml b/GeneXusSftp/pom.xml
index 85e41d2..796d502 100644
--- a/GeneXusSftp/pom.xml
+++ b/GeneXusSftp/pom.xml
@@ -7,7 +7,7 @@
com.genexus
SecurityAPIParent
- 1.0.0.3
+ 16.11.0
diff --git a/GeneXusXmlSignature/pom.xml b/GeneXusXmlSignature/pom.xml
index 964f737..fa2dd36 100644
--- a/GeneXusXmlSignature/pom.xml
+++ b/GeneXusXmlSignature/pom.xml
@@ -7,7 +7,7 @@
com.genexus
SecurityAPIParent
- 1.0.0.3
+ 16.11.0
GeneXusXmlSignature
diff --git a/SecurityAPICommons/pom.xml b/SecurityAPICommons/pom.xml
index cbcd196..47c4503 100644
--- a/SecurityAPICommons/pom.xml
+++ b/SecurityAPICommons/pom.xml
@@ -7,7 +7,7 @@
com.genexus
SecurityAPIParent
- 1.0.0.3
+ 16.11.0
diff --git a/pom.xml b/pom.xml
index 6a7c4b1..b464a99 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.genexus
SecurityAPIParent
- 1.0.0.3
+ 16.11.0
pom
GeneXusSecurityAPI (Parent)
From 29bc7c7c0af5e2f6c01fde62b872df6682e5db74 Mon Sep 17 00:00:00 2001
From: sgrampone <30872877+sgrampone@users.noreply.github.com>
Date: Mon, 22 Jun 2020 16:09:40 -0300
Subject: [PATCH 02/10] Change java-jwt to version 3.10.3 (#19)
---
GeneXusJWT/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/GeneXusJWT/pom.xml b/GeneXusJWT/pom.xml
index 4671d0c..102e9da 100644
--- a/GeneXusJWT/pom.xml
+++ b/GeneXusJWT/pom.xml
@@ -26,7 +26,7 @@
com.auth0
java-jwt
- 3.9.0
+ 3.10.3
From 939b904ee9118a5c0c9413be69e838b7c8111f52 Mon Sep 17 00:00:00 2001
From: sgrampone <30872877+sgrampone@users.noreply.github.com>
Date: Tue, 23 Jun 2020 17:19:09 -0300
Subject: [PATCH 03/10] Nested PrivateClaims implementation (#21)
---
.../main/java/com/genexus/JWT/JWTCreator.java | 149 ++++++++++++++----
.../java/com/genexus/JWT/claims/Claim.java | 20 ++-
.../java/com/genexus/JWT/claims/Claims.java | 5 +-
.../com/genexus/JWT/claims/PrivateClaims.java | 26 ++-
.../genexus/JWT/claims/RegisteredClaims.java | 8 +-
5 files changed, 165 insertions(+), 43 deletions(-)
diff --git a/GeneXusJWT/src/main/java/com/genexus/JWT/JWTCreator.java b/GeneXusJWT/src/main/java/com/genexus/JWT/JWTCreator.java
index a4fc6f2..513898e 100644
--- a/GeneXusJWT/src/main/java/com/genexus/JWT/JWTCreator.java
+++ b/GeneXusJWT/src/main/java/com/genexus/JWT/JWTCreator.java
@@ -1,5 +1,7 @@
package com.genexus.JWT;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -11,6 +13,8 @@
import com.auth0.jwt.interfaces.DecodedJWT;
import com.auth0.jwt.interfaces.JWTVerifier;
import com.auth0.jwt.interfaces.Verification;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.genexus.JWT.claims.Claim;
import com.genexus.JWT.claims.PrivateClaims;
import com.genexus.JWT.claims.PublicClaims;
@@ -25,17 +29,18 @@
import com.genexus.securityapicommons.keys.PrivateKeyManager;
import com.genexus.securityapicommons.utils.SecurityUtils;
-
-
public class JWTCreator extends JWTObject {
+ private int counter;
+
public JWTCreator() {
super();
EncodingUtil eu = new EncodingUtil();
eu.setEncoding("UTF8");
-
+ this.counter = 0;
+
}
-
+
/******** EXTERNAL OBJECT PUBLIC METHODS - BEGIN ********/
public String doCreate(String algorithm, PrivateClaims privateClaims, JWTOptions options) {
if (options.hasError()) {
@@ -98,7 +103,7 @@ public boolean doVerify(String token, String expectedAlgorithm, PrivateClaims pr
this.error.setError("JW005", e.getMessage());
return false;
}
- if (isRevoqued(decodedJWT, options) || !verifyPrivateClaims(decodedJWT, privateClaims)) {
+ if (isRevoqued(decodedJWT, options) || !verifyPrivateClaims(decodedJWT, privateClaims, options)) {
return false;
}
String algorithm = decodedJWT.getAlgorithm();
@@ -107,12 +112,11 @@ public boolean doVerify(String token, String expectedAlgorithm, PrivateClaims pr
return false;
}
JWTAlgorithm expectedJWTAlgorithm = JWTAlgorithm.getJWTAlgorithm(expectedAlgorithm, this.error);
- if(alg.compareTo(expectedJWTAlgorithm) != 0 || this.hasError())
- {
- this.error.setError("JW008", "Expected algorithm does not match token algorithm");
- return false;
- }
-
+ if (alg.compareTo(expectedJWTAlgorithm) != 0 || this.hasError()) {
+ this.error.setError("JW008", "Expected algorithm does not match token algorithm");
+ return false;
+ }
+
Algorithm algorithmType = null;
if (JWTAlgorithm.isPrivate(alg)) {
CertificateX509 cert = options.getCertificate();
@@ -150,7 +154,7 @@ public boolean doVerify(String token, String expectedAlgorithm, PrivateClaims pr
error.setError("JW006", e.getMessage());
return false;
}
-
+
return true;
}
@@ -236,7 +240,11 @@ private Builder doBuildPayload(Builder tokenBuilder, PrivateClaims privateClaims
List privateC = privateClaims.getAllClaims();
for (int i = 0; i < privateC.size(); i++) {
try {
- tokenBuilder.withClaim(privateC.get(i).getKey(), privateC.get(i).getValue());
+ if (privateC.get(i).getNestedClaims() != null) {
+ tokenBuilder.withClaim(privateC.get(i).getKey(), privateC.get(i).getNestedClaims().getNestedMap());
+ } else {
+ tokenBuilder.withClaim(privateC.get(i).getKey(), privateC.get(i).getValue());
+ }
} catch (Exception e) {
this.error.setError("JW004", e.getMessage());
return null;
@@ -275,32 +283,107 @@ private Builder doBuildPayload(Builder tokenBuilder, PrivateClaims privateClaims
// ****END BUILD PAYLOAD****//
return tokenBuilder;
}
-
- private boolean verifyPrivateClaims(DecodedJWT decodedJWT, PrivateClaims privateClaims)
- {
- if(privateClaims == null || privateClaims.isEmpty())
- {
+
+ private boolean verifyPrivateClaims(DecodedJWT decodedJWT, PrivateClaims privateClaims, JWTOptions options) {
+ RegisteredClaims registeredClaims = options.getAllRegisteredClaims();
+ PublicClaims publicClaims = options.getAllPublicClaims();
+ if (privateClaims == null || privateClaims.isEmpty()) {
return true;
}
- Map map = decodedJWT.getClaims();
-
- List claims = privateClaims.getAllClaims();
- for(int i= 0; i < claims.size(); i++)
- {
- Claim c = claims.get(i);
- if(!map.containsKey(c.getKey()))
- {
- return false;
- }
- com.auth0.jwt.interfaces.Claim claim = map.get(c.getKey());
- if(!SecurityUtils.compareStrings(claim.asString().trim(), c.getValue().trim()))
- {
- return false;
+ String base64Part = decodedJWT.getPayload();
+ byte[] base64Bytes = Base64.decodeBase64(base64Part);
+ EncodingUtil eu = new EncodingUtil();
+ String plainTextPart = eu.getString(base64Bytes);
+ HashMap map = new HashMap();
+ ObjectMapper mapper = new ObjectMapper();
+
+ try {
+ map = mapper.readValue(plainTextPart, new TypeReference