2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aaf.certservice.certification;
23 import org.onap.aaf.certservice.certification.configuration.Cmpv2ServerProvider;
24 import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server;
25 import org.onap.aaf.certservice.certification.exception.Cmpv2ClientAdapterException;
26 import org.onap.aaf.certservice.certification.exception.DecryptionException;
27 import org.onap.aaf.certservice.certification.model.CertificationModel;
28 import org.onap.aaf.certservice.certification.model.CsrModel;
29 import org.onap.aaf.certservice.cmpv2client.exceptions.CmpClientException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Service;
36 public class CertificationModelFactory {
38 private static final Logger LOGGER = LoggerFactory.getLogger(CertificationModelFactory.class);
40 private final CsrModelFactory csrModelFactory;
41 private final Cmpv2ServerProvider cmpv2ServerProvider;
42 private final CertificationProvider certificationProvider;
45 CertificationModelFactory(
46 CsrModelFactory csrModelFactory,
47 Cmpv2ServerProvider cmpv2ServerProvider,
48 CertificationProvider certificationProvider
50 this.cmpv2ServerProvider = cmpv2ServerProvider;
51 this.csrModelFactory = csrModelFactory;
52 this.certificationProvider = certificationProvider;
55 public CertificationModel createCertificationModel(String encodedCsr, String encodedPrivateKey, String caName)
56 throws DecryptionException, CmpClientException {
57 CsrModel csrModel = csrModelFactory.createCsrModel(
58 new CsrModelFactory.StringBase64(encodedCsr),
59 new CsrModelFactory.StringBase64(encodedPrivateKey)
61 LOGGER.debug("Received CSR meta data: \n{}", csrModel);
63 Cmpv2Server cmpv2Server = cmpv2ServerProvider.getCmpv2Server(caName);
64 LOGGER.debug("Found server for given CA name: \n{}", cmpv2Server);
66 LOGGER.info("Sending sign request for certification model for CA named: {}, and certificate signing request:\n{}",
68 return certificationProvider.signCsr(csrModel, cmpv2Server);