|
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 "cctcertinfo.h" |
|
20 |
|
21 // MCertInfo /////////////////////////////////////////////////////////////////// |
|
22 |
|
23 EXPORT_C MCertInfo::MCertInfo() : |
|
24 iDeletable(ETrue) |
|
25 { |
|
26 } |
|
27 |
|
28 EXPORT_C MCertInfo::MCertInfo(const TDesC& aLabel, |
|
29 TCertificateFormat aFormat, |
|
30 TCertificateOwnerType aCertificateOwnerType, |
|
31 TInt aSize, |
|
32 const TKeyIdentifier* aSubjectKeyId, |
|
33 const TKeyIdentifier* aIssuerKeyId, |
|
34 TInt aCertificateId, |
|
35 TBool aDeletable) : |
|
36 iLabel(aLabel), iCertificateId(aCertificateId), |
|
37 iFormat(aFormat), iCertificateOwnerType(aCertificateOwnerType), |
|
38 iSize(aSize), iDeletable(aDeletable) |
|
39 { |
|
40 if (aSubjectKeyId) |
|
41 { |
|
42 iSubjectKeyId = *aSubjectKeyId; |
|
43 } |
|
44 else |
|
45 { |
|
46 iSubjectKeyId = KNullDesC8; |
|
47 } |
|
48 if (aIssuerKeyId) |
|
49 { |
|
50 iIssuerKeyId = *aIssuerKeyId; |
|
51 } |
|
52 else |
|
53 { |
|
54 iIssuerKeyId = KNullDesC8; |
|
55 } |
|
56 } |
|
57 |
|
58 EXPORT_C MCertInfo::MCertInfo(const MCertInfo& aOther) : |
|
59 iLabel(aOther.iLabel), |
|
60 iCertificateId(aOther.iCertificateId), |
|
61 iFormat(aOther.iFormat), |
|
62 iCertificateOwnerType(aOther.iCertificateOwnerType), |
|
63 iSize(aOther.iSize), |
|
64 iSubjectKeyId(aOther.iSubjectKeyId), |
|
65 iIssuerKeyId(aOther.iIssuerKeyId), |
|
66 iDeletable(aOther.iDeletable) |
|
67 { |
|
68 } |
|
69 |
|
70 EXPORT_C MCertInfo::~MCertInfo() |
|
71 { |
|
72 delete iIssuerHash; |
|
73 } |
|
74 |
|
75 const TDesC8* MCertInfo::IssuerHash() const |
|
76 { |
|
77 return iIssuerHash; |
|
78 } |
|
79 |
|
80 EXPORT_C void MCertInfo::ConstructL(const TDesC8* aIssuerHash) |
|
81 { |
|
82 delete iIssuerHash; |
|
83 iIssuerHash = NULL; |
|
84 if (aIssuerHash) |
|
85 { |
|
86 iIssuerHash = aIssuerHash->AllocL(); |
|
87 } |
|
88 |
|
89 if (!Valid()) |
|
90 { |
|
91 User::Leave(KErrArgument); |
|
92 } |
|
93 } |
|
94 |
|
95 TBool MCertInfo::Valid() const |
|
96 { |
|
97 if (iLabel.Length() == 0) |
|
98 { |
|
99 return EFalse; |
|
100 } |
|
101 |
|
102 if (iCertificateId < 0) |
|
103 { |
|
104 return EFalse; |
|
105 } |
|
106 |
|
107 if (iFormat != EX509Certificate && iFormat != EWTLSCertificate && |
|
108 iFormat != EX968Certificate && iFormat != EX509CertificateUrl && |
|
109 iFormat != EWTLSCertificateUrl && iFormat != EX968CertificateUrl) |
|
110 { |
|
111 return EFalse; |
|
112 } |
|
113 |
|
114 if (iCertificateOwnerType != ECACertificate && |
|
115 iCertificateOwnerType != EUserCertificate && |
|
116 iCertificateOwnerType != EPeerCertificate) |
|
117 { |
|
118 return EFalse; |
|
119 } |
|
120 |
|
121 if (iSize <= 0) |
|
122 { |
|
123 return EFalse; |
|
124 } |
|
125 |
|
126 if (iIssuerHash && *iIssuerHash == KNullDesC8) |
|
127 { |
|
128 return EFalse; |
|
129 } |
|
130 |
|
131 return ETrue; |
|
132 } |
|
133 |
|
134 /** |
|
135 EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const |
|
136 |
|
137 This method externalizes the MCertInfo object to the given stream. |
|
138 The iDeletable boolean attribute is combined with the iFormat attribute |
|
139 for certstore backward compatibility |
|
140 */ |
|
141 EXPORT_C void MCertInfo::ExternalizeL(RWriteStream& aStream) const |
|
142 { |
|
143 // insert iDeletable flag as most significant digit of iFormat in order |
|
144 // store the flag without changing the externalized record format |
|
145 // The value is OPPOSITE for backward compatibility |
|
146 TUint8 tmpValue = static_cast <TUint8>(iFormat | (iDeletable ? 0 : KReadOnlyFlagMask)); |
|
147 |
|
148 aStream.WriteUint8L(tmpValue); |
|
149 aStream.WriteInt32L(iSize); |
|
150 aStream << iLabel; |
|
151 aStream.WriteInt32L(iCertificateId); |
|
152 aStream.WriteUint8L(iCertificateOwnerType); |
|
153 aStream << iSubjectKeyId; |
|
154 aStream << iIssuerKeyId; |
|
155 } |
|
156 |
|
157 /** |
|
158 EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream) |
|
159 |
|
160 This method internalizes a MCertInfo object from the given stream. |
|
161 The iDeletable boolean and iFormat attributes are both extracted |
|
162 from the stored iFormat value using for certstore backward compatibility |
|
163 */ |
|
164 EXPORT_C void MCertInfo::InternalizeL(RReadStream& aStream) |
|
165 { |
|
166 // get first byte from stream containing iDeletable flag and iFormat value |
|
167 TUint8 tmpValue = aStream.ReadUint8L(); |
|
168 |
|
169 // extract iDeletable flag from most significant digit of iFormat |
|
170 // set iDeletable to the OPPOSITE of the 8th bit value |
|
171 iDeletable = !(tmpValue & KReadOnlyFlagMask); |
|
172 |
|
173 // extract iFormat = the value of the 7 least significant bits |
|
174 iFormat = static_cast <TCertificateFormat>(tmpValue & KFormatMask); |
|
175 |
|
176 iSize = aStream.ReadInt32L(); |
|
177 aStream >> iLabel; |
|
178 iCertificateId = aStream.ReadInt32L(); |
|
179 iCertificateOwnerType = static_cast<TCertificateOwnerType>(aStream.ReadUint8L()); |
|
180 aStream >> iSubjectKeyId; |
|
181 aStream >> iIssuerKeyId; |
|
182 |
|
183 if (!Valid()) |
|
184 { |
|
185 User::Leave(KErrCorrupt); |
|
186 } |
|
187 } |
|
188 |
|
189 // CCTCertInfo ///////////////////////////////////////////////////////////////// |
|
190 |
|
191 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(RReadStream& aStream, MCTToken& aToken) |
|
192 { |
|
193 CCTCertInfo* self = CCTCertInfo::NewLC(aStream, aToken); |
|
194 CleanupStack::Pop(self); |
|
195 return self; |
|
196 } |
|
197 |
|
198 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(RReadStream& aStream, MCTToken& aToken) |
|
199 { |
|
200 CCTCertInfo* self = new(ELeave) CCTCertInfo(aToken); |
|
201 CleanupReleasePushL(*self); |
|
202 self->ConstructL(aStream); |
|
203 return self; |
|
204 } |
|
205 |
|
206 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel, |
|
207 TCertificateFormat aFormat, |
|
208 TCertificateOwnerType aCertificateOwnerType, |
|
209 TInt aSize, |
|
210 const TKeyIdentifier* aSubjectKeyId, |
|
211 const TKeyIdentifier* aIssuerKeyId, |
|
212 MCTToken& aToken, |
|
213 TInt aCertificateId) |
|
214 { |
|
215 CCTCertInfo* self = CCTCertInfo::NewLC(aLabel, |
|
216 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken, |
|
217 aCertificateId, ETrue); |
|
218 CleanupStack::Pop(self); |
|
219 return self; |
|
220 } |
|
221 |
|
222 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const TDesC& aLabel, |
|
223 TCertificateFormat aFormat, |
|
224 TCertificateOwnerType aCertificateOwnerType, |
|
225 TInt aSize, |
|
226 const TKeyIdentifier* aSubjectKeyId, |
|
227 const TKeyIdentifier* aIssuerKeyId, |
|
228 MCTToken& aToken, |
|
229 TInt aCertificateId, |
|
230 TBool aIsDeletable, |
|
231 const TDesC8* aIssuerHash) |
|
232 { |
|
233 CCTCertInfo* self = CCTCertInfo::NewLC(aLabel, |
|
234 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, aToken, |
|
235 aCertificateId, aIsDeletable, aIssuerHash); |
|
236 CleanupStack::Pop(self); |
|
237 return self; |
|
238 } |
|
239 |
|
240 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel, |
|
241 TCertificateFormat aFormat, |
|
242 TCertificateOwnerType aCertificateOwnerType, |
|
243 TInt aSize, |
|
244 const TKeyIdentifier* aSubjectKeyId, |
|
245 const TKeyIdentifier* aIssuerKeyId, |
|
246 MCTToken& aToken, |
|
247 TInt aCertificateId) |
|
248 { |
|
249 return CCTCertInfo::NewLC(aLabel, |
|
250 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, aIssuerKeyId, |
|
251 aToken, aCertificateId, ETrue); |
|
252 } |
|
253 |
|
254 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const TDesC& aLabel, |
|
255 TCertificateFormat aFormat, |
|
256 TCertificateOwnerType aCertificateOwnerType, |
|
257 TInt aSize, |
|
258 const TKeyIdentifier* aSubjectKeyId, |
|
259 const TKeyIdentifier* aIssuerKeyId, |
|
260 MCTToken& aToken, |
|
261 TInt aCertificateId, |
|
262 TBool aIsDeletable, |
|
263 const TDesC8* aIssuerHash) |
|
264 { |
|
265 CCTCertInfo* self = new(ELeave) CCTCertInfo(aLabel, |
|
266 aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, |
|
267 aIssuerKeyId, aToken, aCertificateId, aIsDeletable); |
|
268 CleanupReleasePushL(*self); |
|
269 self->ConstructL(aIssuerHash); |
|
270 return self; |
|
271 } |
|
272 |
|
273 EXPORT_C CCTCertInfo* CCTCertInfo::NewL(const CCTCertInfo& aCertInfo) |
|
274 { |
|
275 CCTCertInfo* self = CCTCertInfo::NewLC(aCertInfo); |
|
276 CleanupStack::Pop(self); |
|
277 return self; |
|
278 } |
|
279 |
|
280 EXPORT_C CCTCertInfo* CCTCertInfo::NewLC(const CCTCertInfo& aCertInfo) |
|
281 { |
|
282 CCTCertInfo* self = new(ELeave) CCTCertInfo(aCertInfo); |
|
283 CleanupReleasePushL(*self); |
|
284 self->ConstructL(aCertInfo.IssuerHash()); |
|
285 return self; |
|
286 } |
|
287 |
|
288 CCTCertInfo::CCTCertInfo(MCTToken& aToken) |
|
289 : MCTTokenObject(aToken), iToken(aToken) |
|
290 { |
|
291 } |
|
292 |
|
293 CCTCertInfo::CCTCertInfo(const TDesC& aLabel, |
|
294 TCertificateFormat aFormat, |
|
295 TCertificateOwnerType aCertificateOwnerType, |
|
296 TInt aSize, |
|
297 const TKeyIdentifier* aSubjectKeyId, |
|
298 const TKeyIdentifier* aIssuerKeyId, |
|
299 MCTToken& aToken, |
|
300 TInt aCertificateId, |
|
301 TBool aIsDeletable) |
|
302 : MCTTokenObject(aToken), |
|
303 MCertInfo(aLabel, aFormat, aCertificateOwnerType, aSize, aSubjectKeyId, |
|
304 aIssuerKeyId, aCertificateId, aIsDeletable), |
|
305 iToken(aToken) |
|
306 { |
|
307 } |
|
308 |
|
309 CCTCertInfo::CCTCertInfo(const CCTCertInfo& aOther) |
|
310 : MCTTokenObject(aOther.iToken), MCertInfo(aOther), iToken(aOther.iToken) |
|
311 { |
|
312 } |
|
313 |
|
314 void CCTCertInfo::ConstructL(RReadStream& aStream) |
|
315 { |
|
316 InternalizeL(aStream); |
|
317 } |
|
318 |
|
319 void CCTCertInfo::ConstructL(const TDesC8* aIssuerHash) |
|
320 { |
|
321 MCertInfo::ConstructL(aIssuerHash); |
|
322 } |
|
323 |
|
324 EXPORT_C CCTCertInfo::~CCTCertInfo() |
|
325 { |
|
326 } |
|
327 |
|
328 const TDesC& CCTCertInfo::Label() const |
|
329 { |
|
330 return iLabel; |
|
331 } |
|
332 |
|
333 TUid CCTCertInfo::Type() const |
|
334 { |
|
335 TUid uid = { KCTObjectCertInfo }; |
|
336 return uid; |
|
337 } |
|
338 |
|
339 EXPORT_C const TKeyIdentifier& CCTCertInfo::SubjectKeyId() const |
|
340 { |
|
341 return iSubjectKeyId; |
|
342 } |
|
343 |
|
344 EXPORT_C const TKeyIdentifier& CCTCertInfo::IssuerKeyId() const |
|
345 { |
|
346 return iIssuerKeyId; |
|
347 } |
|
348 |
|
349 EXPORT_C TCertificateFormat CCTCertInfo::CertificateFormat() const |
|
350 { |
|
351 return iFormat; |
|
352 } |
|
353 |
|
354 EXPORT_C TCertificateOwnerType CCTCertInfo::CertificateOwnerType() const |
|
355 { |
|
356 return iCertificateOwnerType; |
|
357 } |
|
358 |
|
359 EXPORT_C TInt CCTCertInfo::Size() const |
|
360 { |
|
361 return iSize; |
|
362 } |
|
363 |
|
364 MCTToken& CCTCertInfo::Token() const |
|
365 { |
|
366 return iToken; |
|
367 } |
|
368 |
|
369 EXPORT_C TCTTokenObjectHandle CCTCertInfo::Handle() const |
|
370 { |
|
371 return TCTTokenObjectHandle(iToken.Handle(), iCertificateId); |
|
372 } |
|
373 |
|
374 EXPORT_C TBool CCTCertInfo::IsDeletable() const |
|
375 { |
|
376 return iDeletable; |
|
377 } |
|
378 |
|
379 EXPORT_C const TDesC8* CCTCertInfo::IssuerHash() const |
|
380 { |
|
381 return MCertInfo::IssuerHash(); |
|
382 } |
|
383 |
|
384 EXPORT_C TBool CCTCertInfo::operator==(const CCTCertInfo& aCertInfo) const |
|
385 { |
|
386 return aCertInfo.iLabel == iLabel; |
|
387 } |
|
388 |
|
389 EXPORT_C void CCTCertInfo::SetCertificateId(TInt aCertId) |
|
390 { |
|
391 iCertificateId = aCertId; |
|
392 } |