Tizen 2.1 base
[framework/security/security-server.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 "SecurityCommunicationClient.h"
27
28 #include "wrt_ocsp_api.h"
29
30 static WrtSecurity::Communication::Client *communicationClient = NULL;
31
32 wrt_ocsp_return_t wrt_ocsp_initialize(void){
33     if (NULL != communicationClient) {
34         LogError("wrt_ocsp_api already initialized");
35         return WRT_OCSP_INTERNAL_ERROR;
36     }
37
38     Try {
39         communicationClient = new WrtSecurity::Communication::Client(WrtSecurity::OcspServerApi::INTERFACE_NAME());
40     } Catch (WrtSecurity::Communication::Client::Exception::SecurityCommunicationClientException) {
41         LogError("Can't connect to daemon");
42         return WRT_OCSP_INTERNAL_ERROR;
43     }
44     LogInfo("Initialized");
45     return WRT_OCSP_OK;
46 }
47
48 wrt_ocsp_return_t wrt_ocsp_shutdown(void){
49     if (NULL == communicationClient) {
50         LogError("wrt_ocsp_api not initialized");
51         return WRT_OCSP_INTERNAL_ERROR;
52     }
53     delete communicationClient;
54     communicationClient = NULL;
55     LogInfo("Shutdown");
56     return WRT_OCSP_OK;
57 }
58
59 wrt_ocsp_return_t wrt_ocsp_verify_widget(wrt_ocsp_widget_handle_t handle,
60                                          wrt_ocsp_widget_verification_status_t* status){
61
62     LogInfo("Verifying");
63     if (NULL == status) {
64         LogError("Invalid arguments");
65         return WRT_OCSP_INVALID_ARGUMENTS;
66     }
67     int intResponse;
68
69   Try {
70         communicationClient->call(WrtSecurity::OcspServerApi::CHECK_ACCESS_METHOD(),
71                                   handle,
72                                   &intResponse);
73     } Catch (WrtSecurity::Communication::Client::Exception::SecurityCommunicationClientException) {
74         LogError("Problem with connection to daemon");
75         return WRT_OCSP_INTERNAL_ERROR;
76   }
77     (*status) = static_cast<wrt_ocsp_widget_verification_status_t>(intResponse);
78     LogInfo("Widget verified with response " << intResponse);
79     return WRT_OCSP_OK;
80 }