5349a8dbbdabff6adf0a614accf1602f77b0e5df
[platform/core/security/security-manager.git] / wrt_ocsp / src / wrt_ocsp_api.cpp
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file        wrt_ocsp_api.cpp
18  * @author      Zofia Abramowska (z.abramowska@samsung.com)
19  * @version     1.0
20  * @brief       This file contains implementation of WRT OCSP api
21  */
22
23 #include <dpl/log/log.h>
24 #include <dpl/dbus/dbus_client.h>
25 #include "ocsp_server_api.h"
26 #include "security_daemon_dbus_config.h"
27
28 #include "wrt_ocsp_api.h"
29
30 static DPL::DBus::Client *dbusClient = NULL;
31
32 wrt_ocsp_return_t wrt_ocsp_initialize(void){
33   if (NULL != dbusClient) {
34     LogError("wrt_ocsp_api already initialized");
35     return WRT_OCSP_INTERNAL_ERROR;
36   }
37   Try {
38     dbusClient = new DPL::DBus::Client(
39       WrtSecurity::SecurityDaemonConfig::OBJECT_PATH(),
40       WrtSecurity::SecurityDaemonConfig::SERVICE_NAME(),
41       WrtSecurity::OcspServerApi::INTERFACE_NAME());
42
43   } Catch (DPL::DBus::Client::Exception::DBusClientException) {
44     LogError("Can't connect to daemon");
45     return WRT_OCSP_INTERNAL_ERROR;
46   }
47   LogInfo("Initialized");
48   return WRT_OCSP_OK;
49 }
50
51 wrt_ocsp_return_t wrt_ocsp_shutdown(void){
52   if (NULL == dbusClient) {
53     LogError("wrt_ocsp_api not initialized");
54     return WRT_OCSP_INTERNAL_ERROR;
55   }
56   delete dbusClient;
57   dbusClient = NULL;
58   LogInfo("Shutdown");
59   return WRT_OCSP_OK;
60 }
61
62 wrt_ocsp_return_t wrt_ocsp_verify_widget(wrt_ocsp_widget_handle_t handle,
63                                          wrt_ocsp_widget_verification_status_t* status){
64
65   if (NULL == status) {
66     LogError("Invalid arguments");
67     return WRT_OCSP_INVALID_ARGUMENTS;
68   }
69   int intResponse;
70   Try {
71   dbusClient->call(WrtSecurity::OcspServerApi::CHECK_ACCESS_METHOD(),
72     handle,
73     &intResponse);
74   } Catch (DPL::DBus::Client::Exception::DBusClientException){
75     LogError("Problem with connection to daemon");
76     return WRT_OCSP_INTERNAL_ERROR;
77   }
78   (*status) = static_cast<wrt_ocsp_widget_verification_status_t>(intResponse);
79   LogInfo("Widget verified with response " << intResponse);
80   return WRT_OCSP_OK;
81 }