sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <mctkeystore.h>
|
sl@0
|
20 |
#include <asn1dec.h>
|
sl@0
|
21 |
#include <asnpkcs.h>
|
sl@0
|
22 |
#include <unifiedkeystore.h>
|
sl@0
|
23 |
#include <securityerr.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
#include "keytool_commands.h"
|
sl@0
|
26 |
#include "keytool_controller.h"
|
sl@0
|
27 |
#include "controller.h"
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <keytool.rsg>
|
sl@0
|
30 |
|
sl@0
|
31 |
/*static*/ CKeytoolImport* CKeytoolImport::NewLC(CController* aController)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
CKeytoolImport* self = new (ELeave) CKeytoolImport(aController);
|
sl@0
|
34 |
CleanupStack::PushL(self);
|
sl@0
|
35 |
self->ConstructL();
|
sl@0
|
36 |
return self;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
/*static*/ CKeytoolImport* CKeytoolImport::NewL(CController* aController)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
CKeytoolImport* self = CKeytoolImport::NewLC(aController);
|
sl@0
|
42 |
CleanupStack::Pop(self);
|
sl@0
|
43 |
return self;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
CKeytoolImport::~CKeytoolImport()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
Cancel();
|
sl@0
|
49 |
delete iKeyData;
|
sl@0
|
50 |
if (iKeyInfo != NULL)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
iKeyInfo->Release();
|
sl@0
|
53 |
}
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
void CKeytoolImport::ConstructL()
|
sl@0
|
57 |
{
|
sl@0
|
58 |
CActiveScheduler::Add(this);
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
void CKeytoolImport::Pkcs8PreprocessorL()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
RFs fs;
|
sl@0
|
64 |
CleanupClosePushL(fs);
|
sl@0
|
65 |
User::LeaveIfError(fs.Connect());
|
sl@0
|
66 |
|
sl@0
|
67 |
RFile file;
|
sl@0
|
68 |
CleanupClosePushL(file);
|
sl@0
|
69 |
TInt r = file.Open(fs, *(iParams->iDefault), EFileRead);
|
sl@0
|
70 |
if (r != KErrNone)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_OPENFAIL);
|
sl@0
|
73 |
User::Leave(r);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
TInt fileSize = 0;
|
sl@0
|
77 |
file.Size(fileSize);
|
sl@0
|
78 |
|
sl@0
|
79 |
if (fileSize <= 0)
|
sl@0
|
80 |
{
|
sl@0
|
81 |
iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_EMPTYFILE);
|
sl@0
|
82 |
User::Leave(KErrCorrupt);
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
iKeyData = HBufC8::NewMaxL(fileSize);
|
sl@0
|
86 |
TPtr8 data(iKeyData->Des());
|
sl@0
|
87 |
data.FillZ();
|
sl@0
|
88 |
User::LeaveIfError(file.Read(data, fileSize));
|
sl@0
|
89 |
|
sl@0
|
90 |
CleanupStack::PopAndDestroy(&file);
|
sl@0
|
91 |
CleanupStack::PopAndDestroy(&fs);
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
|
sl@0
|
95 |
void CKeytoolImport::DoCommandL(CUnifiedKeyStore& aKeyStore, CKeyToolParameters* aParam)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
Cancel();
|
sl@0
|
98 |
iParams = aParam;
|
sl@0
|
99 |
|
sl@0
|
100 |
TRAPD(err, Pkcs8PreprocessorL());
|
sl@0
|
101 |
if (err != KErrNone)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_PKCS8);
|
sl@0
|
104 |
User::Leave(err);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
// keystore index, key data, usage, label, access type, start, end, keyinfo, status
|
sl@0
|
108 |
// must get proper keystore
|
sl@0
|
109 |
if (aParam->iKeystoreIndex == -1)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
aParam->iKeystoreIndex = 0;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
if (aParam->iKeystoreIndex >= aKeyStore.KeyStoreCount())
|
sl@0
|
114 |
{
|
sl@0
|
115 |
iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_NOTEXIST);
|
sl@0
|
116 |
User::Leave(KErrCorrupt);
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
if (!iParams->iLabel)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
iParams->iLabel = (iParams->iDefault)->AllocL();
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
aKeyStore.ImportKey(iParams->iKeystoreIndex, *iKeyData, iParams->iUsage, *iParams->iLabel,
|
sl@0
|
125 |
iParams->iAccess, TTime(0), iParams->iEndDate, iKeyInfo, iStatus);
|
sl@0
|
126 |
|
sl@0
|
127 |
SetActive();
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
void CKeytoolImport::RunL()
|
sl@0
|
131 |
{
|
sl@0
|
132 |
if (iStatus.Int() != KErrNone)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
// A problem occured. Handle gracefully.
|
sl@0
|
135 |
User::Leave(iStatus.Int());
|
sl@0
|
136 |
}
|
sl@0
|
137 |
iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_IMPORTSUCCESS);
|
sl@0
|
138 |
iController->DisplayKeyL(*iKeyInfo, ETrue, iParams->iPageWise);
|
sl@0
|
139 |
|
sl@0
|
140 |
CActiveScheduler::Stop();
|
sl@0
|
141 |
}
|
sl@0
|
142 |
|
sl@0
|
143 |
TInt CKeytoolImport::RunError(TInt aError)
|
sl@0
|
144 |
{
|
sl@0
|
145 |
CActiveScheduler::Stop();
|
sl@0
|
146 |
switch (aError)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
case KErrBadPassphrase:
|
sl@0
|
149 |
{
|
sl@0
|
150 |
TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_PASSPHRASE, iStatus.Int()));
|
sl@0
|
151 |
}
|
sl@0
|
152 |
break;
|
sl@0
|
153 |
case KErrKeyNotWeakEnough:
|
sl@0
|
154 |
{
|
sl@0
|
155 |
TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_WEAK, iStatus.Int()));
|
sl@0
|
156 |
}
|
sl@0
|
157 |
break;
|
sl@0
|
158 |
case KErrKeyUsage:
|
sl@0
|
159 |
{
|
sl@0
|
160 |
TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_USAGE, iStatus.Int()));
|
sl@0
|
161 |
}
|
sl@0
|
162 |
break;
|
sl@0
|
163 |
default:
|
sl@0
|
164 |
{
|
sl@0
|
165 |
TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_KEYTOOL_ERR_IMPORT, iStatus.Int()));
|
sl@0
|
166 |
}
|
sl@0
|
167 |
}
|
sl@0
|
168 |
return KErrNone;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
|
sl@0
|
172 |
void CKeytoolImport::DoCancel()
|
sl@0
|
173 |
{
|
sl@0
|
174 |
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
CKeytoolImport::CKeytoolImport(CController* aController) : CKeyToolCommand(aController)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|