|
1 /* |
|
2 * Copyright (c) 1998-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 <x509gn.h> |
|
20 #include "asn1dec.h" |
|
21 |
|
22 /* |
|
23 * __SECURITY_PLATSEC_ARCH__: Changes for platform security |
|
24 * |
|
25 * If this macro is defined, the represenation of TPtrC arrays is changed from |
|
26 * using CPtrCArray to RArray<TPtrC>. This is because CPtrCArray is supplied by |
|
27 * bafl.dll, which is not trusted for TCB. x509 needs to be trusted for TCB so |
|
28 * it can be used by software install, hence this dependency was removed. |
|
29 * |
|
30 * This changes is implmented as a series of macros for the basic operations, |
|
31 * to minimise the amount of conditional compilation. |
|
32 */ |
|
33 |
|
34 |
|
35 #define REP_INIT_L /* do nothing */ |
|
36 #define REP_FINAL iRep.Close() |
|
37 #define REP_APPEND_L(X) User::LeaveIfError(iRep.Append(X)) |
|
38 #define REP_COUNT iRep.Count() |
|
39 #define REP_AT(X) iRep[X] |
|
40 #define REP_VAL iRep |
|
41 #define REP_VAL_TYPE RArray<TPtrC> |
|
42 |
|
43 |
|
44 _LIT(KX509RFC822HostDomainSeparator,"@"); |
|
45 _LIT(KX509SubdomainSeparator,"."); |
|
46 _LIT(KX509URISchemeSpecificStart, "//"); |
|
47 _LIT(KX509URIUserPasswordEnd, "@"); |
|
48 _LIT(KX509URIPortStart, ":"); |
|
49 _LIT(KX509URIurlPathStart, "/"); |
|
50 |
|
51 const TInt KX509URISchemeSpecificStartLength = 2; |
|
52 const TInt KX509URIUserPasswordEndLength = 1; |
|
53 const TInt KX509MaxDNSNameLabelLength = 63; |
|
54 |
|
55 //superclass: common functionality for DNS names & RFC 822 email addresses |
|
56 EXPORT_C CX509DomainName::~CX509DomainName() |
|
57 { |
|
58 REP_FINAL; |
|
59 delete iName; |
|
60 } |
|
61 |
|
62 CX509DomainName::CX509DomainName() |
|
63 { |
|
64 } |
|
65 |
|
66 EXPORT_C TPtrC CX509DomainName::Name() const |
|
67 { |
|
68 return *iName; |
|
69 } |
|
70 |
|
71 EXPORT_C TBool CX509DomainName::IsWithinSubtree(const CX509DomainName& aName) const |
|
72 { |
|
73 TInt myCount = REP_COUNT; |
|
74 TInt otherCount = aName.REP_COUNT; |
|
75 if (otherCount > myCount) |
|
76 { |
|
77 return EFalse; |
|
78 } |
|
79 for (TInt i = otherCount-1; i >= 0; i--) |
|
80 { |
|
81 myCount--; |
|
82 if ( KErrNotFound == REP_AT(myCount).MatchF(aName.REP_AT(i)) ) |
|
83 { |
|
84 return EFalse; |
|
85 } |
|
86 } |
|
87 return ETrue; |
|
88 } |
|
89 |
|
90 TBool CX509DomainName::AddDomainL(TInt& aPos) |
|
91 { |
|
92 TInt end = iName->Length(); |
|
93 FOREVER |
|
94 { |
|
95 if (!(AddSubdomainL(aPos))) |
|
96 { |
|
97 return EFalse; |
|
98 } |
|
99 if (aPos == end) |
|
100 { |
|
101 break; |
|
102 } |
|
103 AddSubdomainSeparatorL(aPos); |
|
104 } |
|
105 return ETrue; |
|
106 } |
|
107 |
|
108 TBool CX509DomainName::AddSubdomainL(TInt& aPos) |
|
109 { |
|
110 TBool res = EFalse; |
|
111 TInt end = iName->Length(); |
|
112 if (aPos >= end) |
|
113 { |
|
114 return res; |
|
115 } |
|
116 TPtrC whatsLeft(&(iName->operator[] (aPos)), end - aPos); |
|
117 TInt subdomainEnd = whatsLeft.FindF(KX509SubdomainSeparator); |
|
118 if (subdomainEnd == 0) |
|
119 { |
|
120 return res; |
|
121 } |
|
122 if (subdomainEnd == KErrNotFound) |
|
123 { |
|
124 subdomainEnd = end - aPos; |
|
125 } |
|
126 TPtrC subdomain(&whatsLeft[0], subdomainEnd); |
|
127 if (IsValidString(subdomain)) |
|
128 { |
|
129 REP_APPEND_L(subdomain); |
|
130 res = ETrue; |
|
131 } |
|
132 aPos = aPos + subdomainEnd; |
|
133 return res; |
|
134 } |
|
135 |
|
136 TBool CX509DomainName::AddSubdomainSeparatorL(TInt& aPos) |
|
137 { |
|
138 TBool res = EFalse; |
|
139 TInt end = iName->Length(); |
|
140 if (end <= aPos) |
|
141 { |
|
142 return res; |
|
143 } |
|
144 TPtrC whatsLeft(&(iName->operator[] (aPos)), end - aPos); |
|
145 TInt separatorEnd = whatsLeft.FindF(KX509SubdomainSeparator); |
|
146 if (separatorEnd == 0) |
|
147 { |
|
148 TPtrC separator(&whatsLeft[0], 1); |
|
149 REP_APPEND_L(separator); |
|
150 aPos++; |
|
151 res = ETrue; |
|
152 } |
|
153 return res; |
|
154 } |
|
155 |
|
156 TBool CX509DomainName::IsValidString(const TDesC& aStr) const |
|
157 { |
|
158 TInt pos=0; |
|
159 TInt end=aStr.Length()-1; |
|
160 if (end < 0) |
|
161 { |
|
162 return ETrue; |
|
163 } |
|
164 while (pos<end && IsValidChar(aStr[pos])) |
|
165 { |
|
166 pos++; |
|
167 } |
|
168 return (pos==end && IsValidChar(aStr[end])); |
|
169 } |
|
170 |
|
171 TBool CX509DomainName::IsAlpha(const TChar& aChar) const |
|
172 { |
|
173 return ( ((aChar >= 97) && (aChar <= 122)) || |
|
174 ((aChar >= 65) && (aChar <= 90)) ); |
|
175 } |
|
176 |
|
177 TBool CX509DomainName::IsAlphaOrNum(const TChar& aChar) const |
|
178 { |
|
179 return ((IsAlpha(aChar)) || |
|
180 ((aChar >= 48) && (aChar <= 57)) || (aChar == 42)); |
|
181 } |
|
182 |
|
183 TBool CX509DomainName::IsValidChar(const TChar& aChar) const |
|
184 { |
|
185 //default implementation: must be letter, number or hyphen |
|
186 return ((IsAlphaOrNum(aChar)) || |
|
187 (aChar == 45) || (aChar == 42)); |
|
188 } |
|
189 |
|
190 //RFC 822 email address |
|
191 //subtree |
|
192 EXPORT_C CX509RFC822NameSubtree* CX509RFC822NameSubtree::NewL(const TDesC8& aBinaryData) |
|
193 { |
|
194 CX509RFC822NameSubtree* self = CX509RFC822NameSubtree::NewLC(aBinaryData); |
|
195 CleanupStack::Pop();//self |
|
196 return self; |
|
197 } |
|
198 |
|
199 EXPORT_C CX509RFC822NameSubtree* CX509RFC822NameSubtree::NewLC(const TDesC8& aBinaryData) |
|
200 { |
|
201 CX509RFC822NameSubtree* self = new(ELeave) CX509RFC822NameSubtree; |
|
202 CleanupStack::PushL(self); |
|
203 self->ConstructL(aBinaryData); |
|
204 return self; |
|
205 } |
|
206 |
|
207 void CX509RFC822NameSubtree::ConstructL(const TDesC8& aBinaryData) |
|
208 { |
|
209 TInt pos = 0; |
|
210 TASN1DecIA5String encStr; |
|
211 iName = encStr.DecodeDERL(aBinaryData, pos); |
|
212 REP_INIT_L; |
|
213 //now, parse your data |
|
214 pos = 0; |
|
215 AddLocalHostL(pos); |
|
216 AddSubdomainSeparatorL(pos); |
|
217 if (!(AddDomainL(pos))) |
|
218 { |
|
219 User::Leave(KErrArgument); |
|
220 } |
|
221 } |
|
222 |
|
223 TBool CX509RFC822NameSubtree::AddLocalHostL(TInt& aPos) |
|
224 { |
|
225 TInt localHostLength = iName->FindF(KX509RFC822HostDomainSeparator); |
|
226 if ((localHostLength != KErrNotFound) && (localHostLength > 0)) |
|
227 { |
|
228 TPtrC localHost(&(iName->operator[] (aPos)), localHostLength); |
|
229 //the local host name is not checked here as it caused defect PDEF108960 |
|
230 //and for compatability with IE and Firefox. |
|
231 REP_APPEND_L(localHost); |
|
232 aPos = aPos + localHostLength; |
|
233 aPos++; //skip the @ symbol |
|
234 return ETrue; |
|
235 } |
|
236 return EFalse; //local host not found |
|
237 } |
|
238 |
|
239 |
|
240 EXPORT_C const REP_VAL_TYPE& CX509RFC822NameSubtree::Rep() const |
|
241 { |
|
242 return REP_VAL; |
|
243 } |
|
244 |
|
245 TBool CX509RFC822NameSubtree::IsValidChar(const TChar& aChar) const |
|
246 { |
|
247 //we permit "." here, 'cos it's allowed in local host names |
|
248 //and must have been stripped out by domain parsing code, |
|
249 //since it's the separator char |
|
250 return ( (aChar == 33) || |
|
251 ((aChar >= 35) && (aChar <= 40)) || |
|
252 (aChar == 42) || |
|
253 (aChar == 43) || |
|
254 ((aChar >= 45) && (aChar <= 57)) || |
|
255 (aChar == 61) || |
|
256 (aChar == 63) || |
|
257 ((aChar >= 65) && (aChar <= 90)) || |
|
258 ((aChar >= 94) && (aChar <= 126)) ); |
|
259 } |
|
260 |
|
261 //full rfc 822 name: exactly as subtree, but requires local host and full domain name |
|
262 EXPORT_C CX509RFC822Name* CX509RFC822Name::NewL(const TDesC8& aBinaryData) |
|
263 { |
|
264 CX509RFC822Name* self = CX509RFC822Name::NewLC(aBinaryData); |
|
265 CleanupStack::Pop();//self |
|
266 return self; |
|
267 } |
|
268 |
|
269 EXPORT_C CX509RFC822Name* CX509RFC822Name::NewLC(const TDesC8& aBinaryData) |
|
270 { |
|
271 CX509RFC822Name* self = new(ELeave) CX509RFC822Name; |
|
272 CleanupStack::PushL(self); |
|
273 self->ConstructL(aBinaryData); |
|
274 return self; |
|
275 } |
|
276 |
|
277 void CX509RFC822Name::ConstructL(const TDesC8& aBinaryData) |
|
278 { |
|
279 TInt pos = 0; |
|
280 TASN1DecIA5String encStr; |
|
281 iName = encStr.DecodeDERL(aBinaryData, pos); |
|
282 REP_INIT_L; |
|
283 //now, parse your data |
|
284 pos = 0; |
|
285 if (! ((AddLocalHostL(pos)) && (AddDomainL(pos))) ) |
|
286 { |
|
287 User::Leave(KErrArgument); |
|
288 } |
|
289 } |
|
290 |
|
291 //DNS Name subtree |
|
292 EXPORT_C CX509DNSNameSubtree* CX509DNSNameSubtree::NewL(const TDesC8& aBinaryData) |
|
293 { |
|
294 CX509DNSNameSubtree* self = CX509DNSNameSubtree::NewLC(aBinaryData); |
|
295 CleanupStack::Pop();//self |
|
296 return self; |
|
297 } |
|
298 |
|
299 EXPORT_C CX509DNSNameSubtree* CX509DNSNameSubtree::NewLC(const TDesC8& aBinaryData) |
|
300 { |
|
301 CX509DNSNameSubtree* self = new(ELeave) CX509DNSNameSubtree; |
|
302 CleanupStack::PushL(self); |
|
303 self->ConstructL(aBinaryData); |
|
304 return self; |
|
305 } |
|
306 |
|
307 void CX509DNSNameSubtree::ConstructL(const TDesC8& aBinaryData) |
|
308 { |
|
309 TInt pos = 0; |
|
310 TASN1DecIA5String encStr; |
|
311 iName = encStr.DecodeDERL(aBinaryData, pos); |
|
312 REP_INIT_L; |
|
313 pos = 0; |
|
314 AddSubdomainSeparatorL(pos);//a subtree may start with a period |
|
315 if (!(AddDomainL(pos))) |
|
316 { |
|
317 User::Leave(KErrArgument); |
|
318 } |
|
319 } |
|
320 |
|
321 EXPORT_C const REP_VAL_TYPE& CX509DNSNameSubtree::Rep() const |
|
322 { |
|
323 return REP_VAL; |
|
324 } |
|
325 |
|
326 TBool CX509DNSNameSubtree::IsValidString(const TDesC& aStr) const |
|
327 { |
|
328 //must be <= 63 chars long |
|
329 //must start with letter, end with letter or number |
|
330 TInt len = aStr.Length(); |
|
331 return ( (len <= KX509MaxDNSNameLabelLength) && |
|
332 (IsAlphaOrNum(aStr[0])) && |
|
333 (IsAlphaOrNum(aStr[len-1])) && |
|
334 (CX509DomainName::IsValidString(aStr)) ); |
|
335 } |
|
336 |
|
337 //dns name: exactly as subtree but requires full domain name |
|
338 EXPORT_C CX509DNSName* CX509DNSName::NewL(const TDesC8& aBinaryData) |
|
339 { |
|
340 CX509DNSName* self = CX509DNSName::NewLC(aBinaryData); |
|
341 CleanupStack::Pop();//self |
|
342 return self; |
|
343 } |
|
344 |
|
345 EXPORT_C CX509DNSName* CX509DNSName::NewLC(const TDesC8& aBinaryData) |
|
346 { |
|
347 CX509DNSName* self = new(ELeave) CX509DNSName; |
|
348 CleanupStack::PushL(self); |
|
349 self->ConstructL(aBinaryData); |
|
350 return self; |
|
351 } |
|
352 |
|
353 EXPORT_C CX509DNSName* CX509DNSName::NewL(const CX509DNSName& aName) |
|
354 { |
|
355 CX509DNSName* self = CX509DNSName::NewLC(aName); |
|
356 CleanupStack::Pop();//self |
|
357 return self; |
|
358 } |
|
359 |
|
360 EXPORT_C CX509DNSName* CX509DNSName::NewLC(const CX509DNSName& aName) |
|
361 { |
|
362 CX509DNSName* self = new(ELeave) CX509DNSName; |
|
363 CleanupStack::PushL(self); |
|
364 self->ConstructL(aName); |
|
365 return self; |
|
366 } |
|
367 |
|
368 |
|
369 EXPORT_C CX509DNSName* CX509DNSName::NewL(const TDesC& aNameString) |
|
370 { |
|
371 CX509DNSName* self = CX509DNSName::NewLC(aNameString); |
|
372 CleanupStack::Pop();//self |
|
373 return self; |
|
374 } |
|
375 |
|
376 EXPORT_C CX509DNSName* CX509DNSName::NewLC(const TDesC& aNameString) |
|
377 { |
|
378 CX509DNSName* self = new(ELeave) CX509DNSName; |
|
379 CleanupStack::PushL(self); |
|
380 self->ConstructL(aNameString); |
|
381 return self; |
|
382 } |
|
383 |
|
384 void CX509DNSName::ConstructL(const TDesC& aNameString) |
|
385 { |
|
386 TInt pos = 0; |
|
387 REP_INIT_L; |
|
388 iName = aNameString.AllocL(); |
|
389 AddSubdomainSeparatorL(pos);//a subtree may start with a period |
|
390 if (!(AddDomainL(pos))) |
|
391 { |
|
392 User::Leave(KErrArgument); |
|
393 } |
|
394 } |
|
395 |
|
396 void CX509DNSName::ConstructL(const TDesC8& aBinaryData) |
|
397 { |
|
398 TInt pos = 0; |
|
399 TASN1DecIA5String encStr; |
|
400 iName = encStr.DecodeDERL(aBinaryData, pos); |
|
401 ParseNameL(); |
|
402 } |
|
403 |
|
404 void CX509DNSName::ConstructL(const CX509DNSName& aName) |
|
405 { |
|
406 iName = aName.iName->AllocL(); |
|
407 ParseNameL(); |
|
408 } |
|
409 |
|
410 void CX509DNSName::ParseNameL() |
|
411 { |
|
412 REP_INIT_L; |
|
413 TInt pos = 0; |
|
414 if (!AddDomainL(pos)) |
|
415 { |
|
416 User::Leave(KErrArgument); |
|
417 } |
|
418 } |
|
419 |
|
420 //URI: must be of 'ip-based' form (rfc 1738 section 3.1) |
|
421 //_and_ contain a domain name (not an IP address) |
|
422 EXPORT_C CX509IPBasedURI* CX509IPBasedURI::NewL(const TDesC8& aBinaryData) |
|
423 { |
|
424 CX509IPBasedURI* self = CX509IPBasedURI::NewLC(aBinaryData); |
|
425 CleanupStack::Pop();//self |
|
426 return self; |
|
427 } |
|
428 |
|
429 EXPORT_C CX509IPBasedURI* CX509IPBasedURI::NewLC(const TDesC8& aBinaryData) |
|
430 { |
|
431 CX509IPBasedURI* self = new(ELeave) CX509IPBasedURI; |
|
432 CleanupStack::PushL(self); |
|
433 self->ConstructL(aBinaryData); |
|
434 return self; |
|
435 } |
|
436 |
|
437 void CX509IPBasedURI::ConstructL(const TDesC8& aBinaryData) |
|
438 { |
|
439 TInt pos = 0; |
|
440 TASN1DecIA5String encStr; |
|
441 iName = encStr.DecodeDERL(aBinaryData, pos); |
|
442 iHost = CX509DNSName::NewL(ExtractHostNameL()); |
|
443 } |
|
444 |
|
445 EXPORT_C CX509IPBasedURI::~CX509IPBasedURI() |
|
446 { |
|
447 delete iName; |
|
448 delete iHost; |
|
449 } |
|
450 |
|
451 CX509IPBasedURI::CX509IPBasedURI() |
|
452 :iHost(NULL), iName(NULL) |
|
453 { |
|
454 } |
|
455 |
|
456 EXPORT_C const CX509DNSName& CX509IPBasedURI::Host() const |
|
457 { |
|
458 return *iHost; |
|
459 } |
|
460 |
|
461 EXPORT_C TPtrC CX509IPBasedURI::Name() const |
|
462 { |
|
463 return iName->Des(); |
|
464 } |
|
465 |
|
466 TPtrC CX509IPBasedURI::ExtractHostNameL() const |
|
467 { |
|
468 TInt hostStart; |
|
469 TInt hostEnd; |
|
470 TInt len = iName->Length(); |
|
471 TInt schemeSpecificStart = (iName->FindF(KX509URISchemeSpecificStart) + KX509URISchemeSpecificStartLength); |
|
472 TInt userPasswordEnd = (iName->FindF(KX509URIUserPasswordEnd)) + KX509URIUserPasswordEndLength; |
|
473 hostStart = ((userPasswordEnd == 0)? schemeSpecificStart : userPasswordEnd); |
|
474 if (hostStart == KErrNotFound) |
|
475 { |
|
476 User::Leave(KErrArgument); |
|
477 } |
|
478 TPtrC whatsLeft(&(iName->operator[](hostStart)), len - hostStart); |
|
479 TInt newlen = whatsLeft.Length(); |
|
480 TInt portStart = whatsLeft.FindF(KX509URIPortStart); |
|
481 TInt urlPathStart = whatsLeft.FindF(KX509URIurlPathStart); |
|
482 if (portStart == KErrNotFound) |
|
483 { |
|
484 if (urlPathStart == KErrNotFound) |
|
485 { |
|
486 hostEnd = newlen; |
|
487 } |
|
488 else |
|
489 { |
|
490 hostEnd = urlPathStart; |
|
491 } |
|
492 } |
|
493 else |
|
494 { |
|
495 if (urlPathStart == KErrNotFound) |
|
496 { |
|
497 hostEnd = portStart; |
|
498 } |
|
499 else //both are there, choose the first one |
|
500 { |
|
501 hostEnd = ((urlPathStart > portStart)? portStart: urlPathStart); |
|
502 } |
|
503 } |
|
504 TPtrC host(&(iName->operator[](hostStart)), hostEnd); |
|
505 return host; |
|
506 } |
|
507 |
|
508 //IP Address |
|
509 //subnet mask |
|
510 EXPORT_C CX509IPSubnetMask* CX509IPSubnetMask::NewL(const TDesC8& aBinaryData) |
|
511 { |
|
512 CX509IPSubnetMask* self = CX509IPSubnetMask::NewLC(aBinaryData); |
|
513 CleanupStack::Pop();//self; |
|
514 return self; |
|
515 } |
|
516 |
|
517 EXPORT_C CX509IPSubnetMask* CX509IPSubnetMask::NewLC(const TDesC8& aBinaryData) |
|
518 { |
|
519 CX509IPSubnetMask* self = new(ELeave) CX509IPSubnetMask; |
|
520 CleanupStack::PushL(self); |
|
521 self->ConstructL(aBinaryData); |
|
522 return self; |
|
523 } |
|
524 |
|
525 void CX509IPSubnetMask::ConstructL(const TDesC8& aBinaryData) |
|
526 { |
|
527 //!!!need to correct this when we have octet strings going!!! |
|
528 TASN1DecGeneric encAddr(aBinaryData); |
|
529 encAddr.InitL(); |
|
530 iName = encAddr.GetContentDER().AllocL();// = CASN1OctetString::DecodeDERL(aBinaryData, pos); |
|
531 TInt len = iName->Length(); |
|
532 if (!((len == 8) || (len == 32))) |
|
533 { |
|
534 User::Leave(KErrArgument); |
|
535 } |
|
536 } |
|
537 |
|
538 EXPORT_C CX509IPSubnetMask::~CX509IPSubnetMask() |
|
539 { |
|
540 delete iName; |
|
541 } |
|
542 |
|
543 EXPORT_C TPtrC8 CX509IPSubnetMask::BaseAddress() const |
|
544 { |
|
545 TInt half = iName->Length()/2; |
|
546 TPtrC8 ptr(&(iName->operator [] (0)), half); |
|
547 return ptr; |
|
548 } |
|
549 |
|
550 EXPORT_C TPtrC8 CX509IPSubnetMask::Mask() const |
|
551 { |
|
552 TInt half = iName->Length()/2; |
|
553 TPtrC8 ptr(&(iName->operator [] (half)), half); |
|
554 return ptr; |
|
555 } |
|
556 |
|
557 CX509IPSubnetMask::CX509IPSubnetMask() |
|
558 :iName(NULL) |
|
559 { |
|
560 } |
|
561 |
|
562 //ip address |
|
563 EXPORT_C CX509IPAddress* CX509IPAddress::NewL(const TDesC8& aBinaryData) |
|
564 { |
|
565 CX509IPAddress* self = CX509IPAddress::NewLC(aBinaryData); |
|
566 CleanupStack::Pop();//self |
|
567 return self; |
|
568 } |
|
569 |
|
570 EXPORT_C CX509IPAddress* CX509IPAddress::NewLC(const TDesC8& aBinaryData) |
|
571 { |
|
572 CX509IPAddress* self = new(ELeave) CX509IPAddress; |
|
573 CleanupStack::PushL(self); |
|
574 self->ConstructL(aBinaryData); |
|
575 return self; |
|
576 } |
|
577 |
|
578 void CX509IPAddress::ConstructL(const TDesC8& aBinaryData) |
|
579 { |
|
580 TASN1DecGeneric encAddr(aBinaryData); |
|
581 encAddr.InitL(); |
|
582 iName = encAddr.GetContentDER().AllocL(); |
|
583 TInt len = iName->Length(); |
|
584 if (!(len == 4 || len == 16)) |
|
585 { |
|
586 User::Leave(KErrArgument); |
|
587 } |
|
588 } |
|
589 |
|
590 EXPORT_C CX509IPAddress::~CX509IPAddress() |
|
591 { |
|
592 delete iName; |
|
593 } |
|
594 |
|
595 EXPORT_C TBool CX509IPAddress::IsWithinSubtree(const CX509IPSubnetMask& aName) const |
|
596 { |
|
597 TInt addrLen = iName->Length(); |
|
598 if (((aName.iName->Length())/2) != addrLen) |
|
599 { |
|
600 return EFalse; |
|
601 } |
|
602 for (TInt i = 0; i < addrLen; i++) |
|
603 { |
|
604 //stop stupid compiler warning |
|
605 TUint8 masked = (TUint8) ((iName->operator [] (i)) & (aName.iName->operator [] (i + addrLen))); |
|
606 if (masked != (aName.iName->operator [] (i))) |
|
607 { |
|
608 return EFalse; |
|
609 } |
|
610 } |
|
611 return ETrue; |
|
612 } |
|
613 |
|
614 EXPORT_C TPtrC8 CX509IPAddress::Address() const |
|
615 { |
|
616 return iName->Des(); |
|
617 } |
|
618 |
|
619 CX509IPAddress::CX509IPAddress() |
|
620 :iName(NULL) |
|
621 { |
|
622 } |
|
623 |
|
624 //*******************X.509 General Name**********************// |
|
625 EXPORT_C CX509GeneralName* CX509GeneralName::NewL(const TDesC8& aBinaryData) |
|
626 { |
|
627 TInt pos = 0; |
|
628 return CX509GeneralName::NewL(aBinaryData, pos); |
|
629 } |
|
630 |
|
631 EXPORT_C CX509GeneralName* CX509GeneralName::NewLC(const TDesC8& aBinaryData) |
|
632 { |
|
633 TInt pos = 0; |
|
634 return CX509GeneralName::NewLC(aBinaryData, pos); |
|
635 } |
|
636 |
|
637 EXPORT_C CX509GeneralName* CX509GeneralName::NewL(const TDesC8& aBinaryData, TInt& aPos) |
|
638 { |
|
639 CX509GeneralName* self = CX509GeneralName::NewLC(aBinaryData, aPos); |
|
640 CleanupStack::Pop(); |
|
641 return self; |
|
642 } |
|
643 |
|
644 EXPORT_C CX509GeneralName* CX509GeneralName::NewLC(const TDesC8& aBinaryData, TInt& aPos) |
|
645 { |
|
646 CX509GeneralName* self = new(ELeave) CX509GeneralName; |
|
647 CleanupStack::PushL(self); |
|
648 self->ConstructL(aBinaryData, aPos); |
|
649 return self; |
|
650 } |
|
651 |
|
652 EXPORT_C CX509GeneralName* CX509GeneralName::NewL(const CX509GeneralName& aName) |
|
653 { |
|
654 CX509GeneralName* self = CX509GeneralName::NewLC(aName); |
|
655 CleanupStack::Pop(); |
|
656 return self; |
|
657 } |
|
658 |
|
659 EXPORT_C CX509GeneralName* CX509GeneralName::NewLC(const CX509GeneralName& aName) |
|
660 { |
|
661 CX509GeneralName* self = new(ELeave) CX509GeneralName(aName.iTag); |
|
662 CleanupStack::PushL(self); |
|
663 self->ConstructL(aName.iData->Des()); |
|
664 return self; |
|
665 } |
|
666 |
|
667 void CX509GeneralName::ConstructL(const TDesC8& aBinaryData, TInt& aPos) |
|
668 { |
|
669 TASN1DecGeneric gen(aBinaryData.Right(aBinaryData.Length() - aPos)); |
|
670 gen.InitL(); |
|
671 aPos += gen.LengthDER();//add on header info |
|
672 if (gen.Class() != EContextSpecific) |
|
673 { |
|
674 User::Leave(KErrArgument); |
|
675 } |
|
676 iData = gen.Tag() == 4 ? gen.GetContentDER().AllocL(): gen.Encoding().AllocL(); |
|
677 iTag = gen.Tag(); |
|
678 } |
|
679 |
|
680 void CX509GeneralName::ConstructL(const TDesC8& aData) |
|
681 { |
|
682 iData = aData.AllocL(); |
|
683 } |
|
684 |
|
685 CX509GeneralName::CX509GeneralName(TGNType aType) |
|
686 :iTag(aType) |
|
687 { |
|
688 } |
|
689 |
|
690 CX509GeneralName::CX509GeneralName() |
|
691 { |
|
692 } |
|
693 |
|
694 EXPORT_C TGNType CX509GeneralName::Tag() const |
|
695 { |
|
696 return iTag; |
|
697 } |
|
698 |
|
699 EXPORT_C TPtrC8 CX509GeneralName::Data() const |
|
700 { |
|
701 return iData->Des(); |
|
702 } |
|
703 |
|
704 EXPORT_C TBool CX509GeneralName::ExactMatch(const CX509GeneralName& /*aName*/) const |
|
705 { |
|
706 return EFalse; |
|
707 } |
|
708 |
|
709 EXPORT_C CX509GeneralName::~CX509GeneralName() |
|
710 { |
|
711 delete iData; |
|
712 } |