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