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>
32 #include <system_info.h>
34 #define FEATURE_WIFI "tizen.org/feature/network.internet"
35 #define FEATURE_TELEPHONY "tizen.org/feature/network.telephony"
36 #define FEATURE_TETHERING_BT "tizen.org/feature/network.tethering.bluetooth"
37 #define FEATURE_ETHERNET "tizen.org/feature/network.ethernet"
43 bool isFeatureOn(const char *feature)
47 if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(feature, &value)) {
48 // system info capi error.
55 } // namespace anonymous
58 OCSPLogic::OCSPLogic()
59 : m_isNetAvailable(false)
64 void OCSPLogic::setNetAvailable()
66 if (isFeatureOn(FEATURE_WIFI)
67 || isFeatureOn(FEATURE_TELEPHONY)
68 || isFeatureOn(FEATURE_TETHERING_BT)
69 || isFeatureOn(FEATURE_ETHERNET)) {
70 m_isNetAvailable = true;
73 m_isNetAvailable = false;
77 RawBuffer OCSPLogic::ocspCheck(int commandId, const RawBufferVector &rawChain) {
78 CertificateImplVector certChain;
80 int retCode = CKM_API_SUCCESS;
81 int ocspStatus = CKM_API_OCSP_STATUS_INTERNAL_ERROR;
84 if (!m_isNetAvailable) {
85 // try again for in case of system-info error
89 if (!m_isNetAvailable) {
90 retCode = CKM_API_ERROR_NOT_SUPPORTED;
93 for (auto &e: rawChain) {
94 certChain.push_back(CertificateImpl(e, DataFormat::FORM_DER));
95 if (certChain.rbegin()->empty()) {
96 LogDebug("Error in parsing certificates!");
97 retCode = CKM_API_ERROR_INPUT_PARAM;
102 if (certChain.size() < 2)
103 retCode = CKM_API_ERROR_INPUT_PARAM;
104 else if (retCode == CKM_API_SUCCESS)
105 ocspStatus = ocsp.verify(certChain);
108 return MessageBuffer::Serialize(commandId, retCode, ocspStatus).Pop();