From c1414d546e495abaadb0e160aa465c1452b5fe3f Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Wed, 26 May 2021 16:01:29 +0900 Subject: [PATCH 01/47] Add problem report Signed-off-by: Ethan Sung --- .../controller/issuer/GlobalService.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java b/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java index 148efa4..0f73e6f 100644 --- a/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java +++ b/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java @@ -64,6 +64,7 @@ public void initializeAfterStartup() { } public void handleEvent(String body) { + //log.info("handleEvent >>> body:" + body); String topic = JsonPath.read(body, "$.topic"); String state = topic.equals("problem_report") ? null : JsonPath.read(body, "$.state"); log.info("handleEvent >>> topic:" + topic + ", state:" + state + ", body:" + body); @@ -197,18 +198,28 @@ public String createInvitationUrl() { public boolean checkCredentialProposal(String credExRecord) { String credentialProposal = JsonPath.parse((LinkedHashMap)JsonPath.read(credExRecord, "$.credential_proposal_dict")).jsonString(); + String connectionId = JsonPath.read(credExRecord, "$.connection_id"); + String credExId = JsonPath.read(credExRecord, "$.credential_exchange_id"); try { String requestedCredDefId = JsonPath.read(credentialProposal, "$.cred_def_id"); if (requestedCredDefId.equals(credDefId)){ - String connectionId = JsonPath.read(credExRecord, "$.connection_id"); - String credExId = JsonPath.read(credExRecord, "$.credential_exchange_id"); connIdToCredExId.put(connectionId, credExId); return true; } log.warn("This issuer can issue credDefId:" + credDefId); - log.warn("But, requested credDefId is " + requestedCredDefId + " -> Ignore"); + log.warn("But, requested credDefId is " + requestedCredDefId + " -> problemReport"); + String body = JsonPath.parse("{" + + " description: '본 기관은 요청한 증명서 (credDefId:" + requestedCredDefId + ") 를 발급하지 않습니다'" + + "}").jsonString(); + String response = client.requestPOST(agentApiUrl + "/issue-credential/records/" + credExId + "/problem-report", accessToken, body); + log.info("response: " + response); } catch (PathNotFoundException e) { - log.warn("Requested credDefId does not exist -> Ignore"); + log.warn("Requested credDefId does not exist -> problemReport"); + String body = JsonPath.parse("{" + + " description: '증명서 (credDefId) 가 지정되지 않았습니다'" + + "}").jsonString(); + String response = client.requestPOST(agentApiUrl + "/issue-credential/records/" + credExId + "/problem-report", accessToken, body); + log.info("response: " + response); } return false; } From 16aed353186cb7419a29f473c3e5b799f49c474e Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 31 May 2021 13:34:42 +0900 Subject: [PATCH 02/47] Add problem report Signed-off-by: Ethan Sung --- .../controller/holder/GlobalService.java | 28 +++++++++-- .../controller/issuer/GlobalService.java | 50 +++++++++++-------- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java b/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java index c0b9938..a58d70c 100644 --- a/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java +++ b/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java @@ -75,7 +75,10 @@ public void initialize() { public void handleEvent(String body) { String topic = JsonPath.read(body, "$.topic"); - String state = topic.equals("problem_report") ? null : JsonPath.read(body, "$.state"); + String state = null; + try { + state = JsonPath.read(body, "$.state"); + } catch (PathNotFoundException e) {} log.info("handleEvent >>> topic:" + topic + ", state:" + state + ", body:" + body); switch(topic) { @@ -87,8 +90,12 @@ public void handleEvent(String body) { } break; case "issue_credential": + if (state == null) { + log.warn("- Case (topic:" + topic + ", ProblemReport) -> PrintBody"); + log.warn(" - body:" + body); + } // 4-2. 증명서 preview 받음 -> 증명서 요청 - if (state.equals("offer_received")) { + else if (state.equals("offer_received")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendCredentialRequest"); sendCredentialRequest(JsonPath.read(body, "$.credential_exchange_id")); } @@ -115,8 +122,12 @@ else if (type != null && type.equals("initial_web_view")) { log.warn("- Warning: Unexpected type:" + type); break; case "present_proof": + if (state == null) { + log.warn("- Case (topic:" + topic + ", ProblemReport) -> PrintBody"); + log.warn(" - body:" + body); + } // 3. 모바일 가입증명 검증 요청 받음 -> 모바일 가입 증명 검증 전송 - if (state.equals("request_received")) { + else if (state.equals("request_received")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendPresentation"); String presentationRequest = JsonPath.parse((LinkedHashMap)JsonPath.read(body, "$.presentation_request")).jsonString(); sendPresentation(JsonPath.read(body, "$.presentation_exchange_id"), presentationRequest); @@ -136,7 +147,10 @@ else if (type != null && type.equals("initial_web_view")) { public void handleEventOnPreparation(String body) { String topic = JsonPath.read(body, "$.topic"); - String state = topic.equals("problem_report") ? null : JsonPath.read(body, "$.state"); + String state = null; + try { + state = JsonPath.read(body, "$.state"); + } catch (PathNotFoundException e) {} log.info("handleEvent >>> topic:" + topic + ", state:" + state + ", body:" + body); switch(topic) { @@ -147,7 +161,11 @@ public void handleEventOnPreparation(String body) { } break; case "issue_credential": - if (state.equals("offer_received")) { + if (state == null) { + log.warn("- Case (topic:" + topic + ", ProblemReport) -> PrintBody"); + log.warn(" - body:" + body); + } + else if (state.equals("offer_received")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendCredentialRequest"); sendCredentialRequest(JsonPath.read(body, "$.credential_exchange_id")); } diff --git a/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java b/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java index 0f73e6f..db2a848 100644 --- a/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java +++ b/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java @@ -64,18 +64,27 @@ public void initializeAfterStartup() { } public void handleEvent(String body) { - //log.info("handleEvent >>> body:" + body); String topic = JsonPath.read(body, "$.topic"); - String state = topic.equals("problem_report") ? null : JsonPath.read(body, "$.state"); + String state = null; + try { + state = JsonPath.read(body, "$.state"); + } catch (PathNotFoundException e) {} log.info("handleEvent >>> topic:" + topic + ", state:" + state + ", body:" + body); switch(topic) { case "issue_credential": + if (state == null) { + log.warn("- Case (topic:" + topic + ", ProblemReport) -> PrintBody"); + log.warn(" - body:" + body); + } // 1. holder 가 credential 을 요청함 -> 개인정보이용 동의 요청 - if (state.equals("proposal_received")) { + else if (state.equals("proposal_received")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> checkCredentialProposal && sendAgreement"); - if(checkCredentialProposal(body)) { - sendAgreement(JsonPath.read(body, "$.connection_id")); + String connectionId = JsonPath.read(body, "$.connection_id"); + String credExId = JsonPath.read(body, "$.credential_exchange_id"); + String credentialProposal = JsonPath.parse((LinkedHashMap)JsonPath.read(body, "$.credential_proposal_dict")).jsonString(); + if(checkCredentialProposal(connectionId, credExId, credentialProposal)) { + sendAgreement(connectionId); } } // 4. holder 가 증명서를 정상 저장하였음 -> 완료 (revocation 은 아래 코드 참조) @@ -105,8 +114,12 @@ else if (state.equals("credential_acked")) { log.warn("- Warning: Unexpected type:" + type); break; case "present_proof": + if (state == null) { + log.warn("- Case (topic:" + topic + ", ProblemReport) -> PrintBody"); + log.warn(" - body:" + body); + } // 3. holder 가 보낸 모바일 가입증명 검증 완료 - if (state.equals("verified")) { + else if (state.equals("verified")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> getPresentationResult"); LinkedHashMap attrs = getPresentationResult(body); for(String key : attrs.keySet()) @@ -196,10 +209,15 @@ public String createInvitationUrl() { } } - public boolean checkCredentialProposal(String credExRecord) { - String credentialProposal = JsonPath.parse((LinkedHashMap)JsonPath.read(credExRecord, "$.credential_proposal_dict")).jsonString(); - String connectionId = JsonPath.read(credExRecord, "$.connection_id"); - String credExId = JsonPath.read(credExRecord, "$.credential_exchange_id"); + public void sendCredProblemReport(String credExId, String description) { + String body = JsonPath.parse("{" + + " description: '" + description + "'" + + "}").jsonString(); + String response = client.requestPOST(agentApiUrl + "/issue-credential/records/" + credExId + "/problem-report", accessToken, body); + log.info("response: " + response); + } + + public boolean checkCredentialProposal(String connectionId, String credExId, String credentialProposal) { try { String requestedCredDefId = JsonPath.read(credentialProposal, "$.cred_def_id"); if (requestedCredDefId.equals(credDefId)){ @@ -208,18 +226,10 @@ public boolean checkCredentialProposal(String credExRecord) { } log.warn("This issuer can issue credDefId:" + credDefId); log.warn("But, requested credDefId is " + requestedCredDefId + " -> problemReport"); - String body = JsonPath.parse("{" + - " description: '본 기관은 요청한 증명서 (credDefId:" + requestedCredDefId + ") 를 발급하지 않습니다'" + - "}").jsonString(); - String response = client.requestPOST(agentApiUrl + "/issue-credential/records/" + credExId + "/problem-report", accessToken, body); - log.info("response: " + response); + sendCredProblemReport(credExId, "본 기관은 요청한 증명서 (credDefId:" + requestedCredDefId + ") 를 발급하지 않습니다"); } catch (PathNotFoundException e) { log.warn("Requested credDefId does not exist -> problemReport"); - String body = JsonPath.parse("{" + - " description: '증명서 (credDefId) 가 지정되지 않았습니다'" + - "}").jsonString(); - String response = client.requestPOST(agentApiUrl + "/issue-credential/records/" + credExId + "/problem-report", accessToken, body); - log.info("response: " + response); + sendCredProblemReport(credExId, "증명서 (credDefId) 가 지정되지 않았습니다"); } return false; } From 2fd94375d4f78bb612315bffdc03ebff8f3259b2 Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 31 May 2021 13:40:55 +0900 Subject: [PATCH 03/47] Refactor Signed-off-by: Ethan Sung --- .../controller/holder/GlobalService.java | 22 ++++++++++++------- .../controller/issuer/GlobalService.java | 11 ++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java b/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java index a58d70c..9bdbe13 100644 --- a/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java +++ b/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java @@ -86,7 +86,8 @@ public void handleEvent(String body) { // 1. connection 이 완료됨 -> credential 을 요청함 if (state.equals("active")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendCredentialProposal"); - sendCredentialProposal(JsonPath.read(body, "$.connection_id"), issuerCredDefId); + String connectionId = JsonPath.read(body, "$.connection_id"); + sendCredentialProposal(connectionId, issuerCredDefId); } break; case "issue_credential": @@ -97,7 +98,8 @@ public void handleEvent(String body) { // 4-2. 증명서 preview 받음 -> 증명서 요청 else if (state.equals("offer_received")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendCredentialRequest"); - sendCredentialRequest(JsonPath.read(body, "$.credential_exchange_id")); + String credExId = JsonPath.read(body, "$.credential_exchange_id"); + sendCredentialRequest(credExId); } // 4-3. 증명서를 정상 저장하였음 -> 완료 else if (state.equals("credential_acked")) { @@ -111,7 +113,8 @@ else if (state.equals("credential_acked")) { // 2. 개인정보이용 동의 요청 받음 -> 동의하여 전송 if (type != null && type.equals("initial_agreement")) { log.info("- Case (topic:" + topic + ", state:" + state + ", type:" + type + ") -> sendAgreementAgreed"); - sendAgreementAgreed(JsonPath.read(body, "$.connection_id"), content); + String connectionId = JsonPath.read(body, "$.connection_id"); + sendAgreementAgreed(connectionId, content); } // 4-1. web view를 통한 추가 정보 요구 -> 선택하여 전송 else if (type != null && type.equals("initial_web_view")) { @@ -129,13 +132,14 @@ else if (type != null && type.equals("initial_web_view")) { // 3. 모바일 가입증명 검증 요청 받음 -> 모바일 가입 증명 검증 전송 else if (state.equals("request_received")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendPresentation"); + String presExId = JsonPath.read(body, "$.presentation_exchange_id"); String presentationRequest = JsonPath.parse((LinkedHashMap)JsonPath.read(body, "$.presentation_request")).jsonString(); - sendPresentation(JsonPath.read(body, "$.presentation_exchange_id"), presentationRequest); + sendPresentation(presExId, presentationRequest); } break; case "problem_report": log.warn("- Case (topic:" + topic + ") -> Print body"); - log.warn(" - body:" + prettyJson(body)); + log.warn(" - body:" + body); break; case "revocation_registry": case "issuer_cred_rev": @@ -157,7 +161,8 @@ public void handleEventOnPreparation(String body) { case "connections": if (state.equals("active")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendCredentialProposal"); - sendCredentialProposal(JsonPath.read(body, "$.connection_id"), sampleMobileCredDefId); + String connectionId = JsonPath.read(body, "$.connection_id"); + sendCredentialProposal(connectionId, sampleMobileCredDefId); } break; case "issue_credential": @@ -167,7 +172,8 @@ public void handleEventOnPreparation(String body) { } else if (state.equals("offer_received")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sendCredentialRequest"); - sendCredentialRequest(JsonPath.read(body, "$.credential_exchange_id")); + String credExId = JsonPath.read(body, "$.credential_exchange_id"); + sendCredentialRequest(credExId); } else if (state.equals("credential_acked")) { log.info("- Case (topic:" + topic + ", state:" + state + ") -> sample mobile credential received successfully"); @@ -177,7 +183,7 @@ else if (state.equals("credential_acked")) { break; case "problem_report": log.warn("- Case (topic:" + topic + ") -> Print body"); - log.warn(" - body:" + prettyJson(body)); + log.warn(" - body:" + body); break; case "basicmessages": case "present_proof": diff --git a/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java b/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java index db2a848..b1e9bd6 100644 --- a/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java +++ b/src/main/java/com/sktelecom/initial/controller/issuer/GlobalService.java @@ -107,7 +107,8 @@ else if (state.equals("credential_acked")) { if (type != null && type.equals("initial_agreement_decision")) { if (isAgreementAgreed(content)) { log.info("- Case (topic:" + topic + ", state:" + state + ", type:" + type + ") -> AgreementAgreed & sendPresentationRequest"); - sendPresentationRequest(JsonPath.read(body, "$.connection_id")); + String connectionId = JsonPath.read(body, "$.connection_id"); + sendPresentationRequest(connectionId); } } else @@ -128,18 +129,20 @@ else if (state.equals("verified")) { if (enableWebView) { // 3-1. 검증 값 정보로 발행할 증명서가 한정되지 않는 경우 추가 정보 요구 log.info("Web View enabled -> sendWebView"); - sendWebView(JsonPath.read(body, "$.connection_id"), attrs, body); + String connectionId = JsonPath.read(body, "$.connection_id"); + sendWebView(connectionId, attrs, body); } else { // 3-2. 검증 값 정보 만으로 발행할 증명서가 한정되는 경우 증명서 바로 발행 log.info("Web View is not used -> sendCredentialOffer"); - sendCredentialOffer(JsonPath.read(body, "$.connection_id"), attrs, null); + String connectionId = JsonPath.read(body, "$.connection_id"); + sendCredentialOffer(connectionId, attrs, null); } } break; case "problem_report": log.warn("- Case (topic:" + topic + ") -> Print body"); - log.warn(" - body:" + prettyJson(body)); + log.warn(" - body:" + body); break; case "connections": case "revocation_registry": From f6d5dc304a6fd72240aa26263ac7dbe334318943 Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 31 May 2021 13:46:31 +0900 Subject: [PATCH 04/47] Add manual web view at holder Signed-off-by: Ethan Sung --- build.gradle | 7 +++++++ .../sktelecom/initial/controller/holder/GlobalService.java | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/build.gradle b/build.gradle index 51bd015..a221fd9 100644 --- a/build.gradle +++ b/build.gradle @@ -71,6 +71,13 @@ task holder(type:JavaExec) { main = 'com.sktelecom.initial.controller.holder.Application' args(['--spring.config.location=classpath:/application-holder.properties']) } +task holder_manual_webview(type:JavaExec) { + group 'application' + classpath sourceSets.main.runtimeClasspath + main = 'com.sktelecom.initial.controller.holder.Application' + args(['--spring.config.location=classpath:/application-holder.properties']) + environment("ENABLE_MANUAL_WEBVIEW", "true") +} task holder_prod(type:JavaExec) { group 'application' classpath sourceSets.main.runtimeClasspath diff --git a/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java b/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java index 9bdbe13..9510df3 100644 --- a/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java +++ b/src/main/java/com/sktelecom/initial/controller/holder/GlobalService.java @@ -45,6 +45,9 @@ public class GlobalService { String publicDid; String phase; + // for manual web view example + static boolean enableManualWebView = Boolean.parseBoolean(System.getenv().getOrDefault("ENABLE_MANUAL_WEBVIEW", "false")); + @EventListener(ApplicationReadyEvent.class) public void initialize() { provisionController(); @@ -330,6 +333,10 @@ public void showWebViewAndSelect(String content) { String webViewUrl = JsonPath.read(webViewContent, "$.web_view_url"); // CODE HERE : Show web view to user and user select & submit a item + if (enableManualWebView) { + log.info("browse url and submit: " + webViewUrl); + return; + } // For automation, we submit a item directly String[] token = webViewUrl.split("/web-view/form.html"); From 37347c3f24b3518f3654608e632ad5651443fd2e Mon Sep 17 00:00:00 2001 From: Ethan Sung Date: Mon, 31 May 2021 13:50:34 +0900 Subject: [PATCH 05/47] Update form.html Signed-off-by: Ethan Sung --- src/main/resources/static/web-view/form.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/static/web-view/form.html b/src/main/resources/static/web-view/form.html index b0446a1..b412832 100644 --- a/src/main/resources/static/web-view/form.html +++ b/src/main/resources/static/web-view/form.html @@ -45,6 +45,7 @@ + web-view form