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