diff --git a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/converter/CertificateAuthorityConverter.java b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/converter/CertificateAuthorityConverter.java index dbe6d49f9e..3a6bbd2485 100644 --- a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/converter/CertificateAuthorityConverter.java +++ b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/converter/CertificateAuthorityConverter.java @@ -59,7 +59,6 @@ public CertificateAuthority convert(ApprovedCaDto approvedCaDto) { ca.setPath(String.join(":", approvedCaDto.getSubjectDnPath())); ca.setTopCa(approvedCaDto.isTopCa()); ca.acmeCapable(approvedCaDto.isAcmeCapable()); - ca.acmeEabRequired(approvedCaDto.isAcmeEabRequired()); ca.certificateProfileInfo(approvedCaDto.getCertificateProfileInfo()); ca.acmeServerIpAddresses(ofNullable(approvedCaDto.getAcmeServerIpAddress()) .map(ips -> ips.split(",")) diff --git a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/dto/ApprovedCaDto.java b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/dto/ApprovedCaDto.java index 4928af4ffc..f5a0c06bc9 100644 --- a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/dto/ApprovedCaDto.java +++ b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/dto/ApprovedCaDto.java @@ -49,6 +49,5 @@ public class ApprovedCaDto { private final List subjectDnPath; private final String certificateProfileInfo; private final boolean acmeCapable; - private final boolean acmeEabRequired; private final String acmeServerIpAddress; } diff --git a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/openapi/CertificateAuthoritiesApiController.java b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/openapi/CertificateAuthoritiesApiController.java index b1005d2290..43dcae3570 100644 --- a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/openapi/CertificateAuthoritiesApiController.java +++ b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/openapi/CertificateAuthoritiesApiController.java @@ -182,8 +182,13 @@ public ResponseEntity> getSubjectFieldDescriptio public ResponseEntity hasAcmeExternalAccountBindingCredentials(String caName, KeyUsageType keyUsageType, String memberId) { - boolean hasAcmeEabCredentials = certificateAuthorityService.hasAcmeExternalAccountBindingCredentials(caName, memberId); - return new ResponseEntity<>(new AcmeEabCredentialsStatus(hasAcmeEabCredentials), HttpStatus.OK); + try { + final var isAcmeEabRequired = certificateAuthorityService.isAcmeExternalAccountBindingRequired(caName); + final var hasAcmeEabCredentials = certificateAuthorityService.hasAcmeExternalAccountBindingCredentials(caName, memberId); + return new ResponseEntity<>(new AcmeEabCredentialsStatus(isAcmeEabRequired, hasAcmeEabCredentials), HttpStatus.OK); + } catch (CertificateAuthorityNotFoundException e) { + throw new ResourceNotFoundException(e); + } } @Override diff --git a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/AcmeService.java b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/AcmeService.java index 2364e617fd..eb3731d4aa 100644 --- a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/AcmeService.java +++ b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/AcmeService.java @@ -235,7 +235,7 @@ private void accountWithEabCredentials(AccountBuilder accountBuilder, KeyUsageIn private static Metadata getMetadata(Session session) { try { return session.getMetadata(); - } catch (AcmeException e) { + } catch (Exception e) { throw new AcmeServiceException(FETCHING_METADATA_ERROR, e); } } diff --git a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/CertificateAuthorityService.java b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/CertificateAuthorityService.java index 48a56b9128..40a2490993 100644 --- a/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/CertificateAuthorityService.java +++ b/src/security-server/admin-service/application/src/main/java/org/niis/xroad/securityserver/restapi/service/CertificateAuthorityService.java @@ -54,11 +54,9 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; import java.util.stream.Collectors; import static org.niis.xroad.restapi.exceptions.DeviationCodes.ERROR_CA_CERT_PROCESSING; @@ -189,17 +187,7 @@ private ApprovedCaDto buildCertificateAuthorityDto( builder.name(approvedCAInfo.getName()); builder.certificateProfileInfo(approvedCAInfo.getCertificateProfileInfo()); builder.acmeServerIpAddress(approvedCAInfo.getAcmeServerIpAddress()); - boolean acmeCapable = approvedCAInfo.getAcmeServerDirectoryUrl() != null; - builder.acmeCapable(acmeCapable); - if (acmeCapable) { - try { - builder.acmeEabRequired( - acmeService.isExternalAccountBindingRequired(approvedCAInfo.getAcmeServerDirectoryUrl())); - } catch (AcmeServiceException e) { - log.warn("Acme Server for {} not reachable: {}", approvedCAInfo.getName(), e.getCause().getMessage()); - builder.acmeEabRequired(false); - } - } + builder.acmeCapable(approvedCAInfo.getAcmeServerDirectoryUrl() != null); // properties from X509Certificate builder.notAfter(FormatUtils.fromDateToOffsetDateTime(certificate.getNotAfter())); @@ -241,6 +229,11 @@ List buildPath(X509Certificate certificate, return pathElements; } + public boolean isAcmeExternalAccountBindingRequired(String caName) throws CertificateAuthorityNotFoundException { + final var acmeUrl = getCertificateAuthorityInfo(caName).getAcmeServerDirectoryUrl(); + return acmeUrl != null && acmeService.isExternalAccountBindingRequired(acmeUrl); + } + public boolean hasAcmeExternalAccountBindingCredentials(String caName, String memberId) { return acmeProperties.hasEabCredentials( caName, @@ -262,7 +255,7 @@ public boolean hasAcmeExternalAccountBindingCredentials(String caName, String me public CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo keyUsageInfo, ClientId memberId, boolean isNewMember) throws CertificateAuthorityNotFoundException, CertificateProfileInstantiationException, - WrongKeyUsageException, ClientNotFoundException { + WrongKeyUsageException, ClientNotFoundException { ApprovedCAInfo caInfo = getCertificateAuthorityInfo(caName); if (Boolean.TRUE.equals(caInfo.getAuthenticationOnly()) && KeyUsageInfo.SIGNING == keyUsageInfo) { throw new WrongKeyUsageException(); @@ -302,15 +295,11 @@ public CertificateProfileInfo getCertificateProfile(String caName, KeyUsageInfo * @throws CertificateAuthorityNotFoundException if matching CA was not found */ public ApprovedCAInfo getCertificateAuthorityInfo(String caName) throws CertificateAuthorityNotFoundException { - Collection cas = globalConfService.getApprovedCAsForThisInstance(); - Optional ca = cas.stream() + return globalConfService.getApprovedCAsForThisInstance().stream() .filter(item -> caName.equals(item.getName())) - .findFirst(); - if (ca.isEmpty()) { - throw new CertificateAuthorityNotFoundException("certificate authority " - + caName + " not_found"); - } - return ca.get(); + .findFirst() + .orElseThrow(() -> new CertificateAuthorityNotFoundException("certificate authority " + + caName + " not_found")); } /** diff --git a/src/security-server/admin-service/ui/src/components/wizard/WizardPageCsrDetails.vue b/src/security-server/admin-service/ui/src/components/wizard/WizardPageCsrDetails.vue index 034a5c20f6..f119d498c7 100644 --- a/src/security-server/admin-service/ui/src/components/wizard/WizardPageCsrDetails.vue +++ b/src/security-server/admin-service/ui/src/components/wizard/WizardPageCsrDetails.vue @@ -87,7 +87,7 @@