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