2 * Copyright (c) 2014 Samsung Electronics Co.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
17 * @file ocsp-logic.cpp
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief OCSP logic implementation.
22 #include <ckm/ckm-error.h>
24 #include <dpl/log/log.h>
25 #include <dpl/serialization.h>
27 #include <message-buffer.h>
29 #include <ocsp-logic.h>
34 RawBuffer OCSPLogic::ocspCheck(int commandId, const RawBufferVector &rawChain) {
35 CertificateImplVector certChain;
37 int retCode = CKM_API_SUCCESS;
38 int ocspStatus = CKM_API_OCSP_STATUS_INTERNAL_ERROR;
40 if(rawChain.size() < 2) {
41 LogError("Certificate chain should contain at least 2 certificates");
42 retCode = CKM_API_ERROR_INPUT_PARAM;
44 for (auto &e: rawChain) {
45 certChain.push_back(CertificateImpl(e, DataFormat::FORM_DER));
46 if (certChain.rbegin()->empty()) {
47 LogDebug("Error in parsing certificates!");
48 retCode = CKM_API_ERROR_INPUT_PARAM;
54 if (retCode == CKM_API_SUCCESS)
55 ocspStatus = ocsp.verify(certChain);
57 return MessageBuffer::Serialize(commandId, retCode, ocspStatus).Pop();