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