os/security/cryptoservices/certificateandkeymgmt/inc/cmssignedobject.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) 2006-2009 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
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
 @publishedPartner
sl@0
    22
 @released
sl@0
    23
*/
sl@0
    24
sl@0
    25
#ifndef CMSSIGNEDOBJECT_H
sl@0
    26
#define CMSSIGNEDOBJECT_H
sl@0
    27
sl@0
    28
#include <cmsdefs.h>
sl@0
    29
#include <signed.h>
sl@0
    30
#include <cmscertchoice.h>
sl@0
    31
sl@0
    32
class CCmsSignerInfo;
sl@0
    33
class CDSAPrivateKey;
sl@0
    34
class CRSAPrivateKey;
sl@0
    35
class CCmsSignerIdentifier;
sl@0
    36
class CCmsContentInfo;
sl@0
    37
class CEncapsulatedContentInfo;
sl@0
    38
class CX509Certificate;
sl@0
    39
class CX509AlgorithmIdentifier;
sl@0
    40
class CCmsCertificateChoice;
sl@0
    41
class CASN1EncSequence;
sl@0
    42
class CASN1EncBase;
sl@0
    43
sl@0
    44
const TInt KCmsMaxSignedDataElements = 6;
sl@0
    45
/**
sl@0
    46
 A representation of a RFC2630 (signed data) entity.
sl@0
    47
 */
sl@0
    48
