|
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 * CCTCertInfo.H |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalTechnology |
|
25 */ |
|
26 |
|
27 #ifndef __CCTCERTINFO_H__ |
|
28 #define __CCTCERTINFO_H__ |
|
29 |
|
30 #include <e32base.h> |
|
31 #include <s32strm.h> |
|
32 |
|
33 #include <securitydefs.h> |
|
34 #include <ct/mcttokentype.h> |
|
35 #include <ct/mcttoken.h> |
|
36 #include <ct/mcttokenobject.h> |
|
37 |
|
38 /** Mask constants used for serializing iDeletable and iFormat attributes |
|
39 */ |
|
40 const TUint KReadOnlyFlagMask = 128; |
|
41 const TUint KFormatMask = 127; |
|
42 |
|
43 /** The UID of a CertInfo MCTTokenObject. */ |
|
44 const TInt KCTObjectCertInfo = 0x101F50E6; |
|
45 |
|
46 /** The maximum length of a certificate label. */ |
|
47 const TUint32 KMaxCertLabelLength = 64; |
|
48 |
|
49 /** Defines a modifiable buffer descriptor to contain a human-readable certificate label. |
|
50 * |
|
51 * @publishedAll |
|
52 * @released */ |
|
53 typedef TBuf<KMaxCertLabelLength> TCertLabel; |
|
54 |
|
55 /** |
|
56 * Mix-in class representnig data about a stored certificate. Provides |
|
57 * implementation of serialization. |
|
58 * |
|
59 * Note that for backward compatibility reasons, the issuer hash is not serialised. |
|
60 * |
|
61 * @internalTechnology |
|
62 */ |
|
63 class MCertInfo |
|
64 { |
|
65 public: |
|
66 // Internalization/Externalization |
|
67 // Externalize. Writes the data out to a stream |
|
68 |
|
69 /** Externalises an object of this class to a write stream. |
|
70 * |
|
71 * The presence of this function means that the standard templated operator<<() |
|
72 * can be used to externalise objects of this class. |
|
73 * |
|
74 * @param aStream Stream to which the object should be externalised. */ |
|
75 IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
|
76 |
|
77 // Internalize. Reads the data from a stream |
|
78 /** Internalises an object of this class from a read stream. |
|
79 * |
|
80 * The presence of this function means that the standard templated operator>>() |
|
81 * can be used to internalise objects of this class. |
|
82 * |
|
83 * Note that this function has assignment semantics: it replaces the old value |
|
84 * of the object with a new value read from the read stream. |
|
85 * |
|
86 * @param aStream Stream from which the object should be internalised. */ |
|
87 IMPORT_C void InternalizeL(RReadStream& aStream); |
|
88 |
|
89 protected: |
|
90 IMPORT_C MCertInfo(); |
|
91 IMPORT_C MCertInfo(const TDesC& aLabel, |
|
92 TCertificateFormat aFormat, |
|
93 TCertificateOwnerType aCertificateOwnerType, |
|
94 TInt aSize, |
|
95 const TKeyIdentifier* aSubjectKeyId, |
|
96 const TKeyIdentifier* aIssuerKeyId, |
|
97 TInt aCertificateId, |
|
98 TBool aDeletable); |
|
99 IMPORT_C MCertInfo(const MCertInfo& aOther); |
|
100 IMPORT_C ~MCertInfo(); |
|
101 |
|
102 IMPORT_C void ConstructL(const TDesC8* aIssuerHash); |
|
103 |
|
104 const TDesC8* IssuerHash() const; |
|
105 |
|
106 private: |
|
107 TBool Valid() const; |
|
108 const MCertInfo& operator=(const MCertInfo& aOther); |
|
109 |
|
110 protected: |
|
111 TCertLabel iLabel; |
|
112 TInt iCertificateId; |
|
113 TCertificateFormat iFormat; |
|
114 TCertificateOwnerType iCertificateOwnerType; |
|
115 TInt iSize; |
|
116 TKeyIdentifier iSubjectKeyId; |
|
117 TKeyIdentifier iIssuerKeyId; |
|
118 TBool iDeletable; |
|
119 |
|
120 private: |
|
121 HBufC8* iIssuerHash; |
|
122 }; |
|
123 |
|
124 /** Encapsulates information about a stored certificate. |
|
125 * |
|
126 * Objects of this type are usually returned by a certificate store, to allow |
|
127 * a client to query the contents of the store. |
|
128 * |
|
129 * Note that these objects are normally constructed by certificate stores, not |
|
130 * by clients. |
|
131 * |
|
132 * @publishedAll |
|
133 * @released |
|
134 */ |
|
135 class CCTCertInfo : protected CBase, public MCTTokenObject, public MCertInfo |
|
136 { |
|
137 public: |
|
138 /** Construction -- Note that these objects are normally constructed by certificate stores, not by clients. */ |
|
139 |
|
140 /** |
|
141 * @publishedPartner |
|
142 * @released |
|
143 * |
|
144 * Creates the certificate information object by copying from an existing object. |
|
145 * |
|
146 * @param aCertInfo The source certificate information. |
|
147 * @return A pointer to the new certificate information object. |
|
148 * @leave KErrNoMemory There is no memory to construct it. */ |
|
149 IMPORT_C static CCTCertInfo* NewL(const CCTCertInfo& aCertInfo); |
|
150 |
|
151 /** |
|
152 * @publishedPartner |
|
153 * @released |
|
154 * |
|
155 * Creates the certificate information object by copying from an existing object, |
|
156 * and puts a pointer to the new object onto the cleanup stack. |
|
157 * |
|
158 * @param aCertInfo The source certificate information. |
|
159 * @return A pointer to the new certificate information object. |
|
160 * @leave KErrNoMemory There is no memory to construct it. */ |
|
161 IMPORT_C static CCTCertInfo* NewLC(const CCTCertInfo& aCertInfo); |
|
162 |
|
163 /** |
|
164 * @publishedPartner |
|
165 * @released |
|
166 * |
|
167 * Creates the certificate information object from its constituent parts. |
|
168 * |
|
169 * @param aLabel The certificate's label. |
|
170 * @param aFormat The certificate's format. |
|
171 * @param aCertificateOwnerType The owner type. |
|
172 * @param aSize The size of the certificate. |
|
173 * @param aSubjectKeyId The subject key ID. |
|
174 * @param aIssuerKeyId The issuer key ID. |
|
175 * @param aToken The token that the certificate is within. |
|
176 * @param aCertificateId The ID within the object handle. |
|
177 * @param aDeletable The certificate is deletable. |
|
178 * @param aIssuerHash The hash of the DN of the issuer. |
|
179 * @return A pointer to the new certificate information object. |
|
180 * @leave KErrNoMemory There is no memory to construct it.*/ |
|
181 IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat, |
|
182 TCertificateOwnerType aCertificateOwnerType, TInt aSize, |
|
183 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, |
|
184 MCTToken& aToken, TInt aCertificateId, TBool aDeletable, |
|
185 const TDesC8* aIssuerHash = NULL); |
|
186 |
|
187 /** |
|
188 * @publishedPartner |
|
189 * @released |
|
190 * |
|
191 * Creates the certificate information object from its constituent parts. |
|
192 * |
|
193 * @param aLabel The certificate's label. |
|
194 * @param aFormat The certificate's format. |
|
195 * @param aCertificateOwnerType The owner type. |
|
196 * @param aSize The size of the certificate. |
|
197 * @param aSubjectKeyId The subject key ID. |
|
198 * @param aIssuerKeyId The issuer key ID. |
|
199 * @param aToken The token that the certificate is within. |
|
200 * @param aCertificateId The ID within the object handle. |
|
201 * @return A pointer to the new certificate information object. |
|
202 * @leave KErrNoMemory There is no memory to construct it.*/ |
|
203 IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat, |
|
204 TCertificateOwnerType aCertificateOwnerType, TInt aSize, |
|
205 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, |
|
206 MCTToken& aToken, TInt aCertificateId); |
|
207 |
|
208 /** |
|
209 * @publishedPartner |
|
210 * @released |
|
211 * |
|
212 * Creates the certificate information object from its constituent parts, |
|
213 * and puts a pointer to the new object onto the cleanup stack. |
|
214 * |
|
215 * @param aLabel The certificate's label. |
|
216 * @param aFormat The certificate's format. |
|
217 * @param aCertificateOwnerType The owner type. |
|
218 * @param aSize The size of the certificate. |
|
219 * @param aSubjectKeyId The subject key ID. |
|
220 * @param aIssuerKeyId The issuer key ID. |
|
221 * @param aToken The token that the certificate is within. |
|
222 * @param aCertificateId The ID within the object handle. |
|
223 * @param aDeletable The certificate is deletable. |
|
224 * @param aIssuerHash The hash of the issuer's DN. |
|
225 * @return A pointer to the new certificate information object. |
|
226 * @leave KErrNoMemory There is no memory to construct it.*/ |
|
227 IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat, |
|
228 TCertificateOwnerType aCertificateOwnerType, TInt aSize, |
|
229 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, |
|
230 MCTToken& aToken, TInt aCertificateId, TBool aDeletable, |
|
231 const TDesC8* aIssuerHash = NULL); |
|
232 |
|
233 /** |
|
234 * @publishedPartner |
|
235 * @released |
|
236 * |
|
237 * Creates the certificate information object from its constituent parts, and puts |
|
238 * a pointer to the new object onto the cleanup stack. |
|
239 * |
|
240 * @param aLabel The certificate's label. |
|
241 * @param aFormat The certificate's format. |
|
242 * @param aCertificateOwnerType The owner type. |
|
243 * @param aSize The size of the certificate. |
|
244 * @param aSubjectKeyId The subject key ID. |
|
245 * @param aIssuerKeyId The issuer key ID. |
|
246 * @param aToken The token that the certificate is within. |
|
247 * @param aCertificateId The ID within the object handle. |
|
248 * @return A pointer to the new certificate information object. |
|
249 * @leave KErrNoMemory There is no memory to construct it.*/ |
|
250 IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat, |
|
251 TCertificateOwnerType aCertificateOwnerType, TInt aSize, |
|
252 const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, |
|
253 MCTToken& aToken, TInt aCertificateId); |
|
254 |
|
255 /** |
|
256 * @publishedPartner |
|
257 * @released |
|
258 * |
|
259 * Creates the certificate information object by internalising a previously externalised |
|
260 * one. |
|
261 * |
|
262 * @param aStream The stream from which the object is to be internalised. |
|
263 * @param aToken The token that it is within. |
|
264 * @return A pointer to the new certificate information object. |
|
265 * @leave KErrNoMemory There is no memory to construct it. |
|
266 * @see ExternalizeL |
|
267 * @see InternalizeL */ |
|
268 IMPORT_C static CCTCertInfo* NewL(RReadStream& aStream, MCTToken& aToken); |
|
269 |
|
270 /** |
|
271 * @publishedPartner |
|
272 * @released |
|
273 * |
|
274 * Creates the certificate information object, by internalising a previously externalised |
|
275 * one, and puts a pointer to the new object onto the cleanup stack. |
|
276 * |
|
277 * @param aStream The stream from which the object is to be internalised. |
|
278 * @param aToken The token that it is within. |
|
279 * @return A pointer to the new certificate information object. |
|
280 * @leave KErrNoMemory There is no memory to construct it. |
|
281 * @see ExternalizeL |
|
282 * @see InternalizeL */ |
|
283 IMPORT_C static CCTCertInfo* NewLC(RReadStream& aStream, MCTToken& aToken); |
|
284 |
|
285 /** Gets the subject key ID. |
|
286 * |
|
287 * @return A reference to a key identifier object. */ |
|
288 IMPORT_C const TKeyIdentifier& SubjectKeyId() const; |
|
289 |
|
290 /** Gets the issuer key ID. |
|
291 * |
|
292 * @return A reference to a key identifier object. */ |
|
293 IMPORT_C const TKeyIdentifier& IssuerKeyId() const; |
|
294 |
|
295 /** Gets the certificate format. |
|
296 * |
|
297 * @return The certificate format. */ |
|
298 IMPORT_C TCertificateFormat CertificateFormat() const; |
|
299 |
|
300 /** Gets the owner type. |
|
301 * |
|
302 * @return The owner type. */ |
|
303 IMPORT_C TCertificateOwnerType CertificateOwnerType() const; |
|
304 |
|
305 /** Gets the size of the certificate. |
|
306 * |
|
307 * Note that this function must be called so that the correct size of descriptor |
|
308 * can be allocated when retrieving the certificate (with MCertStore::Retrieve()). |
|
309 * |
|
310 * @return The size of the certificate. */ |
|
311 IMPORT_C TInt Size() const; |
|
312 |
|
313 /** Gets a handle for the object. |
|
314 * |
|
315 * The primary purpose of the handle is to allow token objects to be 'passed' |
|
316 * between processes. |
|
317 * |
|
318 * @return A handle for the object. |
|
319 * @see TCTTokenObjectHandle */ |
|
320 IMPORT_C TCTTokenObjectHandle Handle() const; |
|
321 |
|
322 /** Whether the certificate is deletable. |
|
323 * |
|
324 * @return ETrue if it is possible to delete the certificate; EFalse, otherwise. */ |
|
325 IMPORT_C TBool IsDeletable() const; |
|
326 |
|
327 /** Gets the hash of the issuer's DN. |
|
328 * |
|
329 * @return The hash of the issuer's DN, or NULL if not known. */ |
|
330 IMPORT_C const TDesC8* IssuerHash() const; |
|
331 |
|
332 public: |
|
333 // from MCTTokenObject |
|
334 /** Gets the object's human-readable label. |
|
335 * |
|
336 * @return The object's human-readable label. |
|
337 * @see MCTTokenObject::Label()*/ |
|
338 virtual const TDesC& Label() const; |
|
339 |
|
340 /** Gets a reference to the associated token. |
|
341 * |
|
342 * @return A reference to the associated token. |
|
343 * @see MCTTokenObject::Token()*/ |
|
344 virtual MCTToken& Token() const; |
|
345 |
|
346 /** Gets a UID representing the type of the token object. |
|
347 * |
|
348 * The function overrides MCTTokenObject::Type(). |
|
349 * |
|
350 * The meanings of possible UIDs should be documented in the documentation for |
|
351 * the interface that returns them. |
|
352 * |
|
353 * @return A UID representing the type of the token object; this implementation |
|
354 * returns KCTObjectCertInfo. |
|
355 * @see MCTTokenObject::Type() */ |
|
356 virtual TUid Type() const; |
|
357 |
|
358 // Compares 2 cert infos |
|
359 /** Compares this certificate information object with a specified Certificate |
|
360 * Information object for equality. |
|
361 * |
|
362 * @param aCertInfo The certificate information object to be compared. |
|
363 * @return ETrue, if they are the same; EFalse, otherwise. */ |
|
364 IMPORT_C TBool operator ==(const CCTCertInfo& aCertInfo) const; |
|
365 |
|
366 /** Sets the certificate Id. |
|
367 * |
|
368 * @param aCertId The certificate Id.*/ |
|
369 IMPORT_C void SetCertificateId(TInt aCertId); |
|
370 |
|
371 protected: |
|
372 IMPORT_C virtual ~CCTCertInfo(); |
|
373 |
|
374 private: |
|
375 CCTCertInfo(MCTToken& aToken); |
|
376 CCTCertInfo(const TDesC& aLabel, TCertificateFormat aFormat, |
|
377 TCertificateOwnerType aCertificateOwnerType, |
|
378 TInt aSize, |
|
379 const TKeyIdentifier* aSubjectKeyId, |
|
380 const TKeyIdentifier* aIssuerKeyId, |
|
381 MCTToken& aToken, TInt aCertificateId, |
|
382 TBool aDeletable); |
|
383 CCTCertInfo(const CCTCertInfo& aCertInfo); |
|
384 void ConstructL(RReadStream& aStream); |
|
385 void ConstructL(const TDesC8* aIssuerHash); |
|
386 |
|
387 private: |
|
388 const CCTCertInfo& operator=(const CCTCertInfo& aOther); |
|
389 |
|
390 private: |
|
391 MCTToken& iToken; |
|
392 }; |
|
393 |
|
394 #endif |