Merge "Beautified source code of appfw/src/base/utility" into tizen_2.2
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_CertDbStore.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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  * @file                FSecCert_CertDbStore.h
19  * @brief               This header file contains the declarations of X509 Certificate Database.
20  *
21  * This header file contains the declarations of X509 Certificate Database.
22  */
23
24 #ifndef _FSEC_CERT_INTERNAL_CERT_DB_STORE_H_
25 #define _FSEC_CERT_INTERNAL_CERT_DB_STORE_H_
26
27 #include "FSecCert_CertTypes.h"
28 #include "FBaseString.h"
29 #include "FBaseByteBuffer.h"
30 #include "FBaseResult.h"
31
32 namespace Tizen { namespace Security { namespace Cert
33 {
34
35 struct CaCertRecord
36 {
37         int certId;
38         int certType;
39         int certFormat;
40         char fileName[_MAX_CERTIFICATE_PATH_SIZE];
41         int subjectNameLen;
42         char subjectName[_MAX_ISSUER_SUBJECT_NAME_SIZE];
43         int issuerNameLen;
44         char issuerName[_MAX_ISSUER_SUBJECT_NAME_SIZE];
45         int parentCa;
46         char installed[_MAX_TYPE_RECORD_SIZE];
47         char serialNo[_MAX_SERIAL_NUMBER_SIZE];
48         int serialNoLen;
49 }; //CaCertRecord
50
51 struct UserCertRecord
52 {
53         int certId;
54         char certPubKeyHash[_MAX_CERT_PUB_KEY_HASH_SIZE];
55         int certFormat;
56         char fileName[_MAX_CERTIFICATE_PATH_SIZE];
57         int subjectNameLen;
58         char subjectName[_MAX_ISSUER_SUBJECT_NAME_SIZE];
59         int issuerNameLen;
60         char issuerName[_MAX_ISSUER_SUBJECT_NAME_SIZE];
61         char prvKeyPath[_MAX_PRV_KEY_PATH_SIZE_SIZE];
62         int prvKeyLen;
63         int parentCa;
64         char installed[_MAX_TYPE_RECORD_SIZE];
65         char serialNo[_MAX_SERIAL_NUMBER_SIZE];
66         int serialNoLen;
67 }; //UserCertRecord
68
69 class _CertDbStore
70 {
71 public:
72         _CertDbStore(void);
73
74         virtual ~_CertDbStore(void);
75
76         virtual result RemoveCertificateById(int certId);
77
78         virtual result RemoveAllCertificates(void);
79
80         virtual result GetNumberOfCertificates(int& count);
81
82         result IsRootCaCertTableCreated(void);
83
84         result IsUserCertTableCreated(void);
85
86         result CreateCertificateTables(void);
87
88         result DropCertificateTables(void);
89
90         result DeleteCaCertFiles(void);
91
92         result DeleteUserCertFiles(void);
93
94 private:
95         _CertDbStore(const _CertDbStore& rhs);
96
97         _CertDbStore& operator =(const _CertDbStore& rhs);
98
99 private:
100         bool __rootCaCertTableCreated;
101         bool __userCertTableCreated;
102
103 }; //_CertDbStore
104
105 class _CaCertDbStore
106         : public _CertDbStore
107         , public Tizen::Base::Object
108 {
109 public:
110         _CaCertDbStore(void);
111
112         virtual ~_CaCertDbStore(void);
113
114         result RemoveCertificateById(int certId);
115
116         result RemoveAllCertificates(void);
117
118         result GetNumberOfCertificates(int& count);
119
120         result InsertCaCertificate(CaCertRecord* pCertRecord);
121
122         result UpdateCaCertificate(CaCertRecord* pCertRecord, CaCertRecord* pUpdateCertRecord);
123
124         result UpdateParentCa(int certId, int parentCa);
125
126         result RemoveCertificateBySubjectName(_CaCertType certType, byte* pSubjectName, int subjectNameLen);
127
128         result RemoveCertificateByIssuerNameAndSerialNo(_CaCertType certType, byte* pIssuerName, int issuerNameLen, byte* pSerialNo);
129
130         result RemoveAllCertificateByCondition(byte* pCondition);
131
132         result CheckDuplicateCertificate(_CaCertType certType, byte* pSubjectName, int subjectNameLen);
133
134         result CheckDuplicateCertificate(_CaCertType certType, byte* pIssuerName, int issuerNameLen, byte* pSerialNumber);
135
136         result GetFirstRecordByConditions(byte* pCondition, CaCertRecord* pCertRecord);
137
138         result GetNextRecordByCondition(byte* pCondition, CaCertRecord* pCertRecord, int curCertId);
139
140         result GetCurrentCertId(int& curCertId);
141
142         result CheckIfSameParent(int certId);
143
144         result SelectCaCertificateBycertId(int certId, CaCertRecord* pCertRecord);
145
146 private:
147         _CaCertDbStore(const _CaCertDbStore& rhs);
148
149         _CaCertDbStore& operator =(const _CaCertDbStore& rhs);
150
151 }; //_CaCertDbStore
152
153
154 class _UserCertDbStore
155         : public _CertDbStore
156         , public Tizen::Base::Object
157 {
158
159 public:
160         _UserCertDbStore(void);
161
162         virtual ~_UserCertDbStore(void);
163
164         result RemoveCertificateById(int certId);
165
166         result RemoveAllCertificates(void);
167
168         result GetNumberOfCertificates(int& count);
169
170         result InsertUserCertificate(UserCertRecord* pCertRecord);
171
172         result UpdateParentCa(int certId, int parentCa);
173
174         result UpdateRecordByCondition(byte* pCondition);
175
176         result RemoveCertificateByCondition(byte* pCondition);
177
178         result CheckDuplicateCertificate(byte* pSubjectName, int subjectNameLen);
179
180         result CheckDuplicateCertificate(byte* pIssuerName, int issuerNameLen, byte* pSerialNumber);
181
182         result GetFirstRecordByConditions(byte* pCondition, UserCertRecord* pCertRecord);
183
184         result GetNextRecordByCondition(byte* pCondition, UserCertRecord* pCertRecord, int curCertId);
185
186         result GetCurrentCertId(int& curCertId);
187
188         result GetCountByCondition(byte* pCondition, int& count);
189
190         result GetParentCaByCondition(byte* pCondition, int& parentCa);
191
192         result SelectUserCertificateBycertId(int certId, UserCertRecord* pCertRecord);
193
194 private:
195         _UserCertDbStore(const _UserCertDbStore& rhs);
196
197         _UserCertDbStore& operator =(const _UserCertDbStore& rhs);
198
199
200 }; //_UserCertDbStore
201
202 } } } //Tizen::Security::Cert
203
204 #endif // _FSEC_CERT_INTERNAL_CERT_DB_STORE_H_