Apply reviewed doxygen header
[platform/framework/native/appfw.git] / inc / FSecCertX509Certificate.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                FSecCertX509Certificate.h
19  * @brief               This is the header file for the %X509Certificate class.
20  *
21  * This header file contains the declarations of the %X509Certificate class.
22  */
23 #ifndef _FSEC_CERT_X509_CERTIFICATE_H_
24 #define _FSEC_CERT_X509_CERTIFICATE_H_
25
26 #include <FBase.h>
27 #include <FSecCertICertificate.h>
28
29 namespace Tizen { namespace Security { namespace Cert
30 {
31
32 /**
33  * @class       X509Certificate
34  * @brief       This class provides methods for managing identity certificates.
35  *
36  * @since       2.0
37  *
38  * The %X509Certificate class provides methods for managing identity certificates. @n
39  *
40  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/certificate_namespace.htm">Certificates</a>.
41  *
42  * @see         ICertificate
43  */
44 class _OSP_EXPORT_ X509Certificate
45         : public virtual ICertificate
46         , public Tizen::Base::Object
47 {
48
49 public:
50         /**
51          * This is the default constructor for this class.
52          *
53          * @since               2.0
54          */
55         X509Certificate(void);
56
57         /**
58          * This is the destructor for this class.
59          *
60          * @since               2.0
61          */
62         virtual ~X509Certificate(void);
63
64         /**
65          * Initializes this instance of %X509Certificate with the specified input buffer.
66          *
67          * @since               2.0
68          *
69          * @return              An error code
70          * @param[in]   input                           An instance of Tizen::Base::ByteBuffer
71          * @exception   E_SUCCESS                       The method is successful.
72          * @exception   E_INVALID_ARG           The specified input parameter is invalid.
73          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
74          *                                                                      - A system error has occurred.
75          *                                                                      - The Tizen::Base::ByteBuffer operation has failed.
76          */
77         result Construct(const Tizen::Base::ByteBuffer& input);
78
79         /**
80          * Gets the format of this certificate.
81          *
82          * @since               2.0
83          *
84          * @return              The certificate format
85          */
86         virtual Tizen::Base::String GetFormat(void) const;
87
88         /**
89          * Gets the certificate type.
90          *
91          * @since               2.0
92          *
93          * @return              The certificate type
94          * @exception   E_SUCCESS                       The method is successful.
95          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
96          *                                                                      - A system error has occurred.
97          *                                                                      - The certificate link list operation has failed.
98          * @remarks             The specific error code can be accessed using the GetLastResult() method.
99          */
100         virtual CertificateType GetType(void) const;
101
102         /**
103          * Gets the encoded form of the certificate. @n
104          * It is assumed that each certificate type will have only a single form of encoding. For example, X.509 certificates will 
105          * be encoded as ASN.1 DER.
106          *
107          * @since               2.0
108          *
109          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
110          *                              else @c null if an error occurs
111          * @exception   E_SUCCESS                       The method is successful.
112          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
113          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
114          *                                                                      - A system error has occurred.
115          *                                                                      - The certificate link list operation has failed.
116          *                                                                      - The Tizen::Base::ByteBuffer operation has failed.
117          * @remarks             The specific error code can be accessed using the GetLastResult() method.
118          */
119         virtual Tizen::Base::ByteBuffer* GetEncodedDataN(void) const;
120
121         /**
122          * Gets the fingerprint of the certificate. @n
123          * It is the hash value of the encoding of the certificate.
124          *
125          * @since               2.0
126          *
127          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
128          *                              else @c null if an error occurs
129          * @exception   E_SUCCESS                       The method is successful.
130          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
131          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
132          *                                                                      - A system error has occurred. 
133          *                                                                      - The certificate parsing operation has failed.
134          *                                                                      - The Tizen::Base::ByteBuffer operation has failed.
135          * @remarks             The specific error code can be accessed using the GetLastResult() method.
136          */
137         virtual Tizen::Base::ByteBuffer* GetFingerprintN(void) const;
138
139         /**
140          * Verifies whether the certificate is signed using the private key that corresponds to the specified public key.
141          *
142          * @since               2.0
143          *
144          * @return              @c true if the certificate is signed using the private key that corresponds to the specified public key, @n
145          *                              else @c false
146          * @param[in]   publicKey                       A reference to IPublicKey
147          * @exception   E_SUCCESS                       The method is successful.
148          * @exception   E_INVALID_ARG           The specified @c publicKey is invalid or empty.
149          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
150          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
151          *                                                      - A system error has occurred.
152          *                                                      - The certificate parsing operation has failed.
153          * @remarks             The specific error code can be accessed using the GetLastResult() method.
154          */
155         virtual bool Verify(const Tizen::Security::IPublicKey& publicKey);
156
157         /**
158          * Gets the public key of this certificate.
159          *
160          * @since               2.0
161          *
162          * @return              A pointer to IPublicKey, @n
163          *                              else @c null if an error occurs
164          * @exception   E_SUCCESS                       The method is successful.
165          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
166          * @exception   E_KEY_NOT_FOUND         The key is not found.
167          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
168          *                                                                      - A system error has occurred.
169          *                                                                      - The Tizen::Base::ByteBuffer operation has failed.
170          * @remarks             The specific error code can be accessed using the GetLastResult() method.
171          */
172         virtual Tizen::Security::IPublicKey* GetPublicKeyN(void) const;
173
174         // (X.509 only, that is, not inherited from the ICertificate interface)
175         /**
176          * Gets the specification version value (version number) from the certificate. @n
177          *
178          * This is defined in ASN.1 as demonstrated in the following code:
179          *
180          * @code
181          * version  [0] EXPLICIT Version DEFAULT v1
182          * Version ::=  INTEGER  {  v1(0), v2(1), v3(2)  }
183          * @endcode
184          *
185          * @since               2.0
186          *
187          * @return              The version number of the X.509 certificate (that is, 1, 2, or 3)
188          */
189         int GetSpecVersion(void) const;
190
191         /**
192          * Gets the serial number of the certificate. @n
193          * The serial number is a unique integer assigned by the Certification Authority (CA) to each certificate (that is, 
194          * the issuer name and serial number must identify a unique certificate). @n
195          *
196          * This is defined in ASN.1 as demonstrated in the following code:
197          *
198          * @code
199          * serialNumber     CertificateSerialNumber
200          *
201          * CertificateSerialNumber  ::=  INTEGER
202          * @endcode
203          *
204          * Since the serial number can be greater than the system's maximum defined value for @c int, the output parameter type 
205          * is @c ByteBuffer, instead of @c int.
206          *
207          * @since               2.0
208          *
209          * @return              The serial number of the certificate
210          * @exception   E_SUCCESS                       The method is successful.
211          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
212          * @remarks             The specific error code can be accessed using the GetLastResult() method.
213          */
214         virtual Tizen::Base::String GetSerialNumber(void) const;
215
216         /**
217          * Checks whether the certificate is currently valid. @n
218          * It is valid if the current date and time are within the validity period of the certificate. The validity period consists 
219          * of two date and time values: the initial date and time, and the final date and time for the validity of the certificate. @n
220          *
221          * This is defined in ASN.1 as demonstrated in the following code:
222          *
223          *  @code
224          *      validity             Validity
225          *
226          *      Validity ::= SEQUENCE {
227          *              notBefore      CertificateValidityDate,
228          *              notAfter       CertificateValidityDate }
229          *
230          *      CertificateValidityDate ::= CHOICE {
231          *              utcTime        UTCTime,
232          *              generalTime    GeneralizedTime }
233          *  @endcode
234          *
235          * @since               2.0
236          *
237          * @return              The validity period of the certificate
238          * @exception   E_SUCCESS                       The method is successful.
239          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
240          *                                                                      - A system error has occurred.
241          *                                                                      - The certificate link list operation has failed.
242          * @remarks             The specific error code can be accessed using the GetLastResult() method.
243          */
244         virtual ValidityPeriod CheckValidityPeriod(void);
245
246         /**
247          *  Gets the notBefore value of @c String type from the validity period of the certificate. @n
248          *      This value represents the date and time before which the certificate is not valid.
249          *
250          * @since               2.0
251          *
252          * @return              A string representing the date and time value before which the certificate is not valid
253          * @exception   E_SUCCESS                       The method is successful.
254          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
255          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
256          *                                                                      - A system error has occurred.
257          *                                                                      - The method has failed to get the certificate validity information.
258          * @remarks             The specific error code can be accessed using the GetLastResult() method.
259          * @see                 Tizen::Security::Cert::X509Certificate::CheckValidityPeriod(void) for relevant ASN.1 definitions.
260          */
261         virtual Tizen::Base::String GetNotBefore(void) const;
262
263
264         /**
265          *      Gets the notAfter value of @c String type from the validity period of the certificate. @n
266          *      This value represents the date and time after which the certificate is not valid.
267          *
268          * @since               2.0
269          *
270          * @return              A string representing the date and time value after which the certificate is not valid
271          * @exception   E_SUCCESS                       The method is successful.
272          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
273          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
274          *                                                      - A system error has occurred.
275          *                                                      - The method has failed to get the certificate validity information.
276          * @remarks             The specific error code can be accessed using the GetLastResult() method.
277          * @see                 Tizen::Security::Cert::X509Certificate::CheckValidityPeriod(void) for relevant ASN.1 definitions.
278          */
279         virtual Tizen::Base::String GetNotAfter(void) const;
280
281         /**
282          * Gets the name of the issuer of the certificate.
283          *
284          * @since               2.0
285          *
286          * @return              The name of the issuer of the certificate
287          * @exception   E_SUCCESS                       The method is successful.
288          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
289          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
290          *                                                                      - A system error has occurred.
291          *                                                                      - The method has failed to get the certificate issuer information.
292          * @remarks             The specific error code can be accessed using the GetLastResult() method.
293          */
294         virtual Tizen::Base::String GetIssuer(void) const;
295
296         /**
297          * Gets the subject name of the certificate.
298          *
299          * @since               2.0
300          *
301          * @return              The subject name of the certificate
302          * @exception   E_SUCCESS                       The method is successful.
303          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
304          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
305          *                                                                      - A system error has occurred.
306          *                                                                      - The method has failed to get the certificate issuer information.
307          * @remarks             The specific error code can be accessed using the GetLastResult() method.
308          */
309         virtual Tizen::Base::String GetSubject(void) const;
310
311         /**
312          * Gets the signature algorithm identifier from the given certificate. @n
313          * For example, the string "SHA-1/DSA". @n
314          *
315          * This is defined in ASN.1 as demonstrated in the following code:
316          *
317          *  @code
318          *      signatureAlgorithm   AlgorithmIdentifier
319          *              AlgorithmIdentifier  ::=  SEQUENCE  {
320          *              algorithm               OBJECT IDENTIFIER,
321          *              parameters              ANY DEFINED BY algorithm OPTIONAL  }
322          *  @endcode
323          *
324          * The algorithm name is determined from the algorithm OID string.
325          *
326          * @since               2.0
327          *
328          * @return              The signature algorithm of the certificate
329          * @exception   E_SUCCESS                       The method is successful.
330          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
331          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
332          *                                                                      - A system error has occurred.
333          *                                                                      - The certificate link list operation has failed.
334          * @remarks             The specific error code can be accessed using the GetLastResult() method.
335          */
336         Tizen::Base::String GetSignatureAlgorithm(void) const;
337
338         /**
339          * Gets the signature of the certificate.
340          *
341          * @since               2.0
342          *
343          * @return              A pointer to the Tizen::Base::ByteBuffer class that contains the output, @n
344          *                              else @c null if an error occurs
345          * @exception   E_SUCCESS                       The method is successful.
346          * @exception   E_OUT_OF_MEMORY         The memory is insufficient.
347          * @exception   E_SYSTEM                        Either of the following conditions has occurred:
348          *                                                                      - A system error has occurred.
349          *                                                                      - The certificate link list operation has failed.
350          *                                                                      - The Tizen::Base::ByteBuffer operation has failed.
351          * @remarks             The specific error code can be accessed using the GetLastResult() method.
352          */
353         virtual Tizen::Base::ByteBuffer* GetSignatureN(void) const;
354
355 private:
356         X509Certificate(const X509Certificate& rhs);
357         X509Certificate& operator =(const X509Certificate& rhs);
358
359 private:
360         void* __certHandle;
361         Tizen::Base::String __certFormat;
362         class _X509CertificateImpl* __pX509CertificateImpl;
363         friend class _X509CertificateImpl;
364
365 }; //X509Certificate
366
367 } } } //Tizen::Security::Cert
368
369 #endif // _FSEC_CERT_X509_CERTIFICATE_H_