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