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