|
1 /* |
|
2 * Copyright (c) 2007-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 @file |
|
21 @internalComponent |
|
22 */ |
|
23 |
|
24 #include "dumpprocessor.h" |
|
25 #include <e32cons.h> |
|
26 #include <cryptospi/cryptospidef.h> |
|
27 #include <bacline.h> |
|
28 #include <cryptospi/cryptocharacteristics.h> |
|
29 #include <cryptospi/cryptospistateapi.h> |
|
30 |
|
31 using namespace CryptoSpi; |
|
32 |
|
33 //Copy-right, Tool name format |
|
34 _LIT(KShortName, "Dump CryptoSpi Tool"); |
|
35 _LIT(KName, "Symbian Dump CryptoSpi Tool"); |
|
36 _LIT(KCopyright, "Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved."); |
|
37 _LIT(KDone, "Complete Dumping... \n"); |
|
38 |
|
39 //dumpcryptoplugin options |
|
40 _LIT(KAll, "-all"); |
|
41 _LIT(KAllShort, "-a"); |
|
42 |
|
43 _LIT(KInterface, "-interface"); |
|
44 _LIT(KInterfaceShort, "-i"); |
|
45 |
|
46 _LIT(KAlgorithm, "-algorithm"); |
|
47 _LIT(KAlgorithmShort, "-al"); |
|
48 |
|
49 _LIT(KExtended, "-extended"); |
|
50 _LIT(KExtendedShort, "-e"); |
|
51 |
|
52 _LIT(KDll, "-dll"); |
|
53 _LIT(KDllShort, "-d"); |
|
54 |
|
55 _LIT(KHelp, "-help"); |
|
56 _LIT(KHelpShort, "-h"); |
|
57 |
|
58 _LIT(KOutputFile, "-out"); |
|
59 _LIT(KOutputFileShort, "-o"); |
|
60 |
|
61 |
|
62 //Error messages |
|
63 _LIT(KMissingInterfaceName, "Missing Interface Name. \n"); |
|
64 _LIT(KInvalidInterfaceName, "Invalid Interface Name. \n"); |
|
65 _LIT(KMissingAlgorithmName, "Missing Algorithm Name. \n"); |
|
66 _LIT(KInvalidAlgorithmName, "Invalid Algorithm Name. \n"); |
|
67 _LIT(KMissingDllName, "Missing Plugin Dll Name. \n"); |
|
68 _LIT(KMissingOutputName, "Missing Output Name. \n"); |
|
69 _LIT(KError, "Error=%d \n"); |
|
70 |
|
71 /** |
|
72 The method converts the given interface name to interface uid |
|
73 */ |
|
74 TInt ConvertToInterfaceId(const TDesC& aInterfaceName, TInt32& aInterfaceId) |
|
75 { |
|
76 if (aInterfaceName.CompareF(KHash)==0) |
|
77 { |
|
78 aInterfaceId=KHashInterface; |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 if (aInterfaceName.CompareF(KRandom)==0) |
|
83 { |
|
84 aInterfaceId=KRandomInterface; |
|
85 return KErrNone; |
|
86 } |
|
87 |
|
88 if (aInterfaceName.CompareF(KSymmetricCipher)==0) |
|
89 { |
|
90 aInterfaceId=KSymmetricCipherInterface; |
|
91 return KErrNone; |
|
92 } |
|
93 |
|
94 if (aInterfaceName.CompareF(KAsymmetricCipher)==0) |
|
95 { |
|
96 aInterfaceId=KAsymmetricCipherInterface; |
|
97 return KErrNone; |
|
98 } |
|
99 |
|
100 if (aInterfaceName.CompareF(KSigner)==0) |
|
101 { |
|
102 aInterfaceId=KSignerInterface; |
|
103 return KErrNone; |
|
104 } |
|
105 |
|
106 if (aInterfaceName.CompareF(KVerifier)==0) |
|
107 { |
|
108 aInterfaceId=KVerifierInterface; |
|
109 return KErrNone; |
|
110 } |
|
111 |
|
112 if (aInterfaceName.CompareF(KKeyPairGenerator)==0) |
|
113 { |
|
114 aInterfaceId=KKeypairGeneratorInterface; |
|
115 return KErrNone; |
|
116 } |
|
117 |
|
118 if (aInterfaceName.CompareF(KKeyAgreement)==0) |
|
119 { |
|
120 aInterfaceId=KKeyAgreementInterface; |
|
121 return KErrNone; |
|
122 } |
|
123 |
|
124 if (aInterfaceName.CompareF(KAsyncHash)==0) |
|
125 { |
|
126 aInterfaceId=KAsyncHashInterface; |
|
127 return KErrNone; |
|
128 } |
|
129 |
|
130 if (aInterfaceName.CompareF(KAsyncRandom)==0) |
|
131 { |
|
132 aInterfaceId=KAsyncRandomInterface; |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 if (aInterfaceName.CompareF(KAsyncSymmetricCipher)==0) |
|
137 { |
|
138 aInterfaceId=KAsyncSymmetricCipherInterface; |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 if (aInterfaceName.CompareF(KAsyncAsymmetricCipher)==0) |
|
143 { |
|
144 aInterfaceId=KAsyncAsymmetricCipherInterface; |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 if (aInterfaceName.CompareF(KAsyncSigner)==0) |
|
149 { |
|
150 aInterfaceId=KAsyncSignerInterface; |
|
151 return KErrNone; |
|
152 } |
|
153 |
|
154 if (aInterfaceName.CompareF(KAsyncVerifier)==0) |
|
155 { |
|
156 aInterfaceId=KAsyncVerifierInterface; |
|
157 return KErrNone; |
|
158 } |
|
159 |
|
160 if (aInterfaceName.CompareF(KAsyncKeyPairGenerator)==0) |
|
161 { |
|
162 aInterfaceId=KAsyncKeypairGeneratorInterface; |
|
163 return KErrNone; |
|
164 } |
|
165 |
|
166 if (aInterfaceName.CompareF(KAsyncKeyAgreement)==0) |
|
167 { |
|
168 aInterfaceId=KAsyncKeyAgreementInterface; |
|
169 return KErrNone; |
|
170 } |
|
171 |
|
172 return KErrNotFound; |
|
173 } |
|
174 |
|
175 /** |
|
176 The method converts the given algorithm name to algorithm uid |
|
177 */ |
|
178 TInt ConvertToAlgorithmId(const TDesC& aAlgorithmName, TInt32& aAlgorithmId) |
|
179 { |
|
180 if (aAlgorithmName.CompareF(KMd2)==0) |
|
181 { |
|
182 aAlgorithmId=KAlgorithmHashMd2; |
|
183 return KErrNone; |
|
184 } |
|
185 |
|
186 if (aAlgorithmName.CompareF(KMd5)==0) |
|
187 { |
|
188 aAlgorithmId=KAlgorithmHashMd5; |
|
189 return KErrNone; |
|
190 } |
|
191 |
|
192 if (aAlgorithmName.CompareF(KMd4)==0) |
|
193 { |
|
194 aAlgorithmId=KAlgorithmHashMd4; |
|
195 return KErrNone; |
|
196 } |
|
197 |
|
198 if (aAlgorithmName.CompareF(KSha1)==0) |
|
199 { |
|
200 aAlgorithmId=KAlgorithmHashSha1; |
|
201 return KErrNone; |
|
202 } |
|
203 |
|
204 if (aAlgorithmName.CompareF(KDes)==0) |
|
205 { |
|
206 aAlgorithmId=KAlgorithmCipherDes; |
|
207 return KErrNone; |
|
208 } |
|
209 |
|
210 if (aAlgorithmName.CompareF(K3Des)==0) |
|
211 { |
|
212 aAlgorithmId=KAlgorithmCipher3Des; |
|
213 return KErrNone; |
|
214 } |
|
215 |
|
216 if (aAlgorithmName.CompareF(KRC2)==0) |
|
217 { |
|
218 aAlgorithmId=KAlgorithmCipherRc2; |
|
219 return KErrNone; |
|
220 } |
|
221 |
|
222 if (aAlgorithmName.CompareF(KAes)==0) |
|
223 { |
|
224 aAlgorithmId=KAlgorithmCipherAes; |
|
225 return KErrNone; |
|
226 } |
|
227 |
|
228 if (aAlgorithmName.CompareF(KRC4)==0) |
|
229 { |
|
230 aAlgorithmId=KAlgorithmCipherArc4; |
|
231 return KErrNone; |
|
232 } |
|
233 |
|
234 if (aAlgorithmName.CompareF(KRsaCipher)==0) |
|
235 { |
|
236 aAlgorithmId=KAlgorithmCipherRsa; |
|
237 return KErrNone; |
|
238 } |
|
239 |
|
240 if (aAlgorithmName.CompareF(KRsaSigner)==0) |
|
241 { |
|
242 aAlgorithmId=KAlgorithmSignerRsa; |
|
243 return KErrNone; |
|
244 } |
|
245 |
|
246 if (aAlgorithmName.CompareF(KRsaVerifier)==0) |
|
247 { |
|
248 aAlgorithmId=KAlgorithmVerifierRsa; |
|
249 return KErrNone; |
|
250 } |
|
251 |
|
252 if (aAlgorithmName.CompareF(KRsaKeyPair)==0) |
|
253 { |
|
254 aAlgorithmId=KAlgorithmRSAKeyPairGenerator; |
|
255 return KErrNone; |
|
256 } |
|
257 |
|
258 if (aAlgorithmName.CompareF(KDsaSigner)==0) |
|
259 { |
|
260 aAlgorithmId=KAlgorithmSignerDsa; |
|
261 return KErrNone; |
|
262 } |
|
263 |
|
264 if (aAlgorithmName.CompareF(KDsaVerifier)==0) |
|
265 { |
|
266 aAlgorithmId=KAlgorithmVerifierDsa; |
|
267 return KErrNone; |
|
268 } |
|
269 |
|
270 if (aAlgorithmName.CompareF(KDsaKeyPair)==0) |
|
271 { |
|
272 aAlgorithmId=KAlgorithmDSAKeyPairGenerator; |
|
273 return KErrNone; |
|
274 } |
|
275 |
|
276 if (aAlgorithmName.CompareF(KDhKeyPair)==0) |
|
277 { |
|
278 aAlgorithmId=KAlgorithmDHKeyPairGenerator; |
|
279 return KErrNone; |
|
280 } |
|
281 |
|
282 if (aAlgorithmName.CompareF(KDhKeyAgreement)==0) |
|
283 { |
|
284 aAlgorithmId=KAlgorithmKeyAgreementDH; |
|
285 return KErrNone; |
|
286 } |
|
287 |
|
288 return KErrNotFound; |
|
289 } |
|
290 |
|
291 |
|
292 /** |
|
293 Displays tool name and copy-right informations. |
|
294 */ |
|
295 void BoilerPlate(CConsoleBase* console) |
|
296 { |
|
297 console->Printf(KNewLine); |
|
298 console->Printf(KName); |
|
299 console->Printf(KNewLine); |
|
300 console->Printf(KCopyright); |
|
301 console->Printf(KNewLine); |
|
302 console->Printf(KNewLine); |
|
303 } |
|
304 |
|
305 /** |
|
306 The method retrieves the command line parameters and build the CDumpToolParameters object. |
|
307 */ |
|
308 |
|
309 void ExtractOptionL(const CCommandLineArguments& aInput, CDumpToolParameters& aParam, CConsoleBase* aConsole) |
|
310 { |
|
311 TInt count=aInput.Count(); |
|
312 TInt i=0; |
|
313 while (i<count-1) |
|
314 { |
|
315 i++; |
|
316 |
|
317 //Handle -a and -all |
|
318 if ((aInput.Arg(i).Compare(KAll)==0)||(aInput.Arg(i).Compare(KAllShort)==0)) |
|
319 { |
|
320 continue; |
|
321 } |
|
322 |
|
323 //Handle -i and -interface |
|
324 if ((aInput.Arg(i).Compare(KInterface)==0)||(aInput.Arg(i).Compare(KInterfaceShort)==0)) |
|
325 { |
|
326 //Move to interface name |
|
327 i++; |
|
328 if (i>count-1) |
|
329 { |
|
330 aConsole->Printf(KMissingInterfaceName); |
|
331 User::Leave(KErrArgument); |
|
332 } |
|
333 |
|
334 //Currently point to interface name |
|
335 if (KErrNone!=ConvertToInterfaceId(aInput.Arg(i), aParam.iInterface)) |
|
336 { |
|
337 //Invalid interface name |
|
338 aConsole->Printf(KInvalidInterfaceName); |
|
339 User::Leave(KErrArgument); |
|
340 } |
|
341 continue; |
|
342 } |
|
343 |
|
344 //Handle -al and -algorithm |
|
345 if ((aInput.Arg(i).Compare(KAlgorithm)==0)||(aInput.Arg(i).Compare(KAlgorithmShort)==0)) |
|
346 { |
|
347 //Move to algorithm name |
|
348 i++; |
|
349 if (i>count-1) |
|
350 { |
|
351 aConsole->Printf(KMissingAlgorithmName); |
|
352 User::Leave(KErrArgument); |
|
353 } |
|
354 |
|
355 //Currently point to algorithm name |
|
356 if (KErrNone!=ConvertToAlgorithmId(aInput.Arg(i), aParam.iAlgorithm)) |
|
357 { |
|
358 //Invalid algorithm name |
|
359 aConsole->Printf(KInvalidAlgorithmName); |
|
360 User::Leave(KErrArgument); |
|
361 } |
|
362 continue; |
|
363 } |
|
364 |
|
365 //Handle -e and -extended |
|
366 if ((aInput.Arg(i).Compare(KExtended)==0)||(aInput.Arg(i).Compare(KExtendedShort)==0)) |
|
367 { |
|
368 aParam.iOptions.AppendL(CDumpToolParameters::EOptionExtendedCharacteristic); |
|
369 continue; |
|
370 } |
|
371 |
|
372 //Handle -d and -dll |
|
373 if ((aInput.Arg(i).Compare(KDll)==0)||(aInput.Arg(i).Compare(KDllShort)==0)) |
|
374 { |
|
375 i++; |
|
376 if (i>count-1) |
|
377 { |
|
378 aConsole->Printf(KMissingDllName); |
|
379 User::Leave(KErrArgument); |
|
380 } |
|
381 aParam.iDllName=aInput.Arg(i); |
|
382 continue; |
|
383 } |
|
384 |
|
385 //Handle -o and -out |
|
386 if ((aInput.Arg(i).Compare(KOutputFile)==0)||(aInput.Arg(i).Compare(KOutputFileShort)==0)) |
|
387 { |
|
388 i++; |
|
389 if (i>count-1) |
|
390 { |
|
391 aConsole->Printf(KMissingOutputName); |
|
392 User::Leave(KErrArgument); |
|
393 } |
|
394 aParam.iDumpFileName=aInput.Arg(i); |
|
395 continue; |
|
396 } |
|
397 |
|
398 //Handle -h and -help |
|
399 if ((aInput.Arg(i).Compare(KHelp)==0)||(aInput.Arg(i).Compare(KHelpShort)==0)) |
|
400 { |
|
401 aParam.iOptions.AppendL(CDumpToolParameters::EOptionHelp); |
|
402 continue; |
|
403 } |
|
404 |
|
405 HBufC* temp=aInput.Arg(i).AllocLC(); |
|
406 aParam.iInvalidOptions.AppendL(temp); |
|
407 CleanupStack::Pop(temp); |
|
408 } |
|
409 } |
|
410 |
|
411 |
|
412 void DoProcessL(CConsoleBase* aConsole) |
|
413 { |
|
414 //Get the command line arguments |
|
415 CCommandLineArguments* args = CCommandLineArguments::NewLC(); |
|
416 |
|
417 //Construct the parameters holder |
|
418 CDumpToolParameters* params = CDumpToolParameters::NewLC(); |
|
419 |
|
420 //Retrieve the command line options |
|
421 ExtractOptionL(*args, *params, aConsole); |
|
422 |
|
423 //Process the command line and output the characteristics. |
|
424 CDumpToolProcessor* processor=CDumpToolProcessor::NewLC(*params, aConsole); |
|
425 processor->ProcessL(); |
|
426 aConsole->Printf(KNewLine); |
|
427 CleanupStack::PopAndDestroy(processor); |
|
428 CleanupStack::PopAndDestroy(2, args); // params, args, |
|
429 } |
|
430 |
|
431 /** |
|
432 Main function to retrieve and log the characteristics |
|
433 */ |
|
434 void DoMainL() |
|
435 { |
|
436 //New a console and print tool information |
|
437 CConsoleBase* console = Console::NewL(KShortName, TSize(KDefaultConsWidth, KDefaultConsHeight)); |
|
438 CleanupStack::PushL(console); |
|
439 BoilerPlate(console); |
|
440 TRAPD(err, DoProcessL(console)); |
|
441 if (err!=KErrArgument && err!=KErrNone) |
|
442 { |
|
443 console->Printf(KError, err); |
|
444 } |
|
445 if (err!=KErrNone) |
|
446 { |
|
447 console->Printf(KPressAnyKey); |
|
448 console->Getch(); |
|
449 } |
|
450 console->Printf(KDone); |
|
451 //console->Getch(); |
|
452 CleanupStack::PopAndDestroy(console); // params, args, console |
|
453 } |
|
454 |
|
455 /** |
|
456 @return KErrNone (0) if successful, KErrMemory if out of memory |
|
457 otherwise error result from DoMainL |
|
458 */ |
|
459 TInt E32Main() |
|
460 { |
|
461 __UHEAP_MARK; |
|
462 CTrapCleanup* trapCleanup=CTrapCleanup::New(); |
|
463 if (!trapCleanup) |
|
464 { |
|
465 return KErrNoMemory; |
|
466 } |
|
467 |
|
468 TRAPD(err, DoMainL()); |
|
469 delete trapCleanup; |
|
470 __UHEAP_MARKEND; |
|
471 return err; |
|
472 } |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |