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