os/security/cryptoservices/certificateandkeymgmt/inc/x509cert.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * X509 certificate implementation
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @publishedAll
    23  @released
    24 */
    25  
    26 #ifndef __X509CERT_H__
    27 #define __X509CERT_H__
    28 
    29 #include <e32base.h>
    30 #include <e32std.h>
    31 #include <s32std.h>
    32 #include <signed.h>
    33 #include <x500dn.h>
    34 #include <asn1enc.h>
    35 
    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)}
    39  */ 
    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");
    56 
    57 /* 
    58  * These OIDs have been defined for PKIX with the 
    59  * superior reference to OID 1.2.840.10040.
    60  */
    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");
    65 
    66 /*
    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)}
    70  */
    71 // ANSI X9.42 Ephemeral-Static Diffie-Hellman key agreement algorithm 
    72 _LIT(KDH,"1.2.840.10046.2.1");
    73 
    74 /*
    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)}
    78  */
    79 _LIT(KMD5,"1.2.840.113549.2.5");
    80 _LIT(KMD2,"1.2.840.113549.2.2");
    81 
    82 /*
    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)}
    86  */
    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");
    91 
    92 /*
    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)}
    96  */
    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");
   101 
   102 /** The maximum number of allowed data elements.
   103 * 
   104 * @since v7.0 */
   105 const TInt KX509MaxDataElements = 10;
   106 
   107 class CRSAPublicKey;
   108 class CDSAPublicKey;
   109 class CDSASignature;
   110 class CDSAParameters;
   111 
   112 class CPKCS1SignatureResult : public CRSASignatureResult
   113 /** The signature result in PKCS#1 format.
   114 * 
   115 * @since v6.0 */
   116 	{
   117 public:
   118 	/** Creates a new algorithm ID object copied from an existing object.
   119 	* 
   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);
   124 	
   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.
   127 	* 
   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);
   132 	
   133 	/** Tests whether the signature result is valid.
   134 	* 
   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);
   138 private:
   139 	void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
   140 	TBool DoVerifyL(const TDesC8& aResult);
   141 	};
   142 
   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.
   146 * 
   147 * @since v6.0 */
   148 	{
   149 public:
   150 	/** Gets the RSA public key from the encoding key.
   151 	* 
   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;
   155 	
   156 	/** Gets the RSA signature result.
   157 	* 
   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;
   162 	
   163 	/** Gets the DSA public key from the encoding key.
   164 	* 
   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. 
   169 	* @since 					v8.0 */
   170 	IMPORT_C CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const;
   171 	
   172 	/** Gets the digital DSA signature from the encoding key.
   173 	* 
   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;
   177 	
   178 	/** Gets the DSA parameters from the encoding key.
   179 	* 
   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;
   183 	
   184 	/** Gets the DSA public key from the encoding key.
   185 	* 
   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;
   190 	};
   191 
   192 class CX509ValidityPeriod : public CValidityPeriod
   193 /** The period for which an X.509 certificate is valid.
   194 * 
   195 * @since v6.0 */
   196 	{
   197 public:
   198 	/** Creates a new X.509 validity period object from the specified buffer containing 
   199 	* the binary coded representation.
   200 	* 
   201 	* Initialises the object from its encoded binary form into an internal representation.
   202 	* 
   203 	* @param aBinaryData	The encoded binary representation.
   204 	* @return				The new validity period object. */
   205 	IMPORT_C static CX509ValidityPeriod* NewL(const TDesC8& aBinaryData);
   206 	
   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.
   209 	* 
   210 	* Initialises the object from its encoded binary form into an internal representation.
   211 	* 
   212 	* @param aBinaryData	The encoded binary representation.
   213 	* @return				The new validity period object. */
   214 	IMPORT_C static CX509ValidityPeriod* NewLC(const TDesC8& aBinaryData);
   215 	
   216 	/** Creates a new X.509 validity period object from the specified buffer containing 
   217 	* the binary coded representation, starting at the specified offset.
   218 	* 
   219 	* Initialises the object from its encoded binary form into an internal representation.
   220 	* 
   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);
   225 	
   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.
   229 	* 
   230 	* Initialises the object from its encoded binary form into an internal representation.
   231 	* 
   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);
   236 private:
   237 	CX509ValidityPeriod();
   238 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   239 	};
   240 
   241 class CX509AlgorithmIdentifier : public CAlgorithmIdentifier
   242 /** Algorithm identifier for an X.509 certificate.
   243 *
   244 * @since v6.0 */
   245 	{
   246 public:
   247 	/** Creates a new X.509 algorithm identifier object from the specified buffer containing 
   248 	* the binary coded representation.
   249 	* 
   250 	* The function initialises the object from its encoded binary form into an internal 
   251 	* representation.
   252 	* 
   253 	* @param aBinaryData	The encoded binary representation.
   254 	* @return				The new algorithm identifier object. */
   255 	IMPORT_C static CX509AlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
   256 	
   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.
   259 	* 
   260 	* @param aBinaryData	The encoded binary representation.
   261 	* @return				The new algorithm identifier object. */
   262 	IMPORT_C static CX509AlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
   263 	
   264 	/** Creates a new X.509 algorithm identifier object from the specified buffer containing 
   265 	* the binary coded representation, starting at the specified offset.
   266 	* 
   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);
   271 	
   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.
   275 	* 
   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);
   280 
   281 	/**
   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.
   286 	*/
   287 	IMPORT_C static CX509AlgorithmIdentifier* NewL(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams);
   288 
   289 	/**
   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.
   295 	*/
   296 	IMPORT_C static CX509AlgorithmIdentifier* NewLC(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams);
   297 
   298 	/**
   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.
   302 	*/
   303 	IMPORT_C CASN1EncSequence* EncodeASN1DERLC() const;
   304 
   305 private:
   306 	CX509AlgorithmIdentifier();
   307 	CX509AlgorithmIdentifier(TAlgorithmId& aAlgorithmId);
   308 	void InitializeL(const TDesC8& aBinaryData, TInt& aPos);
   309 	};
   310 
   311 class CX509SigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier
   312 /** Encapsulates the IDs of the algorithms used for signing an X.509 certificate.
   313 *
   314 * @since v6.0 */
   315 	{
   316 public:
   317 	/** Creates a new X.509 signing algorithm Id object from the specified buffer containing 
   318 	* the binary coded representation.
   319 	* 
   320 	* @param aBinaryData	The encoded binary representation.
   321 	* @return				The new signing algorithm Id object. */
   322 	IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
   323 	
   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.
   326 	* 
   327 	* @param aBinaryData	The encoded binary representation.
   328 	* @return				The new signing algorithm Id object. */
   329 	IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
   330 	
   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.
   333 	* 
   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);
   338 	
   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.
   342 	* 
   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
   348 	* 
   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
   354 	* 
   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);
   359 private:
   360 	CX509SigningAlgorithmIdentifier();
   361 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   362 	void ConstructL(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm);
   363 	};
   364 
   365 class CX509SubjectPublicKeyInfo : public CSubjectPublicKeyInfo
   366 /** X.509 subject public key information.
   367 * 
   368 * @since v6.0 */
   369 	{
   370 public:
   371 	/** Creates a new X.509 subject public key object from the specified buffer containing 
   372 	* the binary coded representation.
   373 	* 
   374 	* @param aBinaryData	The encoded binary representation.
   375 	* @return				The new subject public key object. */
   376 	IMPORT_C static CX509SubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData);
   377 	
   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.
   380 	* 
   381 	* @param aBinaryData	The encoded binary representation.
   382 	* @return				The new subject public key object. */
   383 	IMPORT_C static CX509SubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData);
   384 	
   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.
   387 	* 
   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);
   392 	
   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.
   396 	* 
   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);
   401 private:
   402 	CX509SubjectPublicKeyInfo();
   403 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   404 	};
   405 
   406 class CX509CertExtension : public CBase
   407 /** A generic X.509 certificate extension.
   408 * 
   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.
   412 * 
   413 * Consists of an any-defined-by structure along with a boolean flag saying whether 
   414 * the extension is critical or not.
   415 * 
   416 * @since v6.0 */
   417 	{
   418 public:
   419 	/** Creates a new generic X.509 certificate extension object from an existing object.
   420 	* 
   421 	* This is equivalent to a copy constructor.
   422 	* 
   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);
   426 	
   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.
   429 	* 
   430 	* This is equivalent to a copy constructor.
   431 	* 
   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);
   435 	
   436 	/** Creates a new generic X.509 certificate extension object from the specified 
   437 	* buffer containing the binary coded representation.
   438 	* 
   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);
   442 	
   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 .
   446 	* 
   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);
   450 	
   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.
   453 	* 
   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);
   458 	
   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.
   462 	* 
   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);
   467 	
   468 	/** Creates a new generic X.509 certificate extension object from the specified 
   469 	* extension object id, the critcal flag and the extension data.
   470 	* 
   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);
   478 
   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.
   482 	* 
   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);
   490 
   491 	/** Destructor.
   492 	* 
   493 	* Frees all resources owned by the object, prior to its destruction. */
   494 	IMPORT_C ~CX509CertExtension();
   495 	
   496 	/** Tests whether certificate processing code must process this extension for certificate 
   497 	* validation to succeed.
   498 	* 
   499 	* @return	ETrue, if this extension must be processed for validation to succeed; 
   500 	* 			EFalse, otherwise. */
   501 	IMPORT_C TBool Critical() const;
   502 	
   503 	/** Gets the Object Identifier (OID) of the certficate extension.
   504 	* 
   505 	* @return	The OID of the certficate extension. */
   506 	IMPORT_C TPtrC Id() const;	//OID for the extension
   507 	
   508 	/** Gets the encoded binary representation of the specific extension.
   509 	* 
   510 	* @return	A pointer descriptor representing the specific extension. */
   511 	IMPORT_C TPtrC8 Data() const;	//the extension itself 
   512 
   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.
   516 	* 
   517 	* @return	A pointer to a DER encoded ASN.1 sequence */
   518 	IMPORT_C CASN1EncSequence * EncodeASN1DERLC() const;
   519 
   520 private:
   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);
   527 	HBufC* iId;
   528 	TBool iCritical;
   529 	HBufC8* iData;
   530 	};
   531 
   532 class CX509Certificate : public CCertificate
   533 /** An X.509 certificate.
   534 * 
   535 * @since v6.0 */
   536 	{
   537 public:
   538 /** Enumerates values for encoded data element positions in the TBSCertificate data structure.
   539 * 
   540 * These values are to be used as parameters to the DataElementEncoding() function. */
   541 	enum
   542 		{
   543 		EVersionNumber = 0,	//optional - may be NULL
   544 		ESerialNumber = 1,
   545 		EAlgorithmId = 2,
   546 		EIssuerName = 3,
   547 		EValidityPeriod = 4,
   548 		ESubjectName = 5,
   549 		ESubjectPublicKeyInfo = 6,
   550 		EIssuerUID = 7,		//optional - may be NULL
   551 		ESubjectUID = 8,	//optional - may be NULL
   552 		EExtensionList = 9	//optional - may be NULL
   553 		};
   554 	
   555 	/** Creates a new X.509 certificate object from the specified buffer containing 
   556 	* the binary coded representation.
   557 	* 
   558 	* @param aBinaryData	The encoded binary representation.
   559 	* @return				The new X.509 certificate object. */
   560 	IMPORT_C static CX509Certificate* NewL(const TDesC8& aBinaryData);
   561 	
   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.
   564 	* 
   565 	* Initialises the object from its encoded binary form into an internal representation.
   566 	* 
   567 	* @param aBinaryData	The encoded binary representation.
   568 	* @return				The new X.509 certificate object. */
   569 	IMPORT_C static CX509Certificate* NewLC(const TDesC8& aBinaryData);
   570 
   571 	/** Creates a new X.509 certificate object from the specified buffer containing 
   572 	* the binary coded representation, starting at the specified offset.
   573 	* 
   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);
   578 	
   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.
   582 	* 
   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);
   587 
   588 	/** Creates a new X.509 certificate object from the specified read stream.
   589 	* 
   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);
   593 	
   594 	/** Creates a new X.509 certificate object from the specified read stream, and 
   595 	* puts a pointer to it onto the cleanup stack.
   596 	* 
   597 	* Construction is from the stream.
   598 	* 
   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);
   602 
   603 	/** Creates a new X.509 certificate object from an existing object.
   604 	* 
   605 	* This is equivalent to a copy constructor.
   606 	* 
   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);
   610 	
   611 	/** Creates a new X.509 certificate object from an existing object.
   612 	* 
   613 	* This is equivalent to a copy constructor.
   614 	* 
   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);
   618 
   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;
   625 				
   626 
   627 	/** Destructor.
   628 	* 
   629 	* Frees all resources owned by the object, prior to its destruction. */
   630 	IMPORT_C ~CX509Certificate();
   631 	
   632 	/** Tests whether the specified X.509 certificate is equal to this X.509 certificate.
   633 	* 
   634 	* X.509 certificates are equal if both the serial number and the issuer name 
   635 	* are the same.
   636 	* 
   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;
   640 	
   641 	//extra accessors
   642 	/** Gets the certificate's signed data.
   643 	* 
   644 	* @return	A non-modifiable pointer descriptor representing the certificate's 
   645 	* 			signed data. */
   646 	IMPORT_C const TPtrC8 SignedDataL() const;
   647 	
   648 	/** Gets the version number of the certificate.
   649 	* 
   650 	* @return	The version number of the certificate. */
   651 	IMPORT_C TInt Version() const;
   652 	
   653 	/** Gets the X.500 Distinguished Name that identifies the issuer.
   654 	* 
   655 	* @return	The X.500 Distinguished Name that identifies the issuer. */
   656 	IMPORT_C const CX500DistinguishedName& IssuerName() const;
   657 	
   658 	/** Gets the X.500 Distinguished Name that identifies the subject.
   659 	* 
   660 	* @return	The X.500 Distinguished Name that identifies the subject. */
   661 	IMPORT_C const CX500DistinguishedName& SubjectName() const;
   662 	
   663 			//return all your generic extensions
   664 	/** Gets all generic certificate extensions.
   665 	* 
   666 	* @return	The certificate extensions. */
   667 	IMPORT_C const CArrayPtrFlat<CX509CertExtension>& Extensions() const;
   668 		
   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).
   672 	* 
   673 	* @param aExtensionName	The OID identifying the extension.
   674 	* @return				The certificate extension: Note that ownership is not transferred to 
   675 	* 						the caller. */
   676 	IMPORT_C const CX509CertExtension* Extension(const TDesC& aExtensionName) const;
   677 	
   678 	/** Internalises an object of this class from a read stream.
   679 	* 
   680 	* The presence of this function means that the standard templated operator>>() 
   681 	* can be used to internalise objects of this class.
   682 	* 
   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.
   685 	* 
   686 	* @param aStream	Stream from which the object is to be internalised. */
   687 	IMPORT_C void InternalizeL(RReadStream& aStream);
   688 		
   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.
   692 	* 
   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. 
   696 	* @since 		v7.0 */
   697 	IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
   698 
   699 public:	// from CCertificate
   700 	/** Gets the issuer of the certificate.
   701 	* 
   702 	* @return 	A heap descriptor representing the issuer of the certificate. */
   703 	IMPORT_C HBufC* IssuerL() const;
   704 	
   705 	/** Gets the subject of the certificate.
   706 	* 
   707 	* @return	A heap descriptor representing the issuer of the certificate. */
   708 	IMPORT_C HBufC* SubjectL() const;
   709 	
   710 	/** Tests whether the certificate is self-signed.
   711 	* 
   712 	* @return	ETrue, if it is self-signed; EFalse, otherwise. */
   713 	IMPORT_C TBool IsSelfSignedL() const;
   714 	
   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.
   718 	* 
   719 	* @return	A unique key identifier for the certificate. */
   720 	IMPORT_C TKeyIdentifier KeyIdentifierL() const;
   721 	
   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.
   727 	* 
   728 	* @return	The subject key identifier for the certificate. */
   729 	IMPORT_C TKeyIdentifier SubjectKeyIdentifierL() const;
   730 
   731 private:
   732 	CX509Certificate();
   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);
   739 	//private data
   740 	TInt iVersion;
   741 	CX500DistinguishedName* iIssuerName;
   742 	CX500DistinguishedName* iSubjectName;
   743 	HBufC8* iIssuerUid;
   744 	HBufC8* iSubjectUid;
   745 	CArrayPtrFlat<CX509CertExtension>* iExtensions;
   746 	TFixedArray<TPtrC8*, KX509MaxDataElements>* iDataElements;
   747 	};
   748 
   749 #endif