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 is used for managing a variety of identity certificates.
38 * The %X509Certificate class is used for managing a variety of 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 A system error has occurred. @n
74 * The Tizen::Base::ByteBuffer operation has failed.
76 result Construct(const Tizen::Base::ByteBuffer& input);
79 * Gets the format name for this certificate.
83 * @return The format of this certificate
85 virtual Tizen::Base::String GetFormat(void) const;
88 * Gets the certificate type.
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.
98 virtual CertificateType GetType(void) const;
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.
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.
115 virtual Tizen::Base::ByteBuffer* GetEncodedDataN(void) const;
118 * Gets the fingerprint of the certificate. @n
119 * It is the hashed value of the encoding of the certificate.
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.
132 virtual Tizen::Base::ByteBuffer* GetFingerprintN(void) const;
135 * Verifies whether the certificate is signed using the private key that corresponds to the specified public key.
139 * @return @c true if the certificate is signed using the private key that corresponds to the specified public key, @n
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.
149 virtual bool Verify(const Tizen::Security::IPublicKey& publicKey);
152 * Gets the public key of this certificate.
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.
165 virtual Tizen::Security::IPublicKey* GetPublicKeyN(void) const;
167 // (X.509 only, that is, not inherited from the ICertificate interface)
169 * Gets the specification version value (version number) from the certificate. @n
171 * This is defined in ASN.1 as demonstrated in the following code:
174 * version [0] EXPLICIT Version DEFAULT v1
175 * Version ::= INTEGER { v1(0), v2(1), v3(2) }
180 * @return The version number of the X.509 certificate (that is, 1, 2, or 3)
182 int GetSpecVersion(void) const;
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
189 * This is defined in ASN.1 as demonstrated in the following code:
192 * serialNumber CertificateSerialNumber
194 * CertificateSerialNumber ::= INTEGER
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.
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.
206 virtual Tizen::Base::String GetSerialNumber(void) const;
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
213 * This is defined in ASN.1 as demonstrated in the following code:
218 * Validity ::= SEQUENCE {
219 * notBefore CertificateValidityDate,
220 * notAfter CertificateValidityDate }
222 * CertificateValidityDate ::= CHOICE {
224 * generalTime GeneralizedTime }
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.
235 virtual ValidityPeriod CheckValidityPeriod(void);
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.
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.
251 virtual Tizen::Base::String GetNotBefore(void) const;
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.
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.
268 virtual Tizen::Base::String GetNotAfter(void) const;
271 * Gets the name of the issuer of the certificate.
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.
282 virtual Tizen::Base::String GetIssuer(void) const;
285 * Gets the subject name of the certificate.
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.
296 virtual Tizen::Base::String GetSubject(void) const;
299 * Gets the signature algorithm identifier from the given certificate. @n
300 * For example, the string "SHA-1/DSA". @n
302 * This is defined in ASN.1 as demonstrated in the following code:
305 * signatureAlgorithm AlgorithmIdentifier
306 * AlgorithmIdentifier ::= SEQUENCE {
307 * algorithm OBJECT IDENTIFIER,
308 * parameters ANY DEFINED BY algorithm OPTIONAL }
311 * The algorithm name is determined from the algorithm OID string.
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.
322 Tizen::Base::String GetSignatureAlgorithm(void) const;
325 * Gets the signature of the certificate.
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.
338 virtual Tizen::Base::ByteBuffer* GetSignatureN(void) const;
341 X509Certificate(const X509Certificate& rhs);
342 X509Certificate& operator =(const X509Certificate& rhs);
346 Tizen::Base::String __certFormat;
347 class _X509CertificateImpl* __pX509CertificateImpl;
348 friend class _X509CertificateImpl;
352 } } } //Tizen::Security::Cert
354 #endif // _FSEC_CERT_X509_CERTIFICATE_H_