2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSecCertX509Certificate.h
19 * @brief This is the header file for the %X509Certificate class.
21 * This header file contains the declarations of the %X509Certificate class.
23 #ifndef _FSEC_CERT_X509_CERTIFICATE_H_
24 #define _FSEC_CERT_X509_CERTIFICATE_H_
27 #include <FSecCertICertificate.h>
29 namespace Tizen { namespace Security { namespace Cert
33 * @class X509Certificate
34 * @brief This class provides methods for managing identity certificates.
38 * The %X509Certificate class provides methods for managing identity certificates. @n
40 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/security/certificate_namespace.htm">Certificates</a>.
44 class _OSP_EXPORT_ X509Certificate
45 : public virtual ICertificate
46 , public Tizen::Base::Object
51 * This is the default constructor for this class.
55 X509Certificate(void);
58 * This is the destructor for this class.
62 virtual ~X509Certificate(void);
65 * Initializes this instance of %X509Certificate with the specified input buffer.
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.
77 result Construct(const Tizen::Base::ByteBuffer& input);
80 * Gets the format of this certificate.
84 * @return The certificate format
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 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.
100 virtual CertificateType GetType(void) const;
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.
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.
119 virtual Tizen::Base::ByteBuffer* GetEncodedDataN(void) const;
122 * Gets the fingerprint of the certificate. @n
123 * It is the hash value of the encoding of the certificate.
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.
137 virtual Tizen::Base::ByteBuffer* GetFingerprintN(void) const;
140 * Verifies whether the certificate is signed using the private key that corresponds to the specified public key.
144 * @return @c true if the certificate is signed using the private key that corresponds to the specified public key, @n
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.
155 virtual bool Verify(const Tizen::Security::IPublicKey& publicKey);
158 * Gets the public key of this certificate.
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.
172 virtual Tizen::Security::IPublicKey* GetPublicKeyN(void) const;
174 // (X.509 only, that is, not inherited from the ICertificate interface)
176 * Gets the specification version value (version number) from the certificate. @n
178 * This is defined in ASN.1 as demonstrated in the following code:
181 * version [0] EXPLICIT Version DEFAULT v1
182 * Version ::= INTEGER { v1(0), v2(1), v3(2) }
187 * @return The version number of the X.509 certificate (that is, 1, 2, or 3)
189 int GetSpecVersion(void) const;
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
196 * This is defined in ASN.1 as demonstrated in the following code:
199 * serialNumber CertificateSerialNumber
201 * CertificateSerialNumber ::= INTEGER
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.
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.
214 virtual Tizen::Base::String GetSerialNumber(void) const;
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
221 * This is defined in ASN.1 as demonstrated in the following code:
226 * Validity ::= SEQUENCE {
227 * notBefore CertificateValidityDate,
228 * notAfter CertificateValidityDate }
230 * CertificateValidityDate ::= CHOICE {
232 * generalTime GeneralizedTime }
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.
244 virtual ValidityPeriod CheckValidityPeriod(void);
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.
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.
261 virtual Tizen::Base::String GetNotBefore(void) const;
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.
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.
279 virtual Tizen::Base::String GetNotAfter(void) const;
282 * Gets the name of the issuer of the certificate.
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.
294 virtual Tizen::Base::String GetIssuer(void) const;
297 * Gets the subject name of the certificate.
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.
309 virtual Tizen::Base::String GetSubject(void) const;
312 * Gets the signature algorithm identifier from the given certificate. @n
313 * For example, the string "SHA-1/DSA". @n
315 * This is defined in ASN.1 as demonstrated in the following code:
318 * signatureAlgorithm AlgorithmIdentifier
319 * AlgorithmIdentifier ::= SEQUENCE {
320 * algorithm OBJECT IDENTIFIER,
321 * parameters ANY DEFINED BY algorithm OPTIONAL }
324 * The algorithm name is determined from the algorithm OID string.
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.
336 Tizen::Base::String GetSignatureAlgorithm(void) const;
339 * Gets the signature of the certificate.
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.
353 virtual Tizen::Base::ByteBuffer* GetSignatureN(void) const;
356 X509Certificate(const X509Certificate& rhs);
357 X509Certificate& operator =(const X509Certificate& rhs);
361 Tizen::Base::String __certFormat;
362 class _X509CertificateImpl* __pX509CertificateImpl;
363 friend class _X509CertificateImpl;
367 } } } //Tizen::Security::Cert
369 #endif // _FSEC_CERT_X509_CERTIFICATE_H_