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