|
1 /* |
|
2 * Copyright (c) 1997-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 #if !defined (__WTLSNAMES_H__) |
|
21 #define __WTLSNAMES_H__ |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <e32std.h> |
|
25 #include <x500dn.h> |
|
26 |
|
27 /** |
|
28 @file |
|
29 This file contains the definition for class CWTLSName. |
|
30 |
|
31 @internalAll |
|
32 |
|
33 enum { null(0), text(1), binary(2), key_hash_sha(254), x509_name(255)} |
|
34 IdentifierType; |
|
35 |
|
36 We only support text and x509_name as these are the only meaningful identifiers.. |
|
37 x509_name is X.500 Distinguished Name, and should use our existing X.500 DN implementation. |
|
38 |
|
39 struct { |
|
40 IdentifierType identifier_type; |
|
41 select (identifier_type) { |
|
42 case null: struct {}; |
|
43 case text: |
|
44 CharacterSet character_set; |
|
45 opaque name<1.. 2^8-1>; |
|
46 case binary: opaque identifier<1..2^8-1>; |
|
47 case key_hash_sha: opaque key_hash[20]; |
|
48 case x509_name: opaque distinguished_name<1..2^8-1>; |
|
49 } |
|
50 Identifier; |
|
51 |
|
52 uint16 CharacterSet; |
|
53 |
|
54 This maps on to one of the IANA defined character sets. There are rather a lot |
|
55 of these. We just support the text type, with either Latin1 or UTF8 encoding. |
|
56 */ |
|
57 |
|
58 /** |
|
59 * Enumerates the types of WTLS certificate name forms/identifiers. |
|
60 * |
|
61 * Only text strings and X.500 Distinguished Names are currently supported. |
|
62 * |
|
63 * @publishedAll |
|
64 * @released |
|
65 */ |
|
66 enum |
|
67 { |
|
68 /* Null */ |
|
69 EWTLSNull = 0x00, |
|
70 /* Text string (Latin-1 or Unicode). |
|
71 * |
|
72 * A text identifier consists of a 16-bit character set identifier; |
|
73 * this represents the IANA-assigned character set number. */ |
|
74 EWTLSText = 0x01, |
|
75 /* Binary identifier. |
|
76 * |
|
77 * Certificates of this type will be rejected.*/ |
|
78 EWTLSBinary = 0x02, |
|
79 /* Key Hash SHA-1. |
|
80 * |
|
81 * Certificates of this type will be rejected.*/ |
|
82 EWTLSKeyHashSha = 0xfe, |
|
83 /* X.500 Distinguished Name. */ |
|
84 EWTLSX500DN = 0xff |
|
85 }; |
|
86 |
|
87 /** |
|
88 * @publishedAll |
|
89 * @released |
|
90 */ |
|
91 typedef TUint8 TWTLSNameType; |
|
92 |
|
93 /** |
|
94 * @publishedAll |
|
95 * @released |
|
96 */ |
|
97 typedef TInt TWTLSCharSet; |
|
98 |
|
99 // MIBenum constants from the IANA list of character sets. |
|
100 // See http://www.iana.org/assignments/character-sets for more info. |
|
101 |
|
102 /** MIBenum constant for the Latin1 IANA character set */ |
|
103 const TInt KWTLSLatin1CharSet = 4; |
|
104 |
|
105 /** MIBenum constant for the UTF-8 IANA character set */ |
|
106 const TInt KWTLSUTF8CharSet = 106; |
|
107 |
|
108 class CWTLSName : public CBase |
|
109 /** |
|
110 * Stores the type of a WTLS name and the underlying encoding of the type. |
|
111 * |
|
112 * @publishedAll |
|
113 * @released |
|
114 */ |
|
115 { |
|
116 public: |
|
117 /** |
|
118 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation. |
|
119 * |
|
120 * @param aBinaryData The encoded binary representation. |
|
121 * @return The new CWTLSName object. |
|
122 */ |
|
123 IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData); |
|
124 |
|
125 /** |
|
126 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, |
|
127 * and puts a pointer to it onto the cleanup stack. |
|
128 * |
|
129 * @param aBinaryData The encoded binary representation. |
|
130 * @return The new CWTLSName object. |
|
131 */ |
|
132 IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData); |
|
133 |
|
134 /** |
|
135 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, |
|
136 * starting at the specified offset. |
|
137 * |
|
138 * @param aBinaryData The encoded binary representation. |
|
139 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, |
|
140 * and is updated to the position at the end of the object. |
|
141 * @return The new CWTLSName object. |
|
142 */ |
|
143 IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
144 |
|
145 /** |
|
146 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, |
|
147 * starting at the specified offset, and puts a pointer to it onto the cleanup stack. |
|
148 * |
|
149 * @param aBinaryData The encoded binary representation. |
|
150 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, |
|
151 * and is updated to the position at the end of the object. |
|
152 * @return The new CWTLSName object. |
|
153 */ |
|
154 IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
155 |
|
156 /** |
|
157 * Creates a new CWTLSName object from an existing one. |
|
158 * |
|
159 * @param aName An existing CWTLSName object. |
|
160 * @return The new CWTLSName object. |
|
161 */ |
|
162 IMPORT_C static CWTLSName* NewL(const CWTLSName& aName); |
|
163 |
|
164 /** |
|
165 * Creates a new CWTLSName object from an existing one, |
|
166 * and puts a pointer to it onto the cleanup stack. |
|
167 * |
|
168 * @param aName An existing CWTLSName object. |
|
169 * @return The new CWTLSName object. |
|
170 */ |
|
171 IMPORT_C static CWTLSName* NewLC(const CWTLSName& aName); |
|
172 |
|
173 /** |
|
174 * Destructor. |
|
175 * |
|
176 * Frees all resources owned by the object, prior to its destruction. |
|
177 */ |
|
178 IMPORT_C ~CWTLSName(); |
|
179 |
|
180 /** |
|
181 * Performs a simple byte compare between this WTLS name and a specified WTLS name. |
|
182 * |
|
183 * Needed for the constructing/validating of certificate chains. |
|
184 * |
|
185 * @param aName An existing CWTLSName object. |
|
186 * @return ETrue, if the WTLS names match; EFalse, otherwise. |
|
187 */ |
|
188 IMPORT_C TBool ExactMatchL(const CWTLSName& aName) const; |
|
189 |
|
190 /** |
|
191 * Gets the type of the WTLS name. |
|
192 * |
|
193 * @return Type of WTLS name form. |
|
194 */ |
|
195 IMPORT_C TWTLSNameType NameType() const; |
|
196 |
|
197 /** |
|
198 * Gets the encoding of the underlying type of WTLS name. |
|
199 * |
|
200 * @return Pointer descriptor representing the encoding of the WTLS name type. |
|
201 */ |
|
202 IMPORT_C TPtrC8 NameData() const; |
|
203 |
|
204 /** |
|
205 * Gets the decoded value for the common or organisation name. |
|
206 * |
|
207 * Provides the functionality required by the CCertificate::IssuerL() and SubjectL() functions. |
|
208 * |
|
209 * @return A heap descriptor containing the decoded value of the common or organisation name. |
|
210 */ |
|
211 IMPORT_C HBufC* DisplayNameL() const; |
|
212 private: |
|
213 CWTLSName(); |
|
214 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
215 void ConstructL(const CWTLSName& aName); |
|
216 void AllocNameDataL(const TDesC8& aBinaryData, TInt& aPos); |
|
217 void AllocTextDataL(const TDesC8& aBinaryData, TInt& aPos); |
|
218 TWTLSNameType iNameType; |
|
219 HBufC8* iNameData; |
|
220 }; |
|
221 |
|
222 /** |
|
223 * @publishedAll |
|
224 * @released |
|
225 */ |
|
226 class CWTLSText : public CBase |
|
227 { |
|
228 public: |
|
229 /** |
|
230 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation. |
|
231 * |
|
232 * @param aBinaryData The encoded binary representation. |
|
233 * @return The new CWTLSText object. |
|
234 */ |
|
235 IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData); |
|
236 |
|
237 /** |
|
238 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, |
|
239 * and puts a pointer to it onto the cleanup stack. |
|
240 * |
|
241 * @param aBinaryData The encoded binary representation. |
|
242 * @return The new CWTLSText object. |
|
243 */ |
|
244 IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData); |
|
245 |
|
246 /** |
|
247 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, |
|
248 * starting at the specified offset. |
|
249 * |
|
250 * @param aBinaryData The encoded binary representation. |
|
251 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, |
|
252 * and is updated to the position at the end of the object. |
|
253 * @return The new CWTLSText object. |
|
254 */ |
|
255 IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
256 |
|
257 /** |
|
258 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, |
|
259 * starting at the specified offset, and puts a pointer to it onto the cleanup stack. |
|
260 * |
|
261 * @param aBinaryData The encoded binary representation. |
|
262 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, |
|
263 * and is updated to the position at the end of the object. |
|
264 * @return The new CWTLSText object. |
|
265 */ |
|
266 IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
267 |
|
268 /** |
|
269 * Destructor. |
|
270 * |
|
271 * Frees all resources owned by the object, prior to its destruction. |
|
272 */ |
|
273 IMPORT_C ~CWTLSText(); |
|
274 |
|
275 /** |
|
276 * Performs a simple byte compare between this CWTLSText object and a specified CWTLSText object. |
|
277 * |
|
278 * There is a subtle difference between this byte-match and CWTLSName::ExactMatchL(). |
|
279 * As opposed to the latter, this function should successfully match two names that |
|
280 * are the same that were encoded using different character sets. |
|
281 * |
|
282 * @param aName An existing CWTLSText object. |
|
283 * @return ETrue, if the CWTLSText objects match; EFalse, otherwise. |
|
284 */ |
|
285 IMPORT_C TBool ExactMatchL(const CWTLSText& aName) const; |
|
286 |
|
287 /** |
|
288 * Gets the name of the CWTLSText object. |
|
289 * |
|
290 * @return A pointer to the name of the CWTLSText object. |
|
291 */ |
|
292 IMPORT_C TPtrC Name() const; |
|
293 |
|
294 /** |
|
295 * Gets the character set of the CWTLSText object. |
|
296 * |
|
297 * @return The character set |
|
298 */ |
|
299 IMPORT_C TWTLSCharSet CharacterSet() const; |
|
300 protected: |
|
301 /** |
|
302 * @internalAll |
|
303 */ |
|
304 CWTLSText(); |
|
305 /** |
|
306 * @internalAll |
|
307 */ |
|
308 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
309 HBufC* iName; |
|
310 private: |
|
311 TInt iCharacterSet; |
|
312 }; |
|
313 |
|
314 //this class implements the 'structured' variant of the text type defined in the WTLS spec, section 10.5.2: |
|
315 //<servicename>; <organization>; <country>[; <commonname>[; <extension>[; <extension>[ …. ]]]] |
|
316 _LIT(KWTLSCountryName,"C"); |
|
317 _LIT(KWTLSOrganizationName,"O"); |
|
318 _LIT(KWTLSServiceName,"OU"); |
|
319 _LIT(KWTLSTitle,"T"); |
|
320 _LIT(KWTLSCommonName,"CN"); |
|
321 |
|
322 /** |
|
323 * @publishedAll |
|
324 * @released |
|
325 */ |
|
326 class TWTLSStructuredTextField |
|
327 { |
|
328 public: |
|
329 /** |
|
330 * @internalAll |
|
331 */ |
|
332 TWTLSStructuredTextField(const TDesC& aType, const TDesC& aValue); |
|
333 |
|
334 /** |
|
335 * |
|
336 * @return |
|
337 */ |
|
338 IMPORT_C TPtrC Type() const; |
|
339 |
|
340 /** |
|
341 * |
|
342 * @return |
|
343 */ |
|
344 IMPORT_C TPtrC Value() const; |
|
345 |
|
346 private: |
|
347 const TPtrC iType; |
|
348 const TPtrC iValue; |
|
349 }; |
|
350 |
|
351 /** |
|
352 * @publishedAll |
|
353 * @released |
|
354 */ |
|
355 class CWTLSStructuredText : public CWTLSText |
|
356 { |
|
357 public: |
|
358 /** |
|
359 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation. |
|
360 * |
|
361 * @param aBinaryData The encoded binary representation. |
|
362 * @return The new CWTLSStructuredText object. |
|
363 */ |
|
364 IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData); |
|
365 |
|
366 /** |
|
367 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, |
|
368 * and puts a pointer to it onto the cleanup stack. |
|
369 * |
|
370 * @param aBinaryData The encoded binary representation. |
|
371 * @return The new CWTLSStructuredText object. |
|
372 */ |
|
373 IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData); |
|
374 |
|
375 /** |
|
376 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, |
|
377 * starting at the specified offset. |
|
378 * |
|
379 * @param aBinaryData The encoded binary representation. |
|
380 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, |
|
381 * and is updated to the position at the end of the object. |
|
382 * @return The new CWTLSStructuredText object. |
|
383 */ |
|
384 IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
385 |
|
386 /** |
|
387 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, |
|
388 * starting at the specified offset, and puts a pointer to it onto the cleanup stack. |
|
389 * |
|
390 * @param aBinaryData The encoded binary representation. |
|
391 * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, |
|
392 * and is updated to the position at the end of the object. |
|
393 * @return The new CWTLSStructuredText object. |
|
394 */ |
|
395 IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
396 |
|
397 /** |
|
398 * Destructor. |
|
399 * |
|
400 * Frees all resources owned by the object, prior to its destruction. |
|
401 */ |
|
402 IMPORT_C ~CWTLSStructuredText(); |
|
403 |
|
404 /** |
|
405 * |
|
406 * |
|
407 * @return |
|
408 */ |
|
409 IMPORT_C HBufC* DisplayNameL() const; |
|
410 |
|
411 //accessors for defined fields |
|
412 |
|
413 /** |
|
414 * |
|
415 * |
|
416 * @return |
|
417 */ |
|
418 IMPORT_C TPtrC ServiceName() const; |
|
419 |
|
420 /** |
|
421 * |
|
422 * |
|
423 * @return |
|
424 */ |
|
425 IMPORT_C TPtrC Organization() const; |
|
426 |
|
427 /** |
|
428 * |
|
429 * |
|
430 * @return |
|
431 */ |
|
432 IMPORT_C TPtrC Country() const; |
|
433 |
|
434 /** |
|
435 * |
|
436 * |
|
437 * @return |
|
438 */ |
|
439 IMPORT_C TInt Count() const; |
|
440 |
|
441 |
|
442 /** |
|
443 * |
|
444 * |
|
445 * Note |
|
446 * |
|
447 * @param aType |
|
448 * @return A pointer to a TWTLSStructuredTextField object; NULL if field not found. |
|
449 * The returned object remains the property of the structured text object |
|
450 * (so don't delete it). |
|
451 */ |
|
452 IMPORT_C const TWTLSStructuredTextField* FieldByName(const TDesC& aType) const; |
|
453 |
|
454 /** |
|
455 * |
|
456 * |
|
457 * @return |
|
458 */ |
|
459 IMPORT_C const TWTLSStructuredTextField& FieldByIndex(TInt aIndex) const; |
|
460 private: |
|
461 CWTLSStructuredText(); |
|
462 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
463 void AddFieldValueL(const TDesC& aFieldName, TInt& aPos); |
|
464 void AddFieldL(TInt& aPos); |
|
465 TPtrC GetFieldL(TDesC& aString, TInt& aPos); |
|
466 TBool GetSubFieldL(TDesC& aString, TInt& aPos); |
|
467 CArrayFixFlat<TWTLSStructuredTextField>* iFields; |
|
468 }; |
|
469 |
|
470 #endif |