e171929083621911a7cee586394eaa6f57fc0f1e
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_X509CertificateStoreImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FSecCert_X509CertificateStoreImpl.h
20  * @brief               This is the header file for the %_X509CertificateStoreImpl class.
21  *
22  * This header file contains the declarations of the %_X509CertificateStoreImpl class.
23  */
24 #ifndef _FSEC_CERT_INTERNAL_X509_CERTIFICATE_STORE_H_
25 #define _FSEC_CERT_INTERNAL_X509_CERTIFICATE_STORE_H_
26
27 #include <FBaseString.h>
28 #include <FBaseByteBuffer.h>
29 #include <FSecIPrivateKey.h>
30 #include <FSecCertICertificateStore.h>
31 #include <FSecCertICertificateSelector.h>
32 #include <FSecCertX509CertificateStore.h>
33
34 namespace Tizen { namespace Security { namespace Cert
35 {
36
37 class _CertServiceProxy;
38 /**
39  * @brief       This class is used for retrieving and managing certificates from a repository.
40  * @since 2.1
41  *
42  * The %_X509CertificateStoreImpl class is used for retrieving and managing certificates from a repository.
43  */
44 class _X509CertificateStoreImpl
45 {
46
47 public:
48         /**
49          *      This is the default constructor for this class.
50          *
51          *      @since 2.1
52          */
53         _X509CertificateStoreImpl(void);
54
55         /**
56          *      This is the destructor for this class.
57          *
58          *      @since 2.1
59          */
60         virtual ~_X509CertificateStoreImpl(void);
61
62         /**
63          *  Gets the name of the current certificate store.
64          *
65          *      @since 2.1
66          *
67          *      @return                 An error code
68          *      @param[out]             name                    The name of the certificate store
69          *      @exception              E_SUCCESS               The method is successful.
70          */
71         result GetName(Tizen::Base::String& name) const;
72
73         /**
74          *      Sets a list of certificates that match the specified selector.
75          *
76          *      @since 2.1
77          *
78          *      @return                 An error code
79          *      @param[in]              selector                                A selector that defines a set of criterion for selecting certificates
80          *      @exception              E_SUCCESS                               The method is successful.
81          *      @exception              E_OUT_OF_MEMORY                 The memory is insufficient.
82          *      @exception              E_SYSTEM                                A system error has occurred.
83          *                                                                                      - IPC operation failed.
84          *      @exception              E_INVALID_ARG                   The specified @c selector is invalid.
85          *      @exception              E_UNSUPPORTED_OPERATION The type of selector is invalid.
86          * @endif
87          */
88         result SetCertificateSelector(const Tizen::Security::Cert::ICertificateSelector& selector);
89
90         /**
91          *      Gets a count of certificates that match the specified selector.
92          *
93          *      @since 2.1
94          *
95          *      @return                 An error code
96          *  @param[out]         count                   The count of certificates
97          *      @exception              E_SUCCESS               The method is successful.
98          */
99         result GetCertificateCount(int& count) const;
100
101         /**
102          *      Gets each certificate that matches the specified selector.
103          *
104          *      @since 2.1
105          *
106          *      @return                 The certificates that matches the specified selector
107          *      @exception              E_SUCCESS                       The method is successful.
108          *      @exception              E_OUT_OF_MEMORY         The memory is insufficient.
109          *      @exception              E_OBJ_NOT_FOUND         The certificate is not found.
110          *      @exception              E_SYSTEM                        A system error has occurred.
111          *                                                                              - ByteBuffer operation failed.
112          */
113         Tizen::Security::Cert::ICertificate* GetNextCertificateN(void) const;
114
115         /**
116          *  Inserts the certificate into the certificate store.
117          *
118          *      @since 2.1
119          *
120          *      @return                 An error code
121          *  @param[in]          certificateType         The type of the Certificate (ROOT_CA, OPERATOR_DOMAIN, or TRUSTED_THIRD_PARTY_DOMAIN)
122          *  @param[in]          certificate                     A reference to the certificate to insert
123          *      @exception              E_SUCCESS                       The method is successful.
124          *      @exception              E_OUT_OF_MEMORY         The memory is insufficient.
125          *      @exception              E_INVALID_ARG           The specified @c certificate or the certificate data is invalid,
126          *                                                                              or the specified @c certificateType is invalid.
127          *      @exception              E_SYSTEM                        A system error has occurred.
128          *                                                                              - IPC operation failed.
129          *                                                                              - File operation failed.
130          *                                                                              - DB operation failed.
131          */
132         result Insert(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& certificate);
133
134         /**
135          *  Inserts the user certificate of Pkcs 12 format into the certificate store.
136          *
137          *      @since 2.1
138          *
139          *      @return                 An error code
140          *  @param[in]          filePath                        The file path of pkcs 12 certificate to insert.
141          *  @param[in]          password                        Password string to decrypt pkcs 12 certificate.
142          *      @exception              E_SUCCESS                       The method is successful.
143          *      @exception              E_OUT_OF_MEMORY         The memory is insufficient.
144          *      @exception              E_INVALID_ARG           The specified @c certificate or the certificate data is invalid.
145          *      @exception              E_SYSTEM                        A system error has occurred.
146          *                                                                              - IPC operation failed.
147          *                                                                              - File operation failed.
148          *                                                                              - DB operation failed.
149          */
150         result InsertPkcs12(const Tizen::Base::String& filePath, const Tizen::Base::String& password);
151
152         /**
153          *  Updates the certificate in the certificate store.
154          *
155          *      @since 2.1
156          *
157          *      @return                 An error code
158          *  @param[in]          certificateType         The type of the Certificate (ROOT_CA, OPERATOR_DOMAIN, or TRUSTED_THIRD_PARTY_DOMAIN)
159          *  @param[in]          oldCert                         A reference to the old certificate
160          *  @param[in]          newCert                         A reference to the new certificate
161          *      @exception              E_SUCCESS                       The method is successful.
162          *      @exception              E_OUT_OF_MEMORY         The memory is insufficient.
163          *      @exception              E_INVALID_ARG           The specified @c certificate or the certificate data is invalid,
164          *                                                                              or the specified @c certificateType is invalid.
165          *      @exception              E_OBJ_NOT_FOUND         The certificate is not found.
166          *      @exception              E_SYSTEM                        A system error has occurred.
167          *                                                                              - IPC operation failed.
168          *                                                                              - File operation failed.
169          *                                                                              - DB operation failed.
170          */
171         result Update(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& oldCert, const Tizen::Security::Cert::ICertificate& newCert);
172
173         /**
174          *  Removes the certificate from the certificate store.
175          *
176          *      @since 2.1
177          *
178          *      @return                 An error code
179          *  @param[in]          certificateType         The type of the Certificate (ROOT_CA, OPERATOR_DOMAIN, TRUSTED_THIRD_PARTY_DOMAIN)
180          *  @param[in]          certificate                     A reference to the certificate to remove
181          *      @exception              E_SUCCESS                       The method is successful.
182          *      @exception              E_OUT_OF_MEMORY         The memory is insufficient.
183          *      @exception              E_INVALID_ARG           The specified @c certificate or the certificate data is invalid,
184          *                                                                              or the specified @c certificateType is invalid.
185          *      @exception              E_OBJ_NOT_FOUND         The certificate is not found.
186          *      @exception              E_SYSTEM                        A system error has occurred.
187          *                                                                              - IPC operation failed.
188          *                                                                              - File operation failed.
189          *                                                                              - DB operation failed.
190          */
191         result Remove(CertificateType certificateType, const Tizen::Security::Cert::ICertificate& certificate);
192
193         static _X509CertificateStoreImpl* GetInstance(X509CertificateStore& x509CertificateStore);
194         static const _X509CertificateStoreImpl* GetInstance(const X509CertificateStore& x509CertificateStore);
195
196 private:
197         result UpdateCertStoreContext(void);  
198         _X509CertificateStoreImpl(const _X509CertificateStoreImpl& rhs);
199         _X509CertificateStoreImpl& operator =(const _X509CertificateStoreImpl& rhs);
200
201 private:
202         int __certType;
203         int __certificateStoreCtx;
204         _CertServiceProxy* __pCertServiceProxy;
205         friend class X509CertificateStore;
206 }; //X509CertificateStoreImpl
207
208 } } } //Tizen::Security::Cert
209
210 #endif //_FSEC_CERT_INTERNAL_X509_CERTIFICATE_STORE_H_