diff options
8 files changed, 124 insertions, 22 deletions
diff --git a/certService/src/main/java/org/onap/oom/certservice/certification/CertificationModelFactory.java b/certService/src/main/java/org/onap/oom/certservice/certification/CertificationModelFactory.java index a5076a38..dddeb2d3 100644 --- a/certService/src/main/java/org/onap/oom/certservice/certification/CertificationModelFactory.java +++ b/certService/src/main/java/org/onap/oom/certservice/certification/CertificationModelFactory.java @@ -99,7 +99,7 @@ public class CertificationModelFactory { } else { LOGGER.info( "Certificate Signing Request and Old Certificate have different parameters. Preparing Certification Request"); - throw new UnsupportedOperationException("TODO: implement CR in separate MR"); + return certificationProvider.certificationRequest(csrModel, cmpv2Server); } } } diff --git a/certService/src/main/java/org/onap/oom/certservice/certification/CertificationProvider.java b/certService/src/main/java/org/onap/oom/certservice/certification/CertificationProvider.java index bfa83103..17e23e39 100644 --- a/certService/src/main/java/org/onap/oom/certservice/certification/CertificationProvider.java +++ b/certService/src/main/java/org/onap/oom/certservice/certification/CertificationProvider.java @@ -67,6 +67,12 @@ public class CertificationProvider { convertFromX509CertificateListToPemList(certificates.getTrustedCertificates())); } + public CertificationModel certificationRequest(CsrModel csrModel, Cmpv2Server cmpv2Server) throws CmpClientException { + Cmpv2CertificationModel certificates = cmpClient.certificationRequest(csrModel, cmpv2Server); + return new CertificationModel(convertFromX509CertificateListToPemList(certificates.getCertificateChain()), + convertFromX509CertificateListToPemList(certificates.getTrustedCertificates())); + } + private static List<String> convertFromX509CertificateListToPemList(List<X509Certificate> certificates) { return certificates.stream().map(CertificationProvider::convertFromX509CertificateToPem).filter(cert -> !cert.isEmpty()) .collect(Collectors.toList()); diff --git a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/api/CmpClient.java b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/api/CmpClient.java index 5ded3056..88c73c04 100644 --- a/certService/src/main/java/org/onap/oom/certservice/cmpv2client/api/CmpClient.java +++ b/certService/src/main/java/org/onap/oom/certservice/cmpv2client/api/CmpClient.java @@ -88,4 +88,17 @@ public interface CmpClient { */ Cmpv2CertificationModel updateCertificate(CsrModel csrModel, Cmpv2Server cmpv2Server, CertificateUpdateModel certificateUpdateModel) throws CmpClientException; + + /** + * Requests for an additional External Root CA Certificate to be created for the passed keyPair wrapped + * in a CSRMeta with common details. Basic Authentication using 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 csrModel Certificate Signing Request Model. Must not be {@code null}. + * @param cmpv2Server CMPv2 server. Must not be {@code null}. + * @return model for certification containing certificate chain and trusted certificates + * @throws CmpClientException if client error occurs. + */ + Cmpv2CertificationModel certificationRequest(CsrModel csrModel, Cmpv2Server cmpv2Server) throws CmpClientException; } 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 270b5995..549cf6b9 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 @@ -93,18 +93,7 @@ public class CmpClientImpl implements CmpClient { throws CmpClientException { validate(csrModel, server, httpClient, notBefore, notAfter); - - final String iak = server.getAuthentication().getIak(); - final PkiMessageProtection pkiMessageProtection = new PasswordBasedProtection(iak); - final CreateCertRequest certRequest = - getCmpMessageBuilderWithCommonRequestValues(csrModel, server) - .with(CreateCertRequest::setNotBefore, notBefore) - .with(CreateCertRequest::setNotAfter, notAfter) - .with(CreateCertRequest::setSenderKid, server.getAuthentication().getRv()) - .with(CreateCertRequest::setCmpRequestType, PKIBody.TYPE_INIT_REQ) - .with(CreateCertRequest::setProtection, pkiMessageProtection) - .build(); - + final CreateCertRequest certRequest = getIakRvRequest(csrModel, server, notBefore, notAfter, PKIBody.TYPE_INIT_REQ); return executeCmpRequest(csrModel, server, certRequest); } @@ -131,6 +120,32 @@ public class CmpClientImpl implements CmpClient { } + @Override + public Cmpv2CertificationModel certificationRequest(CsrModel csrModel, Cmpv2Server cmpv2Server) throws CmpClientException { + + validate(csrModel, cmpv2Server, httpClient, null, null); + final CreateCertRequest certRequest = getIakRvRequest(csrModel, cmpv2Server, null, null, PKIBody.TYPE_CERT_REQ); + return executeCmpRequest(csrModel, cmpv2Server, certRequest); + } + + private CreateCertRequest getIakRvRequest( + CsrModel csrModel, + Cmpv2Server server, + Date notBefore, + Date notAfter, + int requestType) { + + final String iak = server.getAuthentication().getIak(); + final PkiMessageProtection pkiMessageProtection = new PasswordBasedProtection(iak); + return getCmpMessageBuilderWithCommonRequestValues(csrModel, server) + .with(CreateCertRequest::setNotBefore, notBefore) + .with(CreateCertRequest::setNotAfter, notAfter) + .with(CreateCertRequest::setSenderKid, server.getAuthentication().getRv()) + .with(CreateCertRequest::setCmpRequestType, requestType) + .with(CreateCertRequest::setProtection, pkiMessageProtection) + .build(); + } + private Cmpv2CertificationModel executeCmpRequest(CsrModel csrModel, Cmpv2Server cmpv2Server, CreateCertRequest certRequest) throws CmpClientException { final PKIMessage pkiMessage = certRequest.generateCertReq(); diff --git a/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java b/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java index 1233168c..c7454f46 100644 --- a/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/certification/CertificationModelFactoryTest.java @@ -242,17 +242,25 @@ class CertificationModelFactoryTest { } @Test - void shouldPerformCrWhenCsrAndOldCertDataMatch() throws CertificateDecryptionException, DecryptionException { - //given - mockCsrFactoryModelCreation(); + void shouldPerformCrWhenCsrAndOldCertDataDontMatch() + throws CertificateDecryptionException, DecryptionException, CmpClientException { + // Given + CsrModel csrModel = mockCsrFactoryModelCreation(); + Cmpv2Server testServer = mockCmpv2ProviderServerSelection(); + mockCertificateProviderCertificationRequest(csrModel, testServer); mockCertificateFactoryModelCreation(); + // When when(updateRequestTypeDetector.isKur(any(), any())).thenReturn(false); - //when, then - Exception exception = assertThrows( - UnsupportedOperationException.class, () -> - certificationModelFactory.createCertificationModel(TEST_CERTIFICATE_UPDATE_MODEL) - ); - assertEquals(exception.getMessage(), "TODO: implement CR in separate MR"); + CertificationModel certificationModel = certificationModelFactory + .createCertificationModel(TEST_CERTIFICATE_UPDATE_MODEL); + // Then + assertEquals(2, certificationModel.getCertificateChain().size()); + assertThat(certificationModel.getCertificateChain()).contains(INTERMEDIATE_CERT, ENTITY_CERT); + assertEquals(2, certificationModel.getTrustedCertificates().size()); + assertThat(certificationModel.getTrustedCertificates()).contains(CA_CERT, EXTRA_CA_CERT); + + verify(certificationProvider, times(1)) + .certificationRequest(csrModel, testServer); } @Test @@ -276,6 +284,14 @@ class CertificationModelFactoryTest { ).thenReturn(expectedCertificationModel); } + private void mockCertificateProviderCertificationRequest(CsrModel csrModel, Cmpv2Server testServer) + throws CmpClientException { + CertificationModel expectedCertificationModel = getCertificationModel(); + when( + certificationProvider.certificationRequest(csrModel, testServer) + ).thenReturn(expectedCertificationModel); + } + private void mockCertificateProviderCertificateSigning(CsrModel csrModel, Cmpv2Server testServer) throws CmpClientException { CertificationModel expectedCertificationModel = getCertificationModel(); diff --git a/certService/src/test/java/org/onap/oom/certservice/certification/CertificationProviderTest.java b/certService/src/test/java/org/onap/oom/certservice/certification/CertificationProviderTest.java index 4e7908f5..7d75a655 100644 --- a/certService/src/test/java/org/onap/oom/certservice/certification/CertificationProviderTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/certification/CertificationProviderTest.java @@ -160,6 +160,28 @@ class CertificationProviderTest { } @Test + void shouldCorrectConvertToCertificationModelForCertificationRequest() + throws IOException, CertificateException, CmpClientException { + + when( + cmpClient.certificationRequest(any(CsrModel.class), any(Cmpv2Server.class)) + ).thenReturn(getCMPv2CertificationModel()); + + CertificationModel certificationModel = certificationProvider + .certificationRequest(csrModel, server); + List<String> certificateChain = certificationModel.getCertificateChain(); + List<String> trustedCertificates = certificationModel.getTrustedCertificates(); + + assertThat(certificateChain.size()).isEqualTo(EXPECTED_SIZE_ONE); + assertThat(certificateChain.get(0)).startsWith(EXPECTED_BEGIN_OF_CERTIFICATE); + assertThat(certificateChain.get(0)).endsWith(EXPECTED_END_OF_CERTIFICATE); + + assertThat(trustedCertificates.size()).isEqualTo(EXPECTED_SIZE_ONE); + assertThat(trustedCertificates.get(0)).startsWith(EXPECTED_BEGIN_OF_CERTIFICATE); + assertThat(trustedCertificates.get(0)).endsWith(EXPECTED_END_OF_CERTIFICATE); + } + + @Test void certificationProviderThrowCmpClientWhenCallingClientFailsForUpdateCertificate() throws CmpClientException { // Given diff --git a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java index 5a9a6838..0d8b80bd 100644 --- a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java +++ b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/ClientTestData.java @@ -26,6 +26,7 @@ import org.onap.oom.certservice.certification.model.CertificateUpdateModel.Certi public final class ClientTestData { static final String KUR_CORRECT_SERVER_RESPONSE_ENCODED = "MIIQ1DCCAV0CAQKkVTBTMRUwEwYKCZImiZPyLGQBAQwFMTIzNDUxFTATBgNVBAMMDE1hbmFnZW1lbnRDQTEjMCEGA1UECgwaRUpCQ0EgQ29udGFpbmVyIFF1aWNrc3RhcnSkeTB3MREwDwYDVQQDDAhvbmFwLm9yZzEZMBcGA1UECwwQTGludXgtRm91bmRhdGlvbjENMAsGA1UECgwET05BUDEWMBQGA1UEBwwNU2FuLUZyYW5jaXNjbzETMBEGA1UECAwKQ2FsaWZvcm5pYTELMAkGA1UEBhMCVVOgERgPMjAyMTA3MDExNTIzMTZaoQ8wDQYJKoZIhvcNAQELBQCiFgQU0pApkFDmdpd/O4a/byDxTEP2UvCkEgQQASuQH1HOfmX2elKP64XeAKUSBBDsl5fcNATjjIzirfNQHWSIphIEEPXCSC7+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HU5sZkrG4/YzTXWZ396UYYe6gc/wgOSZuF06HrSCmqeeyVqLbHZyQN/qdYTQELXs2vj2gG6jhAMUIdD4Du+9DJC3v6lBKVCh6/gw6a77Eu+8aChLjyIiL+YRDkeMNmqEEqCRc1iugk4JS003CPnr1UftHnU3kcCTsgCOCn2ZGYAqaO93dcHz7SyNoqVNObsydX4TOH2OSF9Ti0mDFT9A/KFOMUI7bPP1zNmHp9DrlNOrsho04SBt1HlTTsgvq15RGDOtQApc1VHC4LnLX4JeZ3IEoLUgNQfs0GIYnt0XMSbTdOfCvC9ojQ1eeSJHAMpeg6AGxnAJnrcQygt0259YEShLfiSaPgULwbGFCUWe"; private static final String TEST_CA = "TestCA"; private static final String WRONG_OLD_CERT = "wrong old cert"; diff --git a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java index 7ae42b35..de0a100c 100644 --- a/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java +++ b/certService/src/test/java/org/onap/oom/certservice/cmpv2client/Cmpv2ClientTest.java @@ -170,6 +170,35 @@ class Cmpv2ClientTest { } @Test + void shouldReturnCorrectCmpCertificateForCorrectCertificationRequest() throws CmpClientException, IOException { + + // given + setCsrModelAndServerTestDefaultValues(); + when(httpClient.execute(any())).thenReturn(httpResponse); + when(httpResponse.getEntity()).thenReturn(httpEntity); + + doAnswer( + invocation -> { + OutputStream os = invocation.getArgument(0); + os.write(BASE64_DECODER.decode(ClientTestData.CR_CORRECT_SERVER_RESPONSE_ENCODED.getBytes())); + return null; + }) + .when(httpEntity) + .writeTo(any(OutputStream.class)); + CmpClientImpl cmpClient = new CmpClientImpl(httpClient); + + // when + Cmpv2CertificationModel cmpClientResult = + cmpClient.certificationRequest(csrModel, server); + + // then + assertNotNull(cmpClientResult); + assertThat(cmpClientResult.getCertificateChain()).isNotEmpty(); + assertThat(cmpClientResult.getCertificateChain()).isNotEmpty(); + + } + + @Test void shouldThrowCmpClientExceptionWhenCannotParseOldPrivateKey() { setCsrModelAndServerTestDefaultValues(); |