diff options
author | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2021-07-13 15:52:23 +0200 |
---|---|---|
committer | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2021-07-13 15:52:23 +0200 |
commit | 7949b1a9d135263c0ffcdeae80131a83ca8cf63c (patch) | |
tree | e11f0c93b1931c9f589e5c264c54febd613a34a1 /certService/src/main/java | |
parent | 78b60d22b8779d1fbf3e27287b9774862f71404b (diff) |
[OOM-CERT-SERVICE] Fix sonar and checkstyle issues, code cleanup
Issue-ID: OOM-2753
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: Id88b6b2bceba7258745e4ce999dd375fb9ce438f
Diffstat (limited to 'certService/src/main/java')
8 files changed, 33 insertions, 29 deletions
diff --git a/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java b/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java index 8e2a378e..a4389ec2 100644 --- a/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java +++ b/certService/src/main/java/org/onap/oom/certservice/api/CertificationController.java @@ -28,7 +28,6 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import org.onap.oom.certservice.certification.CertificationResponseModelFactory; -import org.onap.oom.certservice.certification.exception.CertificateDecryptionException; import org.onap.oom.certservice.certification.exception.DecryptionException; import org.onap.oom.certservice.certification.exception.ErrorResponseModel; import org.onap.oom.certservice.certification.model.CertificateUpdateModel; @@ -112,7 +111,7 @@ public class CertificationController { @RequestHeader("PK") String encodedPrivateKey, @RequestHeader("OLD_CERT") String encodedOldCert, @RequestHeader("OLD_PK") String encodedOldPrivateKey - ) throws DecryptionException, CmpClientException, CertificateDecryptionException { + ) throws DecryptionException, CmpClientException { caName = replaceWhiteSpaceChars(caName); LOGGER.info("Received certificate update request for CA named: {}", caName); CertificateUpdateModel certificateUpdateModel = new CertificateUpdateModel.CertificateUpdateModelBuilder() diff --git a/certService/src/main/java/org/onap/oom/certservice/certification/CertificationResponseModelFactory.java b/certService/src/main/java/org/onap/oom/certservice/certification/CertificationResponseModelFactory.java index 0e793bb0..af90bf7e 100644 --- a/certService/src/main/java/org/onap/oom/certservice/certification/CertificationResponseModelFactory.java +++ b/certService/src/main/java/org/onap/oom/certservice/certification/CertificationResponseModelFactory.java @@ -25,7 +25,6 @@ import org.onap.oom.certservice.certification.configuration.model.Cmpv2Server; import org.onap.oom.certservice.certification.conversion.CsrModelFactory; import org.onap.oom.certservice.certification.conversion.OldCertificateModelFactory; import org.onap.oom.certservice.certification.conversion.StringBase64; -import org.onap.oom.certservice.certification.exception.CertificateDecryptionException; import org.onap.oom.certservice.certification.exception.DecryptionException; import org.onap.oom.certservice.certification.model.CertificateUpdateModel; import org.onap.oom.certservice.certification.model.CertificationResponseModel; @@ -79,10 +78,9 @@ public class CertificationResponseModelFactory { } public CertificationResponseModel provideCertificationModelFromUpdateRequest(CertificateUpdateModel certificateUpdateModel) - throws DecryptionException, CmpClientException, CertificateDecryptionException { - LOGGER.info("CSR: " + certificateUpdateModel.getEncodedCsr() + - ", old cert: " + certificateUpdateModel.getEncodedOldCert() + - ", CA: " + certificateUpdateModel.getCaName()); + throws DecryptionException, CmpClientException { + LOGGER.info("CSR: {}, old cert: {}, CA: {}", certificateUpdateModel.getEncodedCsr(), + certificateUpdateModel.getEncodedOldCert(), certificateUpdateModel.getCaName()); final CsrModel csrModel = csrModelFactory.createCsrModel( new StringBase64(certificateUpdateModel.getEncodedCsr()), new StringBase64(certificateUpdateModel.getEncodedPrivateKey()) diff --git a/certService/src/main/java/org/onap/oom/certservice/certification/conversion/OldCertificateModelFactory.java b/certService/src/main/java/org/onap/oom/certservice/certification/conversion/OldCertificateModelFactory.java index f5c199f6..d88b6bb0 100644 --- a/certService/src/main/java/org/onap/oom/certservice/certification/conversion/OldCertificateModelFactory.java +++ b/certService/src/main/java/org/onap/oom/certservice/certification/conversion/OldCertificateModelFactory.java @@ -72,7 +72,6 @@ public class OldCertificateModelFactory { return new OldCertificateModel(certificate, subjectData, sans, oldPrivateKey); } catch (StringToCertificateConversionException e) { throw new CertificateDecryptionException("Cannot convert certificate", e); - } catch (CertificateParsingException e) { throw new CertificateDecryptionException("Cannot read Subject Alternative Names from certificate"); } catch (NoSuchAlgorithmException | KeyDecryptionException | CertificateEncodingException | InvalidKeySpecException e) { diff --git a/certService/src/main/java/org/onap/oom/certservice/certification/exception/CertificateDecryptionException.java b/certService/src/main/java/org/onap/oom/certservice/certification/exception/CertificateDecryptionException.java index 16fdb44b..20df03c9 100644 --- a/certService/src/main/java/org/onap/oom/certservice/certification/exception/CertificateDecryptionException.java +++ b/certService/src/main/java/org/onap/oom/certservice/certification/exception/CertificateDecryptionException.java @@ -20,7 +20,7 @@ package org.onap.oom.certservice.certification.exception; -public class CertificateDecryptionException extends Exception { +public class CertificateDecryptionException extends DecryptionException { public CertificateDecryptionException(String message, Throwable cause) { super(message, cause); diff --git a/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateData.java b/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateData.java index 3a00c915..bc701e08 100644 --- a/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateData.java +++ b/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateData.java @@ -20,15 +20,14 @@ package org.onap.oom.certservice.certification.model; -import org.bouncycastle.asn1.x500.X500Name; -import org.bouncycastle.asn1.x509.GeneralName; - import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import org.bouncycastle.asn1.x500.X500Name; +import org.bouncycastle.asn1.x509.GeneralName; public class CertificateData { @@ -49,10 +48,14 @@ public class CertificateData { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - CertificateData that = (CertificateData) o; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + CertificateData that = (CertificateData) obj; return Objects.equals(subject, that.subject) && Objects.equals(sortedSans, that.sortedSans); } diff --git a/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateUpdateModel.java b/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateUpdateModel.java index 699ffe71..770d8812 100644 --- a/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateUpdateModel.java +++ b/certService/src/main/java/org/onap/oom/certservice/certification/model/CertificateUpdateModel.java @@ -31,7 +31,7 @@ public final class CertificateUpdateModel { private final String caName; private CertificateUpdateModel(String encodedCsr, String encodedPrivateKey, String encodedOldCert, - String encodedOldPrivateKey, String caName) { + String encodedOldPrivateKey, String caName) { this.encodedCsr = encodedCsr; this.encodedPrivateKey = encodedPrivateKey; this.encodedOldCert = encodedOldCert; @@ -60,15 +60,19 @@ public final class CertificateUpdateModel { } @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - CertificateUpdateModel that = (CertificateUpdateModel) o; + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + CertificateUpdateModel that = (CertificateUpdateModel) obj; return Objects.equals(encodedCsr, that.encodedCsr) - && Objects.equals(encodedPrivateKey, that.encodedPrivateKey) - && Objects.equals(encodedOldCert, that.encodedOldCert) - && Objects.equals(encodedOldPrivateKey, that.encodedOldPrivateKey) - && Objects.equals(caName, that.caName); + && Objects.equals(encodedPrivateKey, that.encodedPrivateKey) + && Objects.equals(encodedOldCert, that.encodedOldCert) + && Objects.equals(encodedOldPrivateKey, that.encodedOldPrivateKey) + && Objects.equals(caName, that.caName); } @Override @@ -110,7 +114,8 @@ public final class CertificateUpdateModel { } public CertificateUpdateModel build() { - return new CertificateUpdateModel(encodedCsr, encodedPrivateKey, encodedOldCert, encodedOldPrivateKey, caName); + return new CertificateUpdateModel(encodedCsr, encodedPrivateKey, encodedOldCert, encodedOldPrivateKey, + caName); } } } diff --git a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java index bbca91b6..fd2d7085 100644 --- a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java +++ b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/impl/CmpClientImpl.java @@ -100,7 +100,7 @@ public class CmpClientImpl implements CmpClient { final CreateCertRequest certRequest = getCmpMessageBuilderWithCommonRequestValues(csrModel, cmpv2Server) .with(CreateCertRequest::setCmpRequestType, PKIBody.TYPE_KEY_UPDATE_REQ) - .with(CreateCertRequest::setExtraCerts, getCMPCertificate(oldCertificateModel.getOldCertificate())) + .with(CreateCertRequest::setExtraCerts, getCmpCertificate(oldCertificateModel.getOldCertificate())) .with(CreateCertRequest::setProtection, pkiMessageProtection) .build(); @@ -154,7 +154,7 @@ public class CmpClientImpl implements CmpClient { return new SignatureProtection(oldCertificateModel.getOldPrivateKey()); } - private CMPCertificate[] getCMPCertificate(Certificate oldCertificate) { + private CMPCertificate[] getCmpCertificate(Certificate oldCertificate) { CMPCertificate cert = new CMPCertificate(oldCertificate); return new CMPCertificate[]{cert}; } diff --git a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/validation/CmpCertificationValidator.java b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/validation/CmpCertificationValidator.java index 40a2a1d9..f2601b94 100644 --- a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/validation/CmpCertificationValidator.java +++ b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/validation/CmpCertificationValidator.java @@ -52,7 +52,7 @@ public class CmpCertificationValidator { private static final ASN1ObjectIdentifier PASSWORD_BASED_MAC = new ASN1ObjectIdentifier("1.2.840.113533.7.66.13"); private static final Logger LOG = LoggerFactory.getLogger(CmpCertificationValidator.class); - public static void validate( + public void validate( final CsrModel csrModel, final Cmpv2Server server, final CloseableHttpClient httpClient, |