From fe3299f82eb64171f14ff2a3d7ae2f7c98b1cbc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ri=C4=8Dardas=20Bu=C4=8Di=C5=ABnas?= Date: Wed, 6 Dec 2023 14:42:07 +0200 Subject: [PATCH 1/5] feat: allow adding OCSP responder without a certificate. Refs: XRDDEV-2525 --- .../CertificationServicesServiceImpl.java | 7 +++++-- .../service/OcspRespondersServiceImpl.java | 7 +++++-- .../CertificationServicesController.java | 12 ++++++++--- .../TrustServicesOcspRespondersStepDefs.java | 21 ++++++++++++++++++- .../ui/0560-cs-ocsp-responders.feature | 4 ++++ .../ocspResponders/AddOcspResponderDialog.vue | 6 ++---- .../EditOcspResponderDialog.vue | 1 + .../ocspResponders/OcspRespondersList.vue | 1 + .../ui/src/store/modules/trust-services.ts | 6 ++++-- .../main/resources/openapi-definition.yaml | 1 - 10 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/CertificationServicesServiceImpl.java b/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/CertificationServicesServiceImpl.java index acf09822c8..01a9406565 100644 --- a/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/CertificationServicesServiceImpl.java +++ b/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/CertificationServicesServiceImpl.java @@ -221,8 +221,11 @@ private void addOcspAuditData(OcspInfoEntity ocspInfo) { auditDataHelper.put(CA_ID, ocspInfo.getCaInfo().getId()); auditDataHelper.put(OCSP_ID, ocspInfo.getId()); auditDataHelper.put(OCSP_URL, ocspInfo.getUrl()); - auditDataHelper.put(OCSP_CERT_HASH, calculateCertHexHashDelimited(ocspInfo.getCert())); - auditDataHelper.put(OCSP_CERT_HASH_ALGORITHM, DEFAULT_CERT_HASH_ALGORITHM_ID); + + if (ocspInfo.getCert() != null) { + auditDataHelper.put(OCSP_CERT_HASH, calculateCertHexHashDelimited(ocspInfo.getCert())); + auditDataHelper.put(OCSP_CERT_HASH_ALGORITHM, DEFAULT_CERT_HASH_ALGORITHM_ID); + } } } diff --git a/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/OcspRespondersServiceImpl.java b/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/OcspRespondersServiceImpl.java index 53f5548256..6aa8709081 100644 --- a/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/OcspRespondersServiceImpl.java +++ b/src/central-server/admin-service/core/src/main/java/org/niis/xroad/cs/admin/core/service/OcspRespondersServiceImpl.java @@ -86,8 +86,11 @@ public OcspResponder update(OcspResponderRequest updateRequest) { auditDataHelper.put(OCSP_ID, savedOcspInfo.getId()); auditDataHelper.put(OCSP_URL, savedOcspInfo.getUrl()); - auditDataHelper.put(OCSP_CERT_HASH, calculateCertHexHashDelimited(savedOcspInfo.getCert())); - auditDataHelper.put(OCSP_CERT_HASH_ALGORITHM, DEFAULT_CERT_HASH_ALGORITHM_ID); + + if (savedOcspInfo.getCert() != null) { + auditDataHelper.put(OCSP_CERT_HASH, calculateCertHexHashDelimited(savedOcspInfo.getCert())); + auditDataHelper.put(OCSP_CERT_HASH_ALGORITHM, DEFAULT_CERT_HASH_ALGORITHM_ID); + } return ocspResponderConverter.toModel(savedOcspInfo); } diff --git a/src/central-server/admin-service/infra-api-rest/src/main/java/org/niis/xroad/cs/admin/rest/api/openapi/CertificationServicesController.java b/src/central-server/admin-service/infra-api-rest/src/main/java/org/niis/xroad/cs/admin/rest/api/openapi/CertificationServicesController.java index 4332384ecf..c336dbe958 100644 --- a/src/central-server/admin-service/infra-api-rest/src/main/java/org/niis/xroad/cs/admin/rest/api/openapi/CertificationServicesController.java +++ b/src/central-server/admin-service/infra-api-rest/src/main/java/org/niis/xroad/cs/admin/rest/api/openapi/CertificationServicesController.java @@ -110,9 +110,15 @@ public ResponseEntity addCertificationServiceIntermedia @PreAuthorize("hasAuthority('ADD_APPROVED_CA')") public ResponseEntity addCertificationServiceOcspResponder(Integer caId, String url, MultipartFile certificate) { final var addRequest = new OcspResponderAddRequest(); - byte[] fileBytes = MultipartFileUtils.readBytes(certificate); - fileVerifier.validateCertificate(certificate.getOriginalFilename(), fileBytes); - addRequest.setCaId(caId).setUrl(url).setCertificate(fileBytes); + addRequest + .setCaId(caId) + .setUrl(url); + + if (certificate != null && !certificate.isEmpty()) { + byte[] fileBytes = MultipartFileUtils.readBytes(certificate); + fileVerifier.validateCertificate(certificate.getOriginalFilename(), fileBytes); + addRequest.setCertificate(fileBytes); + } var ocspResponder = certificationServicesService.addOcspResponder(addRequest); return status(CREATED).body(ocspResponderDtoConverter.toDto(ocspResponder)); diff --git a/src/central-server/admin-service/ui-system-test/src/intTest/java/org/niis/xroad/cs/test/ui/glue/TrustServicesOcspRespondersStepDefs.java b/src/central-server/admin-service/ui-system-test/src/intTest/java/org/niis/xroad/cs/test/ui/glue/TrustServicesOcspRespondersStepDefs.java index 4e1e903aee..e47ab689c4 100644 --- a/src/central-server/admin-service/ui-system-test/src/intTest/java/org/niis/xroad/cs/test/ui/glue/TrustServicesOcspRespondersStepDefs.java +++ b/src/central-server/admin-service/ui-system-test/src/intTest/java/org/niis/xroad/cs/test/ui/glue/TrustServicesOcspRespondersStepDefs.java @@ -49,7 +49,20 @@ public void ocspRespondersTabIsSelected() { } @Step("OCSP responder with URL {} is added") - public void newOcspResponderIsAdded(String url) throws Exception { + public void newOcspResponderIsAdded(String url) { + ocspRespondersPageObj.btnAddOcspResponder().click(); + commonPageObj.dialog.btnCancel().should(Condition.enabled); + commonPageObj.dialog.btnSave().shouldNotBe(Condition.enabled); + + vTextField(ocspRespondersPageObj.addEditDialog.inputOcspResponderUrl()).setValue(url); + commonPageObj.dialog.btnSave().click(); + + commonPageObj.snackBar.success().shouldBe(visible); + commonPageObj.snackBar.btnClose().click(); + } + + @Step("OCSP responder with URL {} and random cert is added") + public void newOcspResponderWithCertIsAdded(String url) throws Exception { ocspRespondersPageObj.btnAddOcspResponder().click(); commonPageObj.dialog.btnCancel().should(Condition.enabled); commonPageObj.dialog.btnSave().shouldNotBe(Condition.enabled); @@ -103,6 +116,12 @@ public void userIsAbleToViewTheCertificate(String url) { ocspRespondersPageObj.certificateView.certificateDetails().shouldBe(visible); } + @Step("view certificate of OCSP responder with URL {} button is missing") + public void viewCertButtonMissing(String url) { + ocspRespondersPageObj.btnViewOcspResponder(url).shouldNotBe(visible); + ocspRespondersPageObj.certificateView.certificateDetails().shouldBe(visible); + } + @Step("User is able click Edit button in OCSP responder with URL {}") public void userIsAbleToEditOcspResponder(String url) { ocspRespondersPageObj.btnEditOcspResponder(url).click(); diff --git a/src/central-server/admin-service/ui-system-test/src/intTest/resources/behavior/ui/0560-cs-ocsp-responders.feature b/src/central-server/admin-service/ui-system-test/src/intTest/resources/behavior/ui/0560-cs-ocsp-responders.feature index f1f9c3d5f6..47c3d6fac7 100644 --- a/src/central-server/admin-service/ui-system-test/src/intTest/resources/behavior/ui/0560-cs-ocsp-responders.feature +++ b/src/central-server/admin-service/ui-system-test/src/intTest/resources/behavior/ui/0560-cs-ocsp-responders.feature @@ -19,8 +19,12 @@ Feature: 0560 - CS: Trust Services -> CA Details -> OCSP Responders Scenario: OCSP responders list is correctly shown When OCSP responder table is visible And OCSP responder with URL http://e2e-test-ocsp-responder.com is added + And OCSP responder with URL http://e2e-test-ocsp-responder-cert.com with cert is added Then User is able to sort OCSP responders by URL + And OCSP responder with URL http://e2e-test-ocsp-responder.com is visible in the OCSP responders list + And OCSP responder with URL http://e2e-test-ocsp-responder-cert.com is visible in the OCSP responders list And User is able to view the certificate of OCSP responder with URL http://e2e-test-ocsp-responder.com + And view certificate of OCSP responder with URL http://e2e-test-ocsp-responder-cert.com button is missing Scenario: OCSP responder can be edit in list When OCSP responder with URL http://e2e-test-ocsp-responder.com is added diff --git a/src/central-server/admin-service/ui/src/components/ocspResponders/AddOcspResponderDialog.vue b/src/central-server/admin-service/ui/src/components/ocspResponders/AddOcspResponderDialog.vue index 93c0cf184d..a70d9c87d4 100644 --- a/src/central-server/admin-service/ui/src/components/ocspResponders/AddOcspResponderDialog.vue +++ b/src/central-server/admin-service/ui/src/components/ocspResponders/AddOcspResponderDialog.vue @@ -26,7 +26,7 @@ -->