#include <ocsp-logic.h>
#include <ocsp.h>
+#include <system_info.h>
+
+#define FEATURE_WIFI "tizen.org/feature/network.internet"
+#define FEATURE_TELEPHONY "tizen.org/feature/network.telephony"
+#define FEATURE_TETHERING_BT "tizen.org/feature/network.tethering.bluetooth"
+#define FEATURE_ETHERNET "tizen.org/feature/network.ethernet"
+
namespace CKM {
+namespace {
+
+bool isFeatureOn(const char *feature)
+{
+ bool value = false;
+
+ if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(feature, &value)) {
+ // system info capi error.
+ return false;
+ }
+
+ return value;
+}
+
+} // namespace anonymous
+
+
+OCSPLogic::OCSPLogic()
+ : m_isNetAvailable(false)
+{
+ setNetAvailable();
+}
+
+void OCSPLogic::setNetAvailable()
+{
+ if (isFeatureOn(FEATURE_WIFI)
+ || isFeatureOn(FEATURE_TELEPHONY)
+ || isFeatureOn(FEATURE_TETHERING_BT)
+ || isFeatureOn(FEATURE_ETHERNET)) {
+ m_isNetAvailable = true;
+ }
+ else {
+ m_isNetAvailable = false;
+ }
+}
+
RawBuffer OCSPLogic::ocspCheck(int commandId, const RawBufferVector &rawChain) {
CertificateImplVector certChain;
OCSPModule ocsp;
int retCode = CKM_API_SUCCESS;
int ocspStatus = CKM_API_OCSP_STATUS_INTERNAL_ERROR;
- for (auto &e: rawChain) {
- certChain.push_back(CertificateImpl(e, DataFormat::FORM_DER));
- if (certChain.rbegin()->empty()) {
- LogDebug("Error in parsing certificates!");
- retCode = CKM_API_ERROR_INPUT_PARAM;
- break;
- }
+
+ if (!m_isNetAvailable) {
+ // try again for in case of system-info error
+ setNetAvailable();
+ }
+
+ if (!m_isNetAvailable) {
+ retCode = CKM_API_ERROR_NOT_SUPPORTED;
}
+ else {
+ for (auto &e: rawChain) {
+ certChain.push_back(CertificateImpl(e, DataFormat::FORM_DER));
+ if (certChain.rbegin()->empty()) {
+ LogDebug("Error in parsing certificates!");
+ retCode = CKM_API_ERROR_INPUT_PARAM;
+ break;
+ }
+ }
- if (retCode == CKM_API_SUCCESS)
- ocspStatus = ocsp.verify(certChain);
+ if (certChain.size() < 2)
+ retCode = CKM_API_ERROR_INPUT_PARAM;
+ else if (retCode == CKM_API_SUCCESS)
+ ocspStatus = ocsp.verify(certChain);
+ }
return MessageBuffer::Serialize(commandId, retCode, ocspStatus).Pop();
}