os/security/cryptoservices/certificateandkeymgmt/inc/pkcs12.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) 2005-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 __PKCS12_H__
    26 #define __PKCS12_H__
    27 
    28 #include <s32strm.h>
    29 #include <asn1dec.h>
    30 #include <x509cert.h>
    31 #include <asnpkcs.h>
    32 #include <pkcs7contentinfo_v2.h>
    33 #include <pkcs7digestinfo.h>
    34 #include <pkcs7encrypteddataobject.h>
    35 #include <pkcs12macdata.h>
    36 #include <pkcs12safebag.h>
    37 
    38 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    39 #include <pkcs7signedobject.h>
    40 #endif
    41 
    42 namespace PKCS12
    43 {
    44 class CDecPkcs12MacData;
    45 
    46 /** PKCS12 Version */
    47 const TInt KPkcs12Version = 3;   
    48 
    49 /**
    50  Contains methods to decode and return the PFX structure.
    51  The structure contains the Version, MacData and AuthSafe.
    52  MacData is OPTIONAL.
    53  */
    54 class CDecPkcs12 : public CBase
    55 	{
    56 public:
    57 	enum TIntegrityMode
    58 	/**
    59 	 Identifies the type of Integrity Mode used in the PKCS12 PFX Structure
    60 	 */
    61 		{
    62 		/** Password Integrity Mode used in the PKCS12 PFX Structure */
    63 		EPasswordIntegrityMode = 1,
    64 		
    65 		/** Public Key Integrity Mode used in the PKCS12 PFX Structure */
    66 		EPublicKeyIntegrityMode
    67 		};  
    68     /**
    69 	 Creates a new PKCS#12 object.
    70 	 
    71 	 @param  aRawData Contains a PKCS#12 PFX structure
    72 	 @return A pointer to the newly allocated object.
    73 	 @leave  KErrArgument if the aRawData is not Pkcs12 PFX Structure.
    74 	 */
    75 	IMPORT_C static CDecPkcs12* NewL(const TDesC8& aRawData); 
    76 	
    77 	/**
    78 	 Creates a new PKCS#12 object.
    79 	 
    80 	 @param  aRawData Contains a PKCS#12 PFX structure
    81 	 @return A pointer to the newly allocated object.
    82 	 @leave  KErrArgument if the aRawData is not Pkcs12 PFX Structure.
    83 	 */
    84 	IMPORT_C static CDecPkcs12* NewLC(const TDesC8& aRawData);
    85 
    86 	/**
    87 	 Creates a new PKCS#12 object.
    88 	 
    89 	 @param  aStream contains a PKCS#12 PFX structure 
    90 	 @return A pointer to the newly allocated object.
    91 	 @leave  KErrArgument if the aRawData is not Pkcs12 PFX Structure.
    92 	 */
    93 	IMPORT_C static CDecPkcs12* NewL(RReadStream& aStream); 
    94 
    95 	/**
    96 	 Creates a new PKCS#12 object.
    97 	  
    98 	 @param  aStream Contains a PKCS#12 PFX structure
    99 	 @return A pointer to the newly allocated object.
   100 	 @leave  KErrArgument if the aRawData is not Pkcs12 PFX Structure.
   101 	 */
   102 	IMPORT_C static CDecPkcs12* NewLC(RReadStream& aStream);
   103        
   104     /**
   105 	 Identifies the type of integrity mode used.
   106      In the case of Password Integrity mode, OID is 1.2.840.113549.1.7.1.
   107      In the case of Public Key Integrity mode, OID is 1.2.840.113549.1.7.2.
   108 	 
   109      @return An enum that identifies the type of integrity mode used.
   110      */	
   111     IMPORT_C TIntegrityMode IntegrityMode() const;
   112 	
   113 	/**
   114 	 Returns the Version number contained in the PKCS12 PFX Structure.
   115 	 @return Returns the Version number contained in the PKCS12 PFX Structure..
   116      */
   117 	IMPORT_C TInt Version() const;
   118 	
   119 	/**
   120 	 Returns the authenticated safe.
   121 	 This authenticated safe is used to find the integrity mode used
   122 	 and to verify the integrity of the packet. 
   123 	 
   124 	 @return A reference to the CPKCS7ContentInfo object.
   125 	 */	
   126 	IMPORT_C const CPKCS7ContentInfo& AuthenticatedSafe() const;
   127 	
   128 	/**
   129 	 The MacData, which contains:
   130 	 - The Mac, that is the PKCS#7 digest info structure.
   131 	 - The MacSalt.
   132 	 - The iteration count.
   133 	 
   134 	 @return Returns CDecPKCS12MacData object pointer if the MacData is present in the PFX Structure
   135 	         Returns NULL pointer if the MacData is absent in the PFX Structure.
   136 	         Returned pointer ownership retains with the object.
   137 	 */
   138 	IMPORT_C const CDecPkcs12MacData* MacData() const;
   139 	
   140 	/**
   141 	 These objects represents the ContentInfo Sequences present in the
   142 	 AuthenticatedSafe Sequence. 
   143 	 
   144 	 @return An array of ContentInfo objects
   145 	 @see	 CPKCS7ContentInfo
   146 	 */
   147 	IMPORT_C const RPointerArray<CPKCS7ContentInfo>& AuthenticatedSafeContents() const;
   148 	
   149 	/**
   150 	 Destructor.
   151 	 */
   152 	 virtual ~CDecPkcs12();
   153 	
   154 private:
   155     /**
   156      This decodes the entire PFX structure
   157      
   158 	 Main PKCS12 Structure.
   159 	 PFX ::= SEQUENCE 
   160 	  	{
   161 	  	version		INTEGER {v3(3)}(v3,...),
   162 	  	authSafe	ContentInfo,
   163 	  	macData    	MacData OPTIONAL
   164 	  	}
   165      
   166      @param aRawData Contains a PKCS#12 PFX Structure.
   167      @leave KErrArgument if the aRawData is not a Valid Pkcs12 PFX Structure.
   168      @see	CPKCS7ContentInfo, CDecPkcs12MacData, CPKCS7SignedObject.
   169      */
   170 	void ConstructL(const TDesC8& aRawData);
   171 	
   172 	/**
   173 	 This method is used to internalise that object and takes a reference 
   174 	 to an RReadStream as the interface to the read stream. 
   175 	 @param aStream 	 Contains a PKCS#12 PFX Structure.
   176 	 @leave KErrArgument if the aStream is not Pkcs12 PFX Structure.
   177 	 */
   178     void InternalizeL(RReadStream& aStream);
   179 	
   180 	/**
   181 	 Constructor.
   182 	 */
   183 	 CDecPkcs12();
   184 	
   185 	/**
   186 	 Construtor.
   187 	 */
   188 	 CDecPkcs12(RPointerArray<CPKCS7ContentInfo> aContentInfo);
   189 	  
   190 	/**
   191 	 Copy Constructor.
   192 	 @param aDecPkcs12 A CDecPkcs12 object
   193 	 */
   194 	 CDecPkcs12(const CDecPkcs12& aDecPkcs12);
   195 	 
   196 	 /**
   197 	  Assignment operator.
   198 	  @param aDecPkcs12 A CDecPkcs12 object.
   199 	  @return A reference to CDecPkcs12 class.
   200 	  */
   201 	 CDecPkcs12& operator=(const CDecPkcs12& aDecPkcs12);
   202 
   203 private:
   204 	/** PKCS12 PFX Structure Version number */
   205 	TInt iVersion;
   206 	
   207 	/** Integrity Mode used in PKCS12 PFX Structure*/	
   208 	TIntegrityMode iMode;
   209 	
   210 	/** Contains the macData structure present 
   211 	    in the PKCS12 PFX Structure*/
   212     CDecPkcs12MacData* iMacData;
   213     
   214     /** This contains the entire AuthenticatedSafe Data 
   215         present in the PKCS12 PFX Structure*/
   216     CPKCS7ContentInfo* iAuthenticatedSafeData;
   217     
   218     /** This Contains an Array of ContentInfos present 
   219         within the AuthenticatedSafe of PKCS12 PFX Structure*/
   220     RPointerArray<CPKCS7ContentInfo> iContentInfos;
   221   };
   222 } // namespace PKCS12 
   223 
   224 #endif // __PKCS12_H__