First public contribution.
2 * Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * X509 certificate implementation
26 #ifndef __X509CERT_H__
27 #define __X509CERT_H__
36 /* These OIDs have been defined for PKCS#1 with the
37 * superior reference to OID 1.2.840.113549.1.1
38 * {iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs-1(1)}
40 // RSA (PKCS #1 v1.5) key transport algorithm
41 _LIT(KRSA,"1.2.840.113549.1.1.1");
42 // MD2 with RSA Encryption
43 _LIT(KMD2WithRSA,"1.2.840.113549.1.1.2");
44 // RSA (PKCS #1 v1.5) with MD5 signature
45 _LIT(KMD5WithRSA,"1.2.840.113549.1.1.4");
46 // RSA (PKCS #1 v1.5) with SHA-1 signature
47 _LIT(KSHA1WithRSA,"1.2.840.113549.1.1.5");
48 // SHA256 with RSA Encryption
49 _LIT(KSHA256WithRSA,"1.2.840.113549.1.1.11");
50 // SHA384 with RSA Encryption
51 _LIT(KSHA384WithRSA,"1.2.840.113549.1.1.12");
52 // SHA512 with RSA Encryption
53 _LIT(KSHA512WithRSA,"1.2.840.113549.1.1.13");
54 // SHA224 with RSA Encryption
55 _LIT(KSHA224WithRSA,"1.2.840.113549.1.1.14");
58 * These OIDs have been defined for PKIX with the
59 * superior reference to OID 1.2.840.10040.
61 // Digital Signature Algorithm (DSA), also known as the Digital Signature Standard (DSS)
62 _LIT(KDSA,"1.2.840.10040.4.1");
63 // ANSI X9.57 DSA signature generated with SHA-1 hash (DSA x9.30)
64 _LIT(KDSAWithSHA1, "1.2.840.10040.4.3");
67 * These OIDs have been defined for ANSI X9 standard with
68 * superior reference to oid 1.2.840.10046.
69 * {iso(1) member-body(2) us(840) ansi-x942(10046) number-types(2)}
71 // ANSI X9.42 Ephemeral-Static Diffie-Hellman key agreement algorithm
72 _LIT(KDH,"1.2.840.10046.2.1");
75 * These OIDs have been defined for digest algorithms with
76 * superior reference to oid 1.2.840.113549.2
77 * {iso(1) member-body(2) us(840) rsadsi(113549) digestAlgorithm(2)}
79 _LIT(KMD5,"1.2.840.113549.2.5");
80 _LIT(KMD2,"1.2.840.113549.2.2");
83 * These OIDs have been defined for hash algorithms conforming NIST algorithms
84 * with superior reference to oid 2.16.840.1.101.3.4.2
85 * {joint-iso-itu-t(2) country(16) us(840) organization(1) gov(101) csor(3) nistAlgorithm(4) hashAlgs(2)}
87 _LIT(KSHA256,"2.16.840.1.101.3.4.2.1");
88 _LIT(KSHA384,"2.16.840.1.101.3.4.2.2");
89 _LIT(KSHA512,"2.16.840.1.101.3.4.2.3");
90 _LIT(KSHA224,"2.16.840.1.101.3.4.2.4");
93 * These OIDs are for OIW Security Special Interest Group defined algorithms
94 * with superior reference to oid 1.3.14.3.2
95 * {iso(1) identified-organization(3) oiw(14) secsig(3) algorithms(2)}
97 // SHA1 with RSA signature (obsolete)
98 _LIT(KSHA1WithRSASignature,"1.3.14.3.2.29");
99 // Hash algorithm identifier SHA-1 (Secure Hash Algorithm, Revision 1)
100 _LIT(KSHA1,"1.3.14.3.2.26");
102 /** The maximum number of allowed data elements.
105 const TInt KX509MaxDataElements = 10;
110 class CDSAParameters;
112 class CPKCS1SignatureResult : public CRSASignatureResult
113 /** The signature result in PKCS#1 format.
118 /** Creates a new algorithm ID object copied from an existing object.
120 * @param aDigestAlgorithm The algorithm ID object to be copied.
121 * @param aDigest A non-modifiable descriptor representing the digest algorithm.
122 * @return A pointer to the new algorithm ID object. */
123 IMPORT_C static CPKCS1SignatureResult* NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
125 /** Creates a new algorithm ID object copied from an existing
126 * object, and puts a pointer to the new object onto the cleanup stack.
128 * @param aDigestAlgorithm The algorithm ID object to be copied.
129 * @param aDigest A non-modifiable descriptor representing the digest algorithm.
130 * @return A pointer to the new algorithm ID object. */
131 IMPORT_C static CPKCS1SignatureResult* NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
133 /** Tests whether the signature result is valid.
135 * @param aResult The signature result to be verified.
136 * @return ETrue, if the signature result is verified; EFalse, otherwise. */
137 IMPORT_C virtual TBool VerifyL(const TDesC8& aResult);
139 void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
140 TBool DoVerifyL(const TDesC8& aResult);
143 class TX509KeyFactory : public TKeyFactory
144 /** Constructs the public key objects used for signature verification, from their
145 * encoded binary form, for X.509 certificates.
150 /** Gets the RSA public key from the encoding key.
152 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
153 * @return The RSA Public key. */
154 IMPORT_C CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const;
156 /** Gets the RSA signature result.
158 * @param aDigestAlgorithm The digest algorithm ID.
159 * @param aDigest A non-modifiable descriptor representing the digest algorithm.
160 * @return The RSA signature result. */
161 IMPORT_C CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const;
163 /** Gets the DSA public key from the encoding key.
165 * @param aParamsEncoding A non-modifiable descriptor representing
166 * the encoded binary representation of the DSA parameters
167 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
168 * @return The DSA public key.
170 IMPORT_C CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const;
172 /** Gets the digital DSA signature from the encoding key.
174 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
175 * @return The DSA signature. */
176 IMPORT_C CDSASignature* DSASignatureL(const TDesC8& aEncoding) const;
178 /** Gets the DSA parameters from the encoding key.
180 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
181 * @return The DSA parameters. */
182 IMPORT_C CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const;
184 /** Gets the DSA public key from the encoding key.
186 * @param aParams The DSA parameters
187 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
188 * @return The DSA public key. */
189 IMPORT_C CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const;
192 class CX509ValidityPeriod : public CValidityPeriod
193 /** The period for which an X.509 certificate is valid.
198 /** Creates a new X.509 validity period object from the specified buffer containing
199 * the binary coded representation.
201 * Initialises the object from its encoded binary form into an internal representation.
203 * @param aBinaryData The encoded binary representation.
204 * @return The new validity period object. */
205 IMPORT_C static CX509ValidityPeriod* NewL(const TDesC8& aBinaryData);
207 /** Creates a new X.509 validity period object from the specified buffer containing
208 * the binary coded representation, and puts a pointer to it onto the cleanup stack.
210 * Initialises the object from its encoded binary form into an internal representation.
212 * @param aBinaryData The encoded binary representation.
213 * @return The new validity period object. */
214 IMPORT_C static CX509ValidityPeriod* NewLC(const TDesC8& aBinaryData);
216 /** Creates a new X.509 validity period object from the specified buffer containing
217 * the binary coded representation, starting at the specified offset.
219 * Initialises the object from its encoded binary form into an internal representation.
221 * @param aBinaryData The encoded binary representation.
222 * @param aPos The offset position from which to start decoding.
223 * @return The new validity period object. */
224 IMPORT_C static CX509ValidityPeriod* NewL(const TDesC8& aBinaryData, TInt& aPos);
226 /** Creates a new X.509 validity period object from the specified buffer containing
227 * the binary coded representation, starting at the specified offset, and puts
228 * a pointer to it onto the cleanup stack.
230 * Initialises the object from its encoded binary form into an internal representation.
232 * @param aBinaryData The encoded binary representation.
233 * @param aPos The offset position from which to start decoding.
234 * @return The new validity period object. */
235 IMPORT_C static CX509ValidityPeriod* NewLC(const TDesC8& aBinaryData, TInt& aPos);
237 CX509ValidityPeriod();
238 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
241 class CX509AlgorithmIdentifier : public CAlgorithmIdentifier
242 /** Algorithm identifier for an X.509 certificate.
247 /** Creates a new X.509 algorithm identifier object from the specified buffer containing
248 * the binary coded representation.
250 * The function initialises the object from its encoded binary form into an internal
253 * @param aBinaryData The encoded binary representation.
254 * @return The new algorithm identifier object. */
255 IMPORT_C static CX509AlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
257 /** Creates a new X.509 algorithm identifier object from the specified buffer containing
258 * the binary coded representation, and puts a pointer to it onto the cleanup stack.
260 * @param aBinaryData The encoded binary representation.
261 * @return The new algorithm identifier object. */
262 IMPORT_C static CX509AlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
264 /** Creates a new X.509 algorithm identifier object from the specified buffer containing
265 * the binary coded representation, starting at the specified offset.
267 * @param aBinaryData The encoded binary representation.
268 * @param aPos The offset position from which to start decoding.
269 * @return The new algorithm identifier object. */
270 IMPORT_C static CX509AlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
272 /** Creates a new X.509 algorithm identifier object from the specified buffer containing
273 * the binary coded representation, starting at the specified offset, and puts
274 * a pointer to it onto the cleanup stack.
276 * @param aBinaryData The encoded binary representation.
277 * @param aPos The offset position from which to start decoding.
278 * @return The new algorithm identifier object. */
279 IMPORT_C static CX509AlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
282 Creates a X509 Algorithm Identifier object from the given algorithm ID and the encoded parameter.
283 @param aAlgorithmId The algorithm Id used to build the object.
284 @param aEncodedParams The encoded parameter for the algorithm ID.
285 @return The fully constructed object.
287 IMPORT_C static CX509AlgorithmIdentifier* NewL(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams);
290 Creates a X509 Algorithm Identifier object from the given algorithm ID and the encoded parameter
291 and leaves the object on the cleanup stack.
292 @param aAlgorithmId The algorithm Id used to build the object.
293 @param aEncodedParams The encoded parameter for the algorithm ID.
294 @return The fully constructed object.
296 IMPORT_C static CX509AlgorithmIdentifier* NewLC(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams);
299 Creates the ASN1 DER sequence of the X509 algorithm identifier object
300 and leaves it on the cleanup stack.
301 @return ASN1 DER sequence of this object.
303 IMPORT_C CASN1EncSequence* EncodeASN1DERLC() const;
306 CX509AlgorithmIdentifier();
307 CX509AlgorithmIdentifier(TAlgorithmId& aAlgorithmId);
308 void InitializeL(const TDesC8& aBinaryData, TInt& aPos);
311 class CX509SigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier
312 /** Encapsulates the IDs of the algorithms used for signing an X.509 certificate.
317 /** Creates a new X.509 signing algorithm Id object from the specified buffer containing
318 * the binary coded representation.
320 * @param aBinaryData The encoded binary representation.
321 * @return The new signing algorithm Id object. */
322 IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
324 /** Creates a new X.509 signing algorithm Id object from the specified buffer containing
325 * the binary coded representation, and puts a pointer to it onto the cleanup stack.
327 * @param aBinaryData The encoded binary representation.
328 * @return The new signing algorithm Id object. */
329 IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
331 /** Creates a new X.509 signing algorithm Id object from the specified buffer containing
332 * the binary coded representation, starting at the specified offset.
334 * @param aBinaryData The encoded binary representation.
335 * @param aPos The offset position from which to start decoding.
336 * @return The new signing algorithm Id object. */
337 IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
339 /** Creates a new X.509 signing algorithm Id object from the specified buffer containing
340 * the binary coded representation,starting at the specified offset, and puts
341 * a pointer to it onto the cleanup stack.
343 * @param aBinaryData The encoded binary representation.
344 * @param aPos The offset position from which to start decoding.
345 * @return The new signing algorithm Id object. */
346 IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
347 /** Creates a new X.509 signing algorithm Id object from the specified algorithm pair
349 * @param aAsymmetricAlgorithm The asymmetric algorithm
350 * @param aDigestAlgorithm The digest algorithm
351 * @return The new signing algorithm Id object. */
352 IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm);
353 /** Creates a new X.509 signing algorithm Id object from the specified algorithm pair
355 * @param aAsymmetricAlgorithm The asymmetric algorithm
356 * @param aDigestAlgorithm The digest algorithm
357 * @return The new signing algorithm Id object. */
358 IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm);
360 CX509SigningAlgorithmIdentifier();
361 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
362 void ConstructL(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm);
365 class CX509SubjectPublicKeyInfo : public CSubjectPublicKeyInfo
366 /** X.509 subject public key information.
371 /** Creates a new X.509 subject public key object from the specified buffer containing
372 * the binary coded representation.
374 * @param aBinaryData The encoded binary representation.
375 * @return The new subject public key object. */
376 IMPORT_C static CX509SubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData);
378 /** Creates a new X.509 subject public key object from the specified buffer containing
379 * the binary coded representation, and puts a pointer to it onto the cleanup stack.
381 * @param aBinaryData The encoded binary representation.
382 * @return The new subject public key object. */
383 IMPORT_C static CX509SubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData);
385 /** Creates a new X.509 subject public key object from the specified buffer containing
386 * the binary coded representation, starting at the specified offset.
388 * @param aBinaryData The encoded binary representation.
389 * @param aPos The offset position from which to start decoding.
390 * @return The subject public key object. */
391 IMPORT_C static CX509SubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData, TInt& aPos);
393 /** Creates a new X.509 subject public key object from the specified buffer containing
394 * the binary coded representation, starting at the specified offset, and puts
395 * a pointer to it onto the cleanup stack.
397 * @param aBinaryData The encoded binary representation.
398 * @param aPos The offset position from which to start decoding.
399 * @return The new subject public key object. */
400 IMPORT_C static CX509SubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData, TInt& aPos);
402 CX509SubjectPublicKeyInfo();
403 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
406 class CX509CertExtension : public CBase
407 /** A generic X.509 certificate extension.
409 * The creation of a generic extension is the first step in the creation of a
410 * specific extension. Client code gets the decoded Object Identifier (OID) encapsulated
411 * by an instance of this class and uses it to create the specific extension.
413 * Consists of an any-defined-by structure along with a boolean flag saying whether
414 * the extension is critical or not.
419 /** Creates a new generic X.509 certificate extension object from an existing object.
421 * This is equivalent to a copy constructor.
423 * @param aExtension The generic certificate extension to be copied.
424 * @return The new generic certificate extension object. */
425 IMPORT_C static CX509CertExtension* NewL(const CX509CertExtension& aExtension);
427 /** Creates a new generic X.509 certificate extension object from an existing object,
428 * and puts a pointer to it onto the cleanup stack.
430 * This is equivalent to a copy constructor.
432 * @param aExtension The generic certificate extension to be copied.
433 * @return The new generic X.509 certificate extension object. */
434 IMPORT_C static CX509CertExtension* NewLC(const CX509CertExtension& aExtension);
436 /** Creates a new generic X.509 certificate extension object from the specified
437 * buffer containing the binary coded representation.
439 * @param aBinaryData The encoded binary representation.
440 * @return The new generic X.509 certificate extension object. */
441 IMPORT_C static CX509CertExtension* NewL(const TDesC8& aBinaryData);
443 /** Creates a new generic X.509 certificate extension object from the specified
444 * buffer containing the binary coded representation, and puts a pointer to it
445 * onto the cleanup stack .
447 * @param aBinaryData The encoded binary representation.
448 * @return The new generic X.509 certificate extension object. */
449 IMPORT_C static CX509CertExtension* NewLC(const TDesC8& aBinaryData);
451 /** Creates a new generic X.509 certificate extension object from the specified
452 * buffer containing the binary coded representation, starting at the specified offset.
454 * @param aBinaryData The encoded binary representation.
455 * @param aPos The offset position from which to start decoding.
456 * @return The new generic X.509 certificate extension object. */
457 IMPORT_C static CX509CertExtension* NewL(const TDesC8& aBinaryData, TInt& aPos);
459 /** Creates a new generic X.509 certificate extension object from the specified
460 * buffer containing the binary coded representation, starting at the specified
461 * offset, and puts a pointer to it onto the cleanup stack.
463 * @param aBinaryData The encoded binary representation.
464 * @param aPos The offset position from which to start decoding.
465 * @return The new generic X.509 certificate extension object. */
466 IMPORT_C static CX509CertExtension* NewLC(const TDesC8& aBinaryData, TInt& aPos);
468 /** Creates a new generic X.509 certificate extension object from the specified
469 * extension object id, the critcal flag and the extension data.
471 * @param aCertExtOID The OID of the certficate extension.
472 * @param aCritical Flag to convey criticality of the extension.
473 * @param aCertExtValue The data of the specific extension.
474 * @return The new generic X.509 certificate extension object. */
475 IMPORT_C static CX509CertExtension* NewL(const TDesC& aCertExtOID,
476 const TBool aCritical,
477 const TDesC8& aCertExtValue);
479 /** Creates a new generic X.509 certificate extension object from the specified
480 * extension object id, the critcal flag and the extension data, and puts a
481 * pointer to it onto the cleanup stack.
483 * @param aCertExtOID The OID of the certficate extension.
484 * @param aCritical Flag to convey criticality of the extension.
485 * @param aCertExtValue The data of the specific extension.
486 * @return The new generic X.509 certificate extension object. */
487 IMPORT_C static CX509CertExtension* NewLC(const TDesC& aCertExtOID,
488 const TBool aCritical,
489 const TDesC8& aCertExtValue);
493 * Frees all resources owned by the object, prior to its destruction. */
494 IMPORT_C ~CX509CertExtension();
496 /** Tests whether certificate processing code must process this extension for certificate
497 * validation to succeed.
499 * @return ETrue, if this extension must be processed for validation to succeed;
500 * EFalse, otherwise. */
501 IMPORT_C TBool Critical() const;
503 /** Gets the Object Identifier (OID) of the certficate extension.
505 * @return The OID of the certficate extension. */
506 IMPORT_C TPtrC Id() const; //OID for the extension
508 /** Gets the encoded binary representation of the specific extension.
510 * @return A pointer descriptor representing the specific extension. */
511 IMPORT_C TPtrC8 Data() const; //the extension itself
513 /** Creates and returns a DER encoded X.509 certificate extension object in the form
514 * of a ASN.1 Sequence and puts it onto the cleanup stack. This method can be called
515 * repeatedly to get copies of the sequence.
517 * @return A pointer to a DER encoded ASN.1 sequence */
518 IMPORT_C CASN1EncSequence * EncodeASN1DERLC() const;
521 CX509CertExtension();
522 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
523 void ConstructL(const CX509CertExtension& aExtension);
524 void ConstructL(const TDesC& aCertExtOID,
525 const TBool aCritical,
526 const TDesC8& aCertExtValue);
532 class CX509Certificate : public CCertificate
533 /** An X.509 certificate.
538 /** Enumerates values for encoded data element positions in the TBSCertificate data structure.
540 * These values are to be used as parameters to the DataElementEncoding() function. */
543 EVersionNumber = 0, //optional - may be NULL
549 ESubjectPublicKeyInfo = 6,
550 EIssuerUID = 7, //optional - may be NULL
551 ESubjectUID = 8, //optional - may be NULL
552 EExtensionList = 9 //optional - may be NULL
555 /** Creates a new X.509 certificate object from the specified buffer containing
556 * the binary coded representation.
558 * @param aBinaryData The encoded binary representation.
559 * @return The new X.509 certificate object. */
560 IMPORT_C static CX509Certificate* NewL(const TDesC8& aBinaryData);
562 /** Creates a new X.509 certificate object from the specified buffer containing
563 * the binary coded representation, and puts a pointer to it onto the cleanup stack.
565 * Initialises the object from its encoded binary form into an internal representation.
567 * @param aBinaryData The encoded binary representation.
568 * @return The new X.509 certificate object. */
569 IMPORT_C static CX509Certificate* NewLC(const TDesC8& aBinaryData);
571 /** Creates a new X.509 certificate object from the specified buffer containing
572 * the binary coded representation, starting at the specified offset.
574 * @param aBinaryData The encoded binary representation.
575 * @param aPos The offset position from which to start decoding.
576 * @return The new X.509 certificate object. */
577 IMPORT_C static CX509Certificate* NewL(const TDesC8& aBinaryData, TInt& aPos);
579 /** Creates a new X.509 certificate object from the specified buffer containing
580 * the binary coded representation, starting at the specified offset, and puts
581 * a pointer to it onto the cleanup stack.
583 * @param aBinaryData The encoded binary representation.
584 * @param aPos The offset position from which to start decoding.
585 * @return The new X.509 certificate object. */
586 IMPORT_C static CX509Certificate* NewLC(const TDesC8& aBinaryData, TInt& aPos);
588 /** Creates a new X.509 certificate object from the specified read stream.
590 * @param aStream Stream from which the contents should be internalised.
591 * @return The new X.509 certificate object. */
592 IMPORT_C static CX509Certificate* NewL(RReadStream& aStream);
594 /** Creates a new X.509 certificate object from the specified read stream, and
595 * puts a pointer to it onto the cleanup stack.
597 * Construction is from the stream.
599 * @param aStream Stream from which the contents should be internalised.
600 * @return The new X.509 certificate object. */
601 IMPORT_C static CX509Certificate* NewLC(RReadStream& aStream);
603 /** Creates a new X.509 certificate object from an existing object.
605 * This is equivalent to a copy constructor.
607 * @param aCert The X.509 certificate to be copied.
608 * @return The new X.509 certificate object. */
609 IMPORT_C static CX509Certificate* NewL(const CX509Certificate& aCert);
611 /** Creates a new X.509 certificate object from an existing object.
613 * This is equivalent to a copy constructor.
615 * @param aCert The X.509 certificate to be copied.
616 * @return The new X.509 certificate object. */
617 IMPORT_C static CX509Certificate* NewLC(const CX509Certificate& aCert);
619 /** Retrieves the subject key identifier of a certificate based on the decision whether
620 * it is a CA certificate or not. If it is a CA certificate then returns the stored subject key id
621 * as an extension in the certificate, any other certificate it returns the keyidentifier as
622 * calculated by Symbian's proprietary logic.
623 * @return The subject key identifier for the certificate. */
624 IMPORT_C TKeyIdentifier SubjectKeyIdL() const;
629 * Frees all resources owned by the object, prior to its destruction. */
630 IMPORT_C ~CX509Certificate();
632 /** Tests whether the specified X.509 certificate is equal to this X.509 certificate.
634 * X.509 certificates are equal if both the serial number and the issuer name
637 * @param aCert The X.509 certificate to be compared.
638 * @return ETrue, if the certificates are equal;EFalse, otherwise. */
639 IMPORT_C TBool IsEqualL(const CX509Certificate& aCert) const;
642 /** Gets the certificate's signed data.
644 * @return A non-modifiable pointer descriptor representing the certificate's
646 IMPORT_C const TPtrC8 SignedDataL() const;
648 /** Gets the version number of the certificate.
650 * @return The version number of the certificate. */
651 IMPORT_C TInt Version() const;
653 /** Gets the X.500 Distinguished Name that identifies the issuer.
655 * @return The X.500 Distinguished Name that identifies the issuer. */
656 IMPORT_C const CX500DistinguishedName& IssuerName() const;
658 /** Gets the X.500 Distinguished Name that identifies the subject.
660 * @return The X.500 Distinguished Name that identifies the subject. */
661 IMPORT_C const CX500DistinguishedName& SubjectName() const;
663 //return all your generic extensions
664 /** Gets all generic certificate extensions.
666 * @return The certificate extensions. */
667 IMPORT_C const CArrayPtrFlat<CX509CertExtension>& Extensions() const;
669 //return a particular extension: this is NOT OWNED by the client
670 //returns NULL if the ext is not found
671 /** Gets the certificate extension identified by the specified object identifier (OID).
673 * @param aExtensionName The OID identifying the extension.
674 * @return The certificate extension: Note that ownership is not transferred to
676 IMPORT_C const CX509CertExtension* Extension(const TDesC& aExtensionName) const;
678 /** Internalises an object of this class from a read stream.
680 * The presence of this function means that the standard templated operator>>()
681 * can be used to internalise objects of this class.
683 * Note that the function has assignment semantics. It replaces the old value
684 * of the object with a new value read from the read stream.
686 * @param aStream Stream from which the object is to be internalised. */
687 IMPORT_C void InternalizeL(RReadStream& aStream);
689 //return the encoding for a data element at the index specified
690 /** Gets the encoded data for the specified encoded data element (in the To Be
691 * Signed (TBS) certificate data structure) of the signed object.
693 * @param aIndex The encoded data element position in the TBSCertificate data
694 * structure. (See the CX509Certificate enumeration.)
695 * @return The encoded data for the specified data element of the signed object.
697 IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
699 public: // from CCertificate
700 /** Gets the issuer of the certificate.
702 * @return A heap descriptor representing the issuer of the certificate. */
703 IMPORT_C HBufC* IssuerL() const;
705 /** Gets the subject of the certificate.
707 * @return A heap descriptor representing the issuer of the certificate. */
708 IMPORT_C HBufC* SubjectL() const;
710 /** Tests whether the certificate is self-signed.
712 * @return ETrue, if it is self-signed; EFalse, otherwise. */
713 IMPORT_C TBool IsSelfSignedL() const;
715 /** Gets a key identifier for the certificate. This is a unique identifier, calculated according
716 * to the recommended method of computing it from RFC3280, section 4.2.1.2. Please note that this
717 * method does NOT return the value of the Subject Key Id extension, if it is present.
719 * @return A unique key identifier for the certificate. */
720 IMPORT_C TKeyIdentifier KeyIdentifierL() const;
722 /** Gets the subject key identifier for the certificate. This identifier is extracted from the
723 * certificate (if the corresponding extension exists), or calculated (if the extension doesn't exist). If calculated, the recommendation from
724 * section 4.2.1.2, RFC3280 is used (hash of the public key). Please note, that for subject key ids
725 * extracted from the certificate there is a length limit - if the extension is longer than 160 bits,
726 * it is ignored and the value is calculated instead.
728 * @return The subject key identifier for the certificate. */
729 IMPORT_C TKeyIdentifier SubjectKeyIdentifierL() const;
733 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
734 void ConstructL(const CX509Certificate& aCertificate);
735 void ConstructCertL();
736 void InitDataElementsL(const CX509Certificate& aCertificate);
737 HBufC8* DecodeUidL(const TDesC8& aBinaryData, TBool& aHasElementAlready);
738 void DecodeExtsL(const TDesC8& aBinaryData, TBool& aHasElementAlready);
741 CX500DistinguishedName* iIssuerName;
742 CX500DistinguishedName* iSubjectName;
745 CArrayPtrFlat<CX509CertExtension>* iExtensions;
746 TFixedArray<TPtrC8*, KX509MaxDataElements>* iDataElements;