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 SafeBuffer OCSPLogic::ocspCheck(int commandId, const SafeBufferVector &rawChain) {
35 CertificateImplVector certChain;
37 int retCode = CKM_API_SUCCESS;
38 int ocspStatus = CKM_API_OCSP_STATUS_INTERNAL_ERROR;
40 for (auto &e: rawChain) {
41 certChain.push_back(CertificateImpl(e, DataFormat::FORM_DER));
42 if (certChain.rbegin()->empty()) {
43 LogDebug("Error in parsing certificates!");
44 retCode = CKM_API_ERROR_INPUT_PARAM;
49 if (retCode == CKM_API_SUCCESS)
50 ocspStatus = ocsp.verify(certChain);
52 MessageBuffer response;
53 Serialization::Serialize(response, commandId);
54 Serialization::Serialize(response, retCode);
55 Serialization::Serialize(response, ocspStatus);
57 return response.Pop();