|
1 /* |
|
2 * Copyright (c) 2001-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 #include <e32base.h> |
|
20 #include <ct.h> |
|
21 #include "mctauthobject.h" |
|
22 #include "mctkeystore.h" |
|
23 #include "mctkeystoremanager.h" |
|
24 #include <securityerr.h> |
|
25 #include "ct/logger.h" |
|
26 |
|
27 //////////////////////////////////////////////////////////////////////////////// |
|
28 // CKeyInfoBase |
|
29 //////////////////////////////////////////////////////////////////////////////// |
|
30 |
|
31 EXPORT_C CKeyInfoBase::CKeyInfoBase(TKeyIdentifier aID, |
|
32 TKeyUsagePKCS15 aUsage, |
|
33 TUint aSize, |
|
34 HBufC* aLabel, |
|
35 TInt aHandle, |
|
36 const TSecurityPolicy& aUsePolicy, |
|
37 const TSecurityPolicy& aManagementPolicy, |
|
38 EKeyAlgorithm aAlgorithm, |
|
39 TInt aAccessType, |
|
40 TBool aNative, |
|
41 TTime aStartDate, |
|
42 TTime aEndDate, |
|
43 HBufC8* aPKCS8AttributeSet) : |
|
44 iID(aID), |
|
45 iUsage(aUsage), |
|
46 iSize(aSize), |
|
47 iLabel(aLabel), |
|
48 iHandle(aHandle), |
|
49 iUsePolicy(aUsePolicy), |
|
50 iManagementPolicy(aManagementPolicy), |
|
51 iAlgorithm(aAlgorithm), |
|
52 iAccessType(aAccessType), |
|
53 iNative(aNative), |
|
54 iStartDate(aStartDate), |
|
55 iEndDate(aEndDate), |
|
56 iPKCS8AttributeSet(aPKCS8AttributeSet) |
|
57 { |
|
58 } |
|
59 |
|
60 EXPORT_C CKeyInfoBase::CKeyInfoBase() |
|
61 { |
|
62 } |
|
63 |
|
64 EXPORT_C CKeyInfoBase::~CKeyInfoBase() |
|
65 { |
|
66 delete iLabel; |
|
67 delete iPKCS8AttributeSet; |
|
68 } |
|
69 |
|
70 EXPORT_C void CKeyInfoBase::ConstructL() |
|
71 { |
|
72 } |
|
73 |
|
74 EXPORT_C void CKeyInfoBase::ConstructL(RReadStream& aIn) |
|
75 { |
|
76 // Called from derived classes' NewL methods when interalizing a stream |
|
77 |
|
78 InternalizeL(aIn); |
|
79 } |
|
80 |
|
81 EXPORT_C void CKeyInfoBase::ExternalizeL(RWriteStream& aStream) const |
|
82 { |
|
83 aStream.WriteL(iID); |
|
84 aStream.WriteInt32L(iUsage); |
|
85 aStream.WriteUint32L(iSize); |
|
86 aStream.WriteInt32L(iLabel->Length()); |
|
87 TPtr16 theLabel(iLabel->Des()); |
|
88 aStream.WriteL(theLabel); |
|
89 aStream.WriteInt32L(iHandle); |
|
90 aStream.WriteL(TPckgC<TSecurityPolicy>(iUsePolicy)); |
|
91 aStream.WriteL(TPckgC<TSecurityPolicy>(iManagementPolicy)); |
|
92 aStream.WriteInt32L(iAlgorithm); |
|
93 aStream.WriteInt32L(iAccessType); |
|
94 aStream.WriteInt32L(iNative); |
|
95 aStream.WriteL(TPckgC<TTime>(iStartDate)); |
|
96 aStream.WriteL(TPckgC<TTime>(iEndDate)); |
|
97 |
|
98 if (iPKCS8AttributeSet) |
|
99 { |
|
100 aStream.WriteInt32L(iPKCS8AttributeSet->Length()); |
|
101 TPtr8 theAttributes(iPKCS8AttributeSet->Des()); |
|
102 aStream.WriteL(theAttributes); |
|
103 } |
|
104 else |
|
105 aStream.WriteInt32L(0); |
|
106 } |
|
107 |
|
108 void CKeyInfoBase::InternalizeL(RReadStream& aStream) |
|
109 { |
|
110 aStream.ReadL(iID); |
|
111 iUsage = static_cast<TKeyUsagePKCS15>(aStream.ReadInt32L()); |
|
112 iSize = aStream.ReadUint32L(); |
|
113 |
|
114 TInt labelLen = aStream.ReadInt32L(); |
|
115 iLabel = HBufC::NewMaxL(labelLen); |
|
116 TPtr pLabel(iLabel->Des()); |
|
117 pLabel.FillZ(); |
|
118 // This will have made the length of pLabel equal to the length of |
|
119 // the alloc cell of iLabel, which may be longer than labelLen. So |
|
120 // we need to pass the length we want to read into ReadL |
|
121 aStream.ReadL(pLabel, labelLen); |
|
122 |
|
123 iHandle = aStream.ReadInt32L(); |
|
124 |
|
125 TPckg<TSecurityPolicy> usePolicy(iUsePolicy); |
|
126 aStream.ReadL(usePolicy); |
|
127 TPckg<TSecurityPolicy> managementPolicy(iManagementPolicy); |
|
128 aStream.ReadL(managementPolicy); |
|
129 |
|
130 iAlgorithm = (EKeyAlgorithm)(aStream.ReadInt32L()); |
|
131 iAccessType = (EKeyAccess)(aStream.ReadInt32L()); |
|
132 iNative = (TBool)(aStream.ReadInt32L()); |
|
133 TPckg<TTime> startDate(iStartDate); |
|
134 aStream.ReadL(startDate); |
|
135 TPckg<TTime> endDate(iEndDate); |
|
136 aStream.ReadL(endDate); |
|
137 |
|
138 TInt attributeLen = aStream.ReadInt32L(); |
|
139 if (attributeLen > 0) |
|
140 { |
|
141 iPKCS8AttributeSet = HBufC8::NewMaxL(attributeLen); |
|
142 TPtr8 pAttributes(iPKCS8AttributeSet->Des()); |
|
143 pAttributes.FillZ(); |
|
144 // This will have made the length of pAttributes equal to the length of |
|
145 // the alloc cell of iPKCS8AttributeSet, which may be longer than attributeLen |
|
146 // So we need to pass the length we want to read into ReadL |
|
147 aStream.ReadL(pAttributes, attributeLen); |
|
148 } |
|
149 } |
|
150 |
|
151 //////////////////////////////////////////////////////////////////////////////// |
|
152 // CCTKeyInfo |
|
153 //////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
155 EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(TKeyIdentifier aID, |
|
156 TKeyUsagePKCS15 aUsage, |
|
157 TUint aSize, |
|
158 MCTAuthenticationObject* aProtector, |
|
159 HBufC* aLabel, |
|
160 MCTToken& aToken, |
|
161 TInt aHandle, |
|
162 const TSecurityPolicy& aUsePolicy, |
|
163 const TSecurityPolicy& aManagementPolicy, |
|
164 EKeyAlgorithm aAlgorithm, |
|
165 TInt aAccessType, |
|
166 TBool aNative, |
|
167 TTime aStartDate, |
|
168 TTime aEndDate, |
|
169 HBufC8* aPKCS8AttributeSet /*= NULL*/) |
|
170 { |
|
171 CCTKeyInfo* me = NULL; |
|
172 me = new (ELeave) CCTKeyInfo(aID, |
|
173 aUsage, |
|
174 aSize, |
|
175 aProtector, |
|
176 aLabel, |
|
177 aToken, |
|
178 aHandle, |
|
179 aUsePolicy, |
|
180 aManagementPolicy, |
|
181 aAlgorithm, |
|
182 aAccessType, |
|
183 aNative, |
|
184 aStartDate, |
|
185 aEndDate, |
|
186 aPKCS8AttributeSet); |
|
187 |
|
188 CleanupReleasePushL(*me); |
|
189 me->ConstructL(); |
|
190 CleanupStack::Pop(); |
|
191 |
|
192 return me; |
|
193 } |
|
194 |
|
195 CCTKeyInfo::CCTKeyInfo(TKeyIdentifier aID, |
|
196 TKeyUsagePKCS15 aUsage, |
|
197 TUint aSize, |
|
198 MCTAuthenticationObject* aProtector, |
|
199 HBufC* aLabel, |
|
200 MCTToken& aToken, |
|
201 TInt aHandle, |
|
202 const TSecurityPolicy& aUsePolicy, |
|
203 const TSecurityPolicy& aManagementPolicy, |
|
204 EKeyAlgorithm aAlgorithm, |
|
205 TInt aAccessType, |
|
206 TBool aNative, |
|
207 TTime aStartDate, |
|
208 TTime aEndDate, |
|
209 HBufC8* aPKCS8AttributeSet /*= NULL*/) : |
|
210 CKeyInfoBase(aID, |
|
211 aUsage, |
|
212 aSize, |
|
213 aLabel, |
|
214 aHandle, |
|
215 aUsePolicy, |
|
216 aManagementPolicy, |
|
217 aAlgorithm, |
|
218 aAccessType, |
|
219 aNative, |
|
220 aStartDate, |
|
221 aEndDate, |
|
222 aPKCS8AttributeSet), |
|
223 MCTTokenObject(aToken), |
|
224 iToken(aToken), |
|
225 iProtector(aProtector) |
|
226 { |
|
227 LOG1(_L("CCTKeyInfo::CCTKeyInfo() with iProtector %08x"), iProtector); |
|
228 } |
|
229 |
|
230 EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(RReadStream& aStream, MCTToken& aToken) |
|
231 { |
|
232 CCTKeyInfo* me = new (ELeave) CCTKeyInfo(aToken); |
|
233 CleanupReleasePushL(*me); |
|
234 me->ConstructL(aStream); |
|
235 CleanupStack::Pop(); |
|
236 return me; |
|
237 } |
|
238 |
|
239 CCTKeyInfo::CCTKeyInfo(MCTToken& aToken) : |
|
240 CKeyInfoBase(), |
|
241 MCTTokenObject(aToken), |
|
242 iToken(aToken) |
|
243 { |
|
244 } |
|
245 |
|
246 CCTKeyInfo::~CCTKeyInfo() |
|
247 { |
|
248 LOG(_L("CCTKeyInfo::~CCTKeyInfo")); |
|
249 if (iProtector) |
|
250 { |
|
251 LOG_INC_INDENT(); |
|
252 iProtector->Release(); |
|
253 LOG_DEC_INDENT(); |
|
254 } |
|
255 } |
|
256 |
|
257 const TDesC& CCTKeyInfo::Label() const |
|
258 { |
|
259 return CKeyInfoBase::Label(); |
|
260 } |
|
261 |
|
262 MCTToken& CCTKeyInfo::Token() const |
|
263 { |
|
264 return iToken; |
|
265 } |
|
266 |
|
267 TUid CCTKeyInfo::Type() const |
|
268 { |
|
269 return KKeyInfoUID; |
|
270 } |
|
271 |
|
272 TCTTokenObjectHandle CCTKeyInfo::Handle() const |
|
273 { |
|
274 return TCTTokenObjectHandle(Token().Handle(), HandleID()); |
|
275 } |
|
276 |
|
277 //////////////////////////////////////////////////////////////////////////////// |
|
278 // TCTKeyAttributeFilter |
|
279 //////////////////////////////////////////////////////////////////////////////// |
|
280 |
|
281 EXPORT_C TCTKeyAttributeFilter::TCTKeyAttributeFilter() |
|
282 { |
|
283 iKeyId = KNullDesC8; |
|
284 iUsage = EPKCS15UsageAll; |
|
285 iPolicyFilter = EUsableKeys; |
|
286 iKeyAlgorithm = CCTKeyInfo::EInvalidAlgorithm; |
|
287 } |