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