|
1 /* |
|
2 * Copyright (c) 2008 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 "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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "TestHarness.h" |
|
19 |
|
20 #include "midpauthenticationmodule.h" |
|
21 #include "javastoragenames.h" |
|
22 #include "javastorage.h" |
|
23 #include "javastorageexception.h" |
|
24 #include "javaoslayer.h" |
|
25 #include "javacommonutils.h" |
|
26 #include "javauid.h" |
|
27 #include <memory> |
|
28 |
|
29 using namespace java::security; |
|
30 using namespace std; |
|
31 using namespace java::util; |
|
32 using namespace java::storage; |
|
33 |
|
34 const JavaStorageApplicationEntry_t createEntry(const wstring& aUid, |
|
35 const wstring& aName, |
|
36 const wstring& aValue); |
|
37 |
|
38 const JavaStorageApplicationEntry_t createValidCertsEntry( |
|
39 const wstring& aUid, |
|
40 const wstring& aCerts); |
|
41 |
|
42 TEST_GROUP(TestCertChains) |
|
43 { |
|
44 JavaStorage* js; |
|
45 |
|
46 TEST_SETUP() |
|
47 { |
|
48 js = JavaStorage::createInstance(); |
|
49 } |
|
50 |
|
51 TEST_TEARDOWN() |
|
52 { |
|
53 delete js; |
|
54 js = 0; |
|
55 } |
|
56 }; |
|
57 |
|
58 /** |
|
59 * Test MIDPAuthenticationModule::getCertChains() method. |
|
60 * |
|
61 * 1. Test no data in storage. |
|
62 * 2. Test certs value '1' |
|
63 * 3. Test certs value '1,3' |
|
64 * 4. Test certs value '1,3,4,5' |
|
65 * 5. Test certs value '1,,2'. Empty is ignored. Valid chains returned. |
|
66 * 6. Test certs value '1,A,2'. A is ignored. Valid chains returned. |
|
67 * 7. Test certs value '1,2,3,' |
|
68 * 8. Test certs value ',1,2' |
|
69 * 9. Test certs value '1,2,A'. A is ignored. |
|
70 * 10. Test certs value '1' when chain contains multiple certs. |
|
71 * 11. Test certs value '1,3' when chains contain multiple certs. |
|
72 * 12. Test certs value '1 '. Value is trimmed and chain returned. |
|
73 * 13. Test certs value ' 1'. Value is trimmed and chain returned. |
|
74 * 14. Test certs value '1' but no certs belogning to chain. Empty response. |
|
75 */ |
|
76 TEST(TestCertChains, TestCertChains) |
|
77 { |
|
78 auto_ptr<MIDPAuthenticationModule>authMod( |
|
79 MIDPAuthenticationModule::createInstance()); |
|
80 |
|
81 Uid suite1Uid(L"[e00f4577]"); |
|
82 list<string> chains; |
|
83 |
|
84 JavaStorageEntry attr; |
|
85 JavaStorageApplicationEntry_t entry; |
|
86 JavaStorageApplicationEntry_t certEntry; |
|
87 |
|
88 // 1. Test no data in storage. |
|
89 try |
|
90 { |
|
91 authMod->getCertChains(suite1Uid, chains); |
|
92 CHECK(chains.size() == 0); |
|
93 } |
|
94 catch (JavaStorageException& aJse) |
|
95 { |
|
96 string es = "UnExp1: " + aJse.toString(); |
|
97 FAIL(es.c_str()); |
|
98 } |
|
99 |
|
100 // 2. Test certs value '1' |
|
101 try |
|
102 { |
|
103 chains.clear(); |
|
104 entry.clear(); |
|
105 certEntry.clear(); |
|
106 entry = createValidCertsEntry(suite1Uid.toString(), L"1"); |
|
107 |
|
108 js->open(); |
|
109 js->write(MIDP_PACKAGE_TABLE, entry); |
|
110 |
|
111 certEntry = createEntry(suite1Uid.toString(), |
|
112 L"MIDlet-Certificate-1-1", |
|
113 L"abc123"); |
|
114 |
|
115 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
116 |
|
117 JavaStorageApplicationEntry_t foolEntry; |
|
118 attr.setEntry(ID, suite1Uid.toString()); |
|
119 foolEntry.insert(attr); |
|
120 |
|
121 attr.setEntry(NAME, L"Vendor"); |
|
122 foolEntry.insert(attr); |
|
123 |
|
124 attr.setEntry(VALUE, L"1.0.2"); |
|
125 foolEntry.insert(attr); |
|
126 |
|
127 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, foolEntry); |
|
128 |
|
129 authMod->getCertChains(suite1Uid, chains); |
|
130 CHECK(chains.size() == 1); |
|
131 |
|
132 string refString("abc123"); |
|
133 CHECK(chains.front() == refString); |
|
134 |
|
135 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
136 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
137 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, foolEntry); |
|
138 } |
|
139 catch (JavaStorageException& aJse) |
|
140 { |
|
141 string es = "UnExp2: " + aJse.toString(); |
|
142 FAIL(es.c_str()); |
|
143 } |
|
144 |
|
145 js->close(); |
|
146 |
|
147 // 3. Test certs value '1,3' |
|
148 try |
|
149 { |
|
150 chains.clear(); |
|
151 entry.clear(); |
|
152 certEntry.clear(); |
|
153 |
|
154 entry = createValidCertsEntry(suite1Uid.toString(), L"1,3"); |
|
155 |
|
156 js->open(); |
|
157 js->write(MIDP_PACKAGE_TABLE, entry); |
|
158 |
|
159 certEntry = createEntry(suite1Uid.toString(), |
|
160 L"MIDlet-Certificate-1-1", |
|
161 L"abc123"); |
|
162 |
|
163 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
164 |
|
165 JavaStorageApplicationEntry_t certEntry2; |
|
166 certEntry2 = createEntry(suite1Uid.toString(), |
|
167 L"MIDlet-Certificate-3-1", |
|
168 L"def456"); |
|
169 |
|
170 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
171 |
|
172 authMod->getCertChains(suite1Uid, chains); |
|
173 |
|
174 CHECK(chains.size() == 2); |
|
175 |
|
176 list<string>::const_iterator iter = chains.begin(); |
|
177 |
|
178 string cert1Ref("abc123"); |
|
179 CHECK((*iter++) == cert1Ref); |
|
180 string cert2Ref("def456"); |
|
181 CHECK((*iter) == cert2Ref); |
|
182 |
|
183 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
184 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
185 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
186 } |
|
187 catch (JavaStorageException& aJse) |
|
188 { |
|
189 string es = "UnExp3: " + aJse.toString(); |
|
190 FAIL(es.c_str()); |
|
191 } |
|
192 |
|
193 js->close(); |
|
194 |
|
195 // 4. Test certs value '1,3,4,5' |
|
196 try |
|
197 { |
|
198 chains.clear(); |
|
199 entry.clear(); |
|
200 certEntry.clear(); |
|
201 |
|
202 entry = createValidCertsEntry(suite1Uid.toString(), L"1,3,4,5"); |
|
203 |
|
204 js->open(); |
|
205 js->write(MIDP_PACKAGE_TABLE, entry); |
|
206 |
|
207 certEntry = createEntry(suite1Uid.toString(), |
|
208 L"MIDlet-Certificate-1-1", |
|
209 L"abc123"); |
|
210 |
|
211 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
212 |
|
213 JavaStorageApplicationEntry_t certEntry2; |
|
214 certEntry2 = createEntry(suite1Uid.toString(), |
|
215 L"MIDlet-Certificate-3-1", |
|
216 L"def456"); |
|
217 |
|
218 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
219 |
|
220 JavaStorageApplicationEntry_t certEntry3; |
|
221 certEntry3 = createEntry(suite1Uid.toString(), |
|
222 L"MIDlet-Certificate-4-1", |
|
223 L"fooBar"); |
|
224 |
|
225 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
226 |
|
227 JavaStorageApplicationEntry_t certEntry4; |
|
228 certEntry4 = createEntry(suite1Uid.toString(), |
|
229 L"MIDlet-Certificate-5-1", |
|
230 L"HelloWorld"); |
|
231 |
|
232 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry4); |
|
233 |
|
234 authMod->getCertChains(suite1Uid, chains); |
|
235 |
|
236 CHECK(chains.size() == 4); |
|
237 |
|
238 list<string>::const_iterator iter = chains.begin(); |
|
239 |
|
240 string cert1Ref("abc123"); |
|
241 CHECK((*iter++) == cert1Ref); |
|
242 string cert2Ref("def456"); |
|
243 CHECK((*iter++) == cert2Ref); |
|
244 string cert3Ref("fooBar"); |
|
245 CHECK((*iter++) == cert3Ref); |
|
246 string cert4Ref("HelloWorld"); |
|
247 CHECK((*iter) == cert4Ref); |
|
248 |
|
249 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
250 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
251 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
252 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
253 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry4); |
|
254 } |
|
255 catch (JavaStorageException& aJse) |
|
256 { |
|
257 string es = "UnExp4: " + aJse.toString(); |
|
258 FAIL(es.c_str()); |
|
259 } |
|
260 |
|
261 js->close(); |
|
262 |
|
263 // 5. Test certs value '1,,2' |
|
264 try |
|
265 { |
|
266 chains.clear(); |
|
267 entry.clear(); |
|
268 certEntry.clear(); |
|
269 |
|
270 entry = createValidCertsEntry(suite1Uid.toString(), L"1,,2"); |
|
271 |
|
272 js->open(); |
|
273 js->write(MIDP_PACKAGE_TABLE, entry); |
|
274 |
|
275 certEntry = createEntry(suite1Uid.toString(), |
|
276 L"MIDlet-Certificate-1-1", |
|
277 L"abc123"); |
|
278 |
|
279 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
280 |
|
281 JavaStorageApplicationEntry_t certEntry2; |
|
282 certEntry2 = createEntry(suite1Uid.toString(), |
|
283 L"MIDlet-Certificate-2-1", |
|
284 L"def456"); |
|
285 |
|
286 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
287 |
|
288 authMod->getCertChains(suite1Uid, chains); |
|
289 |
|
290 CHECK(chains.size() == 2); |
|
291 |
|
292 list<string>::const_iterator iter = chains.begin(); |
|
293 |
|
294 string cert1Ref("abc123"); |
|
295 CHECK((*iter++) == cert1Ref); |
|
296 string cert2Ref("def456"); |
|
297 CHECK((*iter) == cert2Ref); |
|
298 |
|
299 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
300 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
301 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
302 } |
|
303 catch (JavaStorageException& aJse) |
|
304 { |
|
305 string es = "UnExp5: " + aJse.toString(); |
|
306 FAIL(es.c_str()); |
|
307 } |
|
308 |
|
309 js->close(); |
|
310 |
|
311 // 6. Test certs value '1,A,2' |
|
312 try |
|
313 { |
|
314 chains.clear(); |
|
315 entry.clear(); |
|
316 certEntry.clear(); |
|
317 |
|
318 entry = createValidCertsEntry(suite1Uid.toString(), L"1,A,2"); |
|
319 |
|
320 js->open(); |
|
321 js->write(MIDP_PACKAGE_TABLE, entry); |
|
322 |
|
323 certEntry = createEntry(suite1Uid.toString(), |
|
324 L"MIDlet-Certificate-1-1", |
|
325 L"abc123"); |
|
326 |
|
327 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
328 |
|
329 JavaStorageApplicationEntry_t certEntry2; |
|
330 certEntry2 = createEntry(suite1Uid.toString(), |
|
331 L"MIDlet-Certificate-2-1", |
|
332 L"def456"); |
|
333 |
|
334 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
335 |
|
336 authMod->getCertChains(suite1Uid, chains); |
|
337 |
|
338 CHECK(chains.size() == 2); |
|
339 |
|
340 list<string>::const_iterator iter = chains.begin(); |
|
341 |
|
342 string cert1Ref("abc123"); |
|
343 CHECK((*iter++) == cert1Ref); |
|
344 string cert2Ref("def456"); |
|
345 CHECK((*iter) == cert2Ref); |
|
346 |
|
347 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
348 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
349 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
350 } |
|
351 catch (JavaStorageException& aJse) |
|
352 { |
|
353 string es = "UnExp6: " + aJse.toString(); |
|
354 FAIL(es.c_str()); |
|
355 } |
|
356 |
|
357 js->close(); |
|
358 |
|
359 // 7. Test certs value '1,2,3,' |
|
360 try |
|
361 { |
|
362 chains.clear(); |
|
363 entry.clear(); |
|
364 certEntry.clear(); |
|
365 |
|
366 entry = createValidCertsEntry(suite1Uid.toString(), L"1,2,3,"); |
|
367 |
|
368 js->open(); |
|
369 js->write(MIDP_PACKAGE_TABLE, entry); |
|
370 |
|
371 certEntry = createEntry(suite1Uid.toString(), |
|
372 L"MIDlet-Certificate-1-1", |
|
373 L"abc123"); |
|
374 |
|
375 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
376 |
|
377 JavaStorageApplicationEntry_t certEntry2; |
|
378 certEntry2 = createEntry(suite1Uid.toString(), |
|
379 L"MIDlet-Certificate-2-1", |
|
380 L"def456"); |
|
381 |
|
382 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
383 |
|
384 JavaStorageApplicationEntry_t certEntry3; |
|
385 certEntry3 = createEntry(suite1Uid.toString(), |
|
386 L"MIDlet-Certificate-3-1", |
|
387 L"fooBar"); |
|
388 |
|
389 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
390 |
|
391 authMod->getCertChains(suite1Uid, chains); |
|
392 |
|
393 CHECK(chains.size() == 3); |
|
394 |
|
395 list<string>::const_iterator iter = chains.begin(); |
|
396 |
|
397 string cert1Ref("abc123"); |
|
398 CHECK((*iter++) == cert1Ref); |
|
399 string cert2Ref("def456"); |
|
400 CHECK((*iter++) == cert2Ref); |
|
401 string cert3Ref("fooBar"); |
|
402 CHECK((*iter) == cert3Ref); |
|
403 |
|
404 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
405 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
406 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
407 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
408 } |
|
409 catch (JavaStorageException& aJse) |
|
410 { |
|
411 string es = "UnExp7: " + aJse.toString(); |
|
412 FAIL(es.c_str()); |
|
413 } |
|
414 |
|
415 js->close(); |
|
416 |
|
417 // 8. Test certs value ',1,2' |
|
418 try |
|
419 { |
|
420 chains.clear(); |
|
421 entry.clear(); |
|
422 certEntry.clear(); |
|
423 |
|
424 entry = createValidCertsEntry(suite1Uid.toString(), L",1,2"); |
|
425 |
|
426 js->open(); |
|
427 js->write(MIDP_PACKAGE_TABLE, entry); |
|
428 |
|
429 certEntry = createEntry(suite1Uid.toString(), |
|
430 L"MIDlet-Certificate-1-1", |
|
431 L"abc123"); |
|
432 |
|
433 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
434 |
|
435 JavaStorageApplicationEntry_t certEntry2; |
|
436 certEntry2 = createEntry(suite1Uid.toString(), |
|
437 L"MIDlet-Certificate-2-1", |
|
438 L"def456"); |
|
439 |
|
440 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
441 |
|
442 authMod->getCertChains(suite1Uid, chains); |
|
443 |
|
444 CHECK(chains.size() == 2); |
|
445 |
|
446 list<string>::const_iterator iter = chains.begin(); |
|
447 |
|
448 string cert1Ref("abc123"); |
|
449 CHECK((*iter++) == cert1Ref); |
|
450 string cert2Ref("def456"); |
|
451 CHECK((*iter) == cert2Ref); |
|
452 |
|
453 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
454 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
455 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
456 } |
|
457 catch (JavaStorageException& aJse) |
|
458 { |
|
459 string es = "UnExp8: " + aJse.toString(); |
|
460 FAIL(es.c_str()); |
|
461 } |
|
462 |
|
463 js->close(); |
|
464 |
|
465 // 9. Test certs value '1,2,A' |
|
466 try |
|
467 { |
|
468 chains.clear(); |
|
469 entry.clear(); |
|
470 certEntry.clear(); |
|
471 |
|
472 entry = createValidCertsEntry(suite1Uid.toString(), L"1,2,A"); |
|
473 |
|
474 js->open(); |
|
475 js->write(MIDP_PACKAGE_TABLE, entry); |
|
476 |
|
477 certEntry = createEntry(suite1Uid.toString(), |
|
478 L"MIDlet-Certificate-1-1", |
|
479 L"abc123"); |
|
480 |
|
481 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
482 |
|
483 JavaStorageApplicationEntry_t certEntry2; |
|
484 certEntry2 = createEntry(suite1Uid.toString(), |
|
485 L"MIDlet-Certificate-2-1", |
|
486 L"def456"); |
|
487 |
|
488 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
489 |
|
490 authMod->getCertChains(suite1Uid, chains); |
|
491 |
|
492 CHECK(chains.size() == 2); |
|
493 |
|
494 list<string>::const_iterator iter = chains.begin(); |
|
495 |
|
496 string cert1Ref("abc123"); |
|
497 CHECK((*iter++) == cert1Ref); |
|
498 string cert2Ref("def456"); |
|
499 CHECK((*iter) == cert2Ref); |
|
500 |
|
501 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
502 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
503 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
504 } |
|
505 catch (JavaStorageException& aJse) |
|
506 { |
|
507 string es = "UnExp9: " + aJse.toString(); |
|
508 FAIL(es.c_str()); |
|
509 } |
|
510 |
|
511 js->close(); |
|
512 |
|
513 // 10. Test certs value '1' when chain contains multiple certs. |
|
514 try |
|
515 { |
|
516 chains.clear(); |
|
517 entry.clear(); |
|
518 certEntry.clear(); |
|
519 entry = createValidCertsEntry(suite1Uid.toString(), L"1"); |
|
520 |
|
521 js->open(); |
|
522 js->write(MIDP_PACKAGE_TABLE, entry); |
|
523 |
|
524 certEntry = createEntry(suite1Uid.toString(), |
|
525 L"MIDlet-Certificate-1-1", |
|
526 L"abc123"); |
|
527 |
|
528 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
529 |
|
530 JavaStorageApplicationEntry_t certEntry2; |
|
531 certEntry2 = createEntry(suite1Uid.toString(), |
|
532 L"MIDlet-Certificate-1-2", |
|
533 L"fib8"); |
|
534 |
|
535 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
536 |
|
537 JavaStorageApplicationEntry_t certEntry3; |
|
538 certEntry3 = createEntry(suite1Uid.toString(), |
|
539 L"MIDlet-Certificate-1-3", |
|
540 L"D"); |
|
541 |
|
542 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
543 |
|
544 authMod->getCertChains(suite1Uid, chains); |
|
545 CHECK(chains.size() == 1); |
|
546 |
|
547 string refString("abc123fib8D"); |
|
548 CHECK(chains.front() == refString); |
|
549 |
|
550 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
551 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
552 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
553 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
554 } |
|
555 catch (JavaStorageException& aJse) |
|
556 { |
|
557 string es = "UnExp10: " + aJse.toString(); |
|
558 FAIL(es.c_str()); |
|
559 } |
|
560 |
|
561 js->close(); |
|
562 |
|
563 // 11. Test certs value '1,3' when chains contain multiple certs. |
|
564 try |
|
565 { |
|
566 chains.clear(); |
|
567 entry.clear(); |
|
568 certEntry.clear(); |
|
569 entry = createValidCertsEntry(suite1Uid.toString(), L"1,3"); |
|
570 |
|
571 js->open(); |
|
572 js->write(MIDP_PACKAGE_TABLE, entry); |
|
573 |
|
574 certEntry = createEntry(suite1Uid.toString(), |
|
575 L"MIDlet-Certificate-1-1", |
|
576 L"See"); |
|
577 |
|
578 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
579 |
|
580 JavaStorageApplicationEntry_t certEntry2; |
|
581 certEntry2 = createEntry(suite1Uid.toString(), |
|
582 L"MIDlet-Certificate-1-2", |
|
583 L"No"); |
|
584 |
|
585 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
586 |
|
587 JavaStorageApplicationEntry_t certEntry3; |
|
588 certEntry3 = createEntry(suite1Uid.toString(), |
|
589 L"MIDlet-Certificate-1-3", |
|
590 L"More"); |
|
591 |
|
592 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
593 |
|
594 JavaStorageApplicationEntry_t certEntry4; |
|
595 |
|
596 certEntry4 = createEntry(suite1Uid.toString(), |
|
597 L"MIDlet-Certificate-3-1", |
|
598 L"Me"); |
|
599 |
|
600 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry4); |
|
601 |
|
602 JavaStorageApplicationEntry_t certEntry5; |
|
603 certEntry5 = createEntry(suite1Uid.toString(), |
|
604 L"MIDlet-Certificate-3-2", |
|
605 L"And"); |
|
606 |
|
607 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry5); |
|
608 |
|
609 JavaStorageApplicationEntry_t certEntry6; |
|
610 certEntry6 = createEntry(suite1Uid.toString(), |
|
611 L"MIDlet-Certificate-3-3", |
|
612 L"My"); |
|
613 |
|
614 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry6); |
|
615 |
|
616 authMod->getCertChains(suite1Uid, chains); |
|
617 |
|
618 CHECK(chains.size() == 2); |
|
619 |
|
620 list<string>::const_iterator iter = chains.begin(); |
|
621 |
|
622 string cert1Ref("SeeNoMore"); |
|
623 CHECK((*iter++) == cert1Ref); |
|
624 string cert2Ref("MeAndMy"); |
|
625 CHECK((*iter) == cert2Ref); |
|
626 |
|
627 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
628 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
629 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
630 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
631 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry4); |
|
632 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry5); |
|
633 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry6); |
|
634 } |
|
635 catch (JavaStorageException& aJse) |
|
636 { |
|
637 string es = "UnExp11: " + aJse.toString(); |
|
638 FAIL(es.c_str()); |
|
639 } |
|
640 |
|
641 js->close(); |
|
642 |
|
643 // 12. Test certs value '1 ' |
|
644 try |
|
645 { |
|
646 chains.clear(); |
|
647 entry.clear(); |
|
648 certEntry.clear(); |
|
649 entry = createValidCertsEntry(suite1Uid.toString(), L"1 "); |
|
650 |
|
651 js->open(); |
|
652 js->write(MIDP_PACKAGE_TABLE, entry); |
|
653 |
|
654 certEntry = createEntry(suite1Uid.toString(), |
|
655 L"MIDlet-Certificate-1-1", |
|
656 L"abc123"); |
|
657 |
|
658 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
659 |
|
660 JavaStorageApplicationEntry_t foolEntry; |
|
661 attr.setEntry(ID, suite1Uid.toString()); |
|
662 foolEntry.insert(attr); |
|
663 |
|
664 attr.setEntry(NAME, L"Vendor"); |
|
665 foolEntry.insert(attr); |
|
666 |
|
667 attr.setEntry(VALUE, L"1.0.2"); |
|
668 foolEntry.insert(attr); |
|
669 |
|
670 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, foolEntry); |
|
671 |
|
672 authMod->getCertChains(suite1Uid, chains); |
|
673 CHECK(chains.size() == 1); |
|
674 |
|
675 string refString("abc123"); |
|
676 CHECK(chains.front() == refString); |
|
677 |
|
678 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
679 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
680 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, foolEntry); |
|
681 } |
|
682 catch (JavaStorageException& aJse) |
|
683 { |
|
684 string es = "UnExp2: " + aJse.toString(); |
|
685 FAIL(es.c_str()); |
|
686 } |
|
687 |
|
688 // 13. Test certs value ' 1' |
|
689 try |
|
690 { |
|
691 chains.clear(); |
|
692 entry.clear(); |
|
693 certEntry.clear(); |
|
694 entry = createValidCertsEntry(suite1Uid.toString(), L" 1"); |
|
695 |
|
696 js->open(); |
|
697 js->write(MIDP_PACKAGE_TABLE, entry); |
|
698 |
|
699 certEntry = createEntry(suite1Uid.toString(), |
|
700 L"MIDlet-Certificate-1-1", |
|
701 L"abc123"); |
|
702 |
|
703 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
704 |
|
705 JavaStorageApplicationEntry_t foolEntry; |
|
706 attr.setEntry(ID, suite1Uid.toString()); |
|
707 foolEntry.insert(attr); |
|
708 |
|
709 attr.setEntry(NAME, L"Vendor"); |
|
710 foolEntry.insert(attr); |
|
711 |
|
712 attr.setEntry(VALUE, L"1.0.2"); |
|
713 foolEntry.insert(attr); |
|
714 |
|
715 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, foolEntry); |
|
716 |
|
717 authMod->getCertChains(suite1Uid, chains); |
|
718 CHECK(chains.size() == 1); |
|
719 |
|
720 string refString("abc123"); |
|
721 CHECK(chains.front() == refString); |
|
722 |
|
723 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
724 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
725 js->remove(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, foolEntry); |
|
726 } |
|
727 catch (JavaStorageException& aJse) |
|
728 { |
|
729 string es = "UnExp13: " + aJse.toString(); |
|
730 FAIL(es.c_str()); |
|
731 } |
|
732 |
|
733 js->close(); |
|
734 |
|
735 // 14. Test certs value '1' but no certs belogning to chain. |
|
736 try |
|
737 { |
|
738 chains.clear(); |
|
739 entry.clear(); |
|
740 certEntry.clear(); |
|
741 entry = createValidCertsEntry(suite1Uid.toString(), L"1"); |
|
742 |
|
743 js->open(); |
|
744 js->write(MIDP_PACKAGE_TABLE, entry); |
|
745 |
|
746 authMod->getCertChains(suite1Uid, chains); |
|
747 CHECK(chains.size() == 0); |
|
748 |
|
749 js->remove(MIDP_PACKAGE_TABLE, entry); |
|
750 } |
|
751 catch (JavaStorageException& aJse) |
|
752 { |
|
753 string es = "UnExp14: " + aJse.toString(); |
|
754 FAIL(es.c_str()); |
|
755 } |
|
756 |
|
757 js->close(); |
|
758 } |
|
759 |
|
760 const JavaStorageApplicationEntry_t createEntry(const wstring& aUid, |
|
761 const wstring& aName, |
|
762 const wstring& aValue) |
|
763 { |
|
764 JavaStorageApplicationEntry_t entry; |
|
765 JavaStorageEntry attr; |
|
766 |
|
767 attr.setEntry(ID, aUid); |
|
768 entry.insert(attr); |
|
769 |
|
770 attr.setEntry(NAME, aName); |
|
771 entry.insert(attr); |
|
772 |
|
773 attr.setEntry(VALUE, aValue); |
|
774 entry.insert(attr); |
|
775 |
|
776 return entry; |
|
777 } |
|
778 |
|
779 const JavaStorageApplicationEntry_t createValidCertsEntry(const wstring& aUid, |
|
780 const wstring& aCerts) |
|
781 { |
|
782 JavaStorageApplicationEntry_t entry; |
|
783 JavaStorageEntry attr; |
|
784 |
|
785 attr.setEntry(ID, aUid); |
|
786 entry.insert(attr); |
|
787 |
|
788 attr.setEntry(VALID_CERTS, aCerts); |
|
789 entry.insert(attr); |
|
790 |
|
791 return entry; |
|
792 } |