epoc32/include/x509cert.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 x509cert.h
     1 /*
       
     2 * Copyright (c) 1998-2009 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 
       
    22 /**
       
    23  @file 
       
    24  @internalAll
       
    25 */
       
    26  
       
    27 #ifndef __X509CERT_H__
       
    28 #define __X509CERT_H__
       
    29 
       
    30 #include <e32base.h>
       
    31 #include <e32std.h>
       
    32 #include <s32std.h>
       
    33 #include <signed.h>
       
    34 #include <x500dn.h>
       
    35 #include <asn1enc.h>
       
    36 
       
    37 _LIT(KMD2WithRSA,"1.2.840.113549.1.1.2");
       
    38 _LIT(KMD5WithRSA,"1.2.840.113549.1.1.4");
       
    39 _LIT(KSHA1WithRSA,"1.2.840.113549.1.1.5");
       
    40 _LIT(KDSAWithSHA1,"1.2.840.10040.4.3");
       
    41 
       
    42 _LIT(KRSA,"1.2.840.113549.1.1.1");
       
    43 _LIT(KDH,"1.2.840.10046.2.1");
       
    44 _LIT(KDSA,"1.2.840.10040.4.1");
       
    45 _LIT(KMD5,"1.2.840.113549.2.5");
       
    46 _LIT(KMD2,"1.2.840.113549.2.2");
       
    47 _LIT(KSHA1,"1.3.14.3.2.26");
       
    48 
       
    49 /** The maximum number of allowed data elements.
       
    50 * 
       
    51 * @since v7.0 */
       
    52 const TInt KX509MaxDataElements = 10;
       
    53 
       
    54 class CRSAPublicKey;
       
    55 class CDSAPublicKey;
       
    56 class CDSASignature;
       
    57 class CDSAParameters;
       
    58 
       
    59 class CPKCS1SignatureResult : public CRSASignatureResult
       
    60 /** The signature result in PKCS#1 format.
       
    61 * 
       
    62 * @publishedAll
       
    63 * @released
       
    64 * @since v6.0 */
       
    65 	{
       
    66 public:
       
    67 	/** Creates a new algorithm ID object copied from an existing object.
       
    68 	* 
       
    69 	* @param aDigestAlgorithm	The algorithm ID object to be copied.
       
    70 	* @param aDigest			A non-modifiable descriptor representing the digest algorithm.
       
    71 	* @return					A pointer to the new algorithm ID object. */
       
    72 	IMPORT_C static CPKCS1SignatureResult* NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
       
    73 	
       
    74 	/** Creates a new algorithm ID object copied from an existing
       
    75 	* object, and puts a pointer to the new object onto the cleanup stack.
       
    76 	* 
       
    77 	* @param aDigestAlgorithm	The algorithm ID object to be copied.
       
    78 	* @param aDigest			A non-modifiable descriptor representing the digest algorithm.
       
    79 	* @return					A pointer to the new algorithm ID object. */
       
    80 	IMPORT_C static CPKCS1SignatureResult* NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
       
    81 	
       
    82 	/** Tests whether the signature result is valid.
       
    83 	* 
       
    84 	* @param aResult	The signature result to be verified.
       
    85 	* @return			ETrue, if the signature result is verified; EFalse, otherwise. */
       
    86 	IMPORT_C virtual TBool VerifyL(const TDesC8& aResult);
       
    87 private:
       
    88 	void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
       
    89 	TBool DoVerifyL(const TDesC8& aResult);
       
    90 	};
       
    91 
       
    92 class TX509KeyFactory : public TKeyFactory
       
    93 /** Constructs the public key objects used for signature verification, from their 
       
    94 * encoded binary form, for X.509 certificates.
       
    95 * 
       
    96 * @publishedAll
       
    97 * @released
       
    98 * @since v6.0 */
       
    99 	{
       
   100 public:
       
   101 	/** Gets the RSA public key from the encoding key.
       
   102 	* 
       
   103 	* @param aEncoding	A non-modifiable descriptor representing the entire encoding.
       
   104 	* @return			The RSA Public key. */
       
   105 	IMPORT_C CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const;
       
   106 	
       
   107 	/** Gets the RSA signature result.
       
   108 	* 
       
   109 	* @param aDigestAlgorithm	The digest algorithm ID.
       
   110 	* @param aDigest			A non-modifiable descriptor representing the digest algorithm.
       
   111 	* @return					The RSA signature result. */
       
   112 	IMPORT_C CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const;
       
   113 	
       
   114 	/** Gets the DSA public key from the encoding key.
       
   115 	* 
       
   116 	* @param aParamsEncoding	A non-modifiable descriptor representing 
       
   117 	*							the encoded binary representation of the DSA parameters
       
   118 	* @param aEncoding			A non-modifiable descriptor representing the entire encoding.
       
   119 	* @return					The DSA public key. 
       
   120 	* @since 					v8.0 */
       
   121 	IMPORT_C CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const;
       
   122 	
       
   123 	/** Gets the digital DSA signature from the encoding key.
       
   124 	* 
       
   125 	* @param aEncoding	A non-modifiable descriptor representing the entire encoding.
       
   126 	* @return			The DSA signature. */
       
   127 	IMPORT_C CDSASignature* DSASignatureL(const TDesC8& aEncoding) const;
       
   128 	
       
   129 	/** Gets the DSA parameters from the encoding key.
       
   130 	* 
       
   131 	* @param aEncoding	A non-modifiable descriptor representing the entire encoding.
       
   132 	* @return			The DSA parameters. */
       
   133 	IMPORT_C CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const;
       
   134 	
       
   135 	/** Gets the DSA public key from the encoding key.
       
   136 	* 
       
   137 	* @param aParams	The DSA parameters
       
   138 	* @param aEncoding	A non-modifiable descriptor representing the entire encoding.
       
   139 	* @return			The DSA public key. */
       
   140 	IMPORT_C CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const;
       
   141 	};
       
   142 
       
   143 class CX509ValidityPeriod : public CValidityPeriod
       
   144 /** The period for which an X.509 certificate is valid.
       
   145 * 
       
   146 * @publishedAll
       
   147 * @released
       
   148 * @since v6.0 */
       
   149 	{
       
   150 public:
       
   151 	/** Creates a new X.509 validity period object from the specified buffer containing 
       
   152 	* the binary coded representation.
       
   153 	* 
       
   154 	* Initialises the object from its encoded binary form into an internal representation.
       
   155 	* 
       
   156 	* @param aBinaryData	The encoded binary representation.
       
   157 	* @return				The new validity period object. */
       
   158 	IMPORT_C static CX509ValidityPeriod* NewL(const TDesC8& aBinaryData);
       
   159 	
       
   160 	/** Creates a new X.509 validity period object from the specified buffer containing 
       
   161 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
       
   162 	* 
       
   163 	* Initialises the object from its encoded binary form into an internal representation.
       
   164 	* 
       
   165 	* @param aBinaryData	The encoded binary representation.
       
   166 	* @return				The new validity period object. */
       
   167 	IMPORT_C static CX509ValidityPeriod* NewLC(const TDesC8& aBinaryData);
       
   168 	
       
   169 	/** Creates a new X.509 validity period object from the specified buffer containing 
       
   170 	* the binary coded representation, starting at the specified offset.
       
   171 	* 
       
   172 	* Initialises the object from its encoded binary form into an internal representation.
       
   173 	* 
       
   174 	* @param aBinaryData	The encoded binary representation.
       
   175 	* @param aPos			The offset position from which to start decoding.
       
   176 	* @return				The new validity period object. */
       
   177 	IMPORT_C static CX509ValidityPeriod* NewL(const TDesC8& aBinaryData, TInt& aPos);
       
   178 	
       
   179 	/** Creates a new X.509 validity period object from the specified buffer containing 
       
   180 	* the binary coded representation, starting at the specified offset, and puts 
       
   181 	* a pointer to it onto the cleanup stack.
       
   182 	* 
       
   183 	* Initialises the object from its encoded binary form into an internal representation.
       
   184 	* 
       
   185 	* @param aBinaryData	The encoded binary representation.
       
   186 	* @param aPos			The offset position from which to start decoding.
       
   187 	* @return				The new validity period object. */
       
   188 	IMPORT_C static CX509ValidityPeriod* NewLC(const TDesC8& aBinaryData, TInt& aPos);
       
   189 private:
       
   190 	CX509ValidityPeriod();
       
   191 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
       
   192 	};
       
   193 
       
   194 class CX509AlgorithmIdentifier : public CAlgorithmIdentifier
       
   195 /** Algorithm identifier for an X.509 certificate.
       
   196 *
       
   197 * @publishedAll
       
   198 * @released
       
   199 * @since v6.0 */
       
   200 	{
       
   201 public:
       
   202 	/** Creates a new X.509 algorithm identifier object from the specified buffer containing 
       
   203 	* the binary coded representation.
       
   204 	* 
       
   205 	* The function initialises the object from its encoded binary form into an internal 
       
   206 	* representation.
       
   207 	* 
       
   208 	* @param aBinaryData	The encoded binary representation.
       
   209 	* @return				The new algorithm identifier object. */
       
   210 	IMPORT_C static CX509AlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
       
   211 	
       
   212 	/** Creates a new X.509 algorithm identifier object from the specified buffer containing 
       
   213 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
       
   214 	* 
       
   215 	* @param aBinaryData	The encoded binary representation.
       
   216 	* @return				The new algorithm identifier object. */
       
   217 	IMPORT_C static CX509AlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
       
   218 	
       
   219 	/** Creates a new X.509 algorithm identifier object from the specified buffer containing 
       
   220 	* the binary coded representation, starting at the specified offset.
       
   221 	* 
       
   222 	* @param aBinaryData	The encoded binary representation.
       
   223 	* @param aPos			The offset position from which to start decoding.
       
   224 	* @return				The new algorithm identifier object. */
       
   225 	IMPORT_C static CX509AlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
       
   226 	
       
   227 	/** Creates a new X.509 algorithm identifier object from the specified buffer containing 
       
   228 	* the binary coded representation, starting at the specified offset, and puts 
       
   229 	* a pointer to it onto the cleanup stack.
       
   230 	* 
       
   231 	* @param aBinaryData	The encoded binary representation.
       
   232 	* @param aPos			The offset position from which to start decoding.
       
   233 	* @return				The new algorithm identifier object. */
       
   234 	IMPORT_C static CX509AlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
       
   235 
       
   236 	/**
       
   237 	Creates a X509 Algorithm Identifier object from the given algorithm ID and the encoded parameter.
       
   238 	@param aAlgorithmId The algorithm Id used to build the object.
       
   239 	@param aEncodedParams The encoded parameter for the algorithm ID.	
       
   240 	@return The fully constructed object.
       
   241 	*/
       
   242 	IMPORT_C static CX509AlgorithmIdentifier* NewL(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams);
       
   243 
       
   244 	/**
       
   245 	Creates a X509 Algorithm Identifier object from the given algorithm ID and the encoded parameter
       
   246 	and leaves the object on the cleanup stack.
       
   247 	@param aAlgorithmId The algorithm Id used to build the object.
       
   248 	@param aEncodedParams The encoded parameter for the algorithm ID.	
       
   249 	@return The fully constructed object.
       
   250 	*/
       
   251 	IMPORT_C static CX509AlgorithmIdentifier* NewLC(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams);
       
   252 
       
   253 	/**
       
   254 	Creates the ASN1 DER sequence of the X509 algorithm identifier object
       
   255 	and leaves it on the cleanup stack.
       
   256 	@return  ASN1 DER sequence of this object.
       
   257 	*/
       
   258 	IMPORT_C CASN1EncSequence* EncodeASN1DERLC() const;
       
   259 
       
   260 private:
       
   261 	CX509AlgorithmIdentifier();
       
   262 	CX509AlgorithmIdentifier(TAlgorithmId& aAlgorithmId);
       
   263 	void InitializeL(const TDesC8& aBinaryData, TInt& aPos);
       
   264 	};
       
   265 
       
   266 class CX509SigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier
       
   267 /** Encapsulates the IDs of the algorithms used for signing an X.509 certificate.
       
   268 *
       
   269 * @publishedAll
       
   270 * @released
       
   271 * @since v6.0 */
       
   272 	{
       
   273 public:
       
   274 	/** Creates a new X.509 signing algorithm Id object from the specified buffer containing 
       
   275 	* the binary coded representation.
       
   276 	* 
       
   277 	* @param aBinaryData	The encoded binary representation.
       
   278 	* @return				The new signing algorithm Id object. */
       
   279 	IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
       
   280 	
       
   281 	/** Creates a new X.509 signing algorithm Id object from the specified buffer containing 
       
   282 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
       
   283 	* 
       
   284 	* @param aBinaryData	The encoded binary representation.
       
   285 	* @return				The new signing algorithm Id object. */
       
   286 	IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
       
   287 	
       
   288 	/** Creates a new X.509 signing algorithm Id object from the specified buffer containing 
       
   289 	* the binary coded representation, starting at the specified offset.
       
   290 	* 
       
   291 	* @param aBinaryData	The encoded binary representation.
       
   292 	* @param aPos			The offset position from which to start decoding.
       
   293 	* @return				The new signing algorithm Id object. */
       
   294 	IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
       
   295 	
       
   296 	/** Creates a new X.509 signing algorithm Id object from the specified buffer containing 
       
   297 	* the binary coded representation,starting at the specified offset, and puts 
       
   298 	* a pointer to it onto the cleanup stack.
       
   299 	* 
       
   300 	* @param aBinaryData	The encoded binary representation.
       
   301 	* @param aPos			The offset position from which to start decoding.
       
   302 	* @return				The new signing algorithm Id object. */
       
   303 	IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
       
   304 	/** Creates a new X.509 signing algorithm Id object from the specified algorithm pair
       
   305 	* 
       
   306 	* @param aAsymmetricAlgorithm	The asymmetric algorithm
       
   307 	* @param aDigestAlgorithm		The digest algorithm
       
   308 	* @return						The new signing algorithm Id object. */
       
   309  	IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm);
       
   310 	/** Creates a new X.509 signing algorithm Id object from the specified algorithm pair
       
   311 	* 
       
   312 	* @param aAsymmetricAlgorithm	The asymmetric algorithm
       
   313 	* @param aDigestAlgorithm		The digest algorithm
       
   314 	* @return						The new signing algorithm Id object. */
       
   315  	IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm);
       
   316 private:
       
   317 	CX509SigningAlgorithmIdentifier();
       
   318 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
       
   319 	void ConstructL(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm);
       
   320 	};
       
   321 
       
   322 class CX509SubjectPublicKeyInfo : public CSubjectPublicKeyInfo
       
   323 /** X.509 subject public key information.
       
   324 * 
       
   325 * @publishedAll
       
   326 * @released
       
   327 * @since v6.0 */
       
   328 	{
       
   329 public:
       
   330 	/** Creates a new X.509 subject public key object from the specified buffer containing 
       
   331 	* the binary coded representation.
       
   332 	* 
       
   333 	* @param aBinaryData	The encoded binary representation.
       
   334 	* @return				The new subject public key object. */
       
   335 	IMPORT_C static CX509SubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData);
       
   336 	
       
   337 	/** Creates a new X.509 subject public key object from the specified buffer containing 
       
   338 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
       
   339 	* 
       
   340 	* @param aBinaryData	The encoded binary representation.
       
   341 	* @return				The new subject public key object. */
       
   342 	IMPORT_C static CX509SubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData);
       
   343 	
       
   344 	/** Creates a new X.509 subject public key object from the specified buffer containing 
       
   345 	* the binary coded representation, starting at the specified offset.
       
   346 	* 
       
   347 	* @param aBinaryData	The encoded binary representation.
       
   348 	* @param aPos			The offset position from which to start decoding.
       
   349 	* @return				The subject public key object. */
       
   350 	IMPORT_C static CX509SubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData, TInt& aPos);
       
   351 	
       
   352 	/** Creates a new X.509 subject public key object from the specified buffer containing 
       
   353 	* the binary coded representation, starting at the specified offset, and puts 
       
   354 	* a pointer to it onto the cleanup stack.
       
   355 	* 
       
   356 	* @param aBinaryData	The encoded binary representation.
       
   357 	* @param aPos			The offset position from which to start decoding.
       
   358 	* @return				The new subject public key object. */
       
   359 	IMPORT_C static CX509SubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData, TInt& aPos);
       
   360 private:
       
   361 	CX509SubjectPublicKeyInfo();
       
   362 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
       
   363 	};
       
   364 
       
   365 class CX509CertExtension : public CBase
       
   366 /** A generic X.509 certificate extension.
       
   367 * 
       
   368 * The creation of a generic extension is the first step in the creation of a 
       
   369 * specific extension. Client code gets the decoded Object Identifier (OID) encapsulated 
       
   370 * by an instance of this class and uses it to create the specific extension.
       
   371 * 
       
   372 * Consists of an any-defined-by structure along with a boolean flag saying whether 
       
   373 * the extension is critical or not.
       
   374 * 
       
   375 * @publishedAll
       
   376 * @released
       
   377 * @since v6.0 */
       
   378 	{
       
   379 public:
       
   380 	/** Creates a new generic X.509 certificate extension object from an existing object.
       
   381 	* 
       
   382 	* This is equivalent to a copy constructor.
       
   383 	* 
       
   384 	* @param aExtension	The generic certificate extension to be copied.
       
   385 	* @return			The new generic certificate extension object. */
       
   386 	IMPORT_C static CX509CertExtension* NewL(const CX509CertExtension& aExtension);
       
   387 	
       
   388 	/** Creates a new generic X.509 certificate extension object from an existing object, 
       
   389 	* and puts a pointer to it onto the cleanup stack.
       
   390 	* 
       
   391 	* This is equivalent to a copy constructor.
       
   392 	* 
       
   393 	* @param aExtension	The generic certificate extension to be copied.
       
   394 	* @return			The new generic X.509 certificate extension object. */
       
   395 	IMPORT_C static CX509CertExtension* NewLC(const CX509CertExtension& aExtension);
       
   396 	
       
   397 	/** Creates a new generic X.509 certificate extension object from the specified 
       
   398 	* buffer containing the binary coded representation.
       
   399 	* 
       
   400 	* @param aBinaryData	The encoded binary representation.
       
   401 	* @return				The new generic X.509 certificate extension object. */
       
   402 	IMPORT_C static CX509CertExtension* NewL(const TDesC8& aBinaryData);
       
   403 	
       
   404 	/** Creates a new generic X.509 certificate extension object from the specified 
       
   405 	* buffer containing the binary coded representation, and puts a pointer to it 
       
   406 	* onto the cleanup stack .
       
   407 	* 
       
   408 	* @param aBinaryData	The encoded binary representation.
       
   409 	* @return				The new generic X.509 certificate extension object. */
       
   410 	IMPORT_C static CX509CertExtension* NewLC(const TDesC8& aBinaryData);
       
   411 	
       
   412 	/** Creates a new generic X.509 certificate extension object from the specified 
       
   413 	* buffer containing the binary coded representation, starting at the specified offset.
       
   414 	* 
       
   415 	* @param aBinaryData	The encoded binary representation.
       
   416 	* @param aPos			The offset position from which to start decoding.
       
   417 	* @return				The new generic X.509 certificate extension object. */
       
   418 	IMPORT_C static CX509CertExtension* NewL(const TDesC8& aBinaryData, TInt& aPos);
       
   419 	
       
   420 	/** Creates a new generic X.509 certificate extension object from the specified 
       
   421 	* buffer containing the binary coded representation, starting at the specified 
       
   422 	* offset, and puts a pointer to it onto the cleanup stack.
       
   423 	* 
       
   424 	* @param aBinaryData	The encoded binary representation.
       
   425 	* @param aPos			The offset position from which to start decoding.
       
   426 	* @return				The new generic X.509 certificate extension object. */
       
   427 	IMPORT_C static CX509CertExtension* NewLC(const TDesC8& aBinaryData, TInt& aPos);
       
   428 	
       
   429 	/** Creates a new generic X.509 certificate extension object from the specified 
       
   430 	* extension object id, the critcal flag and the extension data.
       
   431 	* 
       
   432 	* @param aCertExtOID	The OID of the certficate extension.
       
   433 	* @param aCritical		Flag to convey criticality of the extension.
       
   434 	* @param aCertExtValue	The data of the specific extension.
       
   435 	* @return				The new generic X.509 certificate extension object. */
       
   436 	IMPORT_C static CX509CertExtension* NewL(const TDesC& aCertExtOID, 
       
   437 							const TBool aCritical,
       
   438 							const TDesC8& aCertExtValue);
       
   439 
       
   440 	/** Creates a new generic X.509 certificate extension object from the specified 
       
   441 	* extension object id, the critcal flag and the extension data, and puts a 
       
   442 	* pointer to it onto the cleanup stack.
       
   443 	* 
       
   444 	* @param aCertExtOID	The OID of the certficate extension.
       
   445 	* @param aCritical		Flag to convey criticality of the extension.
       
   446 	* @param aCertExtValue	The data of the specific extension.
       
   447 	* @return				The new generic X.509 certificate extension object. */
       
   448 	IMPORT_C static CX509CertExtension* NewLC(const TDesC& aCertExtOID, 
       
   449 							const TBool aCritical,
       
   450 							const TDesC8& aCertExtValue);
       
   451 
       
   452 	/** Destructor.
       
   453 	* 
       
   454 	* Frees all resources owned by the object, prior to its destruction. */
       
   455 	IMPORT_C ~CX509CertExtension();
       
   456 	
       
   457 	/** Tests whether certificate processing code must process this extension for certificate 
       
   458 	* validation to succeed.
       
   459 	* 
       
   460 	* @return	ETrue, if this extension must be processed for validation to succeed; 
       
   461 	* 			EFalse, otherwise. */
       
   462 	IMPORT_C TBool Critical() const;
       
   463 	
       
   464 	/** Gets the Object Identifier (OID) of the certficate extension.
       
   465 	* 
       
   466 	* @return	The OID of the certficate extension. */
       
   467 	IMPORT_C TPtrC Id() const;	//OID for the extension
       
   468 	
       
   469 	/** Gets the encoded binary representation of the specific extension.
       
   470 	* 
       
   471 	* @return	A pointer descriptor representing the specific extension. */
       
   472 	IMPORT_C TPtrC8 Data() const;	//the extension itself 
       
   473 
       
   474 	/** Creates and returns a DER encoded X.509 certificate extension object in the form 
       
   475 	* of a ASN.1 Sequence and puts it onto the cleanup stack. This method can be called
       
   476 	* repeatedly to get copies of the sequence.
       
   477 	* 
       
   478 	* @return	A pointer to a DER encoded ASN.1 sequence */
       
   479 	IMPORT_C CASN1EncSequence * EncodeASN1DERLC() const;
       
   480 
       
   481 private:
       
   482 	CX509CertExtension();
       
   483 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
       
   484 	void ConstructL(const CX509CertExtension& aExtension);
       
   485 	void ConstructL(const TDesC& aCertExtOID, 
       
   486 					const TBool aCritical,
       
   487 					const TDesC8& aCertExtValue);
       
   488 	HBufC* iId;
       
   489 	TBool iCritical;
       
   490 	HBufC8* iData;
       
   491 	};
       
   492 
       
   493 class CX509Certificate : public CCertificate
       
   494 /** An X.509 certificate.
       
   495 * 
       
   496 * @publishedAll
       
   497 * @released
       
   498 * @since v6.0 */
       
   499 	{
       
   500 public:
       
   501 /** Enumerates values for encoded data element positions in the TBSCertificate data structure.
       
   502 * 
       
   503 * These values are to be used as parameters to the DataElementEncoding() function. */
       
   504 	enum
       
   505 		{
       
   506 		EVersionNumber = 0,	//optional - may be NULL
       
   507 		ESerialNumber = 1,
       
   508 		EAlgorithmId = 2,
       
   509 		EIssuerName = 3,
       
   510 		EValidityPeriod = 4,
       
   511 		ESubjectName = 5,
       
   512 		ESubjectPublicKeyInfo = 6,
       
   513 		EIssuerUID = 7,		//optional - may be NULL
       
   514 		ESubjectUID = 8,	//optional - may be NULL
       
   515 		EExtensionList = 9	//optional - may be NULL
       
   516 		};
       
   517 	
       
   518 	/** Creates a new X.509 certificate object from the specified buffer containing 
       
   519 	* the binary coded representation.
       
   520 	* 
       
   521 	* @param aBinaryData	The encoded binary representation.
       
   522 	* @return				The new X.509 certificate object. */
       
   523 	IMPORT_C static CX509Certificate* NewL(const TDesC8& aBinaryData);
       
   524 	
       
   525 	/** Creates a new X.509 certificate object from the specified buffer containing 
       
   526 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
       
   527 	* 
       
   528 	* Initialises the object from its encoded binary form into an internal representation.
       
   529 	* 
       
   530 	* @param aBinaryData	The encoded binary representation.
       
   531 	* @return				The new X.509 certificate object. */
       
   532 	IMPORT_C static CX509Certificate* NewLC(const TDesC8& aBinaryData);
       
   533 
       
   534 	/** Creates a new X.509 certificate object from the specified buffer containing 
       
   535 	* the binary coded representation, starting at the specified offset.
       
   536 	* 
       
   537 	* @param aBinaryData	The encoded binary representation.
       
   538 	* @param aPos			The offset position from which to start decoding.
       
   539 	* @return				The new X.509 certificate object. */
       
   540 	IMPORT_C static CX509Certificate* NewL(const TDesC8& aBinaryData, TInt& aPos);
       
   541 	
       
   542 	/** Creates a new X.509 certificate object from the specified buffer containing 
       
   543 	* the binary coded representation, starting at the specified offset, and puts 
       
   544 	* a pointer to it onto the cleanup stack.
       
   545 	* 
       
   546 	* @param aBinaryData	The encoded binary representation.
       
   547 	* @param aPos			The offset position from which to start decoding.
       
   548 	* @return				The new X.509 certificate object. */
       
   549 	IMPORT_C static CX509Certificate* NewLC(const TDesC8& aBinaryData, TInt& aPos);
       
   550 
       
   551 	/** Creates a new X.509 certificate object from the specified read stream.
       
   552 	* 
       
   553 	* @param aStream	Stream from which the contents should be internalised. 
       
   554 	* @return			The new X.509 certificate object. */
       
   555 	IMPORT_C static CX509Certificate* NewL(RReadStream& aStream);
       
   556 	
       
   557 	/** Creates a new X.509 certificate object from the specified read stream, and 
       
   558 	* puts a pointer to it onto the cleanup stack.
       
   559 	* 
       
   560 	* Construction is from the stream.
       
   561 	* 
       
   562 	* @param aStream	Stream from which the contents should be internalised. 
       
   563 	* @return			The new X.509 certificate object. */
       
   564 	IMPORT_C static CX509Certificate* NewLC(RReadStream& aStream);
       
   565 
       
   566 	/** Creates a new X.509 certificate object from an existing object.
       
   567 	* 
       
   568 	* This is equivalent to a copy constructor.
       
   569 	* 
       
   570 	* @param aCert	The X.509 certificate to be copied.
       
   571 	* @return		The new X.509 certificate object. */
       
   572 	IMPORT_C static CX509Certificate* NewL(const CX509Certificate& aCert);
       
   573 	
       
   574 	/** Creates a new X.509 certificate object from an existing object.
       
   575 	* 
       
   576 	* This is equivalent to a copy constructor.
       
   577 	* 
       
   578 	* @param aCert	The X.509 certificate to be copied.
       
   579 	* @return		The new X.509 certificate object. */
       
   580 	IMPORT_C static CX509Certificate* NewLC(const CX509Certificate& aCert);
       
   581 
       
   582 	/** Destructor.
       
   583 	* 
       
   584 	* Frees all resources owned by the object, prior to its destruction. */
       
   585 	IMPORT_C ~CX509Certificate();
       
   586 	
       
   587 	/** Tests whether the specified X.509 certificate is equal to this X.509 certificate.
       
   588 	* 
       
   589 	* X.509 certificates are equal if both the serial number and the issuer name 
       
   590 	* are the same.
       
   591 	* 
       
   592 	* @param aCert	The X.509 certificate to be compared.
       
   593 	* @return		ETrue, if the certificates are equal;EFalse, otherwise. */
       
   594 	IMPORT_C TBool IsEqualL(const CX509Certificate& aCert) const;
       
   595 	
       
   596 	//extra accessors
       
   597 	/** Gets the certificate's signed data.
       
   598 	* 
       
   599 	* @return	A non-modifiable pointer descriptor representing the certificate's 
       
   600 	* 			signed data. */
       
   601 	IMPORT_C const TPtrC8 SignedDataL() const;
       
   602 	
       
   603 	/** Gets the version number of the certificate.
       
   604 	* 
       
   605 	* @return	The version number of the certificate. */
       
   606 	IMPORT_C TInt Version() const;
       
   607 	
       
   608 	/** Gets the X.500 Distinguished Name that identifies the issuer.
       
   609 	* 
       
   610 	* @return	The X.500 Distinguished Name that identifies the issuer. */
       
   611 	IMPORT_C const CX500DistinguishedName& IssuerName() const;
       
   612 	
       
   613 	/** Gets the X.500 Distinguished Name that identifies the subject.
       
   614 	* 
       
   615 	* @return	The X.500 Distinguished Name that identifies the subject. */
       
   616 	IMPORT_C const CX500DistinguishedName& SubjectName() const;
       
   617 	
       
   618 			//return all your generic extensions
       
   619 	/** Gets all generic certificate extensions.
       
   620 	* 
       
   621 	* @return	The certificate extensions. */
       
   622 	IMPORT_C const CArrayPtrFlat<CX509CertExtension>& Extensions() const;
       
   623 		
       
   624 		//return a particular extension: this is NOT OWNED by the client
       
   625 		//returns NULL if the ext is not found
       
   626 	/** Gets the certificate extension identified by the specified object identifier (OID).
       
   627 	* 
       
   628 	* @param aExtensionName	The OID identifying the extension.
       
   629 	* @return				The certificate extension: Note that ownership is not transferred to 
       
   630 	* 						the caller. */
       
   631 	IMPORT_C const CX509CertExtension* Extension(const TDesC& aExtensionName) const;
       
   632 	
       
   633 	/** Internalises an object of this class from a read stream.
       
   634 	* 
       
   635 	* The presence of this function means that the standard templated operator>>() 
       
   636 	* can be used to internalise objects of this class.
       
   637 	* 
       
   638 	* Note that the function has assignment semantics. It replaces the old value 
       
   639 	* of the object with a new value read from the read stream.
       
   640 	* 
       
   641 	* @param aStream	Stream from which the object is to be internalised. */
       
   642 	IMPORT_C void InternalizeL(RReadStream& aStream);
       
   643 		
       
   644 		//return the encoding for a data element at the index specified
       
   645 	/** Gets the encoded data for the specified encoded data element (in the To Be 
       
   646 	* Signed (TBS) certificate data structure) of the signed object.
       
   647 	* 
       
   648 	* @param aIndex	The encoded data element position in the TBSCertificate data 
       
   649 	* 				structure. (See the CX509Certificate enumeration.)
       
   650 	* @return 		The encoded data for the specified data element of the signed object. 
       
   651 	* @since 		v7.0 */
       
   652 	IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
       
   653 
       
   654 public:	// from CCertificate
       
   655 	/** Gets the issuer of the certificate.
       
   656 	* 
       
   657 	* @return 	A heap descriptor representing the issuer of the certificate. */
       
   658 	IMPORT_C HBufC* IssuerL() const;
       
   659 	
       
   660 	/** Gets the subject of the certificate.
       
   661 	* 
       
   662 	* @return	A heap descriptor representing the issuer of the certificate. */
       
   663 	IMPORT_C HBufC* SubjectL() const;
       
   664 	
       
   665 	/** Tests whether the certificate is self-signed.
       
   666 	* 
       
   667 	* @return	ETrue, if it is self-signed; EFalse, otherwise. */
       
   668 	IMPORT_C TBool IsSelfSignedL() const;
       
   669 	
       
   670 	/** Gets a key identifier for the certificate. This is a unique identifier, calculated according 
       
   671 	* to the recommended method of computing it from RFC3280, section 4.2.1.2. Please note that this
       
   672 	* method does NOT return the value of the Subject Key Id extension, if it is present.
       
   673 	* 
       
   674 	* @return	A unique key identifier for the certificate. */
       
   675 	IMPORT_C TKeyIdentifier KeyIdentifierL() const;
       
   676 	
       
   677 	/** Gets the subject key identifier for the certificate. This identifier is extracted from the
       
   678 	* certificate (if the corresponding extension exists), or calculated (if the extension doesn't exist). If calculated, the recommendation from
       
   679 	* section 4.2.1.2, RFC3280 is used (hash of the public key). Please note, that for subject key ids
       
   680 	* extracted from the certificate there is a length limit - if the extension is longer than 160 bits,
       
   681 	* it is ignored and the value is calculated instead.
       
   682 	* 
       
   683 	* @return	The subject key identifier for the certificate. */
       
   684 	IMPORT_C TKeyIdentifier SubjectKeyIdentifierL() const;
       
   685 
       
   686 private:
       
   687 	CX509Certificate();
       
   688 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
       
   689 	void ConstructL(const CX509Certificate& aCertificate);
       
   690 	void ConstructCertL();
       
   691 	void InitDataElementsL(const CX509Certificate& aCertificate);
       
   692 	HBufC8* DecodeUidL(const TDesC8& aBinaryData, TBool& aHasElementAlready);
       
   693 	void DecodeExtsL(const TDesC8& aBinaryData, TBool& aHasElementAlready);
       
   694 	//private data
       
   695 	TInt iVersion;
       
   696 	CX500DistinguishedName* iIssuerName;
       
   697 	CX500DistinguishedName* iSubjectName;
       
   698 	HBufC8* iIssuerUid;
       
   699 	HBufC8* iSubjectUid;
       
   700 	CArrayPtrFlat<CX509CertExtension>* iExtensions;
       
   701 	TFixedArray<TPtrC8*, KX509MaxDataElements>* iDataElements;
       
   702 	};
       
   703 
       
   704 #endif