|
1 /* |
|
2 * Copyright (c) 2004-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 * Note: This file may contain code to generate corrupt files for test purposes. |
|
16 * Such code is excluded from production builds by use of compiler defines; |
|
17 * it is recommended that such code should be removed if this code is ever published publicly. |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalComponent |
|
25 @released |
|
26 */ |
|
27 |
|
28 #include "parameter.h" |
|
29 #include "openssllicense.h" |
|
30 #include "utility.h" |
|
31 #include <string.h> |
|
32 |
|
33 |
|
34 #include <iostream> |
|
35 |
|
36 CParameter::CParameter () : |
|
37 iSign (false), |
|
38 iUnsign (false), |
|
39 iReport (false), |
|
40 iVerbose (false), |
|
41 iDump (false), |
|
42 iAlgorithm (CSISSignatureAlgorithm::EAlgNone) |
|
43 { |
|
44 } |
|
45 |
|
46 |
|
47 |
|
48 bool CParameter::CommandLine (int argc, _TCHAR* argv[]) |
|
49 |
|
50 { |
|
51 bool help = argc == 1; |
|
52 bool ssl = false; |
|
53 unsigned char stage = 0; |
|
54 bool bien = argc > 1; |
|
55 bool multi = false; |
|
56 |
|
57 iSign = true; |
|
58 |
|
59 for (int index = 1; index < argc; index++) |
|
60 { |
|
61 if ( (argv [index][0] == '-') || |
|
62 (argv [index][0] == '/')) |
|
63 { |
|
64 // cope with multiple arguments following the '-' or '/' |
|
65 int wCharacter = 1; |
|
66 while (argv[index][wCharacter] !='\0') |
|
67 { |
|
68 switch (argv [index][wCharacter]) |
|
69 { |
|
70 case 'a' : |
|
71 case 'A' : |
|
72 #ifdef _DEBUG |
|
73 iDump = true; |
|
74 #endif |
|
75 break; |
|
76 #ifdef GENERATE_ERRORS |
|
77 case 'b' : |
|
78 case 'B' : |
|
79 { |
|
80 for (int offset = wCharacter+1; argv [index] [offset]; offset++) |
|
81 { |
|
82 switch(argv [index] [offset]) |
|
83 { |
|
84 case 'a' : |
|
85 case 'A' : |
|
86 CSISFieldRoot::SetBug (CSISFieldRoot::EBugArrayCount); |
|
87 break; |
|
88 case 'b' : |
|
89 case 'B' : |
|
90 CSISFieldRoot::SetBug (CSISFieldRoot::EBugInsaneBlob); |
|
91 break; |
|
92 case 'c' : |
|
93 case 'C' : |
|
94 CSISFieldRoot::SetBug (CSISFieldRoot::EBugCRCError); |
|
95 break; |
|
96 case 'e' : |
|
97 case 'E' : |
|
98 CSISFieldRoot::SetBug (CSISFieldRoot::EBugBigEndian); |
|
99 break; |
|
100 |
|
101 case 'f' : |
|
102 case 'F' : |
|
103 CSISFieldRoot::SetBug (CSISFieldRoot::EBugDuffFieldType); |
|
104 break; |
|
105 case 'h' : |
|
106 case 'H' : |
|
107 CSISFieldRoot::SetBug (CSISFieldRoot::EBugHashError); |
|
108 break; |
|
109 case 'l' : |
|
110 case 'L' : |
|
111 CSISFieldRoot::SetBug (CSISFieldRoot::EBugInvalidLength); |
|
112 break; |
|
113 case 'm' : |
|
114 case 'M' : |
|
115 CSISFieldRoot::SetBug (CSISFieldRoot::EBugMissingField); |
|
116 break; |
|
117 case 'n' : |
|
118 case 'N' : |
|
119 CSISFieldRoot::SetBug (CSISFieldRoot::EBugNegativeLength); |
|
120 break; |
|
121 case 's' : |
|
122 case 'S' : |
|
123 CSISFieldRoot::SetBug (CSISFieldRoot::EBugInsaneString); |
|
124 break; |
|
125 case 't' : |
|
126 case 'T' : |
|
127 CSISFieldRoot::SetBug (CSISFieldRoot::EBug32As64); |
|
128 break; |
|
129 case 'u' : |
|
130 case 'U' : |
|
131 CSISFieldRoot::SetBug (CSISFieldRoot::EBugUnexpectedField); |
|
132 break; |
|
133 case 'v' : |
|
134 case 'V' : |
|
135 CSISFieldRoot::SetBug (CSISFieldRoot::EBugInvalidValues); |
|
136 break; |
|
137 case 'x' : |
|
138 case 'X' : |
|
139 CSISFieldRoot::SetBug (CSISFieldRoot::EBugUnknownField); |
|
140 break; |
|
141 } |
|
142 wCharacter++; |
|
143 } |
|
144 } |
|
145 break; |
|
146 #endif // GENERATE_ERRORS |
|
147 case 'c' : |
|
148 case 'C' : |
|
149 { |
|
150 switch (argv [index][wCharacter+1]) |
|
151 { |
|
152 case 'd' : |
|
153 case 'D' : |
|
154 if (iAlgorithm != CSISSignatureAlgorithm::EAlgNone) |
|
155 { |
|
156 multi = true; |
|
157 break; |
|
158 } |
|
159 iAlgorithm = CSISSignatureAlgorithm::EAlgDSA; |
|
160 break; |
|
161 case 'r' : |
|
162 case 'R' : |
|
163 if (iAlgorithm != CSISSignatureAlgorithm::EAlgNone) |
|
164 { |
|
165 multi = true; |
|
166 break; |
|
167 } |
|
168 iAlgorithm = CSISSignatureAlgorithm::EAlgRSA; |
|
169 break; |
|
170 } |
|
171 wCharacter++; |
|
172 } |
|
173 break; |
|
174 case 'h' : |
|
175 case 'H' : |
|
176 case '?' : |
|
177 help = true; |
|
178 break; |
|
179 case 'i' : |
|
180 case 'I' : |
|
181 ssl = true; |
|
182 break; |
|
183 case 'o' : |
|
184 case 'O' : |
|
185 iReport = true; |
|
186 iSign = false; |
|
187 break; |
|
188 //EC023 additional prarameter added to extract the certificate |
|
189 case 'p' : |
|
190 case 'P' : |
|
191 iExtractCert = true; |
|
192 iSign = false; |
|
193 break; |
|
194 #ifdef GENERATE_ERRORS |
|
195 case 'q' : |
|
196 case 'Q' : |
|
197 CSISFieldRoot::SetBugStart (atoi(wstring2string (&argv [index] [wCharacter+1]).c_str ())); |
|
198 wCharacter++; |
|
199 break; |
|
200 case 'r' : |
|
201 case 'R' : |
|
202 CSISFieldRoot::SetBugRepeat (atoi (wstring2string (&argv [index] [wCharacter+1]).c_str ())); |
|
203 wCharacter++; |
|
204 break; |
|
205 #endif // GENERATE_ERRORS |
|
206 case 's' : |
|
207 case 'S' : |
|
208 iSign = true; |
|
209 break; |
|
210 case 'u' : |
|
211 case 'U' : |
|
212 iUnsign = true; |
|
213 iSign = false; |
|
214 break; |
|
215 case 'v' : |
|
216 case 'V' : |
|
217 iVerbose = true; |
|
218 break; |
|
219 case 'x' : |
|
220 case 'X' : |
|
221 { |
|
222 for (int offset = wCharacter+1; argv [index][offset]; offset++) |
|
223 { |
|
224 switch(argv[index][offset]) |
|
225 { |
|
226 case 'c' : |
|
227 case 'C' : |
|
228 CSISFieldRoot::SetDebugOption (CSISFieldRoot::EDbgControllerChecksum); |
|
229 break; |
|
230 case 'd' : |
|
231 case 'D' : |
|
232 CSISFieldRoot::SetDebugOption (CSISFieldRoot::EDbgDataChecksum); |
|
233 break; |
|
234 case 'w' : |
|
235 case 'W' : |
|
236 CSISFieldRoot::SetDebugOption (CSISFieldRoot::EDbgCompress); |
|
237 break; |
|
238 case 'x' : |
|
239 case 'X' : |
|
240 CSISFieldRoot::SetDebugOption (CSISFieldRoot::EDbgNoCompress); |
|
241 break; |
|
242 } |
|
243 wCharacter++; |
|
244 } |
|
245 } |
|
246 break; |
|
247 |
|
248 default : |
|
249 std::cout << "Unknown switch " << argv [index]; |
|
250 bien = false; |
|
251 break; |
|
252 } |
|
253 wCharacter++; |
|
254 } |
|
255 } |
|
256 else |
|
257 { |
|
258 switch (stage) |
|
259 { |
|
260 case 0 : |
|
261 iSISFileName = argv [index]; |
|
262 break; |
|
263 case 1 : |
|
264 iOutput = argv [index]; |
|
265 break; |
|
266 case 2 : |
|
267 iCertificate = argv [index]; |
|
268 break; |
|
269 case 3 : |
|
270 iKey = argv [index]; |
|
271 break; |
|
272 case 4 : |
|
273 iPassPhrase = argv [index]; |
|
274 break; |
|
275 default : |
|
276 if (bien) |
|
277 { |
|
278 std::cout << "Unexpected arguments from "; //<< std::string (argv [index]) << "." << std::endl; |
|
279 HANDLE hndl; |
|
280 DWORD bytesWritten; |
|
281 //Get command prompt handle |
|
282 hndl = GetStdHandle(STD_OUTPUT_HANDLE); |
|
283 WriteConsole(hndl, argv [index], wcslen(argv [index]), &bytesWritten, 0); |
|
284 std::cout << "." << std::endl; |
|
285 bien = false; |
|
286 } |
|
287 break; |
|
288 } |
|
289 stage++; |
|
290 } |
|
291 } |
|
292 |
|
293 if (bien && ! iSign && ! iUnsign && ! iReport && !iExtractCert) |
|
294 { |
|
295 std::cout << "Nothing to do." << std::endl; |
|
296 bien = false; |
|
297 } |
|
298 |
|
299 if (bien && multi) |
|
300 { |
|
301 std::cout << "More than one signing algorithm specified." << std::endl; |
|
302 bien = false; |
|
303 } |
|
304 |
|
305 if (bien) |
|
306 { |
|
307 if (iSign && iUnsign) |
|
308 { |
|
309 std::cout << "Can't sign and unsign in single operation." << std::endl; |
|
310 bien = false; |
|
311 } |
|
312 else |
|
313 if (iSign || iUnsign || iReport || iExtractCert) |
|
314 { |
|
315 if (iSISFileName.empty ()) |
|
316 { |
|
317 std::cout << "Please name the input file." << std::endl; |
|
318 bien = false; |
|
319 } |
|
320 else |
|
321 if ((! iReport && iOutput.empty ())&& (! iExtractCert && iOutput.empty())) |
|
322 { |
|
323 std::cout << "Please name the output file." << std::endl; |
|
324 bien = false; |
|
325 } |
|
326 } |
|
327 } |
|
328 |
|
329 if (iVerbose) |
|
330 { |
|
331 ShowBanner (); |
|
332 } |
|
333 |
|
334 if (bien && ! iSign && ! iCertificate.empty ()) |
|
335 { |
|
336 std::cout << "A certificate is only used for signing a sis file." << std::endl; |
|
337 bien = false; |
|
338 } |
|
339 |
|
340 if (! bien && ! help) |
|
341 { |
|
342 std::cout << "Type \"" << "signsis" << " -?\" for command line options." << std::endl; |
|
343 } |
|
344 |
|
345 if (ssl) |
|
346 { |
|
347 for (int index = 0; index < (sizeof(openSSLLicenseString)/sizeof(openSSLLicenseString[0])); index++) |
|
348 std::cout << openSSLLicenseString [index] << std::endl; |
|
349 std::cout << std::endl; |
|
350 bien = false; |
|
351 } |
|
352 |
|
353 if (help) |
|
354 { |
|
355 std::cout << "Usage: SignSIS [-?] [-c...] [-i] [-o[-p]] [-s] [-u] [-v] input [output [certificate key [passphrase] ] ]" << std::endl << std::endl; |
|
356 std::cout << "-? or -h Output this information" << std::endl; |
|
357 std::cout << "-c... Sign using specific algorithm: -cd for DSA, -cr for RSA" << std::endl; |
|
358 std::cout << "-i Output licence information" << std::endl; |
|
359 std::cout << "-o Report on content of sis file (after any other operation)" << std::endl; |
|
360 std::cout << "-p Extracts the certificates present (This option has to be given along with -o option)"<< std::endl; |
|
361 std::cout << "-s Sign SIS file (requires sis file, certificate, key and passphrase)" << std::endl; |
|
362 std::cout << "-u Remove most recent signature from SIS file" << std::endl; |
|
363 std::cout << "-v Verbose output" << std::endl; |
|
364 std::cout << "input The SIS file to be sign, unsigned or investigated" << std::endl; |
|
365 std::cout << "output The SIS file generated by signing or unsigned" << std::endl; |
|
366 std::cout << "certificate The certificate file used for signing" << std::endl; |
|
367 std::cout << "key The certificate's private key file" << std::endl << std::endl; |
|
368 std::cout << "passphrase The certificate's private key file's passphrase" << std::endl << std::endl; |
|
369 std::cout << "You can sign or unsign a file in a single operation." << std::endl; |
|
370 std::cout << "You can generate SIS files using MakeSIS v5." << std::endl << std::endl; |
|
371 bien = false; |
|
372 } |
|
373 |
|
374 return bien; |
|
375 } |
|
376 |
|
377 void CParameter::ShowBanner() |
|
378 // Displays the copyright... |
|
379 { |
|
380 std::cout << std::endl << "SIGNSIS " << " Version 5.1" << std::endl; |
|
381 std::cout << "A utility for signing Software Installation (SIS) files." << std::endl; |
|
382 std::cout << "Copyright (c) 2007 Symbian Software Ltd. All rights reserved. " << std::endl; |
|
383 #ifdef _DEBUG |
|
384 std::cout << std::endl << "Development Version" << std::endl; |
|
385 #endif |
|
386 std::cout << std::endl; |
|
387 } |
|
388 |
|
389 |
|
390 |
|
391 bool CParameter::iExtractCert=false; |