From 9e7af480c854efa880a6973bdca6d019a7685460 Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 14 Aug 2024 13:51:26 +0200 Subject: [PATCH 01/27] fix: debug KeriWeb3Filter --- .../foundation/voting/client/KeriVerificationClient.java | 8 +++++++- .../voting/service/auth/web3/KeriWeb3Filter.java | 8 ++++++++ .../cardano/foundation/voting/config/SpringWebConfig.java | 2 +- .../src/main/resources/application.properties | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 463f91c9d..87b545e7b 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -69,6 +69,8 @@ public Either verifySignature(String aid, } public Either registerOOBI(String oobi) { + log.info("registerOOBI"); + log.info("oobi url: {}", oobi); val url = String.format("%s/oobi", keriVerifierBaseUrl); val headers = new HttpHeaders(); @@ -100,8 +102,10 @@ public Either registerOOBI(String oobi) { } public Either getOOBI(String oobi, Integer maxAttempts) { + log.info("getOOBI"); + log.info("oobi url: {}. Max attempts {}", oobi, maxAttempts); val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); - + log.info("Keria URL to fetch: ", url); val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); @@ -119,6 +123,8 @@ public Either getOOBI(String oobi, Integer maxAttempts) { } } catch (HttpClientErrorException e) { if (e.getStatusCode() != BAD_REQUEST) { + log.error("Error on get oobi: {}. Code: {}", e.getMessage(), e.getStatusCode()); + log.error("Full Error: {}", e); return Either.left(Problem.builder() .withTitle("OOBI_FETCH_ERROR") .withDetail("Unable to fetch OOBI, reason: " + e.getMessage()) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java index 168c0bb1d..3e15c73e8 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java @@ -59,6 +59,8 @@ public class KeriWeb3Filter extends OncePerRequestFilter { protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws ServletException, IOException { + log.info("doFilterInternal"); + log.info("req: {}", req); val logonSystemM = loginSystemDetector.detect(req); if (logonSystemM.isEmpty()) { chain.doFilter(req, res); @@ -76,6 +78,11 @@ protected void doFilterInternal(HttpServletRequest req, val headerAidM = Optional.ofNullable(req.getHeader(X_Ballot_PublicKey)); val headerOobiM = Optional.ofNullable(req.getHeader(X_Ballot_Oobi)); + log.info("headerSignatureM: {}", headerSignatureM); + log.info("headerPayloadM: {}", headerPayloadM); + log.info("headerAidM: {}", headerAidM); + log.info("headerOobiM: {}", headerOobiM); + if (headerSignatureM.isEmpty()) { val problem = Problem.builder() .withTitle("NO_LOGIN_HTTP_HEADERS_SET") @@ -123,6 +130,7 @@ protected void doFilterInternal(HttpServletRequest req, val headerAid = headerAidM.orElseThrow(); val headerOobi = headerOobiM.orElseThrow(); + log.info("OOBI to get after validate it: ", headerOobi); // Step 1: Check if OOBI is already registered Either oobiCheckResult = keriVerificationClient.getOOBI(headerOobi, 1); if (oobiCheckResult.isLeft()) { diff --git a/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java b/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java index 67d6d12b8..bd0474bc0 100644 --- a/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java +++ b/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java @@ -13,7 +13,7 @@ @Configuration public class SpringWebConfig { - @Value("${cors.allowed.origins:http://localhost:3000}") + @Value("${cors.allowed.origins:http://localhost:3000,http://localhost:4000}") private String allowedOrigins; @Bean diff --git a/backend-services/voting-ledger-follower-app/src/main/resources/application.properties b/backend-services/voting-ledger-follower-app/src/main/resources/application.properties index 3e9ed05bc..f5bce820b 100644 --- a/backend-services/voting-ledger-follower-app/src/main/resources/application.properties +++ b/backend-services/voting-ledger-follower-app/src/main/resources/application.properties @@ -68,7 +68,7 @@ apiPrefix=${API_PREFIX:/yaci-api} # default spring profile is a development profile with an external preprod environment spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev--preprod} -cors.allowed.origins=${CORS_ALLOWED_ORIGINS:http://localhost:3000} +cors.allowed.origins=${CORS_ALLOWED_ORIGINS:http://localhost:3000,http://localhost:4000} # disable in production... spring.h2.console.enabled=${H2_CONSOLE_ENABLED:true} From f36f3a57e8c009500c7ea6298c5cc8f410420220 Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 14 Aug 2024 14:42:16 +0200 Subject: [PATCH 02/27] fix: debug keriVerifierBaseUrl --- .../foundation/voting/client/KeriVerificationClient.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 87b545e7b..29da1be5a 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -105,7 +105,8 @@ public Either getOOBI(String oobi, Integer maxAttempts) { log.info("getOOBI"); log.info("oobi url: {}. Max attempts {}", oobi, maxAttempts); val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); - log.info("Keria URL to fetch: ", url); + log.info("keriVerifierBaseUrl: {}", keriVerifierBaseUrl); + log.info("Keria URL to fetch: {}", url); val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); From 6431f2b88965c504f14edc985428df301f9f1ebc Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 14 Aug 2024 14:47:12 +0200 Subject: [PATCH 03/27] fix: compare user-verification and voting-app interaction with Keri service --- .../foundation/voting/client/KeriVerificationClient.java | 7 +++++++ .../foundation/voting/client/KeriVerificationClient.java | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index ea221aa1a..893f79666 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -101,7 +101,12 @@ public Either registerOOBI(String oobi) { } public Either getOOBI(String oobi, Integer maxAttempts) { + log.info("getOOBI"); + log.info("oobi url: {}", oobi); + log.info("Max attempts: {}", maxAttempts); val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); + log.info("keriVerifierBaseUrl: {}", keriVerifierBaseUrl); + log.info("Keria URL to fetch: {}", url); val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); @@ -115,6 +120,8 @@ public Either getOOBI(String oobi, Integer maxAttempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); + log.info("Keria URL to fetch response: {}", response); + if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 29da1be5a..9672ead62 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -103,7 +103,8 @@ public Either registerOOBI(String oobi) { public Either getOOBI(String oobi, Integer maxAttempts) { log.info("getOOBI"); - log.info("oobi url: {}. Max attempts {}", oobi, maxAttempts); + log.info("oobi url: {}", oobi); + log.info("Max attempts: {}", maxAttempts); val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); log.info("keriVerifierBaseUrl: {}", keriVerifierBaseUrl); log.info("Keria URL to fetch: {}", url); @@ -116,8 +117,11 @@ public Either getOOBI(String oobi, Integer maxAttempts) { int attempt = 0; while (attempt < attempts) { + log.info("attempt nº: {}", attempt); + log.info("entity: {}", entity); try { val response = restTemplate.exchange(url, GET, entity, String.class); + log.info("Keria URL to fetch response: {}", response); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); From 52d6fc8a40a8423ac5f31f9871944a428887cbc1 Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 14 Aug 2024 15:17:45 +0200 Subject: [PATCH 04/27] fix: compare user-verification and voting-app interaction with Keri service --- .../foundation/voting/client/KeriVerificationClient.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 893f79666..83e1c17ad 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -117,6 +117,8 @@ public Either getOOBI(String oobi, Integer maxAttempts) { int attempt = 0; while (attempt < attempts) { + log.info("attempt nº: {}", attempt); + log.info("entity: {}", entity); try { val response = restTemplate.exchange(url, GET, entity, String.class); From 0fb8b47f8082de4541c63e25b9b2a74bed125c3b Mon Sep 17 00:00:00 2001 From: J Caso Date: Tue, 20 Aug 2024 11:59:46 +0200 Subject: [PATCH 05/27] fix: handling oobi not found error --- .../src/verifier/controllers.py | 2 ++ .../voting/client/KeriVerificationClient.java | 18 ++++++----------- .../voting/client/KeriVerificationClient.java | 20 ++++++------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/backend-services/keri-ballot-verifier/src/verifier/controllers.py b/backend-services/keri-ballot-verifier/src/verifier/controllers.py index afdb3e7bd..f655901a7 100644 --- a/backend-services/keri-ballot-verifier/src/verifier/controllers.py +++ b/backend-services/keri-ballot-verifier/src/verifier/controllers.py @@ -33,10 +33,12 @@ def __init__(self, hby): def on_get(self, req, resp): # This should be a path param but is causing issues, query will do. oobi = req.params.get('url') + if oobi is None or oobi == "": raise falcon.HTTPBadRequest(description=f"required field url missing from request") result = self.hby.db.roobi.get(keys=(oobi,)) + if result: resp.status = falcon.HTTP_200 resp.text = result.cid diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 83e1c17ad..7d901a7be 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -20,6 +20,7 @@ import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.NOT_FOUND; @Component @Slf4j @@ -101,12 +102,7 @@ public Either registerOOBI(String oobi) { } public Either getOOBI(String oobi, Integer maxAttempts) { - log.info("getOOBI"); - log.info("oobi url: {}", oobi); - log.info("Max attempts: {}", maxAttempts); val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); - log.info("keriVerifierBaseUrl: {}", keriVerifierBaseUrl); - log.info("Keria URL to fetch: {}", url); val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); @@ -117,18 +113,15 @@ public Either getOOBI(String oobi, Integer maxAttempts) { int attempt = 0; while (attempt < attempts) { - log.info("attempt nº: {}", attempt); - log.info("entity: {}", entity); try { val response = restTemplate.exchange(url, GET, entity, String.class); - - log.info("Keria URL to fetch response: {}", response); - if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { - if (e.getStatusCode() != BAD_REQUEST) { + if (e.getStatusCode() == NOT_FOUND) { + log.info("OOBI not found, continuing attempts..."); + } else { return Either.left(Problem.builder() .withTitle("OOBI_FETCH_ERROR") .withDetail("Unable to fetch OOBI, reason: " + e.getMessage()) @@ -155,8 +148,9 @@ public Either getOOBI(String oobi, Integer maxAttempts) { return Either.left(Problem.builder() .withTitle("OOBI_NOT_FOUND") .withDetail("The OOBI was not found after " + attempts + " attempts.") - .withStatus(new HttpStatusAdapter(BAD_REQUEST)) + .withStatus(new HttpStatusAdapter(NOT_FOUND)) .build()); } + } diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 9672ead62..f68a6f6c3 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -19,6 +19,7 @@ import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.HttpStatus.BAD_REQUEST; +import static org.springframework.http.HttpStatus.NOT_FOUND; @RequiredArgsConstructor @Component @@ -102,12 +103,8 @@ public Either registerOOBI(String oobi) { } public Either getOOBI(String oobi, Integer maxAttempts) { - log.info("getOOBI"); - log.info("oobi url: {}", oobi); - log.info("Max attempts: {}", maxAttempts); val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); - log.info("keriVerifierBaseUrl: {}", keriVerifierBaseUrl); - log.info("Keria URL to fetch: {}", url); + val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); @@ -117,19 +114,15 @@ public Either getOOBI(String oobi, Integer maxAttempts) { int attempt = 0; while (attempt < attempts) { - log.info("attempt nº: {}", attempt); - log.info("entity: {}", entity); try { val response = restTemplate.exchange(url, GET, entity, String.class); - log.info("Keria URL to fetch response: {}", response); - if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { - if (e.getStatusCode() != BAD_REQUEST) { - log.error("Error on get oobi: {}. Code: {}", e.getMessage(), e.getStatusCode()); - log.error("Full Error: {}", e); + if (e.getStatusCode() == NOT_FOUND) { + log.info("OOBI not found, continuing attempts..."); + } else { return Either.left(Problem.builder() .withTitle("OOBI_FETCH_ERROR") .withDetail("Unable to fetch OOBI, reason: " + e.getMessage()) @@ -156,8 +149,7 @@ public Either getOOBI(String oobi, Integer maxAttempts) { return Either.left(Problem.builder() .withTitle("OOBI_NOT_FOUND") .withDetail("The OOBI was not found after " + attempts + " attempts.") - .withStatus(new HttpStatusAdapter(BAD_REQUEST)) + .withStatus(new HttpStatusAdapter(NOT_FOUND)) .build()); } - } From 08c050eda4a21386d126b0bb46785d7191e90fdb Mon Sep 17 00:00:00 2001 From: J Caso Date: Tue, 20 Aug 2024 12:00:54 +0200 Subject: [PATCH 06/27] fix: remove debug --- .../foundation/voting/client/KeriVerificationClient.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index f68a6f6c3..4eae9b789 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -70,8 +70,6 @@ public Either verifySignature(String aid, } public Either registerOOBI(String oobi) { - log.info("registerOOBI"); - log.info("oobi url: {}", oobi); val url = String.format("%s/oobi", keriVerifierBaseUrl); val headers = new HttpHeaders(); From 2a5b97d29a29057ad6d62c58a1e23651a6f6177a Mon Sep 17 00:00:00 2001 From: J Caso Date: Tue, 20 Aug 2024 12:12:16 +0200 Subject: [PATCH 07/27] fix: remove debugs --- .../voting/service/auth/web3/KeriWeb3Filter.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java index 3e15c73e8..97d52a4c3 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java @@ -59,8 +59,7 @@ public class KeriWeb3Filter extends OncePerRequestFilter { protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws ServletException, IOException { - log.info("doFilterInternal"); - log.info("req: {}", req); + val logonSystemM = loginSystemDetector.detect(req); if (logonSystemM.isEmpty()) { chain.doFilter(req, res); @@ -78,11 +77,6 @@ protected void doFilterInternal(HttpServletRequest req, val headerAidM = Optional.ofNullable(req.getHeader(X_Ballot_PublicKey)); val headerOobiM = Optional.ofNullable(req.getHeader(X_Ballot_Oobi)); - log.info("headerSignatureM: {}", headerSignatureM); - log.info("headerPayloadM: {}", headerPayloadM); - log.info("headerAidM: {}", headerAidM); - log.info("headerOobiM: {}", headerOobiM); - if (headerSignatureM.isEmpty()) { val problem = Problem.builder() .withTitle("NO_LOGIN_HTTP_HEADERS_SET") @@ -130,7 +124,6 @@ protected void doFilterInternal(HttpServletRequest req, val headerAid = headerAidM.orElseThrow(); val headerOobi = headerOobiM.orElseThrow(); - log.info("OOBI to get after validate it: ", headerOobi); // Step 1: Check if OOBI is already registered Either oobiCheckResult = keriVerificationClient.getOOBI(headerOobi, 1); if (oobiCheckResult.isLeft()) { From a82dabc2cbf34a076e6dc99c5c0bd1ad99a7a414 Mon Sep 17 00:00:00 2001 From: J Caso Date: Tue, 20 Aug 2024 12:24:16 +0200 Subject: [PATCH 08/27] fix: remove unnecessary port 4000 --- .../org/cardano/foundation/voting/config/SpringWebConfig.java | 2 +- .../src/main/resources/application.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java b/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java index bd0474bc0..67d6d12b8 100644 --- a/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java +++ b/backend-services/voting-ledger-follower-app/src/main/java/org/cardano/foundation/voting/config/SpringWebConfig.java @@ -13,7 +13,7 @@ @Configuration public class SpringWebConfig { - @Value("${cors.allowed.origins:http://localhost:3000,http://localhost:4000}") + @Value("${cors.allowed.origins:http://localhost:3000}") private String allowedOrigins; @Bean diff --git a/backend-services/voting-ledger-follower-app/src/main/resources/application.properties b/backend-services/voting-ledger-follower-app/src/main/resources/application.properties index f5bce820b..3e9ed05bc 100644 --- a/backend-services/voting-ledger-follower-app/src/main/resources/application.properties +++ b/backend-services/voting-ledger-follower-app/src/main/resources/application.properties @@ -68,7 +68,7 @@ apiPrefix=${API_PREFIX:/yaci-api} # default spring profile is a development profile with an external preprod environment spring.profiles.active=${SPRING_PROFILES_ACTIVE:dev--preprod} -cors.allowed.origins=${CORS_ALLOWED_ORIGINS:http://localhost:3000,http://localhost:4000} +cors.allowed.origins=${CORS_ALLOWED_ORIGINS:http://localhost:3000} # disable in production... spring.h2.console.enabled=${H2_CONSOLE_ENABLED:true} From cdcb5d9401000b2cb5879165a2cd5cfa3dfa2c5b Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 21 Aug 2024 12:40:41 +0200 Subject: [PATCH 09/27] fix: debugging --- .../src/verifier/controllers.py | 8 +++++- .../voting/client/KeriVerificationClient.java | 28 +++++++++++++++++-- .../voting/client/KeriVerificationClient.java | 26 +++++++++++++++-- 3 files changed, 56 insertions(+), 6 deletions(-) diff --git a/backend-services/keri-ballot-verifier/src/verifier/controllers.py b/backend-services/keri-ballot-verifier/src/verifier/controllers.py index f655901a7..5686a8dfa 100644 --- a/backend-services/keri-ballot-verifier/src/verifier/controllers.py +++ b/backend-services/keri-ballot-verifier/src/verifier/controllers.py @@ -38,7 +38,8 @@ def on_get(self, req, resp): raise falcon.HTTPBadRequest(description=f"required field url missing from request") result = self.hby.db.roobi.get(keys=(oobi,)) - + print("OOBIEnd:") + print(result) if result: resp.status = falcon.HTTP_200 resp.text = result.cid @@ -115,6 +116,11 @@ def on_post(self, req, resp): payload = getRequiredParam(body, 'payload') try: + print("VerificationEnd:") + print(pre) + print(signature) + print(payload) + print(self.hab.kevers[pre]) kever = self.hab.kevers[pre] except KeyError as _: resp.status = falcon.HTTP_404 diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 7d901a7be..3fcf2c459 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -45,6 +45,14 @@ public Either verifySignature(String aid, requestBody.put("signature", signature); requestBody.put("payload", payload); + log.info("\n\nnverifySignature"); + log.info("aid"); + log.info(aid); + log.info("signature"); + log.info(signature); + log.info("payload"); + log.info(payload); + val entity = new HttpEntity>(requestBody, headers); try { @@ -60,6 +68,8 @@ public Either verifySignature(String aid, .withStatus(new HttpStatusAdapter(response.getStatusCode())) .build()); } catch (HttpClientErrorException e) { + log.info("Error on verifySignature"); + log.info(e); log.error("Unable to verify signature, reason: {}", e.getMessage()); return Either.left(Problem.builder() @@ -79,10 +89,16 @@ public Either registerOOBI(String oobi) { val requestBody = new HashMap(); requestBody.put("oobi", oobi); + log.info("\n\nregisterOOBI"); + log.info("oobi"); + log.info(oobi); + val entity = new HttpEntity>(requestBody, headers); try { val response = restTemplate.exchange(url, POST, entity, String.class); + log.info("response"); + log.info(response); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -104,6 +120,12 @@ public Either registerOOBI(String oobi) { public Either getOOBI(String oobi, Integer maxAttempts) { val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); + log.info("\n\ngetOOBI"); + log.info("oobi"); + log.info(oobi); + log.info("maxAttempts"); + log.info(maxAttempts); + val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); @@ -115,12 +137,14 @@ public Either getOOBI(String oobi, Integer maxAttempts) { while (attempt < attempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); + log.info("response"); + log.info(response); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { if (e.getStatusCode() == NOT_FOUND) { - log.info("OOBI not found, continuing attempts..."); + log.info("OOBI not found, continuing attempts... "+attempt); } else { return Either.left(Problem.builder() .withTitle("OOBI_FETCH_ERROR") @@ -151,6 +175,4 @@ public Either getOOBI(String oobi, Integer maxAttempts) { .withStatus(new HttpStatusAdapter(NOT_FOUND)) .build()); } - - } diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 4eae9b789..945b66fb8 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -46,9 +46,18 @@ public Either verifySignature(String aid, val entity = new HttpEntity>(requestBody, headers); + log.info("\n\nnverifySignature"); + log.info("aid"); + log.info(aid); + log.info("signature"); + log.info(signature); + log.info("payload"); + log.info(payload); + try { val response = restTemplate.exchange(url, POST, entity, String.class); - + log.info("response"); + log.info(response); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -79,9 +88,14 @@ public Either registerOOBI(String oobi) { requestBody.put("oobi", oobi); val entity = new HttpEntity>(requestBody, headers); + + log.info("\n\nregisterOOBI"); + log.info("oobi"); + log.info(oobi); try { val response = restTemplate.exchange(url, POST, entity, String.class); - + log.info("response"); + log.info(response); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -111,9 +125,17 @@ public Either getOOBI(String oobi, Integer maxAttempts) { int attempts = (maxAttempts == null) ? 1 : maxAttempts; int attempt = 0; + log.info("\n\ngetOOBI"); + log.info("oobi"); + log.info(oobi); + log.info("maxAttempts"); + log.info(maxAttempts); + while (attempt < attempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); + log.info("response"); + log.info(response); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } From aee0530ddd66b614cec42cc0b754b0daa64b170b Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 21 Aug 2024 13:01:49 +0200 Subject: [PATCH 10/27] fix: debugging --- .../foundation/voting/client/KeriVerificationClient.java | 6 +++--- .../foundation/voting/client/KeriVerificationClient.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 3fcf2c459..9df5fe6c8 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -98,7 +98,7 @@ public Either registerOOBI(String oobi) { val response = restTemplate.exchange(url, POST, entity, String.class); log.info("response"); - log.info(response); + log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -124,7 +124,7 @@ public Either getOOBI(String oobi, Integer maxAttempts) { log.info("oobi"); log.info(oobi); log.info("maxAttempts"); - log.info(maxAttempts); + log.info(String.valueOf(maxAttempts)); val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); @@ -138,7 +138,7 @@ public Either getOOBI(String oobi, Integer maxAttempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); log.info("response"); - log.info(response); + log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 945b66fb8..e359cfed0 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -57,7 +57,7 @@ public Either verifySignature(String aid, try { val response = restTemplate.exchange(url, POST, entity, String.class); log.info("response"); - log.info(response); + log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -95,7 +95,7 @@ public Either registerOOBI(String oobi) { try { val response = restTemplate.exchange(url, POST, entity, String.class); log.info("response"); - log.info(response); + log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -129,13 +129,13 @@ public Either getOOBI(String oobi, Integer maxAttempts) { log.info("oobi"); log.info(oobi); log.info("maxAttempts"); - log.info(maxAttempts); + log.info(String.valueOf(maxAttempts)); while (attempt < attempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); log.info("response"); - log.info(response); + log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } From ae4dfb4ac0e259294d0ccece0b681f2f2a48b8bb Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 21 Aug 2024 13:08:39 +0200 Subject: [PATCH 11/27] fix: debugging test --- .../cardano/foundation/voting/client/KeriVerificationClient.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index e359cfed0..e7c0603ec 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -89,6 +89,7 @@ public Either registerOOBI(String oobi) { val entity = new HttpEntity>(requestBody, headers); + log.info("\n\nregisterOOBI"); log.info("oobi"); log.info(oobi); From a7786cb9c3cc567db37e68e54f9c0c5a93ec5bff Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 21 Aug 2024 13:14:45 +0200 Subject: [PATCH 12/27] fix: debugging test --- .../cardano/foundation/voting/client/KeriVerificationClient.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 9df5fe6c8..f6543c3ea 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -69,7 +69,6 @@ public Either verifySignature(String aid, .build()); } catch (HttpClientErrorException e) { log.info("Error on verifySignature"); - log.info(e); log.error("Unable to verify signature, reason: {}", e.getMessage()); return Either.left(Problem.builder() From 68044f46f9a5c8471f838272f55de7ecf81fdda7 Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 21 Aug 2024 13:58:04 +0200 Subject: [PATCH 13/27] fix: doFilterInternal --- ...DefaultDiscordUserVerificationService.java | 5 +- .../voting/client/KeriVerificationClient.java | 2 + .../service/auth/web3/KeriWeb3Filter.java | 53 ++++++------------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java index d01d6831c..56f784360 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java @@ -427,10 +427,11 @@ private Either handleKeriVerification(DiscordCheckV } // Step 1: Check if OOBI is already registered + log.info("Lets check if the oobi is already registered: {}", headerOobi); Either oobiCheckResult = keriVerificationClient.getOOBI(oobi, 1); - + log.info("oobiCheckResult: {}", oobiCheckResult.get()); if (oobiCheckResult.isRight()) { - log.info("OOBI already registered: {}", oobiCheckResult); + log.info("OOBI already registered: {}", oobiCheckResult.get()); Either verificationResult = keriVerificationClient.verifySignature(walletId, signature, payload); if (verificationResult.isLeft()) { diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index e7c0603ec..0fc7d797e 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -141,6 +141,8 @@ public Either getOOBI(String oobi, Integer maxAttempts) { return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { + log.info("HttpClientErrorException.getStatusCode()"); + log.info(e.getStatusCode().toString()); if (e.getStatusCode() == NOT_FOUND) { log.info("OOBI not found, continuing attempts..."); } else { diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java index 97d52a4c3..88ba17645 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java @@ -125,54 +125,35 @@ protected void doFilterInternal(HttpServletRequest req, val headerOobi = headerOobiM.orElseThrow(); // Step 1: Check if OOBI is already registered + log.info("Lets check if the oobi is already registered: {}", headerOobi); Either oobiCheckResult = keriVerificationClient.getOOBI(headerOobi, 1); - if (oobiCheckResult.isLeft()) { - sendBackProblem(objectMapper, res, oobiCheckResult.getLeft()); - return; - } - - // Log if OOBI is registered or not - log.info("OOBI status: {}", oobiCheckResult.get()); - if (oobiCheckResult.isRight()) { - log.info("OOBI already registered: {}", oobiCheckResult); - Either verificationResult = keriVerificationClient.verifySignature(headerAid, headerSignature, headerSignedJson); - - if (verificationResult.isEmpty()) { - val problem = Problem.builder() - .withTitle("KERI_SIGNATURE_VERIFICATION_FAILED") - .withDetail("Unable to verify KERI header signature, reason: " + verificationResult.swap().get().getDetail()) - .withStatus(BAD_REQUEST) - .build(); + if (oobiCheckResult.isLeft()) { + log.info("OOBI not registered yet: {}", headerOobi); + // Step 2: Register OOBI if not already registered + val oobiRegistrationResultE = keriVerificationClient.registerOOBI(headerOobi); - sendBackProblem(objectMapper, res, problem); + if (oobiRegistrationResultE.isLeft()) { + sendBackProblem(objectMapper, res, oobiRegistrationResultE.getLeft()); return; } - } - log.info("OOBI not registered yet: {}", headerOobi); - // Step 2: Register OOBI if not already registered - val oobiRegistrationResultE = keriVerificationClient.registerOOBI(headerOobi); + log.info("OOBI registered successfully: {}", headerOobi); - if (oobiRegistrationResultE.isLeft()) { - sendBackProblem(objectMapper, res, oobiRegistrationResultE.getLeft()); - return; + // Step 3: Attempt to verify OOBI registration up to 60 times + val oobiFetchResultE = keriVerificationClient.getOOBI(headerOobi, 60); + if (oobiFetchResultE.isLeft()) { + sendBackProblem(objectMapper, res, oobiFetchResultE.getLeft()); + return; + } } - log.info("OOBI registered successfully: {}", headerOobi); - - // Step 3: Attempt to verify OOBI registration up to 60 times - val oobiFetchResultE = keriVerificationClient.getOOBI(headerOobi, 60); - if (oobiFetchResultE.isLeft()) { - sendBackProblem(objectMapper, res, oobiFetchResultE.getLeft()); - return; - } + Either verificationResult = keriVerificationClient.verifySignature(headerAid, headerSignature, headerSignedJson); - val keriVerificationResultE = keriVerificationClient.verifySignature(headerAid, headerSignature, headerSignedJson); - if (keriVerificationResultE.isEmpty()) { + if (verificationResult.isEmpty()) { val problem = Problem.builder() .withTitle("KERI_SIGNATURE_VERIFICATION_FAILED") - .withDetail("Unable to verify KERI header signature, reason: " + keriVerificationResultE.swap().get().getDetail()) + .withDetail("Unable to verify KERI header signature, reason: " + verificationResult.swap().get().getDetail()) .withStatus(BAD_REQUEST) .build(); From e3284d5c9226ec3b07b257746af102c7295c55d6 Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 21 Aug 2024 14:04:27 +0200 Subject: [PATCH 14/27] fix: remove failed log --- .../service/discord/DefaultDiscordUserVerificationService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java index 56f784360..fb240a377 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java @@ -427,7 +427,6 @@ private Either handleKeriVerification(DiscordCheckV } // Step 1: Check if OOBI is already registered - log.info("Lets check if the oobi is already registered: {}", headerOobi); Either oobiCheckResult = keriVerificationClient.getOOBI(oobi, 1); log.info("oobiCheckResult: {}", oobiCheckResult.get()); if (oobiCheckResult.isRight()) { From 95c0dde5cd98851610f76d8072b7445f45c8f51a Mon Sep 17 00:00:00 2001 From: J Caso Date: Wed, 21 Aug 2024 14:22:08 +0200 Subject: [PATCH 15/27] fix: add logs --- .../foundation/voting/client/KeriVerificationClient.java | 1 + .../foundation/voting/service/auth/web3/KeriWeb3Filter.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 0fc7d797e..e118b6085 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -138,6 +138,7 @@ public Either getOOBI(String oobi, Integer maxAttempts) { log.info("response"); log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { + log.info("OOBI got successfully after {} attempts", String.valueOf(attempt+1)); return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java index 88ba17645..f54968e32 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java @@ -145,9 +145,12 @@ protected void doFilterInternal(HttpServletRequest req, if (oobiFetchResultE.isLeft()) { sendBackProblem(objectMapper, res, oobiFetchResultE.getLeft()); return; + } else { + log.info("OOBI successfully got"); } } + log.info("\nLets verify the signature"); Either verificationResult = keriVerificationClient.verifySignature(headerAid, headerSignature, headerSignedJson); if (verificationResult.isEmpty()) { From eba26ecc5bac3f07770072732fa65f261ece3093 Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 22 Aug 2024 04:09:54 +0200 Subject: [PATCH 16/27] fix: add logs --- .../service/discord/DefaultDiscordUserVerificationService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java index fb240a377..670dfaa17 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java @@ -465,13 +465,14 @@ private Either handleKeriVerification(DiscordCheckV log.info("OOBI registered successfully: {}", oobiM); - // Step 3: Attempt to verify OOBI registration up to 10 times + // Step 3: Attempt to verify OOBI registration up to 60 times val oobiFetchResultE = keriVerificationClient.getOOBI(oobi, 60); if (oobiFetchResultE.isLeft()) { return Either.left(oobiFetchResultE.getLeft()); } // Step 4: Verify signature after OOBI registration + log.info("\nLets verify the signature"); val verificationResultE = keriVerificationClient.verifySignature(walletId, signature, payload); if (verificationResultE.isLeft()) { return Either.left(verificationResultE.getLeft()); From 7640d17ff97ac9d73c3a731731715112ad9065ad Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 22 Aug 2024 04:38:29 +0200 Subject: [PATCH 17/27] fix: remove log --- .../service/discord/DefaultDiscordUserVerificationService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java index 670dfaa17..744baff18 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java @@ -428,7 +428,6 @@ private Either handleKeriVerification(DiscordCheckV // Step 1: Check if OOBI is already registered Either oobiCheckResult = keriVerificationClient.getOOBI(oobi, 1); - log.info("oobiCheckResult: {}", oobiCheckResult.get()); if (oobiCheckResult.isRight()) { log.info("OOBI already registered: {}", oobiCheckResult.get()); Either verificationResult = keriVerificationClient.verifySignature(walletId, signature, payload); From b7264bd97255fc40d96025c7bfb30a257f92c67e Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 22 Aug 2024 10:28:59 +0200 Subject: [PATCH 18/27] fix: remove logs --- .../src/verifier/controllers.py | 7 ----- .../voting/client/KeriVerificationClient.java | 23 --------------- ...DefaultDiscordUserVerificationService.java | 1 - .../voting/client/KeriVerificationClient.java | 28 +------------------ .../service/auth/web3/KeriWeb3Filter.java | 4 --- 5 files changed, 1 insertion(+), 62 deletions(-) diff --git a/backend-services/keri-ballot-verifier/src/verifier/controllers.py b/backend-services/keri-ballot-verifier/src/verifier/controllers.py index 5686a8dfa..f503e43c1 100644 --- a/backend-services/keri-ballot-verifier/src/verifier/controllers.py +++ b/backend-services/keri-ballot-verifier/src/verifier/controllers.py @@ -38,8 +38,6 @@ def on_get(self, req, resp): raise falcon.HTTPBadRequest(description=f"required field url missing from request") result = self.hby.db.roobi.get(keys=(oobi,)) - print("OOBIEnd:") - print(result) if result: resp.status = falcon.HTTP_200 resp.text = result.cid @@ -116,11 +114,6 @@ def on_post(self, req, resp): payload = getRequiredParam(body, 'payload') try: - print("VerificationEnd:") - print(pre) - print(signature) - print(payload) - print(self.hab.kevers[pre]) kever = self.hab.kevers[pre] except KeyError as _: resp.status = falcon.HTTP_404 diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index f6543c3ea..2dc7f6804 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -45,14 +45,6 @@ public Either verifySignature(String aid, requestBody.put("signature", signature); requestBody.put("payload", payload); - log.info("\n\nnverifySignature"); - log.info("aid"); - log.info(aid); - log.info("signature"); - log.info(signature); - log.info("payload"); - log.info(payload); - val entity = new HttpEntity>(requestBody, headers); try { @@ -68,7 +60,6 @@ public Either verifySignature(String aid, .withStatus(new HttpStatusAdapter(response.getStatusCode())) .build()); } catch (HttpClientErrorException e) { - log.info("Error on verifySignature"); log.error("Unable to verify signature, reason: {}", e.getMessage()); return Either.left(Problem.builder() @@ -88,16 +79,10 @@ public Either registerOOBI(String oobi) { val requestBody = new HashMap(); requestBody.put("oobi", oobi); - log.info("\n\nregisterOOBI"); - log.info("oobi"); - log.info(oobi); - val entity = new HttpEntity>(requestBody, headers); try { val response = restTemplate.exchange(url, POST, entity, String.class); - log.info("response"); - log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -119,12 +104,6 @@ public Either registerOOBI(String oobi) { public Either getOOBI(String oobi, Integer maxAttempts) { val url = String.format("%s/oobi?url=%s", keriVerifierBaseUrl, oobi); - log.info("\n\ngetOOBI"); - log.info("oobi"); - log.info(oobi); - log.info("maxAttempts"); - log.info(String.valueOf(maxAttempts)); - val headers = new HttpHeaders(); headers.add("Content-Type", "application/json"); @@ -136,8 +115,6 @@ public Either getOOBI(String oobi, Integer maxAttempts) { while (attempt < attempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); - log.info("response"); - log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(response.getBody()); } diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java index 744baff18..8fbe02b50 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java @@ -471,7 +471,6 @@ private Either handleKeriVerification(DiscordCheckV } // Step 4: Verify signature after OOBI registration - log.info("\nLets verify the signature"); val verificationResultE = keriVerificationClient.verifySignature(walletId, signature, payload); if (verificationResultE.isLeft()) { return Either.left(verificationResultE.getLeft()); diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index e118b6085..85c5ea71f 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -46,18 +46,8 @@ public Either verifySignature(String aid, val entity = new HttpEntity>(requestBody, headers); - log.info("\n\nnverifySignature"); - log.info("aid"); - log.info(aid); - log.info("signature"); - log.info(signature); - log.info("payload"); - log.info(payload); - try { val response = restTemplate.exchange(url, POST, entity, String.class); - log.info("response"); - log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -89,14 +79,9 @@ public Either registerOOBI(String oobi) { val entity = new HttpEntity>(requestBody, headers); - - log.info("\n\nregisterOOBI"); - log.info("oobi"); - log.info(oobi); try { val response = restTemplate.exchange(url, POST, entity, String.class); - log.info("response"); - log.info(response.toString()); + if (response.getStatusCode().is2xxSuccessful()) { return Either.right(true); } @@ -126,24 +111,13 @@ public Either getOOBI(String oobi, Integer maxAttempts) { int attempts = (maxAttempts == null) ? 1 : maxAttempts; int attempt = 0; - log.info("\n\ngetOOBI"); - log.info("oobi"); - log.info(oobi); - log.info("maxAttempts"); - log.info(String.valueOf(maxAttempts)); - while (attempt < attempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); - log.info("response"); - log.info(response.toString()); if (response.getStatusCode().is2xxSuccessful()) { - log.info("OOBI got successfully after {} attempts", String.valueOf(attempt+1)); return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { - log.info("HttpClientErrorException.getStatusCode()"); - log.info(e.getStatusCode().toString()); if (e.getStatusCode() == NOT_FOUND) { log.info("OOBI not found, continuing attempts..."); } else { diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java index f54968e32..4c0efab8d 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java @@ -125,7 +125,6 @@ protected void doFilterInternal(HttpServletRequest req, val headerOobi = headerOobiM.orElseThrow(); // Step 1: Check if OOBI is already registered - log.info("Lets check if the oobi is already registered: {}", headerOobi); Either oobiCheckResult = keriVerificationClient.getOOBI(headerOobi, 1); if (oobiCheckResult.isLeft()) { @@ -145,12 +144,9 @@ protected void doFilterInternal(HttpServletRequest req, if (oobiFetchResultE.isLeft()) { sendBackProblem(objectMapper, res, oobiFetchResultE.getLeft()); return; - } else { - log.info("OOBI successfully got"); } } - log.info("\nLets verify the signature"); Either verificationResult = keriVerificationClient.verifySignature(headerAid, headerSignature, headerSignedJson); if (verificationResult.isEmpty()) { From ac4c98ca4755799b5900fc9d32c94e43cbd81091 Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 22 Aug 2024 12:29:16 +0200 Subject: [PATCH 19/27] fix: set logs --- .../cardano/foundation/voting/client/KeriVerificationClient.java | 1 + .../cardano/foundation/voting/client/KeriVerificationClient.java | 1 + 2 files changed, 2 insertions(+) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 2dc7f6804..6d8241cde 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -116,6 +116,7 @@ public Either getOOBI(String oobi, Integer maxAttempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); if (response.getStatusCode().is2xxSuccessful()) { + log.info("OOBI successfully retrieved after {} attempts", attempt+1); return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 85c5ea71f..87c1cc911 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -115,6 +115,7 @@ public Either getOOBI(String oobi, Integer maxAttempts) { try { val response = restTemplate.exchange(url, GET, entity, String.class); if (response.getStatusCode().is2xxSuccessful()) { + log.info("OOBI successfully retrieved after {} attempts", attempt+1); return Either.right(response.getBody()); } } catch (HttpClientErrorException e) { From dc6a9b20b134da5bf94fd00ede3d99b5ea81097e Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 22 Aug 2024 12:33:33 +0200 Subject: [PATCH 20/27] fix: set logs to keri verifier --- .../keri-ballot-verifier/src/verifier/controllers.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend-services/keri-ballot-verifier/src/verifier/controllers.py b/backend-services/keri-ballot-verifier/src/verifier/controllers.py index f503e43c1..4e3d9d467 100644 --- a/backend-services/keri-ballot-verifier/src/verifier/controllers.py +++ b/backend-services/keri-ballot-verifier/src/verifier/controllers.py @@ -38,6 +38,8 @@ def on_get(self, req, resp): raise falcon.HTTPBadRequest(description=f"required field url missing from request") result = self.hby.db.roobi.get(keys=(oobi,)) + print("OOBIEnd:") + print(result) if result: resp.status = falcon.HTTP_200 resp.text = result.cid @@ -114,6 +116,12 @@ def on_post(self, req, resp): payload = getRequiredParam(body, 'payload') try: + print("VerificationEndpoint:") + print(pre) + print(signature) + print(payload) + print(self.hab.kevers) + print(self.hab.kevers[pre]) kever = self.hab.kevers[pre] except KeyError as _: resp.status = falcon.HTTP_404 From 31ac21e6b8ec5bb3e08abaca1d949a2cd6b54a33 Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 22 Aug 2024 13:55:23 +0200 Subject: [PATCH 21/27] fix: remove logs from keri verifier --- .../keri-ballot-verifier/src/verifier/controllers.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/backend-services/keri-ballot-verifier/src/verifier/controllers.py b/backend-services/keri-ballot-verifier/src/verifier/controllers.py index 4e3d9d467..f655901a7 100644 --- a/backend-services/keri-ballot-verifier/src/verifier/controllers.py +++ b/backend-services/keri-ballot-verifier/src/verifier/controllers.py @@ -38,8 +38,7 @@ def on_get(self, req, resp): raise falcon.HTTPBadRequest(description=f"required field url missing from request") result = self.hby.db.roobi.get(keys=(oobi,)) - print("OOBIEnd:") - print(result) + if result: resp.status = falcon.HTTP_200 resp.text = result.cid @@ -116,12 +115,6 @@ def on_post(self, req, resp): payload = getRequiredParam(body, 'payload') try: - print("VerificationEndpoint:") - print(pre) - print(signature) - print(payload) - print(self.hab.kevers) - print(self.hab.kevers[pre]) kever = self.hab.kevers[pre] except KeyError as _: resp.status = falcon.HTTP_404 From bc945e30782e342dd562a9326fc88343dda79ea6 Mon Sep 17 00:00:00 2001 From: J Caso Date: Mon, 26 Aug 2024 09:11:13 +0200 Subject: [PATCH 22/27] feat: add key state endpoint in KeriVerificationClient --- .../voting/client/KeriVerificationClient.java | 85 +++++++++++++++++++ ...DefaultDiscordUserVerificationService.java | 14 ++- .../CardanoSummit2024PreProdCommands.java | 4 +- 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 6d8241cde..2182e5ab3 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -152,4 +152,89 @@ public Either getOOBI(String oobi, Integer maxAttempts) { .withStatus(new HttpStatusAdapter(NOT_FOUND)) .build()); } + + public Either updateAndVerifyKeyState(String aid, Integer maxAttempts) { + val updateUrl = String.format("%s/keystate", keriVerifierBaseUrl); + val verifyUrl = String.format("%s/keystate/%s", keriVerifierBaseUrl, aid); + + val headers = new HttpHeaders(); + headers.add("Content-Type", "application/json"); + + val requestBody = new HashMap(); + requestBody.put("pre", aid); + + val entity = new HttpEntity>(requestBody, headers); + + // Attempt to update the key state + try { + val response = restTemplate.exchange(updateUrl, POST, entity, String.class); + if (response.getStatusCode().is2xxSuccessful()) { + log.info("Key state updated successfully for aid: {}", aid); + return verifyKeyState(verifyUrl, maxAttempts); + } else { + return Either.left(Problem.builder() + .withTitle("KEY_STATE_UPDATE_FAILED") + .withDetail("Failed to update key state.") + .withStatus(new HttpStatusAdapter(response.getStatusCode())) + .build()); + } + } catch (HttpClientErrorException e) { + log.error("Unable to update key state, reason: {}", e.getMessage()); + return Either.left(Problem.builder() + .withTitle("KEY_STATE_UPDATE_ERROR") + .withDetail("Unable to update key state, reason: " + e.getMessage()) + .withStatus(new HttpStatusAdapter(e.getStatusCode())) + .build()); + } + } + + private Either verifyKeyState(String url, Integer maxAttempts) { + val headers = new HttpHeaders(); + headers.add("Content-Type", "application/json"); + val entity = new HttpEntity(headers); + + int attempts = (maxAttempts == null) ? 1 : maxAttempts; + int attempt = 0; + + while (attempt < attempts) { + try { + val response = restTemplate.exchange(url, GET, entity, String.class); + if (response.getStatusCode().is2xxSuccessful()) { + log.info("Key state verified successfully after {} attempts", attempt + 1); + return Either.right(true); + } + } catch (HttpClientErrorException e) { + if (e.getStatusCode() == NOT_FOUND) { + log.info("Key state not found, continuing attempts... " + (attempt + 1)); + } else { + return Either.left(Problem.builder() + .withTitle("KEY_STATE_VERIFICATION_ERROR") + .withDetail("Unable to verify key state, reason: " + e.getMessage()) + .withStatus(new HttpStatusAdapter(e.getStatusCode())) + .build()); + } + } + + attempt++; + if (attempt < attempts) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return Either.left(Problem.builder() + .withTitle("INTERRUPTED_ERROR") + .withDetail("Thread was interrupted while waiting to retry.") + .withStatus(new HttpStatusAdapter(NOT_FOUND)) + .build()); + } + } + } + + return Either.left(Problem.builder() + .withTitle("KEY_STATE_VERIFICATION_FAILED") + .withDetail("The key state verification failed after " + attempts + " attempts.") + .withStatus(new HttpStatusAdapter(NOT_FOUND)) + .build()); + } + } diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java index 8fbe02b50..b1a34946c 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java @@ -430,6 +430,13 @@ private Either handleKeriVerification(DiscordCheckV Either oobiCheckResult = keriVerificationClient.getOOBI(oobi, 1); if (oobiCheckResult.isRight()) { log.info("OOBI already registered: {}", oobiCheckResult.get()); + + // Step 1.1:Update key state + Either keyStateUpdateResult = keriVerificationClient.updateAndVerifyKeyState(walletId, 60); + if (keyStateUpdateResult.isLeft()) { + return Either.left(keyStateUpdateResult.getLeft()); + } + Either verificationResult = keriVerificationClient.verifySignature(walletId, signature, payload); if (verificationResult.isLeft()) { @@ -470,7 +477,12 @@ private Either handleKeriVerification(DiscordCheckV return Either.left(oobiFetchResultE.getLeft()); } - // Step 4: Verify signature after OOBI registration + // Step 4: Update key state + Either keyStateUpdateResult = keriVerificationClient.updateAndVerifyKeyState(walletId, 60); + if (keyStateUpdateResult.isLeft()) { + return Either.left(keyStateUpdateResult.getLeft()); + } + // Step 5: Verify signature after OOBI registration val verificationResultE = keriVerificationClient.verifySignature(walletId, signature, payload); if (verificationResultE.isLeft()) { return Either.left(verificationResultE.getLeft()); diff --git a/backend-services/voting-admin-app/src/main/java/org/cardano/foundation/voting/shell/CardanoSummit2024PreProdCommands.java b/backend-services/voting-admin-app/src/main/java/org/cardano/foundation/voting/shell/CardanoSummit2024PreProdCommands.java index 88037021d..49eaaef64 100644 --- a/backend-services/voting-admin-app/src/main/java/org/cardano/foundation/voting/shell/CardanoSummit2024PreProdCommands.java +++ b/backend-services/voting-admin-app/src/main/java/org/cardano/foundation/voting/shell/CardanoSummit2024PreProdCommands.java @@ -46,12 +46,12 @@ public String createCFSummit2024Event() { log.info("Creating CF-Summit 2024 on a PRE-PROD network..."); - long startSlot = 67868350; + long startSlot = 68725647; long endSlot = startSlot + (604800*2); // 2 weeks later var createEventCommand = CreateEventCommand.builder() //CF_SUMMIT_2024_7BCC - .id(EVENT_NAME + "_" + "10BCC") + .id(EVENT_NAME + "_" + "11BCC-STG") .startSlot(Optional.of(startSlot)) .endSlot(Optional.of(endSlot)) .votingPowerAsset(Optional.empty()) From 0bf8bf6abffa6e50af73843c90021feeee6cd650 Mon Sep 17 00:00:00 2001 From: J Caso Date: Mon, 26 Aug 2024 10:57:59 +0200 Subject: [PATCH 23/27] feat: add key state endpoint in KeriVerificationClient in voting-app and mock tests --- .../voting/client/KeriVerificationClient.java | 84 +++++++++++++++++++ .../service/auth/web3/KeriWeb3Filter.java | 7 ++ .../service/auth/web3/KeriWeb3FilterTest.java | 14 ++++ 3 files changed, 105 insertions(+) diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java index 87c1cc911..dd13efa1b 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java @@ -151,4 +151,88 @@ public Either getOOBI(String oobi, Integer maxAttempts) { .withStatus(new HttpStatusAdapter(NOT_FOUND)) .build()); } + + public Either updateAndVerifyKeyState(String aid, Integer maxAttempts) { + val updateUrl = String.format("%s/keystate", keriVerifierBaseUrl); + val verifyUrl = String.format("%s/keystate/%s", keriVerifierBaseUrl, aid); + + val headers = new HttpHeaders(); + headers.add("Content-Type", "application/json"); + + val requestBody = new HashMap(); + requestBody.put("pre", aid); + + val entity = new HttpEntity>(requestBody, headers); + + // Attempt to update the key state + try { + val response = restTemplate.exchange(updateUrl, POST, entity, String.class); + if (response.getStatusCode().is2xxSuccessful()) { + log.info("Key state updated successfully for aid: {}", aid); + return verifyKeyState(verifyUrl, maxAttempts); + } else { + return Either.left(Problem.builder() + .withTitle("KEY_STATE_UPDATE_FAILED") + .withDetail("Failed to update key state.") + .withStatus(new HttpStatusAdapter(response.getStatusCode())) + .build()); + } + } catch (HttpClientErrorException e) { + log.error("Unable to update key state, reason: {}", e.getMessage()); + return Either.left(Problem.builder() + .withTitle("KEY_STATE_UPDATE_ERROR") + .withDetail("Unable to update key state, reason: " + e.getMessage()) + .withStatus(new HttpStatusAdapter(e.getStatusCode())) + .build()); + } + } + + private Either verifyKeyState(String url, Integer maxAttempts) { + val headers = new HttpHeaders(); + headers.add("Content-Type", "application/json"); + val entity = new HttpEntity(headers); + + int attempts = (maxAttempts == null) ? 1 : maxAttempts; + int attempt = 0; + + while (attempt < attempts) { + try { + val response = restTemplate.exchange(url, GET, entity, String.class); + if (response.getStatusCode().is2xxSuccessful()) { + log.info("Key state verified successfully after {} attempts", attempt + 1); + return Either.right(true); + } + } catch (HttpClientErrorException e) { + if (e.getStatusCode() == NOT_FOUND) { + log.info("Key state not found, continuing attempts... " + (attempt + 1)); + } else { + return Either.left(Problem.builder() + .withTitle("KEY_STATE_VERIFICATION_ERROR") + .withDetail("Unable to verify key state, reason: " + e.getMessage()) + .withStatus(new HttpStatusAdapter(e.getStatusCode())) + .build()); + } + } + + attempt++; + if (attempt < attempts) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return Either.left(Problem.builder() + .withTitle("INTERRUPTED_ERROR") + .withDetail("Thread was interrupted while waiting to retry.") + .withStatus(new HttpStatusAdapter(NOT_FOUND)) + .build()); + } + } + } + + return Either.left(Problem.builder() + .withTitle("KEY_STATE_VERIFICATION_FAILED") + .withDetail("The key state verification failed after " + attempts + " attempts.") + .withStatus(new HttpStatusAdapter(NOT_FOUND)) + .build()); + } } diff --git a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java index 4c0efab8d..dfe426b8e 100644 --- a/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java +++ b/backend-services/voting-app/src/main/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3Filter.java @@ -147,6 +147,13 @@ protected void doFilterInternal(HttpServletRequest req, } } + // Step 1.1:Update key state + Either keyStateUpdateResult = keriVerificationClient.updateAndVerifyKeyState(headerAid, 60); + if (keyStateUpdateResult.isLeft()) { + sendBackProblem(objectMapper, res, keyStateUpdateResult.getLeft()); + return; + } + Either verificationResult = keriVerificationClient.verifySignature(headerAid, headerSignature, headerSignedJson); if (verificationResult.isEmpty()) { diff --git a/backend-services/voting-app/src/test/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3FilterTest.java b/backend-services/voting-app/src/test/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3FilterTest.java index 068e9cf84..b98d35779 100644 --- a/backend-services/voting-app/src/test/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3FilterTest.java +++ b/backend-services/voting-app/src/test/java/org/cardano/foundation/voting/service/auth/web3/KeriWeb3FilterTest.java @@ -127,6 +127,7 @@ void doFilterInternal_shouldReturnBadRequest_whenKeriVerificationFails() throws when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.left(mock(Problem.class))); filter.doFilterInternal(request, response, chain); @@ -144,6 +145,7 @@ void doFilterInternal_shouldReturnBadRequest_whenKeriEnvelopeDecodingFails() thr when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(jsonService.decodeGenericKeri(any())).thenReturn(Either.left(mock(Problem.class))); @@ -168,6 +170,7 @@ void doFilterInternal_shouldReturnBadRequest_whenWalletIdIsMissingInEnvelope() t when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); val genericEnvelope = KERIEnvelope.>builder() @@ -198,6 +201,7 @@ void doFilterInternal_shouldReturnBadRequest_whenInvalidWalletType() throws Serv when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); val genericEnvelope = KERIEnvelope.>builder() @@ -231,6 +235,7 @@ void doFilterInternal_shouldReturnBadRequest_whenSlotIsNotNumeric() throws Servl when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( @@ -270,6 +275,7 @@ void doFilterInternal_shouldReturnInternalServerError_whenChainTipFails() throws when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.left(Problem.builder() @@ -312,6 +318,7 @@ void doFilterInternal_shouldReturnBadRequest_whenSlotIsExpired() throws ServletE when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(expirationService.isSlotExpired(any(), anyLong())).thenReturn(true); @@ -354,6 +361,7 @@ void doFilterInternal_shouldReturnBadRequest_whenNetworkIsInvalid() throws Servl when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( @@ -394,6 +402,7 @@ void doFilterInternal_shouldReturnBadRequest_whenChainNetworkMismatch() throws S when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( @@ -434,6 +443,7 @@ void doFilterInternal_shouldReturnBadRequest_whenAidCheckFails() throws ServletE when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( @@ -474,6 +484,7 @@ void doFilterInternal_shouldReturnBadRequest_whenAidMismatch() throws ServletExc when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( @@ -514,6 +525,7 @@ void doFilterInternal_shouldReturnInternalServerError_whenEventDetailsFails() th when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( @@ -561,6 +573,7 @@ void doFilterInternal_shouldReturnBadRequest_whenEventDetailsNotFound() throws S when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( @@ -603,6 +616,7 @@ void doFilterInternal_shouldAuthenticate_whenAllConditionsMet() throws ServletEx when(keriVerificationClient.getOOBI(anyString(), anyInt())).thenReturn(Either.right("http://localhost:3902/oobi/EBfYGHqQUk-iHVRDW5r3LKb2y5VpF1id8OF-RGXfcyRm/agent/EBfZKfhCQEssQXFUoIMk0otn3OB1DcCCxss6dBNWu2FZ")); when(keriVerificationClient.registerOOBI(anyString())).thenReturn(Either.right(true)); + when(keriVerificationClient.updateAndVerifyKeyState(anyString(), anyInt())).thenReturn(Either.right(true)); when(keriVerificationClient.verifySignature(any(), any(), any())).thenReturn(Either.right(true)); when(chainFollowerClient.getChainTip()).thenReturn(Either.right( From 6e4aa68d58fd01deabd903c3163d82676b5af8f5 Mon Sep 17 00:00:00 2001 From: J Caso Date: Tue, 10 Sep 2024 13:23:02 +0200 Subject: [PATCH 24/27] feat: new event --- .../src/main/resources/application.properties | 2 +- .../src/main/resources/application.properties | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend-services/user-verification-service/src/main/resources/application.properties b/backend-services/user-verification-service/src/main/resources/application.properties index f45f01154..1204577fc 100644 --- a/backend-services/user-verification-service/src/main/resources/application.properties +++ b/backend-services/user-verification-service/src/main/resources/application.properties @@ -67,7 +67,7 @@ max.pending.verification.attempts=${MAX_PENDING_VERIFICATION_ATTEMPTS:5} spring.h2.console.enabled=${H2_CONSOLE_ENABLED:true} phone.number.salt=${SALT:67274569c9671a4ae3f753b9647ca719} -discord.bot.eventId.binding=${DISCORD_BOT_EVENT_ID_BINDING:CF_SUMMIT_2024_10BCC} +discord.bot.eventId.binding=${DISCORD_BOT_EVENT_ID_BINDING:CF_SUMMIT_2024_15BCC} discord.bot.username=${DISCORD_BOT_USERNAME:discord_bot} discord.bot.password=${DISCORD_BOT_PASSWORD:test} diff --git a/backend-services/voting-ledger-follower-app/src/main/resources/application.properties b/backend-services/voting-ledger-follower-app/src/main/resources/application.properties index 3e9ed05bc..18655304b 100644 --- a/backend-services/voting-ledger-follower-app/src/main/resources/application.properties +++ b/backend-services/voting-ledger-follower-app/src/main/resources/application.properties @@ -49,7 +49,7 @@ cardano-client-lib.backend.type=${CLI_BACKEND:BLOCKFROST} organiser.account.stakeAddress=${ORGANISER_STAKE_ADDRESS} # comma separated list of event ids that this app will be binding / serving -bind.on.event.ids=${BIND_ON_EVENT_IDS:CF_SUMMIT_2024_10BCC} +bind.on.event.ids=${BIND_ON_EVENT_IDS:CF_SUMMIT_2024_15BCC} # yaci store props store.cardano.host=${CARDANO_NODE_HOST:preprod-node.world.dev.cardano.org} @@ -57,8 +57,8 @@ store.cardano.port=${CARDANO_NODE_PORT:30000} # protocol magic 1 = Cardano PreProd network store.cardano.protocol-magic=${CARDANO_NODE_PROTOCOL_MAGIC:1} -store.cardano.sync-start-blockhash=${YACI_STORE_CARDANO_SYNC_START_BLOCK_HASH:274218b4101de63d02dd38fa0ff9be75a1c146667f4aa67fe8a04e462c8c55b1} -store.cardano.sync-start-slot=${YACI_STORE_CARDANO_SYNC_START_SLOT:67868386} +store.cardano.sync-start-blockhash=${YACI_STORE_CARDANO_SYNC_START_BLOCK_HASH:be8c117c4e5ecbfbb233ab282eaf370764972585f0edbd6c3b195d532ef5eca8} +store.cardano.sync-start-slot=${YACI_STORE_CARDANO_SYNC_START_SLOT:69312000} # 1 day store.blocks.epoch-calculation-interval=86400 From c73be347996442cf93b5805ec0c74b6d6dd5e45e Mon Sep 17 00:00:00 2001 From: J Caso Date: Tue, 10 Sep 2024 14:30:55 +0200 Subject: [PATCH 25/27] feat: add TODO --- .../service/discord/DefaultDiscordUserVerificationService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java index b1a34946c..a70ce97f8 100644 --- a/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java +++ b/backend-services/user-verification-service/src/main/java/org/cardano/foundation/voting/service/discord/DefaultDiscordUserVerificationService.java @@ -431,6 +431,8 @@ private Either handleKeriVerification(DiscordCheckV if (oobiCheckResult.isRight()) { log.info("OOBI already registered: {}", oobiCheckResult.get()); + // TODO: Review this implementation once the KERI watchers are operational. + // This solution is temporary and might need adjustments to integrate with the new KERI components // Step 1.1:Update key state Either keyStateUpdateResult = keriVerificationClient.updateAndVerifyKeyState(walletId, 60); if (keyStateUpdateResult.isLeft()) { From 1282436544a61a3ac2fbdc7e1f83602418ba84d3 Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 12 Sep 2024 15:02:31 +0200 Subject: [PATCH 26/27] fix: enum not null --- .../foundation/voting/domain/VoteVerificationRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java b/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java index aba3c92b2..6843ac8bc 100644 --- a/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java +++ b/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java @@ -18,7 +18,7 @@ public class VoteVerificationRequest { @Schema(description = "Root hash of the merkle tree", required = true) private String rootHash; - @NotBlank + @NotNull @Schema(description = "Cardano or KERI", required = true) private WalletType walletType; From 315257b50c92c2e037cbf2930184d046ae3bb44c Mon Sep 17 00:00:00 2001 From: J Caso Date: Thu, 12 Sep 2024 15:12:30 +0200 Subject: [PATCH 27/27] fix: enum not null missing import --- .../foundation/voting/domain/VoteVerificationRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java b/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java index 6843ac8bc..aed4c90f3 100644 --- a/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java +++ b/backend-services/voting-verification-app/src/main/java/org/cardano/foundation/voting/domain/VoteVerificationRequest.java @@ -2,6 +2,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.*; import java.util.List;