secsrv_plat/cms_api/inc/CCMSSignedData.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 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 "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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CCMSSignedData_H
       
    21 #define CCMSSignedData_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "CCMSSequence.h"
       
    25 #include "CCMSEncapsulatedContentInfo.h"
       
    26 #include "CCMSX509AlgorithmIdentifier.h"
       
    27 #include "CCMSSignerInfo.h"
       
    28 #include "CCMSX509CertificateList.h"
       
    29 #include "CCMSCertificateChoices.h"
       
    30 #include <badesca.h>
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 
       
    34 // Extension
       
    35 class MCMSSignedDataExtension;
       
    36 
       
    37 
       
    38 // CLASS DECLARATION
       
    39 /**
       
    40 *  Attribute type module
       
    41 *
       
    42 *  ASN.1 Definition:
       
    43 *  SignedData ::= SEQUENCE {
       
    44 *  	 version CMSVersion,
       
    45 *    digestAlgorithms DigestAlgorithmIdentifiers,
       
    46 *    encapContentInfo EncapsulatedContentInfo,
       
    47 *    certificates [0] IMPLICIT CertificateSet OPTIONAL,
       
    48 *    crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
       
    49 *    signerInfos SignerInfos }
       
    50 *
       
    51 *  DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
       
    52 *
       
    53 *  SignerInfos ::= SET OF SignerInfo
       
    54 *
       
    55 *  @lib cms.lib
       
    56 *  @since 2.8
       
    57 */
       
    58 class CCMSSignedData : public CCMSSequence
       
    59     {
       
    60     public:  // Constructors and destructor
       
    61 		/**
       
    62         * Two-phased constructor.
       
    63         * NOTE: Encrypt will leave with KErrArgument if
       
    64         * valid parameters are not set.
       
    65         */
       
    66         IMPORT_C static CCMSSignedData* NewLC();
       
    67 
       
    68         /**
       
    69         * Two-phased constructor.
       
    70         * Takes copy of all parameters.
       
    71         * Leaves newly created instance in CleanupStack
       
    72 		*
       
    73 		* @param aDigestAlgorithmIdentifiers Array of digest algorithm 
       
    74 		*		 identifiers, mandatory
       
    75         * @param aContentInfo Encapsulated content info, mandatory
       
    76 		* @param aSignerInfos, Array of signer infos, mandatory
       
    77         */
       
    78         IMPORT_C static CCMSSignedData* NewLC(
       
    79 			const CArrayPtr< CCMSX509AlgorithmIdentifier >& aDigestAlgorithmIdentifiers,
       
    80         	const CCMSEncapsulatedContentInfo& aContentInfo,
       
    81         	const CArrayPtr< CCMSSignerInfo >& aSignerInfos );
       
    82 
       
    83 		/**
       
    84         * Two-phased constructor.
       
    85         * Same as above although takes only one value
       
    86 		* Leaves newly created instance in CleanupStack
       
    87 		* @param aDigestAlgorithmIdentifiers Array of digest algorithm 
       
    88 		*		 identifiers, mandatory
       
    89         * @param aContentInfo Encapsulated content info, mandatory
       
    90 		* @param aSignerInfos, Array of signer infos, mandatory
       
    91 		* @param aCertificates Array of certificates choices, optional
       
    92 		* @param aRevokedCertificates Array of revoked certificates, optional
       
    93         */
       
    94         IMPORT_C static CCMSSignedData* NewLC(
       
    95 			const CArrayPtr< CCMSX509AlgorithmIdentifier >& aDigestAlgorithmIdentifiers,
       
    96         	const CCMSEncapsulatedContentInfo& aContentInfo,
       
    97         	const CArrayPtr< CCMSSignerInfo >& aSignerInfos,
       
    98         	const CArrayPtr< CCMSCertificateChoices >* aCertificates,
       
    99         	const CArrayPtr< CCMSX509CertificateList >* aRevokedCertificates );
       
   100 
       
   101         /**
       
   102         * Destructor.
       
   103         */
       
   104         virtual ~CCMSSignedData();
       
   105 
       
   106     public: // New functions
       
   107 
       
   108     	/**
       
   109 		* Getter for Version
       
   110 		*
       
   111 		* Version is the syntax version number.  If no attribute
       
   112 		* certificates are present in the certificates field, the
       
   113 		* encapsulated content type is id-data, and all of the elements of
       
   114 		* SignerInfos are version 1, then the value of version shall be 1.
       
   115 		* Alternatively, if attribute certificates are present, the
       
   116 		* encapsulated content type is other than id-data, or any of the
       
   117 		* elements of SignerInfos are version 3, then the value of version
       
   118 		* shall be 3.
       
   119 		*
       
   120 		* @since 2.8
       
   121 		* @return version number, 1 or 3
       
   122 		*/
       
   123 		IMPORT_C TInt Version() const;
       
   124 
       
   125     	/**
       
   126 		* Getter for DigestAlgorithmIdentifiers
       
   127 		*
       
   128 		* DigestAlgorithms is a collection of message digest algorithm
       
   129 		* identifiers.  There may be any number of elements in the
       
   130 		* collection, including zero.  Each element identifies the message
       
   131 		* digest algorithm, along with any associated parameters, used by
       
   132 		* one or more signer.  The collection is intended to list the
       
   133 		* message digest algorithms employed by all of the signers, in any
       
   134 		* order, to facilitate one-pass signature verification.
       
   135 		*
       
   136 		* @since 2.8
       
   137 		* @return Array of digest algorithm identifiers.
       
   138 		*/
       
   139 		IMPORT_C const CArrayPtr< CCMSX509AlgorithmIdentifier >& DigestAlgorithmIdentifiers() const;
       
   140 
       
   141     	/**
       
   142 		* Getter for EncapsulatedContentInfo
       
   143 		*
       
   144 		* EncapsulatedContentInfo is the signed content, consisting of a content
       
   145 		* type identifier and the content itself.
       
   146 		* 
       
   147 		* @since 2.8
       
   148 		* @return Encapsulated content info.
       
   149 		*/
       
   150         IMPORT_C const CCMSEncapsulatedContentInfo& EncapsulatedContentInfo() const;
       
   151 
       
   152     	/**
       
   153 		* Getter for SignerInfos
       
   154 		*
       
   155 		* SignerInfos is a collection of per-signer information.  There may
       
   156 		* be any number of elements in the collection, including zero.
       
   157 		*
       
   158 		* @since 2.8
       
   159 		* @return Array of signer infos, array might be also empty
       
   160 		*/
       
   161         IMPORT_C const CArrayPtr< CCMSSignerInfo >& SignerInfos() const;
       
   162 
       
   163     	/**
       
   164 		* Getter for Certificate
       
   165 		*
       
   166 		* Certificates is a collection of certificates.  It is intended that
       
   167 		* the set of certificates be sufficient to contain chains from a
       
   168 		* recognized "root" or "top-level certification authority" to all of
       
   169 		* the signers in the signerInfos field.  There may be more
       
   170 		* certificates than necessary, and there may be certificates
       
   171 		* sufficient to contain chains from two or more independent top-
       
   172 		* level certification authorities.  There may also be fewer
       
   173 		* certificates than necessary, if it is expected that recipients
       
   174 		* have an alternate means of obtaining necessary certificates (e.g.,
       
   175 		* from a previous set of certificates).  
       
   176 		*
       
   177 		* @since 2.8
       
   178 		* @return Array of certificates or NULL if certificates are absent
       
   179 		*/
       
   180         IMPORT_C const CArrayPtr< CCMSCertificateChoices >* Certificates() const;
       
   181 
       
   182     	/**
       
   183 		* Getter for RevokedCertificates
       
   184 		*
       
   185 		* RevokedCertificates is a collection of certificate revocation lists (CRLs).  
       
   186 		* It is intended that the set contain information sufficient to
       
   187 		* determine whether or not the certificates in the certificates
       
   188 		* field are valid, but such correspondence is not necessary.  There
       
   189 		* may be more CRLs than necessary, and there may also be fewer CRLs
       
   190 		* than necessary.
       
   191 		*
       
   192 		* @since 2.8
       
   193 		* @return Array of revoked certificates or NULL if there is no revoked
       
   194 		*	      certificates
       
   195 		*/
       
   196         IMPORT_C 
       
   197 		const CArrayPtr< CCMSX509CertificateList >* RevokedCertificates() const;
       
   198 
       
   199 		/**
       
   200         * Setter for DigestAlgorithmIdentifiers, takes copy
       
   201 		*
       
   202         * @since 2.8
       
   203         * @param aDigestAlgorithmIdentifiers Array of digest algorithm identifiers
       
   204         */
       
   205 		IMPORT_C void SetDigestAlgorithmIdentifiersL(
       
   206 			const CArrayPtr< CCMSX509AlgorithmIdentifier >&
       
   207 											aDigestAlgorithmIdentifiers );
       
   208 
       
   209 		/**
       
   210         * Setter for EncapsulatedContentInfo, takes copy
       
   211         * @since 2.8
       
   212         * @param aContentInfo Encapsulated content info
       
   213         */
       
   214         IMPORT_C void SetEncapsulatedContentInfoL(
       
   215 			const CCMSEncapsulatedContentInfo& aContentInfo );
       
   216 
       
   217 		/**
       
   218         * Setter for SignerInfos, takes copy
       
   219         * @since 2.8
       
   220         * @param aSignerInfos Array of signer info, array can be also empty
       
   221         */
       
   222         IMPORT_C void SetSignerInfosL(
       
   223 			const CArrayPtr< CCMSSignerInfo >& aSignerInfos );
       
   224 
       
   225 		/**
       
   226         * Setter for Certificates, takes copy
       
   227         * @since 2.8
       
   228         * @param aCertificates Array of certificates or NULL if certificates
       
   229 		*	     are intented to remove from this instance
       
   230         */
       
   231         IMPORT_C void SetCertificatesL(
       
   232 			const CArrayPtr< CCMSCertificateChoices >* aCertificates );
       
   233 
       
   234 		/**
       
   235         * Setter for RevokedCertificates, takes copy
       
   236         * @since 2.8
       
   237         * @param aRevokedCertificates Array of revoked certificates or NULL if
       
   238 		*		 removing revoked certificates from this instance
       
   239         */
       
   240         IMPORT_C void SetRevokedCertificatesL(
       
   241 			const CArrayPtr< CCMSX509CertificateList >* aRevokedCertificates );
       
   242 
       
   243     public: // Functions from base classes
       
   244 
       
   245 	 	/**
       
   246         * From MCMSModule
       
   247         * @since 2.8
       
   248         * @param aRawData raw-data to be parsed in this instance
       
   249         */
       
   250         void DecodeL( const TDesC8& aRawData );
       
   251 
       
   252 	 	/**
       
   253         * From MCMSModule
       
   254         * @since 2.8
       
   255         * @return Returns ASN1 encoder and leaves it in CleanupStack
       
   256         */
       
   257         CASN1EncBase* EncoderLC() const;
       
   258 
       
   259     protected:  // New functions
       
   260 
       
   261 	   /**
       
   262         * Protected construction to allow derivation
       
   263         */
       
   264         IMPORT_C void ConstructL();
       
   265 
       
   266 	   /**
       
   267         * Protected construction to allow derivation
       
   268         */
       
   269         IMPORT_C void ConstructL(
       
   270 			const CArrayPtr< CCMSX509AlgorithmIdentifier >& aDigestAlgorithmIdentifiers,
       
   271         	const CCMSEncapsulatedContentInfo& aContentInfo,
       
   272         	const CArrayPtr< CCMSSignerInfo >& aSignerInfos,
       
   273         	const CArrayPtr< CCMSCertificateChoices >* aCertificates,
       
   274         	const CArrayPtr< CCMSX509CertificateList >* aRevokedCertificates );
       
   275 
       
   276         /**
       
   277         * C++ default constructor.
       
   278         */
       
   279         IMPORT_C CCMSSignedData();
       
   280 
       
   281 	private:
       
   282 		
       
   283 		/**
       
   284 		 * Finds out right version with following rules:
       
   285 		 *
       
   286 		 * If no attribute certificates are present in the certificates field, the
       
   287 		 * encapsulated content type is id-data, and all of the elements of
       
   288 		 * SignerInfos are version 1, then the value of version shall be 1.
       
   289 		 *
       
   290 		 * Alternatively, if attribute certificates are present, the
       
   291 		 * encapsulated content type is other than id-data, or any of the
       
   292 		 * elements of SignerInfos are version 3, then the value of version
       
   293 		 * shall be 3.
       
   294 		 */
       
   295 		void ValidateVersion();
       
   296 
       
   297     private:    // Data
       
   298 		TInt iVersion;
       
   299 
       
   300 		// DigestAlgorithmIdentifiers, owned
       
   301 		CArrayPtr< CCMSX509AlgorithmIdentifier >* iDigestAlgorithmIdentifiers;
       
   302 		// Encapsulate Content Info, owned
       
   303 		CCMSEncapsulatedContentInfo* iContentInfo;
       
   304 		// Signer Infos, owned
       
   305 		CArrayPtr< CCMSSignerInfo >* iSignerInfos;
       
   306 		// Certificates, owned, null if absent
       
   307 		CArrayPtr< CCMSCertificateChoices >* iCertificates;
       
   308 		// Revoked certificates, owned, null if absent
       
   309 		CArrayPtr< CCMSX509CertificateList >* iRevokedCertificates;
       
   310 
       
   311 		// Reserved for extensions
       
   312 		MCMSSignedDataExtension* iReserved;
       
   313     };
       
   314 
       
   315 #endif      // CCMSSignedData_H
       
   316 
       
   317 // End of File