From 5be846ddf01abf99ca1d15ec6ad0f3c53354272f Mon Sep 17 00:00:00 2001 From: Michal Banka Date: Wed, 18 Mar 2020 12:40:13 +0100 Subject: Removed unused parameters when creating certificate Signed-off-by: Michal Banka Change-Id: I72d9e3ea30d3c2ba8e4e6c7e5afa0cfad2508bc5 Issue-ID: AAF-1107 --- .../aaf/certservice/cmpv2client/api/CmpClient.java | 18 +------------ .../cmpv2client/impl/CmpClientImpl.java | 30 ++++++++-------------- 2 files changed, 11 insertions(+), 37 deletions(-) (limited to 'certService/src/main/java/org/onap/aaf/certservice/cmpv2client') diff --git a/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/api/CmpClient.java b/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/api/CmpClient.java index 7de3b712..6ff1bf68 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/api/CmpClient.java +++ b/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/api/CmpClient.java @@ -41,13 +41,8 @@ public interface CmpClient { * IAK/RV, Verification of the signature (proof-of-possession) on the request is performed and an * Exception thrown if verification fails or issue encountered in fetching certificate from CA. * - * @param caName Information about the External Root Certificate Authority (CA) performing the - * event CA Name. Could be {@code null}. - * @param profile Profile on CA server Client/RA Mode configuration on Server. Could be {@code - * null}. * @param csrModel Certificate Signing Request model. Must not be {@code null}. * @param server CMPv2 Server. Must not be {@code null}. - * @param csr Certificate Signing Request {.cer} file. Must not be {@code null}. * @param notBefore An optional validity to set in the created certificate, Certificate not valid * before this date. * @param notAfter An optional validity to set in the created certificate, Certificate not valid @@ -56,11 +51,8 @@ public interface CmpClient { * @throws CmpClientException if client error occurs. */ List> createCertificate( - String caName, - String profile, CsrModel csrModel, Cmpv2Server server, - X509Certificate csr, Date notBefore, Date notAfter) throws CmpClientException; @@ -71,21 +63,13 @@ public interface CmpClient { * IAK/RV, Verification of the signature (proof-of-possession) on the request is performed and an * Exception thrown if verification fails or issue encountered in fetching certificate from CA. * - * @param caName Information about the External Root Certificate Authority (CA) performing the - * event CA Name. Could be {@code null}. - * @param profile Profile on CA server Client/RA Mode configuration on Server. Could be {@code - * null}. * @param csrModel Certificate Signing Request Model. Must not be {@code null}. * @param server CMPv2 server. Must not be {@code null}. - * @param csr Certificate Signing Request {.cer} file. Must not be {@code null}. * @return {@link X509Certificate} The newly created Certificate. * @throws CmpClientException if client error occurs. */ List> createCertificate( - String caName, - String profile, CsrModel csrModel, - Cmpv2Server server, - X509Certificate csr) + Cmpv2Server server) throws CmpClientException; } diff --git a/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/impl/CmpClientImpl.java b/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/impl/CmpClientImpl.java index 79656e91..08c43031 100644 --- a/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/impl/CmpClientImpl.java +++ b/certService/src/main/java/org/onap/aaf/certservice/cmpv2client/impl/CmpClientImpl.java @@ -48,6 +48,7 @@ import org.bouncycastle.asn1.cmp.PKIBody; import org.bouncycastle.asn1.cmp.PKIHeader; import org.bouncycastle.asn1.cmp.PKIMessage; import org.bouncycastle.asn1.x509.AlgorithmIdentifier; +import org.onap.aaf.certservice.certification.configuration.model.CaMode; import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server; import org.onap.aaf.certservice.certification.model.CsrModel; import org.onap.aaf.certservice.cmpv2client.exceptions.CmpClientException; @@ -64,7 +65,6 @@ public class CmpClientImpl implements CmpClient { private static final Logger LOG = LoggerFactory.getLogger(CmpClientImpl.class); private final CloseableHttpClient httpClient; - private static final String DEFAULT_PROFILE = "RA"; private static final String DEFAULT_CA_NAME = "Certification Authority"; public CmpClientImpl(CloseableHttpClient httpClient) { @@ -73,16 +73,13 @@ public class CmpClientImpl implements CmpClient { @Override public List> createCertificate( - String caName, - String profile, CsrModel csrModel, Cmpv2Server server, - X509Certificate cert, Date notBefore, Date notAfter) throws CmpClientException { - validate(csrModel, server, cert, caName, profile, httpClient, notBefore, notAfter); + validate(csrModel, server, httpClient, notBefore, notAfter); KeyPair keyPair = new KeyPair(csrModel.getPublicKey(), csrModel.getPrivateKey()); final CreateCertRequest certRequest = @@ -99,14 +96,13 @@ public class CmpClientImpl implements CmpClient { final PKIMessage pkiMessage = certRequest.generateCertReq(); Cmpv2HttpClient cmpv2HttpClient = new Cmpv2HttpClient(httpClient); - return retrieveCertificates(caName, csrModel, server, pkiMessage, cmpv2HttpClient); + return retrieveCertificates(csrModel, server, pkiMessage, cmpv2HttpClient); } @Override - public List> createCertificate( - String caName, String profile, CsrModel csrModel, Cmpv2Server server, X509Certificate csr) + public List> createCertificate(CsrModel csrModel, Cmpv2Server server) throws CmpClientException { - return createCertificate(caName, profile, csrModel, server, csr, null, null); + return createCertificate(csrModel, server, null, null); } private void checkCmpResponse( @@ -197,23 +193,18 @@ public class CmpClientImpl implements CmpClient { * * @param csrModel Certificate Signing Request model. Must not be {@code null}. * @param server CMPv2 Server. Must not be {@code null}. - * @param cert Certificate object needed to validate response from CA server. - * @param incomingCaName Date specifying certificate is not valid before this date. - * @param incomingProfile Date specifying certificate is not valid after this date. * @throws IllegalArgumentException if Before Date is set after the After Date. */ private static void validate( final CsrModel csrModel, final Cmpv2Server server, - final X509Certificate cert, - final String incomingCaName, - final String incomingProfile, final CloseableHttpClient httpClient, final Date notBefore, final Date notAfter) { - String caName = CmpUtil.isNullOrEmpty(incomingCaName) ? incomingCaName : DEFAULT_CA_NAME; - String caProfile = CmpUtil.isNullOrEmpty(incomingProfile) ? incomingProfile : DEFAULT_PROFILE; + + String caName = CmpUtil.isNullOrEmpty(server.getCaName()) ? server.getCaName() : DEFAULT_CA_NAME; + String caProfile = server.getCaMode() != null ? String.valueOf(server.getCaMode()) : String.valueOf(CaMode.RA); LOG.info( "Validate before creating Certificate Request for CA :{} in Mode {} ", caName, caProfile); @@ -224,7 +215,6 @@ public class CmpClientImpl implements CmpClient { CmpUtil.notNull(server.getIssuerDN(), "Issuer DN"); CmpUtil.notNull(server.getUrl(), "External CA URL"); CmpUtil.notNull(server.getAuthentication().getIak(), "IAK/RV Password"); - CmpUtil.notNull(cert, "Certificate Signing Request (CSR)"); CmpUtil.notNull(httpClient, "Closeable Http Client"); if (notBefore != null && notAfter != null && notBefore.compareTo(notAfter) > 0) { @@ -233,9 +223,9 @@ public class CmpClientImpl implements CmpClient { } private List> retrieveCertificates( - String caName, CsrModel csrModel, Cmpv2Server server, PKIMessage pkiMessage, Cmpv2HttpClient cmpv2HttpClient) + CsrModel csrModel, Cmpv2Server server, PKIMessage pkiMessage, Cmpv2HttpClient cmpv2HttpClient) throws CmpClientException { - final byte[] respBytes = cmpv2HttpClient.postRequest(pkiMessage, server.getUrl(), caName); + final byte[] respBytes = cmpv2HttpClient.postRequest(pkiMessage, server.getUrl(), server.getCaName()); try { final PKIMessage respPkiMessage = PKIMessage.getInstance(respBytes); LOG.info("Received response from Server"); -- cgit 1.2.3-korg