Implemented client-server model and changed code for thread safety
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_CertDbManager.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_CertDbManager.h
20  * @brief               This header file contains the declarations of X509 Certificate interface layer.
21  *
22  * This header file contains the declarations of X509 Certificate interface layer.
23  */
24
25 #ifndef _FSEC_CERT_INTERNAL_CERT_DB_MANAGER_H_
26 #define _FSEC_CERT_INTERNAL_CERT_DB_MANAGER_H_
27
28 #include "FSecCert_CertTypes.h"
29 #include "FSecCert_CertDbStore.h"
30 #include "FSecCert_CertChain.h"
31 #include "FSecCert_CertPrivateKeyInfo.h"
32
33 namespace Tizen { namespace Security { namespace Cert
34 {
35
36 class _OSP_EXPORT_ _CertDbManager
37 {
38 public:
39         static _CertDbManager* GetInstance(void);
40
41         bool IsCertificateTablesCreated(void);
42
43         result RemoveCaCertificateByType(_CaCertType certType);
44
45         result RemoveUserCaCertificateByCertId(int certId);
46
47         result RemoveAllUserCertificate(void);
48
49         result CreateCertificateTables(void);
50
51         result ResetCertificateTables(void);
52
53         result RemoveCertificateTables(void);
54
55         result RemoveCertificateChainByCertId(int certId);
56
57         result InsertDefaultCaCertificateFromBuffer(_CaCertType certType, _CertFormat certFormat, byte* pCertBuf, int certLen);
58
59         result InsertCaCertificateFromBuffer(_CaCertType certType, _CertFormat certFormat, byte* pCertBuf, int certLen, bool checkValidity = true);
60
61         result UpdateCaCertificateFromBuffer(_CaCertType certType, _CertFormat certFormat, byte* pCurCertBuf, int curCertLen, byte* pNewCertBuf, int newCertLen);
62
63         result RemoveCaCertificateFromBuffer(_CaCertType certType, _CertFormat certFormat, byte* pCertBuf, int certLen);
64
65         result GetCaCertificateId(byte* pSubjectName, int subjectNameSize, byte* pIssuerName, int issuerNameSize, int& certId, _CaCertType certType = _CERT_TYPE_NOT_BOUNDED);
66
67         result GetUserCertificateId(byte* pSubjectName, int subjectNameSize, byte* pIssuerName, int issuerNameSize, int& certId);
68
69         result GetCertificateListByFormat(_CertFormat certFormat, _CertificateListInfo** ppCertList, int& count);
70
71         result GetUserCertificateListByFormat(_CertFormat certFormat, _CertificateListInfo** ppCertList, int& count);
72
73         result GetCaCertificateListByCertId(int certId, _CertificateListInfo** ppCertList);
74
75         result FindIssuerCertificateAndTypeN(_CertFormat certFormat, char* pIssuerName, byte** ppCert, int& certLen, _CaCertType& certType);
76
77         result FindIssuerCertificateByTypeN(_CertFormat certFormat, _CaCertType certType, char* pIssuerName, byte** ppCert, int& certLen);
78
79         result FindCertType(_CertFormat certFormat, char* pIssuerName, char* pSubjectName, _CaCertType* pCertType);
80
81         result GetUserCertificateListByCertId(int certId, _CertificateListInfo** ppCertList);
82
83         result GetHashOfCertFile(byte* pFilePath, int* pLen, char* pBuf);
84
85         result InsertCertChain(_CertFormat certFormat, _CertChain* pCertChain);
86
87         result InsertCertificateChain(_CertFormat certFormat, _CertChain* pCertChain, _CertPrivateKeyInfo* pPrivateKeyInfo = null);
88
89         result InsertUserCertificateFromBuffer(_CertFormat certFormat, byte* pCertBuffer, int certLength, byte* pPrivateKey, int privateKeyLen, int parentCa = 0);
90
91         result GetUserCertificateChain(char* pIssuerName, int issuerNameLen, char* pSubjectName, int subjectNameLen, _CertEncodingType encodingType, _CertificateListInfo** ppCertListInfoTypes);
92
93         result GetUserCertificateChain(_CertFormat certFormat, _CertChain* pCertChain, _CertPrivateKeyInfo* pPrivateKeyInfo, char* pSubjectName = null);
94
95         result GetUserCertificateInfoByCertId(int pCertId, int* pSubjectLength, byte* pSubjectName, int* pIssuerLength, byte* pIssuerName);
96
97         result GetUserCertificateInfoByCertId(int certId, _CertEncodingType encodingType, _CertInfo** ppUserCertInfo);
98
99 private:
100         result DeleteCertificateChain(int devCertId, int devParentCa);
101
102         result DeleteCertificateByIdNTableName(int certId, Tizen::Base::String tableName);
103
104         _CertDbManager(void);
105
106         virtual ~_CertDbManager(void);
107
108         _CertDbManager(const _CertDbManager& rhs);
109
110         _CertDbManager& operator =(const _CertDbManager& rhs);
111
112         static void Construct(void);
113
114
115 private:
116         _CaCertDbStore __caCertDbStore;
117         _UserCertDbStore __userCertDbStore;
118
119         static _CertDbManager* __pCertDb;
120
121 }; // _CertDbManager
122
123 } } } //Tizen::Security::Cert
124
125 #endif // _FSEC_CERT_INTERNAL_CERT_DB_MANAGER_H_