Tizen 2.1 base
[framework/web/wrt-commons.git] / modules / vcore / src / vcore / CertificateCacheDAO.h
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  *
18  *
19  * @file       CertificateCacheDAO.h
20  * @author     Tomasz Swierczek (t.swierczek@samsung.com)
21  * @version    0.1
22  * @brief      Header file for class managing CRL and OCSP cached responses
23  */
24
25 #ifndef _WRT_SRC_CONFIGURATION_CERTIFICATE_CACHE_DAO_H_
26 #define _WRT_SRC_CONFIGURATION_CERTIFICATE_CACHE_DAO_H_
27
28 #include <string>
29 #include <list>
30
31 #include <dpl/exception.h>
32
33 #include "VerificationStatus.h"
34
35 namespace ValidationCore {
36
37 struct OCSPCachedStatus
38 {
39     std::string cert_chain;
40     VerificationStatus ocsp_status;
41     bool end_entity_check;
42     time_t next_update_time;
43 };
44
45 typedef std::list<OCSPCachedStatus> OCSPCachedStatusList;
46
47 struct CRLCachedData
48 {
49     std::string distribution_point;
50     std::string crl_body;
51     time_t next_update_time;
52 };
53
54 typedef std::list<CRLCachedData> CRLCachedDataList;
55
56 class CertificateCacheDAO {
57   public:
58     class Exception
59     {
60       public:
61         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
62         DECLARE_EXCEPTION_TYPE(Base, DatabaseError)
63     };
64
65     // OCSP statuses
66
67     static void setOCSPStatus(const std::string& cert_chain,
68                               VerificationStatus ocsp_status,
69                               bool end_entity_check,
70                               time_t next_update_time);
71
72     /*
73      * fill cert_chain and end_entity_check in cached_status
74      * returns true iff cached status found without errors
75      */
76     static bool getOCSPStatus(OCSPCachedStatus* cached_status);
77     static void getOCSPStatusList(OCSPCachedStatusList* cached_status_list);
78
79     // CRL responses
80
81     static void setCRLResponse(const std::string& distribution_point,
82                                const std::string& crl_body,
83                                time_t next_update_time);
84
85     /*
86      * fill distribution_point
87      * returns true iff cached list for dist. point found without errors
88      */
89     static bool getCRLResponse(CRLCachedData* cached_data);
90     static void getCRLResponseList(CRLCachedDataList* cached_data_list);
91
92
93     // clears CRL and OCSP cached data
94     static void clearCertificateCache();
95
96   private:
97
98     static VerificationStatus intToVerificationStatus(int p);
99
100     CertificateCacheDAO()
101     {
102     }
103 };
104
105 } // namespace ValidationCore
106
107 #endif /* _WRT_SRC_CONFIGURATION_CERTIFICATE_CACHE_DAO_H_ */