|
1 # |
|
2 # Copyright (c) 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 # Perl script that test SignSIS tools |
|
18 use File::Basename; |
|
19 my $scriptdir= dirname $0; |
|
20 print "Changing dir to $scriptdir\n"; |
|
21 chdir $scriptdir; |
|
22 |
|
23 $logFile = "/epoc32/winscw/c/signsis_test.txt"; |
|
24 |
|
25 |
|
26 # |
|
27 # Function to create a file (test.txt or any PKG) |
|
28 # |
|
29 sub CreateFile { |
|
30 my ($filename, $contents) = @_; |
|
31 |
|
32 unless (open($fh, "> $filename")) { |
|
33 printf STDERR "Can't open $filename: $!\n"; |
|
34 return; |
|
35 } |
|
36 print $fh $contents; |
|
37 close $fh; |
|
38 |
|
39 |
|
40 } |
|
41 |
|
42 # |
|
43 #Function to write log into file |
|
44 # |
|
45 sub WriteLog |
|
46 { |
|
47 my ($log) = @_; |
|
48 unless( open($fh, ">> $logFile")) |
|
49 { |
|
50 printf STDERR "Can\'t open $logfile:$!\n"; |
|
51 return; |
|
52 } |
|
53 printf $fh $log; |
|
54 printf $log; |
|
55 close $fh; |
|
56 } |
|
57 |
|
58 # |
|
59 # Run SIGNSIS with prepared sis file, log and administrate its result |
|
60 # |
|
61 sub SignSISFile |
|
62 { |
|
63 my ($sisfile) = @_[0]; |
|
64 my ($expectedResult) = @_[1]; |
|
65 $sisfile =~ s/\.sis//; |
|
66 $neededfolder=""; |
|
67 $neededfile=""; |
|
68 $emptylinecertsisfile="./data/emptylinescert.signed.sis"; |
|
69 if("$sisfile.signed.sis" eq $emptylinecertsisfile) |
|
70 { |
|
71 @retval = system("/epoc32/tools/signsis -o -p $sisfile.signed.sis > $sisfile.log"); |
|
72 $logMsg = sprintf "Expected code:%5d result Code:%5d\n", $expectedResult, $?; |
|
73 WriteLog( $logMsg); |
|
74 if ( $^O =~ /^MSWIN32$/i ) |
|
75 { |
|
76 $result = `findstr /C:"Issuer" $sisfile.log`; |
|
77 } |
|
78 else |
|
79 { |
|
80 $result = system(`grep "Issuer" $sisfile.log`) ; |
|
81 } |
|
82 } |
|
83 else |
|
84 { |
|
85 @retval = system("/epoc32/tools/signsis -o $sisfile.sis > $sisfile.log"); |
|
86 $logMsg = sprintf "Expected code:%5d result Code:%5d\n", $expectedResult, $?; |
|
87 WriteLog( $logMsg); |
|
88 if ( $^O =~ /^MSWIN32$/i ) |
|
89 { |
|
90 $result = `findstr /C:"Issued by" $sisfile.log `; |
|
91 } |
|
92 else |
|
93 { |
|
94 $result = system(`grep "Issued by" $sisfile.log`); |
|
95 } |
|
96 @retval = system("/epoc32/tools/signsis -o -p $sisfile.sis > $sisfile.log"); |
|
97 } |
|
98 |
|
99 $neededfolder="Chain"; |
|
100 $neededfile .= "$neededfolder"."/". "cert1.pem"; |
|
101 $NumberOfTests++; |
|
102 if( $? == $expectedResult && -e $neededfile && -s $neededfile && length($result)>0 ) |
|
103 { |
|
104 if("$sisfile.signed.sis" eq $emptylinecertsisfile) |
|
105 { |
|
106 my $res=`diff "./data/emptylinescertandkey.out" "$sisfile.log"`; |
|
107 if(length($res) == 0) |
|
108 { |
|
109 $NumberOfPassed++; |
|
110 WriteLog("Signing successful\n\n"); |
|
111 WriteLog("Passed\n\n"); |
|
112 } |
|
113 else |
|
114 { |
|
115 $NumberOfFailed++; |
|
116 WriteLog("Failed\n\n"); |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 $NumberOfPassed++; |
|
122 WriteLog("Passed\n\n"); |
|
123 } |
|
124 } |
|
125 elsif($? == $expectedResult) |
|
126 { |
|
127 if("$sisfile.sis" eq "simple.sis" ||"$sisfile.sis" eq "test04.sis") |
|
128 { |
|
129 if ( $^O =~ /^MSWIN32$/i ) |
|
130 { |
|
131 $result = `findstr /C:"No primary signatures" $sisfile.log `; |
|
132 } |
|
133 else |
|
134 { |
|
135 $result = system(`grep "No primary signatures" $sisfile.log`); |
|
136 } |
|
137 if(length($result)>0) |
|
138 { |
|
139 $NumberOfPassed++; |
|
140 WriteLog("Passed\n\n"); |
|
141 } |
|
142 else |
|
143 { |
|
144 $NumberOfFailed++; |
|
145 WriteLog("Failed\n\n"); |
|
146 } |
|
147 } |
|
148 else |
|
149 { |
|
150 $NumberOfPassed++; |
|
151 WriteLog("Passed\n\n"); |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 $NumberOfFailed++; |
|
157 WriteLog("Failed\n\n"); |
|
158 } |
|
159 |
|
160 unlink("$sisfile.log"); |
|
161 unlink("$sisfile.signed.sis"); |
|
162 opendir(DIR, $neededfolder); |
|
163 while (defined($file=readdir(DIR))) |
|
164 { |
|
165 unlink("$neededfolder"."/"."$file"); |
|
166 } |
|
167 close(DIR); |
|
168 } |
|
169 |
|
170 # |
|
171 # New test code for DEF093156 - SIGNSIS does not process correctly non European symbols in cmd line |
|
172 # This test checks whether the pkg file with japanese symbols is signed by signsis successfully . |
|
173 # |
|
174 sub TestDEF093156 { |
|
175 |
|
176 my $path = "\\epoc32\\winscw\\c\\tswi\\tsignsis"; |
|
177 $DEF093156Log = "DEF093156.log"; |
|
178 $ResFile="ResultSignSIS.txt"; |
|
179 |
|
180 WriteLog("Test for DEF093156 - Test for successful creation of a signed sis file with japanese symbols created by signsis.\n"); |
|
181 |
|
182 # sign a pkg with japanese symbols using a certificate and a file with japanese sym,bols |
|
183 system("WScript.exe //B //Nologo $path\\testsignsis.vbs > $DEF093156Log"); |
|
184 |
|
185 $NumberOfTests++; |
|
186 if ( -f $ResFile ) |
|
187 { |
|
188 $NumberOfPassed++; |
|
189 WriteLog("Passed\n\n"); |
|
190 } |
|
191 else |
|
192 { |
|
193 $NumberOfFailed++; |
|
194 WriteLog("Failed\n\n"); |
|
195 } |
|
196 |
|
197 unlink $DEF093156Log; |
|
198 unlink $ResFile; |
|
199 } |
|
200 |
|
201 |
|
202 # |
|
203 # New test code for DEF093156 - SIGNSIS does not process correctly non European symbols in cmd line |
|
204 # This test checks whether the pkg file with japanese symbols is signed by signsis successfully . |
|
205 # |
|
206 sub TestLDEF093156 { |
|
207 |
|
208 $DEF093156Log = "DEF093156.log"; |
|
209 $ResFile="ResultSignSIS.txt"; |
|
210 $SignedSISFile = "pkg_乕乖乗乘_kanji_signed.SIS"; |
|
211 |
|
212 # Data to write in the created file for Linux test |
|
213 $TempData = "Exist"; |
|
214 |
|
215 system("cp -f pkg_kanji.SIS pkg_乕乖乗乘_kanji.SIS"); |
|
216 system("cp -f kanji_key.key 丟両丣kanji_key.key"); |
|
217 system("cp -f kanji_cer.cer 丁丂七丄kanji_cer.cer"); |
|
218 |
|
219 system("/epoc32/tools/signsis -v -s pkg_乕乖乗乘_kanji.SIS pkg_乕乖乗乘_kanji_signed.SIS 丁丂七丄kanji_cer.cer 丟両丣kanji_key.key 乕乖乗乘pass > DEF093156Log"); |
|
220 |
|
221 WriteLog("Test for DEF093156 - Test for successful creation of a signed sis file with japanese symbols created by signsis.\n"); |
|
222 |
|
223 if( -f $SignedSISFile){ |
|
224 CreateFile($ResFile, $TempData); |
|
225 } |
|
226 |
|
227 $NumberOfTests++; |
|
228 |
|
229 if ( -f $ResFile ) { |
|
230 $NumberOfPassed++; |
|
231 WriteLog("Passed\n\n"); |
|
232 } |
|
233 else { |
|
234 $NumberOfFailed++; |
|
235 WriteLog("Failed\n\n"); |
|
236 } |
|
237 |
|
238 unlink $DEF093156Log; |
|
239 unlink $ResFile; |
|
240 } |
|
241 |
|
242 # |
|
243 # Test code for DEF111563 - SignSIS fails if an embedded package has a dependency. |
|
244 # This test checks whether an embedding pkg (whose embedded pkg has a dependency ) is signed by signsis successfully. |
|
245 # |
|
246 |
|
247 sub TestDEF111563 { |
|
248 |
|
249 $pkgEmbeddedFile = "Emdedded.pkg"; |
|
250 $sisEmbeddedFile = "Embedded.sis"; |
|
251 $pkgFile = "Emdedding.pkg"; |
|
252 $sisFile = "Embedding.sis"; |
|
253 $DEF111563LogFile = "DEF111563.log"; |
|
254 |
|
255 WriteLog("DEF111563 - Test for successful creation of signed sis file for package whose embedded pkg has dependency.\n"); |
|
256 |
|
257 # Generate test PKG file contents for embedded pkg file. |
|
258 $PkgFile = sprintf( $EmbeddedpkgFile, "-1,-1,-1"); |
|
259 |
|
260 # Create PKG file |
|
261 CreateFile($pkgEmbeddedFile , $PkgFile); |
|
262 |
|
263 # Create a sis file |
|
264 my $result = system("/epoc32/tools/makesis $pkgEmbeddedFile $sisEmbeddedFile > $DEF111563LogFile"); |
|
265 |
|
266 # Sign the embedded sis file with dependency using SignSIS. |
|
267 my $result1 = system("/epoc32/tools/signsis -s $sisEmbeddedFile $sisEmbeddedFile ./signingdata/good-r5.pem ./signingdata/good-r5.key.pem > $DEF111563LogFile"); |
|
268 |
|
269 # Generate test PKG file contents for embedding pkg file. |
|
270 $PkgFile = sprintf( $EmbeddingpkgFile, "-1,-1,-1"); |
|
271 |
|
272 # Create PKG file |
|
273 CreateFile($pkgFile , $PkgFile); |
|
274 |
|
275 # Create a sis file |
|
276 my $result2 = system("/epoc32/tools/makesis $pkgFile $sisFile > $DEF111563LogFile"); |
|
277 |
|
278 # Sign the embedding sis file using SignSIS. |
|
279 my $result3 = system("/epoc32/tools/signsis -s $sisFile $sisFile ./signingdata/good-r5.pem ./signingdata/good-r5.key.pem > $DEF111563LogFile"); |
|
280 |
|
281 |
|
282 $NumberOfTests++; |
|
283 |
|
284 if ($result == 0 && $result1 == 0 && $result2 == 0 && $result3 == 0 ) |
|
285 { |
|
286 $NumberOfPassed++; |
|
287 WriteLog("Passed\n\n"); |
|
288 } |
|
289 else |
|
290 { |
|
291 $NumberOfFailed++; |
|
292 WriteLog("Failed\n\n"); |
|
293 } |
|
294 |
|
295 unlink $pkgEmbeddedFile; |
|
296 unlink $sisEmbeddedFile; |
|
297 unlink $pkgFile; |
|
298 unlink $sisFile; |
|
299 unlink $DEF111563LogFile; |
|
300 } |
|
301 |
|
302 # |
|
303 # Test code for DEF138538 - Signsis crashes when displaying signing info for SIS files. |
|
304 # This test checks tat Singnsis displays the signing information for SIS files correctly |
|
305 # and doesn't fail if the subject name of the signing certificate is in the UTF8 format. |
|
306 # |
|
307 |
|
308 sub TestDEF138538 { |
|
309 |
|
310 $sisFileName = "\\epoc32\\winscw\\c\\tswi\\tsignsis\\data\\CertWithUnicodeSubjectLine.SIS"; |
|
311 $DEF138538LogFile = "DEF138538.log"; |
|
312 |
|
313 WriteLog("DEF138538 - Test if Singnsis displays the signing information for SIS file correctly.\n"); |
|
314 |
|
315 # Create a sis file |
|
316 my $result1 = system("/epoc32/tools/signsis.exe -p -o $sisFileName > $DEF138538LogFile"); |
|
317 |
|
318 my $result2 = 0; |
|
319 $result2 = `findstr /C:"Issuer: CN=Nokia Online CA, O=Nokia" $DEF138538LogFile`; |
|
320 |
|
321 $NumberOfTests++; |
|
322 |
|
323 if (($result1 == 0) && $result2) |
|
324 { |
|
325 $NumberOfPassed++; |
|
326 WriteLog("Passed\n\n"); |
|
327 } |
|
328 else |
|
329 { |
|
330 $NumberOfFailed++; |
|
331 WriteLog("Failed\n\n"); |
|
332 } |
|
333 |
|
334 unlink $DEF138538LogFile; |
|
335 } |
|
336 |
|
337 # |
|
338 # Package template string to generate an embedded PKG file having a dependency. |
|
339 # |
|
340 $EmbeddedpkgFile = " |
|
341 ; |
|
342 ; Autogenerated test install file |
|
343 ; |
|
344 &EN |
|
345 ; |
|
346 #{\"Test Embedded\"}, (0x01001235), 1, 1, 1, TYPE=SA |
|
347 ; |
|
348 %{\"Symbian Software Ltd\"} |
|
349 :\"Symbian Software Ltd\" |
|
350 ; |
|
351 ;Installation name and header data |
|
352 (0x101f74a0),%s,{\"Test Embedded\"} |
|
353 ; |
|
354 (0x01001225), *, *, *, {\"embedded2\"} |
|
355 ; |
|
356 "; |
|
357 |
|
358 # |
|
359 # Package template string to generate an embedding PKG file whose embedded pkg has a dependency. |
|
360 # |
|
361 $EmbeddingpkgFile = " |
|
362 ; |
|
363 ; Autogenerated test install file |
|
364 ; |
|
365 &EN |
|
366 ; |
|
367 #{\"Test Application SA1\"}, (0x01001234), 1, 0, 1, TYPE=SA |
|
368 ; |
|
369 %{\"Symbian Software Ltd\"} |
|
370 :\"Symbian Software Ltd\" |
|
371 ; |
|
372 ;Installation name and header data |
|
373 (0x01001234),%s,{\"Test Application SA1\"} |
|
374 ; |
|
375 (0x01001235), *, *, *, {\"embedded\"} |
|
376 ; |
|
377 \@\"embedded.sis\" , (0x01001235) |
|
378 ; |
|
379 "; |
|
380 |
|
381 # |
|
382 # Main |
|
383 # |
|
384 # Create environment and control test flow to testing SIGNSIS.EXE |
|
385 # |
|
386 # |
|
387 |
|
388 unlink($logFile); |
|
389 WriteLog("SIGNSIS test.\n\n"); |
|
390 |
|
391 # |
|
392 # Counters for results |
|
393 # |
|
394 $NumberOfTests = 0; |
|
395 $NumberOfPassed = 0; |
|
396 $NumberOfFailed = 0; |
|
397 |
|
398 # |
|
399 # Windows "FindStr" only understand "\" for path to read the log file |
|
400 # |
|
401 if ( $^O =~ /^MSWIN32$/i ) |
|
402 { |
|
403 |
|
404 # |
|
405 # Array of contents of test sis file and expected results |
|
406 # |
|
407 # file name, expected , expected log, Title |
|
408 # result message |
|
409 # ---------------------------------------------------------------------------------------------------- |
|
410 @TestItems = ( ["simple.signed.sis", 0, , "Created", "Test for normal Signed sis file"], |
|
411 ["simple.sis", 0, , "Created", "Test for Unsigned sis file"], |
|
412 ["data\\signedctltest.sis", 0, , "Created", "Test for Stub sis controller file"], |
|
413 ["data\\pkgromctltest.sis", 0, , "Created", "Test for Stub sis controller for package file in ROM"], |
|
414 ["data\\nonsisfile.sis", 256, , "Verification Failed", "Test for Non sis or non Stub sis controller file"], |
|
415 ["data\\corrupted.sis", 256, , "Verification Failed", "Corrupted sis file"], |
|
416 ["data\\eshell_hybrid.sis", 256, , "Verification Failed", "Stored and computed hash values do not match"], |
|
417 ["data\\emptylinescert.sis", 0, , "Created", "Test for successful signing when certificate(.cer) and key has few empty lines."], |
|
418 ); |
|
419 |
|
420 } |
|
421 |
|
422 # Linux tests : |
|
423 |
|
424 else |
|
425 |
|
426 { |
|
427 |
|
428 # |
|
429 # Array of contents of test sis file and expected results |
|
430 # |
|
431 # file name, expected , expected log, Title |
|
432 # result message |
|
433 # ---------------------------------------------------------------------------------------------------- |
|
434 @TestItems = ( ["simple.signed.sis", 0, , "Created", "Test for normal Signed sis file"], |
|
435 ["simple.sis", 0, , "Created", "Test for Unsigned sis file"], |
|
436 ["data/signedctltest.sis", 0, , "Created", "Test for Stub sis controller file"], |
|
437 ["data/pkgromctltest.sis", 0, , "Created", "Test for Stub sis controller for package file in ROM"], |
|
438 ["data/nonsisfile.sis", 256, , "Verification Failed", "Test for Non sis or non Stub sis controller file"], |
|
439 ["data/corrupted.sis", 256, , "Verification Failed", "Corrupted sis file"], |
|
440 ["data/eshell_hybrid.sis", 256, , "Verification Failed", "Stored and computed hash values do not match"], |
|
441 ["data/emptylinescert.sis", 0, , "Created", "Test for successful signing when certificate(.cer) and key has few empty lines."], |
|
442 ); |
|
443 |
|
444 |
|
445 } |
|
446 |
|
447 # |
|
448 # Do test for each elements of TestItems array |
|
449 # |
|
450 $datapath = "data/"; |
|
451 opendir(DIR,"./data/"); |
|
452 my @pkgfiles = readdir DIR; |
|
453 foreach my $files (@pkgfiles) |
|
454 { |
|
455 $files =~ s/\.pkg//; |
|
456 |
|
457 $pkgfilepath = "$datapath"."$files"; |
|
458 $pkgfile = "./data/emptylinescert.sis"; |
|
459 if(-e "$pkgfilepath.pkg") |
|
460 { |
|
461 @retval = system("makesis -v $pkgfilepath.pkg $files.sis > $files.log"); |
|
462 if( $? != 0) |
|
463 { |
|
464 WriteLog("\n\nProblem While Creating makesis for $files.pkg\n"); |
|
465 } |
|
466 else |
|
467 { |
|
468 WriteLog("\n\nCreated $files.sis file from $files.pkg\n"); |
|
469 WriteLog("\n\nSigning $files.sis using certificate\n\n"); |
|
470 @retval = system("/epoc32/tools/signsis -s $pkgfilepath.sis $files.signed.sis ./signingdata/good-r5.pem ./signingdata/good-r5.key.pem"); |
|
471 if( $? != 0) |
|
472 { |
|
473 WriteLog("\n\nProblem While signing $files.sis\n"); |
|
474 } |
|
475 } |
|
476 } |
|
477 |
|
478 if($pkgfilepath eq $pkgfile) |
|
479 { |
|
480 $files =~ s/\.sis//; |
|
481 $signedsispath = "data\\" . $files; |
|
482 @retval = system("/epoc32/tools/signsis -s $pkgfilepath $signedsispath.signed.sis ./signingdata/emptylinescert.pem ./signingdata/emptylinescert.key.pem"); |
|
483 } |
|
484 } |
|
485 |
|
486 for my $Test ( @TestItems ) |
|
487 { |
|
488 # Do SIGNSIS test |
|
489 $testid = sprintf "SEC-SWI-I-SIGNSIS-000%d\n",$NumberOfTests+1; |
|
490 WriteLog($testid); |
|
491 $logMsg = sprintf "%s", $Test->[3]; |
|
492 WriteLog($logMsg); |
|
493 WriteLog("\t$Test->[0]\n"); |
|
494 SignSISFile($Test->[0], $Test->[1]); |
|
495 } |
|
496 |
|
497 opendir(DIR, "."); |
|
498 while (defined($file=readdir(DIR))) |
|
499 { |
|
500 $file =~ s/\.sis//; |
|
501 if(-e "$file.sis") |
|
502 { |
|
503 unlink("$file.sis"); |
|
504 unlink("$file.log"); |
|
505 } |
|
506 rmdir("chain"); |
|
507 } |
|
508 close(DIR); |
|
509 |
|
510 |
|
511 # |
|
512 # Test for DEF093156. |
|
513 # |
|
514 if ($^O =~ /^MSWIN32$/i) |
|
515 { |
|
516 TestDEF093156(); |
|
517 } |
|
518 if ($^O =~ /^LINUX$/i) |
|
519 { |
|
520 TestLDEF093156(); |
|
521 } |
|
522 |
|
523 # |
|
524 # Test for DEF111563. |
|
525 # |
|
526 TestDEF111563(); |
|
527 |
|
528 |
|
529 # |
|
530 # Test for DEF138538 . |
|
531 # |
|
532 TestDEF138538 (); |
|
533 |
|
534 |
|
535 # |
|
536 # Display the result |
|
537 # |
|
538 WriteLog("\n\nTests completed OK\n"); |
|
539 WriteLog(sprintf "Run: %d\n", $NumberOfTests ); |
|
540 WriteLog(sprintf "Passed: %d\n", $NumberOfPassed ); |
|
541 WriteLog(sprintf "%d tests failed out of %d\n", $NumberOfFailed, $NumberOfTests ); |