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.DecryptionException;
26 import org.onap.aaf.certservice.certification.model.CertificationModel;
27 import org.onap.aaf.certservice.certification.model.CsrModel;
28 import org.onap.aaf.certservice.cmpv2client.exceptions.CmpClientException;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Service;
35 public class CertificationModelFactory {
37 private static final Logger LOGGER = LoggerFactory.getLogger(CertificationModelFactory.class);
39 private final CsrModelFactory csrModelFactory;
40 private final Cmpv2ServerProvider cmpv2ServerProvider;
41 private final CertificationProvider certificationProvider;
44 CertificationModelFactory(
45 CsrModelFactory csrModelFactory,
46 Cmpv2ServerProvider cmpv2ServerProvider,
47 CertificationProvider certificationProvider
49 this.cmpv2ServerProvider = cmpv2ServerProvider;
50 this.csrModelFactory = csrModelFactory;
51 this.certificationProvider = certificationProvider;
54 public CertificationModel createCertificationModel(String encodedCsr, String encodedPrivateKey, String caName)
55 throws DecryptionException, CmpClientException {
56 CsrModel csrModel = csrModelFactory.createCsrModel(
57 new CsrModelFactory.StringBase64(encodedCsr),
58 new CsrModelFactory.StringBase64(encodedPrivateKey)
60 LOGGER.debug("Received CSR meta data: \n{}", csrModel);
62 Cmpv2Server cmpv2Server = cmpv2ServerProvider.getCmpv2Server(caName);
63 LOGGER.debug("Found server for given CA name: \n{}", cmpv2Server);
65 LOGGER.info("Sending sign request for certification model for CA named: {}, and certificate signing request:\n{}",
67 return certificationProvider.signCsr(csrModel, cmpv2Server);