os/security/cryptoservices/certificateandkeymgmt/inc/cmssignerinfo.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 CMSSIGNERINFO_H
sl@0
    26
#define CMSSIGNERINFO_H
sl@0
    27
sl@0
    28
#include <e32base.h>
sl@0
    29
sl@0
    30
class CX509AlgorithmIdentifier;
sl@0
    31
class CPKCS7IssuerAndSerialNumber;
sl@0
    32
class CCmsSignerIdentifier;
sl@0
    33
class CASN1EncSequence;
sl@0
    34
class CX509Certificate;
sl@0
    35
class CDSAPrivateKey;
sl@0
    36
class CRSAPrivateKey;
sl@0
    37
class CMessageDigest;
sl@0
    38
class CASN1EncOctetString;
sl@0
    39
class CASN1EncBase;
sl@0
    40
sl@0
    41
sl@0
    42
/**
sl@0
    43
Represents CMS signer information as defined in RFC2630.
sl@0
    44
SignedAttributes and UnsignedAttributes are not supported.
sl@0
    45
*/
sl@0
    46
class CCmsSignerInfo : public CBase
sl@0
    47
	{
sl@0
    48
public:
sl@0
    49
sl@0
    50
	/**
sl@0
    51
	@internalComponent
sl@0
    52
	
sl@0
    53
	Creates a CMS signer info object as defined in RFC2630.
sl@0
    54
	@param aDataToBeSigned The data content or its hash to be signed.
sl@0
    55
	@param aIsHash Indicates whether the first parameter is a hash.
sl@0
    56
	@param aKey The DSA private key used to sign.
sl@0
    57
	@param aSignerIdentifier The signer identifier. Ownership of
sl@0
    58
		the signer identifier is taken by this newly created signer info object.
sl@0
    59
		If construction fails, ownership is not transferred. The user
sl@0
    60
		needs to push aSignerIdentifier onto the cleanup stack before calling this
sl@0
    61
		method, and pop it off the cleanup stack after successful construction.
sl@0
    62
	@param aDigestAlgorithm	The digest algorithm used to create the hash.
sl@0
    63
		Ownership of the digest algorithm instance is taken by
sl@0
    64
		this newly created signer info object. If construction fails, ownership
sl@0
    65
		is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before
sl@0
    66
		calling this method and pop it off the cleanup stack after successful construction.
sl@0
    67
	@param aSignatureAlgorithm The signature algorithm to create the signature.
sl@0
    68
		Ownership of the signature algorithm instance is taken by this
sl@0
    69
		newly created signer info object. If construction fails, ownership is not transferred.
sl@0
    70
		The user needs to push aDigestAlgorithm onto the cleanup stack before calling this
sl@0
    71
		method and pop it off the cleanup stack after successful construction.
sl@0
    72
	@return	The fully constructed object.
sl@0
    73
	*/
sl@0
    74
	static CCmsSignerInfo* NewL(const TDesC8& aDataToBeSigned,
sl@0
    75
								TBool aIsHash,
sl@0
    76
								const CDSAPrivateKey& aKey,
sl@0
    77
								CCmsSignerIdentifier* aSignerIdentifier,
sl@0
    78
								CX509AlgorithmIdentifier* aDigestAlgorithm,
sl@0
    79
								CX509AlgorithmIdentifier* aSignatureAlgorithm);
sl@0
    80
	/**
sl@0
    81
	@internalComponent
sl@0
    82
	
sl@0
    83
	Creates a CMS signer info object as defined in RFC2630
sl@0
    84
	and leaves it on the cleanup stack.
sl@0
    85
	@param aDataToBeSigned The data content or its hash to be signed.
sl@0
    86
	@param aIsHash Indicates whether the first parameter is a hash.
sl@0
    87
	@param aKey The DSA private key used to sign.
sl@0
    88
	@param aSignerIdentifier The signer identifier. Ownership of
sl@0
    89
		the signer identifier is taken by this newly created signer info object.
sl@0
    90
		If construction fails, ownership is not transferred. The user
sl@0
    91
		needs to push aSignerIdentifier onto the cleanup stack before calling this
sl@0
    92
		method, and pop it off the cleanup stack after successful construction.
sl@0
    93
	@param aDigestAlgorithm	The digest algorithm used to create the hash.
sl@0
    94
		Ownership of the digest algorithm instance is taken by
sl@0
    95
		this newly created signer info object. If construction fails, ownership
sl@0
    96
		is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before
sl@0
    97
		calling this method and pop it off the cleanup stack after successful construction.
sl@0
    98
	@param aSignatureAlgorithm The signature algorithm to create the signature.
sl@0
    99
		Ownership of the signature algorithm instance is taken by this
sl@0
   100
		newly created signer info object. If construction fails, ownership is not transferred.
sl@0
   101
		The user needs to push aDigestAlgorithm onto the cleanup stack before calling this
sl@0
   102
		method and pop it off the cleanup stack after successful construction.
sl@0
   103
	@return	The fully constructed object.
sl@0
   104
	*/
sl@0
   105
	static CCmsSignerInfo* NewLC(const TDesC8& aDataToBeSigned,
sl@0
   106
								TBool aIsHash,
sl@0
   107
								const CDSAPrivateKey& aKey,
sl@0
   108
								CCmsSignerIdentifier* aSignerIdentifier,
sl@0
   109
								CX509AlgorithmIdentifier* aDigestAlgorithm,
sl@0
   110
								CX509AlgorithmIdentifier* aSignatureAlgorithm);
sl@0
   111
	/**
sl@0
   112
	@internalComponent
sl@0
   113
	
sl@0
   114
	Creates a CMS signer info object as defined in RFC2630.
sl@0
   115
	@param aDataToBeSigned The data content or its hash to be signed.
sl@0
   116
	@param aIsHash Indicates whether the first parameter is a hash.
sl@0
   117
	@param aKey The RSA private key used to sign.
sl@0
   118
	@param aSignerIdentifier The signer identifier. Ownership of
sl@0
   119
		the signer identifier is taken by this newly created signer info object.
sl@0
   120
		If construction fails, ownership is not transferred. The user
sl@0
   121
		needs to push aSignerIdentifier onto the cleanup stack before calling this
sl@0
   122
		method, and pop it off the cleanup stack after successful construction.
sl@0
   123
	@param aDigestAlgorithm	The digest algorithm used to create the hash.
sl@0
   124
		Ownership of the digest algorithm instance is taken by
sl@0
   125
		this newly created signer info object. If construction fails, ownership
sl@0
   126
		is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before
sl@0
   127
		calling this method and pop it off the cleanup stack after successful construction.
sl@0
   128
	@param aSignatureAlgorithm The signature algorithm to create the signature.
sl@0
   129
		Ownership of the signature algorithm instance is taken by this
sl@0
   130
		newly created signer info object. If construction fails, ownership is not transferred.
sl@0
   131
		The user needs to push aDigestAlgorithm onto the cleanup stack before calling this
sl@0
   132
		method and pop it off the cleanup stack after successful construction.
sl@0
   133
	@return	The fully constructed object.
sl@0
   134
	*/
sl@0
   135
	static CCmsSignerInfo* NewL(const TDesC8& aDataToBeSigned,
sl@0
   136
								TBool aIsHash,
sl@0
   137
								const CRSAPrivateKey& aKey,
sl@0
   138
								CCmsSignerIdentifier* aSignerIdentifier,
sl@0
   139
								CX509AlgorithmIdentifier* aDigestAlgorithm,
sl@0
   140
								CX509AlgorithmIdentifier* aSignatureAlgorithm);
sl@0
   141
	/**
sl@0
   142
	@internalComponent
sl@0
   143
	
sl@0
   144
	Creates a CMS signer info object as defined in RFC2630
sl@0
   145
	and leaves it on the cleanup stack.
sl@0
   146
	@param aDataToBeSigned The data content or its hash to be signed.
sl@0
   147
	@param aIsHash Indicates whether the first parameter is a hash.
sl@0
   148
	@param aKey The RSA private key used to sign.
sl@0
   149
	@param aSignerIdentifier The signer identifier. Ownership of
sl@0
   150
		the signer identifier is taken by this newly created signer info object.
sl@0
   151
		If construction fails, ownership is not transferred. The user
sl@0
   152
		needs to push aSignerIdentifier onto the cleanup stack before calling this
sl@0
   153
		method, and pop it off the cleanup stack after successful construction.
sl@0
   154
	@param aDigestAlgorithm	The digest algorithm used to create the hash.
sl@0
   155
		Ownership of the digest algorithm instance is taken by
sl@0
   156
		this newly created signer info object. If construction fails, ownership
sl@0
   157
		is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before
sl@0
   158
		calling this method and pop it off the cleanup stack after successful construction.
sl@0
   159
	@param aSignatureAlgorithm The signature algorithm to create the signature.
sl@0
   160
		Ownership of the signature algorithm instance is taken by this
sl@0
   161
		newly created signer info object. If construction fails, ownership is not transferred.
sl@0
   162
		The user needs to push aDigestAlgorithm onto the cleanup stack before calling this
sl@0
   163
		method and pop it off the cleanup stack after successful construction.
sl@0
   164
	@return	The fully constructed object.
sl@0
   165
	*/										
sl@0
   166
	static CCmsSignerInfo* NewLC(const TDesC8& aDataToBeSigned,
sl@0
   167
								TBool aIsHash,
sl@0
   168
								const CRSAPrivateKey& aKey,
sl@0
   169
								CCmsSignerIdentifier* aSignerIdentifier,
sl@0
   170
								CX509AlgorithmIdentifier* aDigestAlgorithm,
sl@0
   171
								CX509AlgorithmIdentifier* aSignatureAlgorithm);
sl@0
   172
								
sl@0
   173
	/**
sl@0
   174
	@internalComponent
sl@0
   175
	
sl@0
   176
	Creates a CMS signer info object as defined in RFC2630.
sl@0
   177
	@param aRawData the encoded signer info.
sl@0
   178
	@return	The fully constructed object.
sl@0
   179
	*/
sl@0
   180
	static CCmsSignerInfo* NewL(const TDesC8& aRawData);
sl@0
   181
sl@0
   182
	/**
sl@0
   183
	@internalComponent
sl@0
   184
	
sl@0
   185
	Creates a CMS signer info object as defined in RFC2630
sl@0
   186
	and leaves it on the cleanup stack.
sl@0
   187
	@param aRawData The encoded signer info.
sl@0
   188
	@return	The fully constructed object.
sl@0
   189
	*/
sl@0
   190
	static CCmsSignerInfo* NewLC(const TDesC8& aRawData);	
sl@0
   191
	virtual ~CCmsSignerInfo();
sl@0
   192
sl@0
   193
	/**
sl@0
   194
	Returns the version of the CMS signer info object.
sl@0
   195
	@return	The version of the CMS signer info object.
sl@0
   196
	*/
sl@0
   197
	IMPORT_C TInt Version() const;
sl@0
   198
	
sl@0
   199
	/**
sl@0
   200
	Returns	whether signed attributes are present or not.
sl@0
   201
	@return Boolean indicating whether signed attributes are present or not.
sl@0
   202
	*/
sl@0
   203
	IMPORT_C TBool IsSignedAttributesPresent() const;
sl@0
   204
sl@0
   205
	/**
sl@0
   206
	Returns	whether unsigned attributes are present or not.
sl@0
   207
	@return Boolean indicating whether unsigned attributes are present or not.
sl@0
   208
	*/
sl@0
   209
	IMPORT_C TBool IsUnsignedAttributesPresent() const;	
sl@0
   210
	
sl@0
   211
	/**
sl@0
   212
	Returns the digest algorithm identifier.
sl@0
   213
	@return The digest algorithm identifier reference.
sl@0
   214
	*/
sl@0
   215
	IMPORT_C const CX509AlgorithmIdentifier& DigestAlgorithm() const;
sl@0
   216
sl@0
   217
	/**
sl@0
   218
	Returns the signature algorithm identifier.
sl@0
   219
	@return The signature algorithm identifier reference.
sl@0
   220
	*/			
sl@0
   221
	IMPORT_C const CX509AlgorithmIdentifier& SignatureAlgorithm() const;
sl@0
   222
	
sl@0
   223
	/**
sl@0
   224
	Returns the signature value.
sl@0
   225
	@return The signature value.
sl@0
   226
	*/
sl@0
   227
	IMPORT_C const TPtrC8 SignatureValue() const;
sl@0
   228
sl@0
   229
	/**
sl@0
   230
	Returns the signer identifier.
sl@0
   231
	@return the signer identifier reference.
sl@0
   232
	*/
sl@0
   233
	IMPORT_C const CCmsSignerIdentifier& SignerIdentifier() const;
sl@0
   234
sl@0
   235
	/**
sl@0
   236
	@internalComponent
sl@0
   237
sl@0
   238
	Creates the ASN.1 sequence of this CMS signed object and leaves it on the cleanup stack.
sl@0
   239
	@return  ASN.1 sequence of this object.
sl@0
   240
	*/
sl@0
   241
	CASN1EncSequence* EncodeASN1DERLC() const;	
sl@0
   242
	
sl@0
   243
private:
sl@0
   244
	/**
sl@0
   245
	Constructor.
sl@0
   246
	*/
sl@0
   247
	CCmsSignerInfo();
sl@0
   248
	
sl@0
   249
sl@0
   250
private:
sl@0
   251
	/**
sl@0
   252
	second phase constructor
sl@0
   253
	@param aDataToBeSigned the data or its hash
sl@0
   254
	@param aIsHash a flag to represent if the first paramter is hash or data content
sl@0
   255
	@param aKey the DSA private key used to create the signature.
sl@0
   256
	@param aSignerIdentifier the signer identifier.
sl@0
   257
	@param aDigestAlgorithm	the digest algorithm used to create hash.
sl@0
   258
	@param aSignatureAlgorithm	the signature alogorithm to create signature
sl@0
   259
	*/
sl@0
   260
	void ConstructL(const TDesC8& aDataToBeSigned, 
sl@0
   261
					TBool aIsHash, 
sl@0
   262
					const CDSAPrivateKey& aKey,					
sl@0
   263
					CCmsSignerIdentifier* aSignerIdentifier,
sl@0
   264
					CX509AlgorithmIdentifier* aDigestAlgorithm,
sl@0
   265
					CX509AlgorithmIdentifier* aSignatureAlgorithm);
sl@0
   266
sl@0
   267
	/**
sl@0
   268
	second phase constructor
sl@0
   269
	@param aDataToBeSigned the data or its hash
sl@0
   270
	@param aIsHash a flag to represent if the first paramter is hash or data content
sl@0
   271
	@param aKey the RSA private key used to create the signature.
sl@0
   272
	@param aSignerIdentifier the signer identifier.
sl@0
   273
	@param aDigestAlgorithm	the digest algorithm used to create hash.
sl@0
   274
	@param aSignatureAlgorithm	the signature alogorithm to create signature.	
sl@0
   275
	*/	
sl@0
   276
	void ConstructL(const TDesC8& aDataToBeSigned, 
sl@0
   277
					TBool aIsHash, 
sl@0
   278
					const CRSAPrivateKey& aKey,
sl@0
   279
					CCmsSignerIdentifier* aSignerIdentifier,
sl@0
   280
					CX509AlgorithmIdentifier* aDigestAlgorithm,
sl@0
   281
					CX509AlgorithmIdentifier* aSignatureAlgorithm);
sl@0
   282
	
sl@0
   283
	/**
sl@0
   284
	Second phase constructor
sl@0
   285
	@param aRawData the encoded the CMS content info
sl@0
   286
	*/		
sl@0
   287
	void ConstructL(const TDesC8& aRawData);
sl@0
   288
	
sl@0
   289
	/**
sl@0
   290
	Encode the signer identifier
sl@0
   291
	@return encoding of the signer identifier
sl@0
   292
	*/			
sl@0
   293
	CASN1EncBase* EncodeSignerIdentifierLC() const;
sl@0
   294
	
sl@0
   295
	/**
sl@0
   296
	Decode the signature
sl@0
   297
	@param aRawData the encoded signature
sl@0
   298
	*/
sl@0
   299
	void DecodeEncryptedDigestL(const TDesC8& aRawData);
sl@0
   300
	
sl@0
   301
	/**
sl@0
   302
	Decode the signer identifier
sl@0
   303
	@param aRawData the encoded signer identifier
sl@0
   304
	*/	
sl@0
   305
	void DecodeSignerIdentifierL(const TDesC8& aRawData);
sl@0
   306
	
sl@0
   307
private:
sl@0
   308
	/**
sl@0
   309
	Represents if the Signed Attribute is present
sl@0
   310
	*/
sl@0
   311
	TBool iSignedAttributesPresent;
sl@0
   312
	
sl@0
   313
	/**
sl@0
   314
	Represents if the Unsigned Attribute is present
sl@0
   315
	*/	
sl@0
   316
	TBool iUnsignedAttributesPresent;
sl@0
   317
	
sl@0
   318
	/**
sl@0
   319
	The version of the signer info
sl@0
   320
	*/
sl@0
   321
	TInt iVersion;
sl@0
   322
	
sl@0
   323
	/**
sl@0
   324
	the signer identifier
sl@0
   325
	*/
sl@0
   326
	CCmsSignerIdentifier* iSignerIdentifier;
sl@0
   327
	
sl@0
   328
	/**
sl@0
   329
	The digest algorithm identifier
sl@0
   330
	*/
sl@0
   331
	CX509AlgorithmIdentifier* iDigestAlgorithm;
sl@0
   332
	/**
sl@0
   333
	The signature algorithm identifier
sl@0
   334
	*/	
sl@0
   335
	CX509AlgorithmIdentifier* iSignatureAlgorithm;
sl@0
   336
		
sl@0
   337
	/**
sl@0
   338
	the signature value
sl@0
   339
	*/
sl@0
   340
	HBufC8* iSignatureValue;
sl@0
   341
	};
sl@0
   342
sl@0
   343
#endif
sl@0
   344
sl@0
   345
sl@0
   346
sl@0
   347
sl@0
   348
sl@0
   349
sl@0
   350
sl@0
   351
sl@0
   352
sl@0
   353
sl@0
   354
sl@0
   355
sl@0
   356
sl@0
   357
sl@0
   358
sl@0
   359
sl@0
   360
sl@0
   361
sl@0
   362
sl@0
   363