class CCmsSignedObject : public CSignedObject
sl@0
    49
	{
sl@0
    50
public:
sl@0
    51
sl@0
    52
	/**
sl@0
    53
	Index of CMS object fields.
sl@0
    54
	*/
sl@0
    55
	enum
sl@0
    56
		{
sl@0
    57
		/**
sl@0
    58
		Index of version field
sl@0
    59
		*/
sl@0
    60
		EVersionNumber = 0,
sl@0
    61
		
sl@0
    62
		/**
sl@0
    63
		Index of digest algorithm set field
sl@0
    64
		*/		
sl@0
    65
		EDigestAlgorithms = 1,
sl@0
    66
sl@0
    67
		/**
sl@0
    68
		Index of encapsulated content info field
sl@0
    69
		*/				
sl@0
    70
		EEncapsulatedContentInfo = 2,
sl@0
    71
		
sl@0
    72
		/**
sl@0
    73
		Index of certificate set field
sl@0
    74
		*/						
sl@0
    75
		ECertificates = 3,
sl@0
    76
		
sl@0
    77
		/**
sl@0
    78
		Index of revocation list field
sl@0
    79
		*/						
sl@0
    80
		ERevocationLists = 4,
sl@0
    81
		
sl@0
    82
		/**
sl@0
    83
		Index of signer info set field
sl@0
    84
		*/						
sl@0
    85
		ESignedInfo = 5
sl@0
    86
		};
sl@0
    87
sl@0
    88
	/**
sl@0
    89
	Creates a CMS signed data object as defined in RFC2630. The CMS signed data created by 
sl@0
    90
		this API contains no signer info. SignL() method can be called to add more signer info.
sl@0
    91
	@param aType The type of the encapsulated content.
sl@0
    92
	@param aIsDetached A boolean indicating whether the encapsulated data is detached.
sl@0
    93
	@param aContentData The encapsulated data. 
sl@0
    94
		If aIsDetached is EFalse, aContentData must not be KNullDesC8. Otherwise this API leave 
sl@0
    95
		with KErrArgument.
sl@0
    96
		If aIsDetached is ETrue, aContentData can be KNullDesC8. But user must provide hash 
sl@0
    97
		value when later calling SignL(). Otherwise SignL() leaves with KErrArguement.	
sl@0
    98
	@return The fully constructed object.
sl@0
    99
	*/
sl@0
   100
	IMPORT_C static CCmsSignedObject* NewL(TCmsContentInfoType aType,
sl@0
   101
											TBool aIsDetached,
sl@0
   102
											const TDesC8& aContentData);
sl@0
   103
sl@0
   104
	/**
sl@0
   105
	Creates a CMS signed data object as defined in RFC2630, and leaves the object on the cleanup stack.
sl@0
   106
		this API contains no signer info. SignL() method can be called to add more signer info.
sl@0
   107
	@param aType The type of the encapsulated content.
sl@0
   108
	@param aIsDetached A boolean indicating whether the encapsulated data is detached.
sl@0
   109
	@param aContentData The encapsulated data.
sl@0
   110
		If aIsDetached is EFalse, aContentData must not be KNullDesC8. Otherwise this API leave 
sl@0
   111
		with KErrArgument.
sl@0
   112
		If aIsDetached is ETrue, aContentData can be KNullDesC8. But user must provide hash 
sl@0
   113
		value when later calling SignL(). Otherwise SignL() leaves with KErrArguement.	
sl@0
   114
	@return The fully constructed object.
sl@0
   115
	*/
sl@0
   116
	IMPORT_C static CCmsSignedObject* NewLC(TCmsContentInfoType aType,
sl@0
   117
											TBool aIsDetached,
sl@0
   118
											const TDesC8& aContentData);
sl@0
   119
	
sl@0
   120
	/**
sl@0
   121
	Creates a CMS signed data object as defined in RFC2630. This API only creates detached signed data 
sl@0
   122
		as no data content is provided. The CMS signed data created by this API contains one signer info. 
sl@0
   123
		SignL() method can be called to add more signer info.
sl@0
   124
	@param aType Encapsulated Content data type.
sl@0
   125
	@param aHashValue The hash value of the data content to be signed.
sl@0
   126
	@param aDigestAlgorithm The digest algorithm used to create the hash.
sl@0
   127
	@param aKey The DSA private key used to sign.
sl@0
   128
	@param aCert The signer's certificate.
sl@0
   129
	@param aAddCertificate A boolean indicating whether the signer's certificate is added to the signed data object.
sl@0
   130
	@return	The fully constructed object.
sl@0
   131
	*/	
sl@0
   132
	IMPORT_C static CCmsSignedObject* NewL(TCmsContentInfoType aType,
sl@0
   133
										const TDesC8& aHashValue,
sl@0
   134
										TAlgorithmId aDigestAlgorithm,
sl@0
   135
										const CDSAPrivateKey& aKey,
sl@0
   136
										const CX509Certificate& aCert,
sl@0
   137
										TBool aAddCertificate);
sl@0
   138
											
sl@0
   139
	/**
sl@0
   140
	Creates a CMS signed data object as defined in RFC2630 and leaves the object on the cleanup stack.
sl@0
   141
        This API only creates detached signed data as no data content is provided. The CMS signed data 
sl@0
   142
        created by this API contains one signer info. SignL() method can be called to add more signer info.
sl@0
   143
	@param aType Encapsulated Content data type.
sl@0
   144
	@param aHashValue The hash value of the data content to be signed.
sl@0
   145
	@param aDigestAlgorithm The digest algorithm used to create the hash.
sl@0
   146
	@param aKey The DSA private key used to sign.
sl@0
   147
	@param aCert The signer's certificate.
sl@0
   148
	@param aAddCertificate A boolean indicating whether the signer's certificate is added to the signed data object.
sl@0
   149
	@return	The fully constructed object.
sl@0
   150
	*/			
sl@0
   151
	IMPORT_C static CCmsSignedObject* NewLC(TCmsContentInfoType aType,
sl@0
   152
										const TDesC8& aHashValue,
sl@0
   153
										TAlgorithmId aDigestAlgorithm,
sl@0
   154
										const CDSAPrivateKey& aKey,
sl@0
   155
										const CX509Certificate& aCert,
sl@0
   156
										TBool aAddCertificate);
sl@0
   157
sl@0
   158
	/**
sl@0
   159
	Creates a CMS signed data object as defined in RFC2630. This API only creates detached signed data 
sl@0
   160
		as no data content is provided. The CMS signed data created by this API contains one signer info. 
sl@0
   161
		SignL() method can be called to add more signer info.
sl@0
   162
	@param aType Encapsulated Content data type.
sl@0
   163
	@param aHashValue The hash value of the data content to be signed.
sl@0
   164
	@param aDigestAlgorithm The digest algorithm used to create the hash.
sl@0
   165
	@param aKey The RSA private key used to sign.
sl@0
   166
	@param aCert aCert The signer's certificate.
sl@0
   167
	@param aAddCertificate A boolean indicating whether the signer's certificate is added to the signed data object.
sl@0
   168
	@return	The fully constructed object.
sl@0
   169
	*/	
sl@0
   170
	IMPORT_C static CCmsSignedObject* NewL(TCmsContentInfoType aType,
sl@0
   171
										const TDesC8& aHashValue,
sl@0
   172
										TAlgorithmId aDigestAlgorithm,
sl@0
   173
										const CRSAPrivateKey& aKey,
sl@0
   174
										const CX509Certificate& aCert,
sl@0
   175
										TBool aAddCertificate);
sl@0
   176
											
sl@0
   177
	/**
sl@0
   178
	Creates a CMS signed data object as defined in RFC2630 and leaves the object on the cleanup stack.
sl@0
   179
        This API only creates detached signed data as no data content is provided. The CMS signed data 
sl@0
   180
        created by this API contains one signer info. SignL() method can be called to add more signer info.
sl@0
   181
	@param aType Encapsulated Content data type.
sl@0
   182
	@param aHashValue The hash value of the data content to be signed.
sl@0
   183
	@param aDigestAlgorithm The digest algorithm used to create the hash.
sl@0
   184
	@param aKey The RSA private key used to sign.
sl@0
   185
	@param aCert The signer's certificate.
sl@0
   186
	@param aAddCertificate A boolean indicating whether the signer's certificate is added to the signed data object.
sl@0
   187
	@return	The fully constructed object.
sl@0
   188
	*/			
sl@0
   189
	IMPORT_C static CCmsSignedObject* NewLC(TCmsContentInfoType aType,
sl@0
   190
										const TDesC8& aHashValue,
sl@0
   191
										TAlgorithmId aDigestAlgorithm,
sl@0
   192
										const CRSAPrivateKey& aKey,
sl@0
   193
										const CX509Certificate& aCert,
sl@0
   194
										TBool aAddCertificate);
sl@0
   195
sl@0
   196
	/**
sl@0
   197
	Creates a CMS signed data object as defined in RFC2630.
sl@0
   198
	@param aContentInfo	The CMS content info that contains the encoded signed object.
sl@0
   199
	@return			The fully constructed object.
sl@0
   200
	*/
sl@0
   201
	IMPORT_C static CCmsSignedObject* NewL(const CCmsContentInfo& aContentInfo);
sl@0
   202
	
sl@0
   203
	/**
sl@0
   204
	Creates a CMS signed data object as defined in RFC2630 and leaves it on the cleanup stack.
sl@0
   205
	@param aContentInfo	The CMS content info that contains the encoded signed object.
sl@0
   206
	@return			The fully constructed object.
sl@0
   207
	*/	
sl@0
   208
	IMPORT_C static CCmsSignedObject* NewLC(const CCmsContentInfo& aContentInfo);
sl@0
   209
sl@0
   210
sl@0
   211
	/**
sl@0
   212
	Creates one signature and adds it to the Signer info list. The signing certificate
sl@0
   213
	is added to the certificate list if the last boolean parameter aAddCertificate is true and 
sl@0
   214
	it does not exist in the list. The digest algorithm is added to the digest algorithm list if it 
sl@0
   215
	does not exist in the list. Calling this API multiple times will create multiple signatures.
sl@0
   216
	@param aHashValue The hash value to be signed. If this is an empty string,
sl@0
   217
					  the content data to be signed must have been passed in via 
sl@0
   218
					  NewL method and hash value will be calculated by the implementation
sl@0
   219
					  of this method. 
sl@0
   220
	@param aDigestAlgorithm The digest algorithm used to create the hash.
sl@0
   221
	@param aKey the DSA private key used to sign.
sl@0
   222
	@param aCert the signer's certificate.
sl@0
   223
	@param aAddCertificate A boolean indicating whether the signer's certificate is added to the signed data object.
sl@0
   224
	@leave KErrArgument if no hash nor data content is provided.
sl@0
   225
	*/
sl@0
   226
	IMPORT_C void SignL(const TDesC8& aHashValue,
sl@0
   227
						TAlgorithmId aDigestAlgorithm,
sl@0
   228
						const CDSAPrivateKey& aKey,
sl@0
   229
						const CX509Certificate& aCert,
sl@0
   230
						TBool aAddCertificate);
sl@0
   231
						
sl@0
   232
sl@0
   233
	/**
sl@0
   234
	Creates one signature and adds it to the Signer info list. The signing certificate
sl@0
   235
	is added to the certificate list if the last boolean parameter aAddCertificate is true and 
sl@0
   236
	it does not exist in the list. The digest algorithm is added to the digest algorithm list if it 
sl@0
   237
	does not exist in the list. Calling this API multiple times will create multiple signatures.
sl@0
   238
	@param aHashValue The hash value to be signed. If this is an empty string,
sl@0
   239
					  the content data to be signed must have been passed in via 
sl@0
   240
					  NewL method and hash value will be calculated by the implementation
sl@0
   241
					  of this method. 
sl@0
   242
	@param aDigestAlgorithm The digest algorithm used to create the hash.
sl@0
   243
	@param aKey the RSA private key used to sign.
sl@0
   244
	@param aCert the signer's certificate.
sl@0
   245
	@param aAddCertificate A boolean indicating whether the signer's certificate is added to the signed data object.
sl@0
   246
	@leave KErrArgument if no hash nor data content is provided.
sl@0
   247
	*/
sl@0
   248
	IMPORT_C void SignL(const TDesC8& aHashValue,
sl@0
   249
						TAlgorithmId aDigestAlgorithm,
sl@0
   250
						const CRSAPrivateKey& aKey,
sl@0
   251
						const CX509Certificate& aCert,
sl@0
   252
						TBool aAddCertificate);
sl@0
   253
sl@0
   254
	/**
sl@0
   255
	Destructor
sl@0
   256
	*/
sl@0
   257
	IMPORT_C ~CCmsSignedObject();
sl@0
   258
sl@0
   259
	/*
sl@0
   260
	virtual from signedobject class
sl@0
   261
	*/
sl@0
   262
	IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
sl@0
   263
	IMPORT_C virtual void InternalizeL(RReadStream& aStream) ;
sl@0
   264
	IMPORT_C virtual const TPtrC8 SignedDataL() const;
sl@0
   265
		
sl@0
   266
	/**
sl@0
   267
	Returns whether the certificate list exists.
sl@0
   268
	@return	Boolean indicating whether the certificate list exists.
sl@0
   269
	*/
sl@0
   270
	IMPORT_C TBool IsCertificateSetPresent() const;
sl@0
   271
sl@0
   272
	/**
sl@0
   273
	Returns whether the certificate revocation list exists.
sl@0
   274
	@return	Boolean indicating whether the certificate Revocation list exists.
sl@0
   275
	*/
sl@0
   276
	IMPORT_C TBool IsCertificateRevocationListsPresent() const;
sl@0
   277
sl@0
   278
	/**
sl@0
   279
	Returns the version of this CMS signed object.
sl@0
   280
	@return The version of this CMS signed object.
sl@0
   281
	*/
sl@0
   282
	IMPORT_C TInt Version() const;
sl@0
   283
sl@0
   284
	/**
sl@0
   285
	Returns the employed algorithm list.
sl@0
   286
	@return	The employed algorithm list reference.
sl@0
   287
	*/
sl@0
   288
	IMPORT_C const RPointerArray<CX509AlgorithmIdentifier>& DigestAlgorithms() const;
sl@0
   289
	
sl@0
   290
	/**
sl@0
   291
	Returns the certificates list.
sl@0
   292
	@return	The certificates list reference.
sl@0
   293
	*/
sl@0
   294
	IMPORT_C const RPointerArray<CCmsCertificateChoice>& Certificates() const;
sl@0
   295
	
sl@0
   296
	/**
sl@0
   297
	Returns the encapsulated content info of this signed object.
sl@0
   298
	@return The encapsulated content info reference.
sl@0
   299
	*/
sl@0
   300
	IMPORT_C const CEncapsulatedContentInfo& ContentInfo() const;
sl@0
   301
sl@0
   302
	
sl@0
   303
	/**
sl@0
   304
	Retrieves the list of SignerInfo objects.
sl@0
   305
	@return The signer info list reference.
sl@0
   306
	*/
sl@0
   307
	IMPORT_C const RPointerArray<CCmsSignerInfo>& SignerInfo() const;
sl@0
   308
sl@0
   309
sl@0
   310
	/**
sl@0
   311
	Creates the ASN1 sequence of this CMS signed object and leaves it on the cleanup stack.
sl@0
   312
	@return  ASN1 sequence of this object.
sl@0
   313
	*/
sl@0
   314
	IMPORT_C CASN1EncSequence* EncodeASN1DERLC() const;
sl@0
   315
	
sl@0
   316
	/**
sl@0
   317
	Appends the X509 certificate to the certificate list.
sl@0
   318
	@param aCert The X509 certificate to be appended.
sl@0
   319
	*/
sl@0
   320
	IMPORT_C void AddCertificateL(const CX509Certificate& aCert);
sl@0
   321
sl@0
   322
sl@0
   323
	/**
sl@0
   324
	Appends an encoded attribute certificate to the certificate list. 
sl@0
   325
	@param aCert The encoded certificate to be appended.
sl@0
   326
	@param aType The type of the encoded certificate..
sl@0
   327
	*/
sl@0
   328
	IMPORT_C void AddCertificateL(const TDesC8& aCert, CCmsCertificateChoice::TCertificateType aType);	
sl@0
   329
	
sl@0
   330
	/**
sl@0
   331
	Validates the signer and creates the certificate chain for that signer. This API is used to validate attached signature.
sl@0
   332
	@param aSignerInfo The signer to be validated.
sl@0
   333
	@param aCertChainEncoding The certificate chain. This is created and pushed onto the cleanup stack by the function.
sl@0
   334
	@leave KErrNotFound There is no matching certificate.
sl@0
   335
	@return Boolean that identifies whether the signer can be validated.
sl@0
   336
    */
sl@0
   337
	IMPORT_C TBool ValidateSignerLC(const CCmsSignerInfo& aSignerInfo, HBufC8*& aCertChainEncoding);
sl@0
   338
sl@0
   339
	/**
sl@0
   340
	Validates the signer and creates the certificate chain for that signer. This API is used to validate attached signature.
sl@0
   341
	@param aSignerInfo The signer to be validated.
sl@0
   342
	@param aCertificates The certificate list provided by the user to validate the signature.
sl@0
   343
	@param aCertChainEncoding The certificate chain. This is created and pushed onto the cleanup stack by the function.
sl@0
   344
	@return Boolean that identifies whether the signer can be validated.
sl@0
   345
	@leave KErrNotFound There is no matching certificate.
sl@0
   346
	*/
sl@0
   347
	IMPORT_C TBool ValidateSignerLC(const CCmsSignerInfo& aSignerInfo, const RPointerArray<CX509Certificate>& aCertificates, HBufC8*& aCertChainEncoding);
sl@0
   348
sl@0
   349
sl@0
   350
sl@0
   351
	/**
sl@0
   352
	Validates the signer and creates the certificate chain for that signer. This API is used to validate detached signature.
sl@0
   353
	@param aSignerInfo The signer to be validated.
sl@0
   354
	@param aCertChainEncoding The certificate chain. This is created and pushed onto the cleanup stack by the function.
sl@0
   355
	@param aIsHash The flag represent if the next parameter is the hash of the data content.
sl@0
   356
	@param aContentDataOrHash the descriptor that contains the data content or its hash
sl@0
   357
	@leave KErrNotFound There is no matching certificate.
sl@0
   358
	@return Boolean that identifies whether the signer can be validated.
sl@0
   359
    */
sl@0
   360
	IMPORT_C TBool ValidateSignerLC(const CCmsSignerInfo& aSignerInfo, HBufC8*& aCertChainEncoding, TBool aIsHash, const TDesC8& aContentDataOrHash);
sl@0
   361
sl@0
   362
	/**
sl@0
   363
	Validates the signer and creates the certificate chain for that signer. This API is used to validate detached signature.
sl@0
   364
	@param aSignerInfo The signer to be validated.
sl@0
   365
	@param aCertificates The certificate list provided by the user to validate the signature.
sl@0
   366
	@param aCertChainEncoding The certificate chain. This is created and pushed onto the cleanup stack by the function.
sl@0
   367
	@param aIsHash The flag represent if the next parameter is the hash of the data content.
sl@0
   368
	@param aContentDataOrHash the descriptor that contains the data content or its hash	
sl@0
   369
	@return Boolean that identifies whether the signer can be validated.
sl@0
   370
	@leave KErrNotFound There is no matching certificate.
sl@0
   371
	*/
sl@0
   372
	IMPORT_C TBool ValidateSignerLC(const CCmsSignerInfo& aSignerInfo, const RPointerArray<CX509Certificate>& aCertificates, HBufC8*& aCertChainEncoding, TBool aIsHash, const TDesC8& aContentDataOrHash);
sl@0
   373
sl@0
   374
	
sl@0
   375
private:
sl@0
   376
	/**
sl@0
   377
	Constructor
sl@0
   378
	*/
sl@0
   379
	CCmsSignedObject();
sl@0
   380
	
sl@0
   381
	
sl@0
   382
private:
sl@0
   383
	/**
sl@0
   384
	Second phase constructor for decoding a CMS signed data object
sl@0
   385
	@param aContentInfo the content info which contains the CMS signed data.
sl@0
   386
	*/		
sl@0
   387
	void ConstructL(const CCmsContentInfo& aContentInfo);
sl@0
   388
	
sl@0
   389
	/**
sl@0
   390
	Second phase constructor for constructing a CMS signed data object from data content.
sl@0
   391
	@param aType the encapsulated content info type.
sl@0
   392
	@param aIsDetached if the CMS signed data does not contains the data content being signed.
sl@0
   393
	@param aContentData the content data descriptor.
sl@0
   394
	*/			
sl@0
   395
	void ConstructL(TCmsContentInfoType aType, TBool aIsDetached, const TDesC8& aContentData);
sl@0
   396
	
sl@0
   397
	/**
sl@0
   398
	Second phase constructor for constructing a CMS signed data object from data content hash
sl@0
   399
	@param aType the encapsulated content info type.
sl@0
   400
	@param aHashValue the hash of the data content to create the signature.
sl@0
   401
	@param aDigestAlgorithm the digest algorithm.
sl@0
   402
	@param aKey the DSA private to create signature.
sl@0
   403
	@param aCert the signer's certficate
sl@0
   404
	@param aAddCertificate a flag to represent if the signer's certificate is added to certificate set.
sl@0
   405
	*/				
sl@0
   406
	void ConstructL(TCmsContentInfoType aType,
sl@0
   407
					const TDesC8& aHashValue,
sl@0
   408
					TAlgorithmId aDigestAlgorithm,
sl@0
   409
					const CDSAPrivateKey& aKey,
sl@0
   410
					const CX509Certificate& aCert,
sl@0
   411
					TBool aAddCertificate);
sl@0
   412
	/**
sl@0
   413
	Second phase constructor for constructing a CMS signed data object from data content hash
sl@0
   414
	@param aType the encapsulated content info type.
sl@0
   415
	@param aHashValue the hash of the data content to create the signature.
sl@0
   416
	@param aDigestAlgorithm the digest algorithm.
sl@0
   417
	@param aKey the RSA private to create signature.
sl@0
   418
	@param aCert the signer's certficate
sl@0
   419
	@param aAddCertificate a flag to represent if the signer's certificate is added to certificate set.
sl@0
   420
	*/								
sl@0
   421
	void ConstructL(TCmsContentInfoType aType,
sl@0
   422
					const TDesC8& aHashValue,
sl@0
   423
					TAlgorithmId aDigestAlgorithm,
sl@0
   424
					const CRSAPrivateKey& aKey,
sl@0
   425
					const CX509Certificate& aCert,
sl@0
   426
					TBool aAddCertificate);
sl@0
   427
	/**
sl@0
   428
	Append the algorithm to the algoritm list
sl@0
   429
	@param aDigestAlgorithm the algorithm ID.
sl@0
   430
	*/
sl@0
   431
	void AddDigestAlgorithmL(TAlgorithmId aDigestAlgorithm);
sl@0
   432
					
sl@0
   433
	/**
sl@0
   434
	Build the signer's identifier from the signer's certificate. If the signer's certificate
sl@0
   435
	contains the subject identifier extension, the signer identifier is subject id extension.
sl@0
   436
	otherwise, the signer identifier is isuuer name and serial number.
sl@0
   437
	@param aCert the signer's certificate.
sl@0
   438
	@return a CMS signer identifier instance pointer
sl@0
   439
	*/
sl@0
   440
	CCmsSignerIdentifier* BuildSignerIdentifierLC(const CX509Certificate& aCert);
sl@0
   441
	
sl@0
   442
	/**
sl@0
   443
	Build the signer list, algorithm list and certificate list in the CMS signer data.
sl@0
   444
	@param aDigestAlgorithm the digest algorithm identifier.
sl@0
   445
	@param aIsHash A flag the represent if the next descriptor is the hash value rather that original data
sl@0
   446
	@param aValue the data content or its hash.
sl@0
   447
	@param aKey the DSA private used to sign.
sl@0
   448
	@param aCert the signer's certificate
sl@0
   449
	@param aAddCertificate the flag to represent if the certificate is added to the certificate set
sl@0
   450
	*/	
sl@0
   451
	void BuildSignerInfoCertListAndAlgoritmListL(TAlgorithmId aDigestAlgorithm,
sl@0
   452
												TBool aIsHash,
sl@0
   453
												const TDesC8& aValue,
sl@0
   454
												const CDSAPrivateKey& aKey,
sl@0
   455
												const CX509Certificate& aCert,
sl@0
   456
												TBool aAddCertificate);
sl@0
   457
sl@0
   458
	/**
sl@0
   459
	Build the signer list, algorithm list and certificate list in the CMS signer data.
sl@0
   460
	@param aDigestAlgorithm the digest algorithm identifier.
sl@0
   461
	@param aIsHash A flag the represent if the next descriptor is the hash value rather that original data
sl@0
   462
	@param aValue the data content or its hash.
sl@0
   463
	@param aKey the RSA private used to sign.
sl@0
   464
	@param aCert the signer's certificate
sl@0
   465
	@param aAddCertificate the flag to represent if the certificate is added to the certificate set
sl@0
   466
	*/		
sl@0
   467
	void BuildSignerInfoCertListAndAlgoritmListL(TAlgorithmId aDigestAlgorithm,
sl@0
   468
												TBool aIsHash,
sl@0
   469
												const TDesC8& aValue,
sl@0
   470
												const CRSAPrivateKey& aKey,
sl@0
   471
												const CX509Certificate& aCert,
sl@0
   472
												TBool aAddCertificate);
sl@0
   473
	/**
sl@0
   474
	Initialise the signed data base class members for the validation process.
sl@0
   475
	@param aRawData the raw data of the CMS signed data.
sl@0
   476
	*/
sl@0
   477
	void InitSignedObjectL(const TDesC8& aRawData);
sl@0
   478
	
sl@0
   479
	
sl@0
   480
	/**
sl@0
   481
	Decode the CMS Signer data.
sl@0
   482
	@param aRawData the raw data of the CMS signed data.
sl@0
   483
	*/
sl@0
   484
	void DecodeSignedDataL(const TDesC8& aRawData);	
sl@0
   485
sl@0
   486
	/**
sl@0
   487
	Decode the digest algorithm set.
sl@0
   488
	@param the raw data of the algorithm list.
sl@0
   489
	*/
sl@0
   490
	void DecodeDigestAlgorithmsL(const TDesC8& aRawData);
sl@0
   491
sl@0
   492
	/**
sl@0
   493
	Decode the encapsulated content info
sl@0
   494
	@param the raw data of the encapsulated content info.
sl@0
   495
	*/
sl@0
   496
	void DecodeEncapsulatedContentInfoL(const TDesC8& aRawData);
sl@0
   497
	
sl@0
   498
	/**
sl@0
   499
	Decode the certificate set.
sl@0
   500
	@param the raw data of the certificate list
sl@0
   501
	*/	
sl@0
   502
	void DecodeCertificatesL(const TDesC8& aRawData);
sl@0
   503
	
sl@0
   504
	/**
sl@0
   505
	Decode the certificate revocation set. Not implemented now!
sl@0
   506
	@param the raw data of the certificate revocation list.
sl@0
   507
	*/		
sl@0
   508
	void DecodeRevocationListsL(const TDesC8& aRawData);
sl@0
   509
sl@0
   510
	/**
sl@0
   511
	Decode the signer info set.
sl@0
   512
	@param the raw data of the certificate revocation list.
sl@0
   513
	*/			
sl@0
   514
	void DecodeSignerInfoL(const TDesC8& aRawData);
sl@0
   515
sl@0
   516
	/**
sl@0
   517
	Encode the certificate set
sl@0
   518
	@return the encoding of the certificate set
sl@0
   519
	*/													
sl@0
   520
	CASN1EncBase* EncodeCertificatesLC() const;
sl@0
   521
	
sl@0
   522
	/**
sl@0
   523
	Encode the algorithm set
sl@0
   524
	@return the encoding of the digest algorithm set
sl@0
   525
	*/
sl@0
   526
	CASN1EncBase* EncodeAlgorithmsLC() const;
sl@0
   527
	
sl@0
   528
	/**
sl@0
   529
	Encode the signer info set
sl@0
   530
	@return the encoding of the certificate set
sl@0
   531
	*/
sl@0
   532
	CASN1EncBase* EncodeSignerInfoLC() const;
sl@0
   533
	
sl@0
   534
	/**
sl@0
   535
	Validate the signature by the given certificate.
sl@0
   536
	@param aSignerInfo the signer info reference contains the signature
sl@0
   537
	@param aEndEntityCert the certificate used to create the signature.
sl@0
   538
	@return if the signature can be validated
sl@0
   539
	*/
sl@0
   540
	TBool ValidateSignatureL(const CCmsSignerInfo& aSignerInfo, const CX509Certificate& aEndEntityCert);
sl@0
   541
	
sl@0
   542
	/**
sl@0
   543
	This function is called when validating a detached CMS signed object.
sl@0
   544
	It sets the data content being signed so that the signed data can be validated.
sl@0
   545
	@param aContentData The data content being signed.
sl@0
   546
	*/
sl@0
   547
	void SetContentData(const TDesC8& aContentData);
sl@0
   548
sl@0
   549
	/**
sl@0
   550
	This function is called when validating a detached CMS signed object.
sl@0
   551
	It sets the hash being signed so that the signed data can be validated.
sl@0
   552
	@param aHash The hash being signed.
sl@0
   553
	*/
sl@0
   554
	void SetHash(const TDesC8& aHash);
sl@0
   555
	
sl@0
   556
	
sl@0
   557
private:
sl@0
   558
	/**
sl@0
   559
	Reprents if the certificate set is present
sl@0
   560
	*/
sl@0
   561
	TBool iIsCertificateSetPresent;
sl@0
   562
	
sl@0
   563
	/**
sl@0
   564
	Reprents if the certificate revocationlisy is present
sl@0
   565
	*/	
sl@0
   566
	TBool iIsCertificateRevocationListsPresent;
sl@0
   567
	
sl@0
   568
	/**
sl@0
   569
	Version of the Signed object
sl@0
   570
	*/
sl@0
   571
	TInt iVersion;
sl@0
   572
	
sl@0
   573
	/**
sl@0
   574
	Algorithm Set
sl@0
   575
	*/
sl@0
   576
	RPointerArray<CX509AlgorithmIdentifier> iDigestAlgorithms;
sl@0
   577
	
sl@0
   578
	/**
sl@0
   579
	Encapsulated Content List
sl@0
   580
	*/
sl@0
   581
	CEncapsulatedContentInfo* iContentInfo;
sl@0
   582
	
sl@0
   583
	/**
sl@0
   584
	Certificate Set
sl@0
   585
	*/
sl@0
   586
	RPointerArray<CCmsCertificateChoice> iCertificates;
sl@0
   587
	
sl@0
   588
	/**
sl@0
   589
	Signer Info Set
sl@0
   590
	*/
sl@0
   591
	RPointerArray<CCmsSignerInfo> iSignerInfo;
sl@0
   592
	
sl@0
   593
	/**
sl@0
   594
	Array of Encoded fields
sl@0
   595
	*/	
sl@0
   596
	TFixedArray<TPtrC8*, KCmsMaxSignedDataElements> iDataElements;
sl@0
   597
	
sl@0
   598
	/**
sl@0
   599
	The data content being signed
sl@0
   600
	*/
sl@0
   601
	TPtrC8 iContentData;
sl@0
   602
	
sl@0
   603
	/**
sl@0
   604
	The Hash being signed
sl@0
   605
	*/
sl@0
   606
	TPtrC8 iHash;
sl@0
   607
	};
sl@0
   608
sl@0
   609
sl@0
   610
#endif //CMSSIGNEDOBJECT_H