Implemented client-server model and changed code for thread safety
[platform/framework/native/appfw.git] / src / security / cert / FSecCert_Certificate.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_Certificate.h
20  * @brief       This header file contains the declarations of parsing class.
21  *
22  * This header file contains the declarations of parsing class.
23  */
24
25 #ifndef _FSEC_CERT_INTERNAL_CERTIFICATE_H_
26 #define _FSEC_CERT_INTERNAL_CERTIFICATE_H_
27
28 #include <unique_ptr.h>
29 #include <FBaseDateTime.h>
30 #include "FSecCert_CertExtension.h"
31 #include "FSecCert_CertSignature.h"
32 #include "FSecCert_CertTime.h"
33 #include "FSecCert_Asn1Parser.h"
34 #include "FSecCert_CertTypes.h"
35
36
37 namespace Tizen { namespace Security { namespace Cert
38 {
39
40 class _OSP_EXPORT_ _X509CertValidity
41 {
42 public:
43         _X509CertValidity(void);
44
45         _X509CertValidity(byte* pNotBefore, byte* pNotAfter);
46
47         virtual ~_X509CertValidity(void);
48
49         result GetValidity(Tizen::Base::DateTime& drmTime);
50
51         result SetTimes(byte* pNotBefore, byte* pNotAfter);
52
53         result GetBeforeTimes(Tizen::Base::DateTime& notBefore);
54
55         result GetAfterTimes(Tizen::Base::DateTime& notAfter);
56
57 private:
58         _X509CertValidity(const _X509CertValidity& rhs);
59
60         _X509CertValidity& operator =(const _X509CertValidity& rhs);
61
62 private:
63         _CertTime __notBefore;
64         _CertTime __notAfter;
65
66 }; //_X509CertValidity
67
68 class _OSP_EXPORT_ _X509CertSubPublicKeyInfo
69 {
70 public:
71         _X509CertSubPublicKeyInfo(void);
72
73         _X509CertSubPublicKeyInfo(const char* pAlg, int keyLen, byte* pPubKey);
74
75         virtual ~_X509CertSubPublicKeyInfo(void);
76
77         result GetPubKeyN(int& keyLen, byte** ppPubKey);
78
79         result SetPubKey(int keyLen, byte* pPubKey);
80
81         char* GetPubKeyAlgoId(void);
82
83         result SetPubKeyAlgoId(const char* pPubKeyAlgoId);
84
85 private:
86         _X509CertSubPublicKeyInfo(const _X509CertSubPublicKeyInfo& rhs);
87
88         _X509CertSubPublicKeyInfo& operator =(const _X509CertSubPublicKeyInfo& rhs);
89
90 private:
91         std::unique_ptr< char[] > __pPubKeyAlg;
92         std::unique_ptr< byte[] > __publicKey;
93         int __publicKeySize;
94
95 }; //_X509CertSubPublicKeyInfo
96
97 class _OSP_EXPORT_ _X509TbsCert
98 {
99 public:
100         _X509TbsCert(void);
101
102         virtual ~_X509TbsCert(void);
103
104         void SetVersion(byte* pVersion, int len);
105
106         void SetVersion(int version);
107
108         int GetVersion(void);
109
110         void SetSerialNumber(byte* pSerial, int len);
111
112         result GetSerialNumber(byte*& pSerial, int& len);
113
114         result SetSignatureAlgoId(const char* pAlgoId);
115
116         char* GetSignatureAlgoId(void);
117
118         result SetIssuerName(byte* pName);
119
120         byte* GetIssuerName(void);
121
122         result SetValidity(byte* pNotBefore, byte* pNotAfter);
123
124         result GetValidity(void);
125
126         result GetBeforeTimes(Tizen::Base::DateTime& notBefore);
127
128         result GetAfterTimes(Tizen::Base::DateTime& notAfter);
129
130         result SetSubjectName(byte* pName);
131
132         byte* GetSubjectName(void);
133
134         result SetPublicKeyInfo(int keyLen, byte* pPubKey);
135
136         result GetPublicKeyInfoN(int& keyLen, byte** ppPubKey);
137
138         char* GetPublicKeyAlgoIdInfo(void);
139
140         result SetPublicKeyAlgoIdInfo(const char* pPubKeyAlgoId);
141
142         result AddExtension(byte* pOid, bool critical, byte* pValue, int len);
143
144         _CertExtension* GetCertExtension(void);
145
146 private:
147         _X509TbsCert(const _X509TbsCert& rhs);
148
149         _X509TbsCert& operator =(const _X509TbsCert& rhs);
150
151 private:
152         int __version;
153         int __serialNumberLen;
154         byte __serialNumber[_MAX_SERIAL_NUMBER_SIZE];
155         std::unique_ptr< byte[] > __pIssuer;
156         std::unique_ptr< byte[] > __pSubject;
157         std::unique_ptr< char[] > __pSignatureAlgoId;
158         _CertExtension __extension;
159         _X509CertSubPublicKeyInfo __subPubKeyInfo;
160         _X509CertValidity __validity;
161
162 }; //_X509TbsCert
163
164 class _OSP_EXPORT_ _Certificate
165         : public _Asn1Parser
166 {
167 public:
168         _Certificate(void);
169
170         virtual ~_Certificate(void);
171
172         result ParseObject(void);
173
174         virtual result GetKeyIdN(byte** ppKeyid);
175
176         virtual bool IsSelfSigned(void);
177
178         _Certificate* GetNextEntry(void);
179
180         void SetCertFormat(_CertFormat certFormat);
181
182         _CertFormat GetCertFormat(void);
183
184 private:
185         _Certificate(const _Certificate& rhs);
186
187         _Certificate& operator =(const _Certificate& rhs);
188
189 private:
190         _CertFormat __certFormat;
191
192 }; //_Certificate
193
194 class _OSP_EXPORT_ _X509Certificate
195         : public _Certificate
196 {
197 public:
198         _X509Certificate(void);
199
200         virtual ~_X509Certificate(void);
201
202         result ParseObject(void);
203
204         _X509TbsCert* GetTbsCertInstance(void);
205
206         _CertSignature* GetSignInstance(void);
207
208         result GetKeyIdN(byte** ppKeyid);
209
210         bool IsSelfSigned(void);
211
212         bool IsContextCertificate(void);
213
214         void SetContextCertificate(bool contextCert);
215
216         result GetCertBuffer(byte*& pBuf, int& bufSize);
217
218         result GetIssuerBuffer(byte*& pBuf, int& bufSize);
219
220         result GetSubjectNameBuffer(byte*& pBuf, int& bufSize);
221
222         result VerifySignature(byte* pPublicKey, int keySize);
223
224         bool IsCaCertificate();
225
226         _X509Certificate* GetNextEntry(void);
227
228         bool IsIssuer(_X509Certificate* pCertIssuer);
229
230         void* GetX509CertObject();
231
232 private:
233         _X509Certificate(const _X509Certificate& rhs);
234
235         _X509Certificate& operator =(const _X509Certificate& rhs);
236
237         result ParseRun(void);
238
239         result ParseTbsCertHeader(void);
240
241         result ParseVersion(void);
242
243         result ParseSerialNumber(void);
244
245         result ParseAlgorithmIdentifier(void);
246
247         result ParseIssuerName(void);
248
249         result ParseValidity(void);
250
251         result ParseSubjectName(void);
252
253         result ParseSubjectPublicKeyInfo(void);
254
255         result ParseExtensions(void);
256
257         result ParseSignature(void);
258
259 private:
260         bool __contextCert;
261         bool __isCaCert;
262         bool __x509IsSelfSign;
263         void* __pX509Certificate;
264         _X509TbsCert __tbsCert;
265         _CertSignature __signautreInfo;
266
267 }; //_X509Certificate
268
269 } } } //Tizen::Security::Cert
270
271 #endif // _FSEC_CERT_INTERNAL_CERTIFICATE_H_