840a51d9378ba6a5b85e3ea32545b363deb92888
[platform/framework/web/wrt-security.git] / src / services / vcore_service.cpp
1 /*
2  * Copyright (c) 2011 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        vcore_service.cpp
18  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @version     1.0
20  * @brief       This is implementation file of VCoreService service
21  */
22
23 #include <dpl/log/log.h>
24 #include <dpl/event/controller.h>
25 #include <dpl/generic_event.h>
26 #include <string>
27 #include <list>
28
29 #include <vcore/VCore.h>
30 #include <vcore/CachedOCSP.h>
31 #include <vcore/CachedCRL.h>
32 #include <dpl/wrt-dao-ro/global_config.h>
33
34 #include "security_daemon.h"
35
36 namespace VCoreService {
37 DECLARE_GENERIC_EVENT_0(UpdateCacheTimeReachedEvent)
38 using namespace ValidationCore;
39
40 class VCoreService : public SecurityDaemon::DaemonService,
41     DPL::Event::Controller<DPL::TypeListDecl<UpdateCacheTimeReachedEvent>::Type>
42 {
43   public:
44     VCoreService() :
45         m_ignoreFurtherCacheUpdates(false),
46         m_timespan(static_cast<double>(CachedOCSP::OCSP_minTimeValid))
47     {
48         Touch();
49     }
50
51   private:
52     virtual void initialize()
53     {
54         using namespace WrtDB;
55         LogDebug("VCoreService initializing");
56         ValidationCore::AttachToThread();
57         ValidationCore::VCoreInit(
58             std::string(GlobalConfig::GetFingerprintListFile()),
59             std::string(GlobalConfig::GetFingerprintListSchema()),
60             std::string(GlobalConfig::GetVCoreDatabaseFilePath()));
61     }
62
63     virtual void start()
64     {
65         LogDebug("Starting VCoreService");
66         OnEventReceived(UpdateCacheTimeReachedEvent());
67     }
68
69     virtual void stop()
70     {
71         LogDebug("Stopping VCoreService");
72         m_ignoreFurtherCacheUpdates = true;
73     }
74
75     virtual void deinitialize()
76     {
77         LogDebug("VCoreService deinitializing");
78     }
79
80     void OnEventReceived(const UpdateCacheTimeReachedEvent& /*event*/)
81     {
82         if (m_ignoreFurtherCacheUpdates) return;
83
84         this->PostTimedEvent(UpdateCacheTimeReachedEvent(), m_timespan);
85
86         LogDebug("calling ocsp module to cache update ...");
87         m_ocspCache.updateCache();
88         LogDebug("calling crl module to cache update ...");
89         m_crlCache.updateCache();
90     }
91
92     CachedOCSP m_ocspCache;
93     CachedCRL m_crlCache;
94     bool m_ignoreFurtherCacheUpdates;
95
96     const double m_timespan;
97 };
98
99 DAEMON_REGISTER_SERVICE_MODULE(VCoreService)
100
101 }//namespace VCoreService
102