1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 /* |
2 // All rights reserved. |
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 // This component and the accompanying materials are made available |
3 * All rights reserved. |
4 // under the terms of the License "Symbian Foundation License v1.0" |
4 * This component and the accompanying materials are made available |
5 // which accompanies this distribution, and is available |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
6 * which accompanies this distribution, and is available |
7 // |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 // Initial Contributors: |
8 * |
9 // Nokia Corporation - initial contribution. |
9 * Initial Contributors: |
10 // |
10 * Nokia Corporation - initial contribution. |
11 // Contributors: |
11 * |
12 // |
12 * Contributors: |
13 // Description: |
13 * |
14 // |
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
15 |
18 |
16 #include <e32cons.h> |
19 #include <e32cons.h> |
17 #include <bacline.h> |
20 #include <bacline.h> |
|
21 #include <keytool.rsg> |
18 |
22 |
19 #include "keytool_utils.h" |
23 #include "keytool_utils.h" |
20 #include "keytool_defs.h" |
24 #include "keytool_defs.h" |
21 #include "keytool_controller.h" |
25 #include "keytool_controller.h" |
22 #include "keytool_view_imp.h" |
26 #include "keytool_view_imp.h" |
23 #include "keytool_commands.h" |
27 #include "keytool_commands.h" |
24 #include "keytoolfileview.h" |
28 #include "keytoolfileview.h" |
25 |
29 |
26 |
30 |
27 // Boiler plate |
31 // Boiler plate |
28 _LIT(KShortName, "Symbian OS KeyTool"); |
32 _LIT(KShortName, "Nokia KeyTool"); |
29 _LIT(KName, "Symbian OS KeyStore Manipulation Tool"); |
33 _LIT(KName, "Nokia KeyStore Manipulation Tool"); |
30 _LIT(KCopyright, "Copyright (c) 2004 - 2007 Symbian Software Ltd. All rights reserved."); |
34 _LIT(KCopyright, "Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved."); |
31 |
35 |
32 _LIT(KNewLine, "\n"); |
36 _LIT(KNewLine, "\n"); |
33 |
37 |
34 _LIT(KDone, "Press any key to continue... \n"); |
38 _LIT(KDone, "Press any key to continue... \n"); |
35 |
39 |
74 _LIT(KDetailsShort, "-d"); |
78 _LIT(KDetailsShort, "-d"); |
75 |
79 |
76 _LIT(KPageWise, "-page"); |
80 _LIT(KPageWise, "-page"); |
77 _LIT(KPageWiseShort, "-p"); |
81 _LIT(KPageWiseShort, "-p"); |
78 |
82 |
|
83 #ifdef KEYTOOL |
|
84 _LIT(KMigrateStore, "-migratestore"); |
|
85 _LIT(KNewFileName, "-new"); |
|
86 _LIT(KAuthExpression, "-expr"); |
|
87 _LIT(KFreshness, "-freshness"); |
|
88 #endif // KEYTOOL |
79 |
89 |
80 const TInt KMaxArgs = 10; |
90 const TInt KMaxArgs = 10; |
81 |
91 |
82 /** |
92 /** |
83 * Displays tool name and copyright informations. |
93 * Displays tool name and copyright informations. |
160 |
178 |
161 RFile file; |
179 RFile file; |
162 // command: keytool inputfile outputfile |
180 // command: keytool inputfile outputfile |
163 if (cmdArgsCount == 3) |
181 if (cmdArgsCount == 3) |
164 { |
182 { |
165 interactiveMode = EFalse; |
183 if (KeyToolUtils::DoesFileExistsL(fs,cmdArgs->Arg(1))) |
166 TInt error = file.Open(fs, cmdArgs->Arg(1), EFileRead|EFileShareAny); |
|
167 file.Close(); |
|
168 TInt error1 = file.Replace(fs, cmdArgs->Arg(2), EFileWrite|EFileShareExclusive); |
|
169 CleanupClosePushL(file); |
|
170 // If the input file doesn't exist or not able to create outputfile |
|
171 // switch to Interactive mode |
|
172 if (error != KErrNone || error1 != KErrNone) |
|
173 { |
184 { |
174 CleanupStack::PopAndDestroy(&file); |
185 interactiveMode = EFalse; |
175 interactiveMode = ETrue; |
186 TInt error = file.Open(fs, cmdArgs->Arg(1), EFileRead|EFileShareAny); |
176 } |
187 file.Close(); |
|
188 |
|
189 TInt error1 = file.Replace(fs, cmdArgs->Arg(2), EFileWrite|EFileShareExclusive); |
|
190 CleanupClosePushL(file); |
|
191 // If the input file doesn't exist or not able to create outputfile |
|
192 // switch to Interactive mode |
|
193 if (error != KErrNone || error1 != KErrNone) |
|
194 { |
|
195 CleanupStack::PopAndDestroy(&file); |
|
196 interactiveMode = ETrue; |
|
197 } |
|
198 } |
177 } |
199 } |
178 |
200 |
179 CKeytoolConsoleView* view = CKeytoolConsoleView::NewLC(*console); |
201 CKeytoolConsoleView* view = CKeytoolConsoleView::NewLC(*console); |
180 CKeyToolController* controller = CKeyToolController::NewLC(*view); |
202 CKeyToolController* controller = CKeyToolController::NewLC(*view); |
181 CArrayFixFlat<TPtrC>* args = new (ELeave) CArrayFixFlat<TPtrC> (10); |
203 CArrayFixFlat<TPtrC>* args = new (ELeave) CArrayFixFlat<TPtrC> (10); |
286 } |
308 } |
287 params->iUIDs.Append(app); |
309 params->iUIDs.Append(app); |
288 params->iIsDetailed = ETrue; |
310 params->iIsDetailed = ETrue; |
289 } |
311 } |
290 } |
312 } |
|
313 |
|
314 #ifdef KEYTOOL |
|
315 if(commd.CompareF(KMigrateStore) == 0 ) |
|
316 { |
|
317 int mandatoryParams = 2; |
|
318 if(argsCount-1 >= ++i) |
|
319 { |
|
320 params->iOldKeyFile = args->At(i).AllocL(); |
|
321 } |
|
322 else |
|
323 { |
|
324 controller->DisplayLocalisedMsgL(R_KEYTOOL_USAGE_OLDKEY_ABSENT); |
|
325 --mandatoryParams; |
|
326 } |
|
327 if(argsCount-1 >= ++i) |
|
328 { |
|
329 params->iPassphrase = args->At(i).AllocL(); |
|
330 } |
|
331 else |
|
332 { |
|
333 controller->DisplayLocalisedMsgL(R_KEYTOOL_USAGE_PASSPHRASE_ABSENT); |
|
334 --mandatoryParams; |
|
335 } |
|
336 |
|
337 if( mandatoryParams != 2 ) |
|
338 { |
|
339 command = KeyToolDefController::KUsageCommand; |
|
340 } |
|
341 else |
|
342 { |
|
343 TInt count = args->Count(); |
|
344 |
|
345 while(++i < count ) |
|
346 { |
|
347 TDesC& commd = args->At(i); |
|
348 if(commd.CompareF(KNewFileName) == 0 && argsCount-1 >= ++i) |
|
349 { |
|
350 delete params->iNewKeyFile; |
|
351 params->iNewKeyFile=NULL; |
|
352 params->iNewKeyFile = args->At(i++).AllocL(); |
|
353 } |
|
354 else if(commd.CompareF(KAuthExpression) == 0 && argsCount-1 >= ++i ) |
|
355 { |
|
356 params->iAuthExpression = args->At(i++).AllocL(); |
|
357 } |
|
358 else if(commd.CompareF(KFreshness) == 0 && argsCount-1 >= ++i ) |
|
359 { |
|
360 TLex lex(args->At(i++)); |
|
361 TInt err = lex.Val(params->iFreshness); |
|
362 } |
|
363 } // while |
|
364 } // if(mandatoryParams == 0) |
|
365 } // if |
|
366 |
|
367 #endif // KEYTOOL |
291 continue; |
368 continue; |
292 } |
369 } |
293 |
370 |
294 TDesC& cmd = args->At(i); |
371 TDesC& cmd = args->At(i); |
295 if (cmd.CompareF(KHelp) == 0 || cmd.Compare(KHelpShort) == 0 || |
372 if (cmd.CompareF(KHelp) == 0 || cmd.Compare(KHelpShort) == 0 || |