2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FSecCertX509Certificate.h
20 * @brief This is the header file for the %X509Certificate class.
22 * This header file contains the declarations of the %X509Certificate class.
24 #ifndef _FSEC_CERT_X509_CERTIFICATE_H_
25 #define _FSEC_CERT_X509_CERTIFICATE_H_
28 #include <FSecCertICertificate.h>
30 namespace Tizen { namespace Security { namespace Cert
34 * @class X509Certificate
35 * @brief This class is used for managing a variety of identity certificates.
39 * The %X509Certificate class is used for managing a variety of identity certificates. @n
41 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/certificate_namespace.htm">Certificates</a>.
45 class _OSP_EXPORT_ X509Certificate
46 : public virtual ICertificate
47 , public Tizen::Base::Object
52 * This is the default constructor for this class.
56 X509Certificate(void);
59 * This is the destructor for this class.
63 virtual ~X509Certificate(void);
66 * Initializes this instance of %X509Certificate with the specified input buffer.
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.
77 result Construct(const Tizen::Base::ByteBuffer& input);
80 * Gets the format name for this certificate.
84 * @return The format of this certificate
86 virtual Tizen::Base::String GetFormat(void) const;
89 * Gets the certificate type.
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.
99 virtual CertificateType GetType(void) const;
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.
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.
116 virtual Tizen::Base::ByteBuffer* GetEncodedDataN(void) const;
119 * Gets the fingerprint of the certificate. @n
120 * It is the hashed value of the encoding of the certificate.
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.
133 virtual Tizen::Base::ByteBuffer* GetFingerprintN(void) const;
136 * Verifies whether the certificate is signed using the private key that corresponds to the specified public key.
140 * @return @c true if the certificate is signed using the private key that corresponds to the specified public key, @n
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.
150 virtual bool Verify(const Tizen::Security::IPublicKey& publicKey);
153 * Gets the public key of this certificate.
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.
166 virtual Tizen::Security::IPublicKey* GetPublicKeyN(void) const;
168 // (X.509 only, that is, not inherited from the ICertificate interface)
170 * Gets the specification version value (version number) from the certificate. @n
172 * This is defined in ASN.1 as demonstrated in the following code:
175 * version [0] EXPLICIT Version DEFAULT v1
176 * Version ::= INTEGER { v1(0), v2(1), v3(2) }
181 * @return The version number of the X.509 certificate (that is, 1, 2, or 3)
183 int GetSpecVersion(void) const;
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
190 * This is defined in ASN.1 as demonstrated in the following code:
193 * serialNumber CertificateSerialNumber
195 * CertificateSerialNumber ::= INTEGER
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.
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.
207 virtual Tizen::Base::String GetSerialNumber(void) const;
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
214 * This is defined in ASN.1 as demonstrated in the following code:
219 * Validity ::= SEQUENCE {
220 * notBefore CertificateValidityDate,
221 * notAfter CertificateValidityDate }
223 * CertificateValidityDate ::= CHOICE {
225 * generalTime GeneralizedTime }
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.
236 virtual ValidityPeriod CheckValidityPeriod(void);
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.
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.
252 virtual Tizen::Base::String GetNotBefore(void) const;
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.
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.
269 virtual Tizen::Base::String GetNotAfter(void) const;
272 * Gets the name of the issuer of the certificate.
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.
283 virtual Tizen::Base::String GetIssuer(void) const;
286 * Gets the subject name of the certificate.
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.
297 virtual Tizen::Base::String GetSubject(void) const;
300 * Gets the signature algorithm identifier from the given certificate. @n
301 * For example, the string "SHA-1/DSA". @n
303 * This is defined in ASN.1 as demonstrated in the following code:
306 * signatureAlgorithm AlgorithmIdentifier
307 * AlgorithmIdentifier ::= SEQUENCE {
308 * algorithm OBJECT IDENTIFIER,
309 * parameters ANY DEFINED BY algorithm OPTIONAL }
312 * The algorithm name is determined from the algorithm OID string.
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.
323 Tizen::Base::String GetSignatureAlgorithm(void) const;
326 * Gets the signature of the certificate.
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.
339 virtual Tizen::Base::ByteBuffer* GetSignatureN(void) const;
342 X509Certificate(const X509Certificate& rhs);
343 X509Certificate& operator =(const X509Certificate& rhs);
347 Tizen::Base::String __certFormat;
348 class _X509CertificateImpl* __pX509CertificateImpl;
349 friend class _X509CertificateImpl;
353 } } } //Tizen::Security::Cert
355 #endif // _FSEC_CERT_X509_CERTIFICATE_H_