39
|
1 |
/*
|
|
2 |
* Copyright (c) 2005 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 "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: Implementation of CDevEncUiEncryptionOperator.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include <DevEncExternalCRKeys.h>
|
|
20 |
// Class includes
|
|
21 |
#include "DevEncLog.h"
|
|
22 |
#include "DevEncUids.hrh"
|
|
23 |
#include "DevEncUiEncryptionOperator.h"
|
|
24 |
|
|
25 |
#include "DevEncUiFileManager.h"
|
|
26 |
|
|
27 |
//System includes
|
|
28 |
#include <aknmessagequerydialog.h>
|
|
29 |
#include <aknViewAppUi.h>
|
|
30 |
#include <AknWaitNoteWrapper.h>
|
|
31 |
#include <aknnotewrappers.h> // for CAknErrorNote
|
|
32 |
#include <bautils.h> // For BAFL, localized resource files
|
|
33 |
#include <centralrepository.h>
|
|
34 |
#include <coemain.h>
|
|
35 |
#include <data_caging_path_literals.hrh> // for resource files dir
|
|
36 |
#include <devencui.rsg>
|
|
37 |
#include <eikenv.h>
|
|
38 |
#include <e32property.h>
|
|
39 |
#include <etelmm.h>
|
|
40 |
#include <f32file.h>
|
|
41 |
#include <gsfwviewuids.h> // For general settings view UIDs (autolock)
|
|
42 |
#include <hwrmpowerstatesdkpskeys.h> // For power state
|
|
43 |
#include <secuisecuritysettings.h> // for autolock
|
|
44 |
#include <settingsinternalcrkeys.h>
|
|
45 |
#include <StringLoader.h>
|
|
46 |
#include <utf.h> // For character conversion
|
|
47 |
#include <TerminalControl3rdPartyAPI.h>
|
|
48 |
|
|
49 |
#include <DevEncKeyUtils.h>
|
|
50 |
|
|
51 |
//User includes
|
|
52 |
#include "DevEncLog.h"
|
|
53 |
#include "DevEnc.hrh"
|
|
54 |
#include "DevEncUiCreateKeyProcess.h"
|
|
55 |
#include "DevEncDef.h"
|
|
56 |
#include "DevEncUiMemoryEntity.h"
|
|
57 |
#include "DevEncUiSecretMinMaxCodeQuery.h"
|
|
58 |
//for KMaxAutolockPeriod = 20;
|
|
59 |
#include "DevEncSession.h"
|
|
60 |
|
|
61 |
// --------------------------------------------------------------------------
|
|
62 |
// CDevEncUiEncryptionOperator::~CDevEncUiEncryptionOperator
|
|
63 |
//
|
|
64 |
// --------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
CDevEncUiEncryptionOperator::~CDevEncUiEncryptionOperator()
|
|
67 |
{
|
|
68 |
}
|
|
69 |
|
|
70 |
// --------------------------------------------------------------------------
|
|
71 |
// CDevEncUiEncryptionOperator::NewL
|
|
72 |
//
|
|
73 |
// --------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
CDevEncUiEncryptionOperator* CDevEncUiEncryptionOperator::NewL( CEikonEnv& aEikonEnv,
|
|
76 |
CAknViewAppUi& aAppUi,
|
|
77 |
CRepository*& aCrSettings )
|
|
78 |
{
|
|
79 |
CDevEncUiEncryptionOperator* self =
|
|
80 |
CDevEncUiEncryptionOperator::NewLC( aEikonEnv,
|
|
81 |
aAppUi,
|
|
82 |
aCrSettings );
|
|
83 |
CleanupStack::Pop( self );
|
|
84 |
return self;
|
|
85 |
}
|
|
86 |
|
|
87 |
// --------------------------------------------------------------------------
|
|
88 |
// CDevEncUiEncryptionOperator::NewLC
|
|
89 |
//
|
|
90 |
// --------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
CDevEncUiEncryptionOperator* CDevEncUiEncryptionOperator::NewLC( CEikonEnv& aEikonEnv,
|
|
93 |
CAknViewAppUi& aAppUi,
|
|
94 |
CRepository*& aCrSettings )
|
|
95 |
{
|
|
96 |
CDevEncUiEncryptionOperator* self =
|
|
97 |
new ( ELeave ) CDevEncUiEncryptionOperator( aEikonEnv,
|
|
98 |
aAppUi,
|
|
99 |
aCrSettings );
|
|
100 |
CleanupStack::PushL( self );
|
|
101 |
self->ConstructL();
|
|
102 |
return self;
|
|
103 |
}
|
|
104 |
|
|
105 |
// --------------------------------------------------------------------------
|
|
106 |
// CDevEncUiEncryptionOperator::CDevEncUiEncryptionOperator
|
|
107 |
//
|
|
108 |
// --------------------------------------------------------------------------
|
|
109 |
//
|
|
110 |
CDevEncUiEncryptionOperator::CDevEncUiEncryptionOperator( CEikonEnv& aEikonEnv,
|
|
111 |
CAknViewAppUi& aAppUi,
|
|
112 |
CRepository*& aCrSettings )
|
|
113 |
: iEikEnv( aEikonEnv ),
|
|
114 |
iAppUi( aAppUi ),
|
|
115 |
iCrSettings( aCrSettings )
|
|
116 |
{
|
|
117 |
}
|
|
118 |
|
|
119 |
// --------------------------------------------------------------------------
|
|
120 |
// CDevEncUiEncryptionOperator::ConstructL
|
|
121 |
//
|
|
122 |
// --------------------------------------------------------------------------
|
|
123 |
//
|
|
124 |
void CDevEncUiEncryptionOperator::ConstructL()
|
|
125 |
{
|
|
126 |
}
|
|
127 |
|
|
128 |
// --------------------------------------------------------------------------
|
|
129 |
// CDevEncUiEncryptionOperator::HandlePhoneMemEncryptRequestL()
|
|
130 |
// --------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
void CDevEncUiEncryptionOperator::HandlePhoneMemEncryptRequestL( CDevEncUiMemoryEntity* aMem, CDevEncUiMemoryEntity* aPrimaryMem )
|
|
133 |
{
|
|
134 |
// Check the battery level first
|
|
135 |
if ( ! CheckBatteryL() )
|
|
136 |
{
|
|
137 |
// The battery level is too low and no charger is connected.
|
|
138 |
// Show a note to the user.
|
|
139 |
ErrorNoteL( R_DEVENCUI_TEXT_BATTERY_LOW );
|
|
140 |
User::Leave( KErrNotReady );
|
|
141 |
}
|
|
142 |
|
|
143 |
if ( (aMem->State() == EDecrypted) || (aPrimaryMem && (aPrimaryMem->State() == EDecrypted)) )
|
|
144 |
{
|
|
145 |
// Encryption is off -> encrypt
|
|
146 |
if ( PrepareEncryptionL() )
|
|
147 |
{
|
|
148 |
if ( aMem->State() == EDecrypted )
|
|
149 |
{
|
|
150 |
DFLOG( "Starting Mass Storage encryption" );
|
|
151 |
aMem->StartEncryptionL();
|
|
152 |
}
|
|
153 |
if( aPrimaryMem && (aPrimaryMem->State() == EDecrypted) )
|
|
154 |
{
|
|
155 |
DFLOG( "Starting phone memory encryption" );
|
|
156 |
aPrimaryMem->StartEncryptionL();
|
|
157 |
}
|
|
158 |
}
|
|
159 |
else
|
|
160 |
{
|
|
161 |
DFLOG( "Encryption cancelled" );
|
|
162 |
}
|
|
163 |
}
|
|
164 |
else if ( (aMem->State() == EEncrypted) || (aPrimaryMem && (aPrimaryMem->State() == EEncrypted)) )
|
|
165 |
{
|
|
166 |
if ( PrepareDecryptionL() )
|
|
167 |
{
|
|
168 |
if ( aMem->State() == EEncrypted )
|
|
169 |
{
|
|
170 |
DFLOG( "Starting Mass Storage decryption" );
|
|
171 |
aMem->StartDecryptionL();
|
|
172 |
}
|
|
173 |
if( aPrimaryMem && (aPrimaryMem->State() == EEncrypted) )
|
|
174 |
{
|
|
175 |
DFLOG( "Starting phone memory decryption" );
|
|
176 |
aPrimaryMem->StartDecryptionL();
|
|
177 |
}
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
DFLOG( "Decryption cancelled" );
|
|
182 |
}
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
DFLOG2( "Phone memory busy, state = %d, no action", aMem->State() );
|
|
187 |
}
|
|
188 |
|
|
189 |
// Depending on the user's selection, the memory may be in the same
|
|
190 |
// state as before or in a new state. This call will let all observers
|
|
191 |
// know what state the memory ended up in.
|
|
192 |
aMem->UpdateMemoryInfo();
|
|
193 |
}
|
|
194 |
|
|
195 |
// --------------------------------------------------------------------------
|
|
196 |
// CDevEncUiEncryptionOperator::PrepareEncryptionL()
|
|
197 |
// --------------------------------------------------------------------------
|
|
198 |
//
|
|
199 |
TBool CDevEncUiEncryptionOperator::PrepareEncryptionL()
|
|
200 |
{
|
|
201 |
TBool result( EFalse );
|
|
202 |
|
|
203 |
// Show the confirmation query about autolock
|
|
204 |
CAknMessageQueryDialog* yesNoQuery = new ( ELeave ) CAknMessageQueryDialog;
|
|
205 |
if ( ! yesNoQuery->ExecuteLD( R_DEVENCUI_ENCRYPT_CONFIRMATION_QUERY_DIALOG ) )
|
|
206 |
{
|
|
207 |
// User answered no. Do nothing
|
|
208 |
DFLOG( "User cancelled after autolock warning. No action." );
|
|
209 |
return result;
|
|
210 |
}
|
|
211 |
|
|
212 |
// Autolock must be on before encryption can be enabled.
|
|
213 |
// Get the current autolock status and the current max autolock period
|
|
214 |
TInt lockTime = 0;
|
|
215 |
TBuf8<21> autoLockPeriodBuf;
|
|
216 |
|
|
217 |
RTerminalControl terminalCtrl;
|
|
218 |
TInt ctrlConnect = terminalCtrl.Connect();
|
|
219 |
DFLOG2( "DEVENC: terminal control connected %d", ctrlConnect );
|
|
220 |
|
|
221 |
RTerminalControl3rdPartySession session;
|
|
222 |
TInt retValue = session.Open( terminalCtrl );
|
|
223 |
DFLOG2( "DEVENC: terminal control session open %d", retValue );
|
|
224 |
|
|
225 |
TInt err2 = session.GetDeviceLockParameter( RTerminalControl3rdPartySession::ETimeout, autoLockPeriodBuf );
|
|
226 |
DFLOG2( "DEVENC: max value get returned value %d", err2 );
|
|
227 |
|
|
228 |
TLex8 lexAutolock( autoLockPeriodBuf );
|
|
229 |
lexAutolock.Val( lockTime );
|
|
230 |
DFLOG2( "lockTime = %d", lockTime );
|
|
231 |
|
|
232 |
//Get current max autolock period
|
|
233 |
TBuf8<21> oldMaxPeriodBuf;
|
|
234 |
TInt maxperioderr = session.GetDeviceLockParameter( RTerminalControl3rdPartySession::EMaxTimeout, oldMaxPeriodBuf );
|
|
235 |
DFLOG2( "DEVENC: max value set returned value %d", maxperioderr );
|
|
236 |
|
|
237 |
#ifndef __WINS__
|
|
238 |
// Setting the autolock works only in target
|
|
239 |
|
|
240 |
if ( lockTime == 0 )
|
|
241 |
{
|
|
242 |
// Autolock disabled. Go to the autolock settings
|
|
243 |
DFLOG( "Autolock currently disabled, going to settings" );
|
|
244 |
|
|
245 |
// Create the filename of the SecUi resource file
|
|
246 |
_LIT( KFileDrive, "z:" );
|
|
247 |
_LIT( KSecUiResourceFileName, "SecUi.rsc" );
|
|
248 |
TFileName filename;
|
|
249 |
filename += KFileDrive;
|
|
250 |
filename += KDC_RESOURCE_FILES_DIR;
|
|
251 |
filename += KSecUiResourceFileName;
|
|
252 |
|
|
253 |
// Convert to a localized resource filename if possible
|
|
254 |
RFs fs;
|
|
255 |
User::LeaveIfError( fs.Connect() );
|
|
256 |
BaflUtils::NearestLanguageFile( fs, filename );
|
|
257 |
|
|
258 |
// Load the SecUi resource file
|
|
259 |
TInt rfileOffset( 0 );
|
|
260 |
TRAPD( err, rfileOffset = iEikEnv.AddResourceFileL( filename ) );
|
|
261 |
if ( err )
|
|
262 |
{
|
|
263 |
DFLOG2( "Add resource file error %d", err );
|
|
264 |
}
|
|
265 |
User::LeaveIfError( err );
|
|
266 |
|
|
267 |
// Set maximum autolock period
|
|
268 |
|
|
269 |
TBuf8<21> maxPeriodBuf;
|
|
270 |
maxPeriodBuf.AppendNum( KMaxAutolockPeriod );
|
|
271 |
TInt err3 = session.SetDeviceLockParameter( RTerminalControl3rdPartySession::EMaxTimeout, maxPeriodBuf );
|
|
272 |
DFLOG2( "DEVENC: max value set returned value %d", err3 );
|
|
273 |
|
|
274 |
// Let the user set an autolock period
|
|
275 |
CSecuritySettings* secSett = CSecuritySettings::NewL();
|
|
276 |
CleanupStack::PushL( secSett );
|
|
277 |
TInt newLockTime = secSett->ChangeAutoLockPeriodL( lockTime );
|
|
278 |
CleanupStack::PopAndDestroy( secSett );
|
|
279 |
|
|
280 |
iEikEnv.DeleteResourceFile( rfileOffset );
|
|
281 |
|
|
282 |
if ( newLockTime == 0 )
|
|
283 |
{
|
|
284 |
// User cancelled or set autolock off -> do nothing
|
|
285 |
DFLOG( "User selected not to enable autolock. No action." );
|
|
286 |
|
|
287 |
//restore the old maximum period value
|
|
288 |
TInt err3 = session.SetDeviceLockParameter( RTerminalControl3rdPartySession::EMaxTimeout, oldMaxPeriodBuf );
|
|
289 |
DFLOG2( "DEVENC: max value set returned value %d", err3 );
|
|
290 |
|
|
291 |
//the autolock period is now at KMaxAutolockPeriod( =20 ) so we have to set it as it was previously
|
|
292 |
err3 = session.SetDeviceLockParameter( RTerminalControl3rdPartySession::ETimeout, autoLockPeriodBuf );
|
|
293 |
DFLOG2( "DEVENC: max value set returned value %d", err3 );
|
|
294 |
|
|
295 |
session.Close();
|
|
296 |
terminalCtrl.Close();
|
|
297 |
return result;
|
|
298 |
}
|
|
299 |
|
|
300 |
TBuf8<21> newLockTimeBuf;
|
|
301 |
newLockTimeBuf.AppendNum( newLockTime );
|
|
302 |
|
|
303 |
TInt setResult = session.SetDeviceLockParameter( RTerminalControl3rdPartySession::ETimeout, newLockTimeBuf );
|
|
304 |
if ( setResult )
|
|
305 |
{
|
|
306 |
// TBI: Log the failure and leave with error
|
|
307 |
DFLOG2( "ERROR: session.SetDeviceLockParameter( RTerminalControl3rdPartySession::ETimeout, .. ) returned %d", setResult );
|
|
308 |
session.Close();
|
|
309 |
terminalCtrl.Close();
|
|
310 |
return result;
|
|
311 |
}
|
|
312 |
lockTime = newLockTime;
|
|
313 |
}
|
|
314 |
else
|
|
315 |
{
|
|
316 |
DFLOG( "Autolock already enabled. Set only the current maximum period" );
|
|
317 |
|
|
318 |
//By setting the max autolock period the autolock period is set to max if it was greater than that
|
|
319 |
TBuf8<21> maxPeriodBuf;
|
|
320 |
maxPeriodBuf.AppendNum( KMaxAutolockPeriod );
|
|
321 |
TInt err3 = session.SetDeviceLockParameter( RTerminalControl3rdPartySession::EMaxTimeout, maxPeriodBuf );
|
|
322 |
DFLOG2( "DEVENC: max value set returned value %d", err3 );
|
|
323 |
}
|
|
324 |
#endif // __WINS__
|
|
325 |
|
|
326 |
DFLOG2( "Autolock time is %d", lockTime );
|
|
327 |
|
|
328 |
// Autolock is now enabled, so we can proceed with the encryption
|
|
329 |
// Warn the user about the long encryption process
|
|
330 |
if ( MessageQueryL( R_DEVENCUI_TEXT_NOTE_ENCRYPTING ) )
|
|
331 |
{
|
|
332 |
result = ETrue;
|
|
333 |
DFLOG( "Starting encryption" );
|
|
334 |
}
|
|
335 |
else
|
|
336 |
{
|
|
337 |
DFLOG( "Encryption cancelled" );
|
|
338 |
//the encryption was cancelled. Let's set the old autolock values
|
|
339 |
//restore the old maximum period value
|
|
340 |
TInt err3 = session.SetDeviceLockParameter( RTerminalControl3rdPartySession::EMaxTimeout, oldMaxPeriodBuf );
|
|
341 |
DFLOG2( "DEVENC: max value set returned value %d", err3 );
|
|
342 |
|
|
343 |
//the autolock period is now at KMaxAutolockPeriod( =20 ) so we have to set it as it was previously
|
|
344 |
err3 = session.SetDeviceLockParameter( RTerminalControl3rdPartySession::ETimeout, autoLockPeriodBuf );
|
|
345 |
DFLOG2( "DEVENC: max value set returned value %d", err3 );
|
|
346 |
}
|
|
347 |
|
|
348 |
session.Close();
|
|
349 |
terminalCtrl.Close();
|
|
350 |
|
|
351 |
return result;
|
|
352 |
}
|
|
353 |
|
|
354 |
// --------------------------------------------------------------------------
|
|
355 |
// CDevEncUiEncryptionOperator::PrepareDecryptionL()
|
|
356 |
// --------------------------------------------------------------------------
|
|
357 |
//
|
|
358 |
TBool CDevEncUiEncryptionOperator::PrepareDecryptionL()
|
|
359 |
{
|
|
360 |
// Warn the user about the long decryption process
|
|
361 |
return MessageQueryL( R_DEVENCUI_TEXT_NOTE_PHONE_DECRYPTING );
|
|
362 |
}
|
|
363 |
|
|
364 |
// --------------------------------------------------------------------------
|
|
365 |
// CDevEncUiEncryptionOperator::MessageQueryL()
|
|
366 |
// --------------------------------------------------------------------------
|
|
367 |
//
|
|
368 |
TBool CDevEncUiEncryptionOperator::MessageQueryL( TInt aResourceId,
|
|
369 |
TInt aSoftKeysId )
|
|
370 |
{
|
|
371 |
TBool result( EFalse );
|
|
372 |
|
|
373 |
// Show a message query with OK and Cancel buttons and the specified text
|
|
374 |
CAknMessageQueryDialog* query =
|
|
375 |
new ( ELeave ) CAknMessageQueryDialog;
|
|
376 |
query->PrepareLC( R_DEVENCUI_ENCRYPT_CONFIRMATION_QUERY_DIALOG );
|
|
377 |
query->ButtonGroupContainer().SetCommandSetL( aSoftKeysId );
|
|
378 |
HBufC* prompt = StringLoader::LoadLC( aResourceId, &iEikEnv );
|
|
379 |
query->SetMessageTextL( *prompt );
|
|
380 |
CleanupStack::PopAndDestroy( prompt );
|
|
381 |
if ( query->RunLD() )
|
|
382 |
{
|
|
383 |
result = ETrue;
|
|
384 |
}
|
|
385 |
return result;
|
|
386 |
}
|
|
387 |
|
|
388 |
// --------------------------------------------------------------------------
|
|
389 |
// CDevEncUiEncryptionOperator::QueryDialog()
|
|
390 |
// --------------------------------------------------------------------------
|
|
391 |
//
|
|
392 |
TBool CDevEncUiEncryptionOperator::QueryDialogL( TInt aResourceId,
|
|
393 |
TInt aSoftKeysId )
|
|
394 |
{
|
|
395 |
TBool result( EFalse );
|
|
396 |
CAknQueryDialog* query = CAknQueryDialog::NewL();
|
|
397 |
query->PrepareLC( R_DEVENCUI_CONFIRMATION_QUERY ); // CleanupStack OK
|
|
398 |
HBufC* prompt = StringLoader::LoadLC( aResourceId, &iEikEnv );
|
|
399 |
query->SetPromptL( *prompt );
|
|
400 |
query->ButtonGroupContainer().SetCommandSetL( aSoftKeysId );
|
|
401 |
|
|
402 |
CleanupStack::PopAndDestroy( prompt );
|
|
403 |
if ( query->RunLD() )
|
|
404 |
{
|
|
405 |
result = ETrue;
|
|
406 |
}
|
|
407 |
return result;
|
|
408 |
}
|
|
409 |
|
|
410 |
// --------------------------------------------------------------------------
|
|
411 |
// CDevEncUiEncryptionOperator::DataQueryDialogL()
|
|
412 |
// --------------------------------------------------------------------------
|
|
413 |
//
|
|
414 |
TBool CDevEncUiEncryptionOperator::DataQueryDialogL( TDes& aResult,
|
|
415 |
TInt aPromptResourceId,
|
|
416 |
TInt aMaxLength )
|
|
417 |
{
|
|
418 |
// The descriptor contained the prompt text for the query. The prompt
|
|
419 |
// text can also be defined in the resource structure of the query
|
|
420 |
HBufC* prompt = StringLoader::LoadLC( aPromptResourceId, &iEikEnv );
|
|
421 |
|
|
422 |
// create dialog instance
|
|
423 |
CAknTextQueryDialog* dlg =
|
|
424 |
new( ELeave ) CAknTextQueryDialog( aResult, *prompt );
|
|
425 |
|
|
426 |
CleanupStack::PopAndDestroy( prompt );
|
|
427 |
|
|
428 |
// Sets the maximum length of the text editor
|
|
429 |
dlg->SetMaxLength( aMaxLength );
|
|
430 |
|
|
431 |
// Prepares the dialog, constructing it from the specified resource
|
|
432 |
dlg->PrepareLC( R_DEVENCUI_DATA_QUERY );
|
|
433 |
|
|
434 |
// Launch the dialog
|
|
435 |
return dlg->RunLD();
|
|
436 |
}
|
|
437 |
|
|
438 |
// --------------------------------------------------------------------------
|
|
439 |
// CDevEncUiEncryptionOperator::HandleMmcEncryptRequestL()
|
|
440 |
// --------------------------------------------------------------------------
|
|
441 |
//
|
|
442 |
void CDevEncUiEncryptionOperator::HandleMmcEncryptRequestL( CDevEncUiMemoryEntity* aMem,
|
|
443 |
TInt aCommand )
|
|
444 |
{
|
|
445 |
// Check the battery level first
|
|
446 |
if ( ! CheckBatteryL() )
|
|
447 |
{
|
|
448 |
// The battery level is too low and no charger is connected.
|
|
449 |
// Show a note to the user.
|
|
450 |
ErrorNoteL( R_DEVENCUI_TEXT_BATTERY_LOW );
|
|
451 |
User::Leave( KErrNotReady );
|
|
452 |
}
|
|
453 |
|
|
454 |
TBool proceed( EFalse );
|
|
455 |
switch ( aCommand )
|
|
456 |
{
|
|
457 |
case EDevEncUiCommandEncryptWithRestoredKey:
|
|
458 |
{
|
|
459 |
DFLOG( "Encrypt with restored key selected" );
|
|
460 |
proceed = LoadAndSetKeyL(); // No cleanup stack needed
|
|
461 |
break;
|
|
462 |
}
|
|
463 |
|
|
464 |
case EDevEncUiCommandEncryptAndSaveKey:
|
|
465 |
{
|
|
466 |
DFLOG( "Encrypt and save key selected" );
|
|
467 |
proceed = CreateAndSaveKeyL(); // No cleanup stack needed
|
|
468 |
if( proceed )
|
|
469 |
{
|
|
470 |
InfoNoteL( R_DEVENCUI_TEXT_NOTE_SAVEINFO, ETrue );
|
|
471 |
DFLOG( "Key saved succesfully" );
|
|
472 |
}
|
|
473 |
break;
|
|
474 |
}
|
|
475 |
|
|
476 |
case EDevEncUiCommandEncryptWithoutSavingKey:
|
|
477 |
{
|
|
478 |
DFLOG( "Encrypt without saving key selected" );
|
|
479 |
// Create an encryption key and take it in use
|
|
480 |
// The key will remain in the driver until the next key is set,
|
|
481 |
// and it can not be retrieved.
|
|
482 |
proceed = CreateKeyL(); // No cleanup stack needed
|
|
483 |
break;
|
|
484 |
}
|
|
485 |
|
|
486 |
case EDevEncUiCommandEncryptWithCurrentKey:
|
|
487 |
{
|
|
488 |
DFLOG( "Encrypt with current key selected" );
|
|
489 |
proceed = ETrue;
|
|
490 |
}
|
|
491 |
|
|
492 |
default:
|
|
493 |
{
|
|
494 |
DFLOG( "Invalid command" );
|
|
495 |
break;
|
|
496 |
}
|
|
497 |
}
|
|
498 |
|
|
499 |
if ( aMem->State() == EUnmounted )
|
|
500 |
{
|
|
501 |
if( !proceed )
|
|
502 |
{
|
|
503 |
// The encryption operation was cancelled, just go back to encryption view
|
|
504 |
DFLOG( "No Mmc present and operation was cancelled -> no encryption" );
|
|
505 |
}
|
|
506 |
else
|
|
507 |
{
|
|
508 |
// The encryption operation was succesfull, go back to main view
|
|
509 |
iAppUi.ActivateLocalViewL( TUid::Uid( EDevEncUiMainViewId ) );
|
|
510 |
proceed = EFalse;
|
|
511 |
DFLOG( "No Mmc present -> no encryption" );
|
|
512 |
}
|
|
513 |
}
|
|
514 |
|
|
515 |
if ( aMem->State() == ECorrupted )
|
|
516 |
{
|
|
517 |
if( !proceed )
|
|
518 |
{
|
|
519 |
DFLOG( "Mmc probably enc with another key -> wait for remount" );
|
|
520 |
}
|
|
521 |
else
|
|
522 |
{
|
|
523 |
// Mmc was probably encrypted with another key. We have just set a
|
|
524 |
// new key, so now we have to wait until the state changes and hope
|
|
525 |
// that the card is readable. If it is, a note will be shown to the
|
|
526 |
// user. (See UI spec 2.7)
|
|
527 |
InfoNoteL( R_DEVENCUI_TEXT_NOTE_MEMORYCARD_ENCRYPTED, ETrue );
|
|
528 |
iAppUi.ActivateLocalViewL( TUid::Uid( EDevEncUiMainViewId ) );
|
|
529 |
proceed = EFalse;
|
|
530 |
DFLOG( "Mmc probably enc with another key -> wait for remount" );
|
|
531 |
RemountMmcL();
|
|
532 |
}
|
|
533 |
}
|
|
534 |
|
|
535 |
if ( proceed )
|
|
536 |
{
|
|
537 |
TInt encrypt( 0 );
|
|
538 |
|
|
539 |
// Check DM admin status
|
|
540 |
TInt dmControlSetting( 0 );
|
|
541 |
iCrSettings->Get( KDevEncUiDmControl, dmControlSetting );
|
|
542 |
|
|
543 |
if( ( dmControlSetting & KDmControlsMemoryCard ) && ( aCommand == EDevEncUiCommandEncryptWithCurrentKey ) )
|
|
544 |
{
|
|
545 |
//if the DM admin is controlling the encryption, encrypt straight away
|
|
546 |
encrypt = ETrue;
|
|
547 |
}
|
|
548 |
else
|
|
549 |
{
|
|
550 |
encrypt = MessageQueryL( R_DEVENCUI_TEXT_NOTE_ENCRYPTING );
|
|
551 |
}
|
|
552 |
|
|
553 |
// Warn the user about the long encryption process
|
|
554 |
if ( encrypt )
|
|
555 |
{
|
|
556 |
// Start the encryption
|
|
557 |
DFLOG( "Starting encryption" );
|
|
558 |
aMem->StartEncryptionL();
|
|
559 |
// Go back to main view
|
|
560 |
iAppUi.ActivateLocalViewL( TUid::Uid( EDevEncUiMainViewId ) );
|
|
561 |
}
|
|
562 |
else
|
|
563 |
{
|
|
564 |
DFLOG( "Encryption cancelled" );
|
|
565 |
// Stay in the Encryption view
|
|
566 |
// Show a note to the user about that the new key is in use,
|
|
567 |
// but the card is still decrypted (UI spec 2.3)
|
|
568 |
InfoNoteL( R_DEVENCUI_TEXT_NOTE_ENCRYPTIONINTERRUPT, ETrue );
|
|
569 |
iAppUi.ActivateLocalViewL( TUid::Uid( EDevEncUiMainViewId ) );
|
|
570 |
}
|
|
571 |
}
|
|
572 |
|
|
573 |
// Depending on the user's selection, the memory may be in the same
|
|
574 |
// state as before or in a new state. This call will let all observers
|
|
575 |
// know what state the memory ended up in.
|
|
576 |
aMem->UpdateMemoryInfo();
|
|
577 |
}
|
|
578 |
|
|
579 |
// --------------------------------------------------------------------------
|
|
580 |
// CDevEncUiEncryptionOperator::CreateKeyL()
|
|
581 |
// --------------------------------------------------------------------------
|
|
582 |
//
|
|
583 |
TBool CDevEncUiEncryptionOperator::CreateKeyL()
|
|
584 |
{
|
|
585 |
TBool proceed( EFalse );
|
|
586 |
CDevEncKeyUtils* utils = new ( ELeave ) CDevEncKeyUtils;
|
|
587 |
CleanupStack::PushL( utils );
|
|
588 |
// User::LeaveIfError(utils->Connect());
|
|
589 |
TRequestStatus status;
|
|
590 |
utils->CreateSetKey( status, KEncryptionKeyLength );
|
|
591 |
User::WaitForRequest( status );
|
|
592 |
// utils->Close();
|
|
593 |
CleanupStack::PopAndDestroy( utils );
|
|
594 |
if ( ! status.Int() )
|
|
595 |
{
|
|
596 |
// Save the Mmc encryption key status
|
|
597 |
User::LeaveIfError( iCrSettings->Set( KDevEncUserSettingMemoryCard,
|
|
598 |
ETrue ) );
|
|
599 |
proceed = ETrue;
|
|
600 |
}
|
|
601 |
return proceed;
|
|
602 |
}
|
|
603 |
|
|
604 |
// --------------------------------------------------------------------------
|
|
605 |
// CDevEncUiEncryptionOperator::CreateAndSaveKeyL()
|
|
606 |
// --------------------------------------------------------------------------
|
|
607 |
//
|
|
608 |
TBool CDevEncUiEncryptionOperator::CreateAndSaveKeyL()
|
|
609 |
{
|
|
610 |
TBool proceed( EFalse );
|
|
611 |
|
|
612 |
TBool passwordOk( EFalse );
|
|
613 |
TBool keyFileNameOk( EFalse );
|
|
614 |
TBool keyCreated( EFalse );
|
|
615 |
TBool keySaved( EFalse );
|
|
616 |
CFileStore* file( NULL );
|
|
617 |
HBufC* keyFileName = HBufC::NewLC( KMaxFilenameLength );
|
|
618 |
|
|
619 |
// Get the key password from the user
|
|
620 |
HBufC8* password = HBufC8::NewLC( KMaxPasswordLength );
|
|
621 |
TPtr8 passwordPtr = password->Des();
|
|
622 |
passwordOk = PasswordQueryL( R_DEVENCUI_TEXT_PASSPHRASE_PROTECT,
|
|
623 |
passwordPtr );
|
|
624 |
|
|
625 |
CDevEncUiFileManager* fm = new ( ELeave ) CDevEncUiFileManager;
|
|
626 |
CleanupStack::PushL( fm );
|
|
627 |
fm->ConstructL();
|
|
628 |
|
|
629 |
HBufC8* pkcs5Key( NULL );
|
|
630 |
|
|
631 |
if ( passwordOk )
|
|
632 |
{
|
|
633 |
DFLOG( "Password entered" );
|
|
634 |
// The user entered the correct password
|
|
635 |
|
|
636 |
// Construct file path
|
|
637 |
_LIT( KDevEncKeyFileExtension, ".pk5");
|
|
638 |
TBuf<KMaxFileName> filePath;
|
|
639 |
User::LeaveIfError( fm->KeyFolder( filePath ) );
|
|
640 |
TInt pathLen( filePath.Length() );
|
|
641 |
|
|
642 |
// Get the key file name from the user
|
|
643 |
TBool filenameEntered( EFalse );
|
|
644 |
TBool cancelPressed( EFalse );
|
|
645 |
TPtr16 keyFileNamePtr = keyFileName->Des();
|
|
646 |
while ( ( ! cancelPressed ) && ( ! file ) )
|
|
647 |
{
|
|
648 |
filenameEntered = DataQueryDialogL( keyFileNamePtr,
|
|
649 |
R_DEVENCUI_TEXT_FILENAME,
|
|
650 |
KMaxFilenameLength );
|
|
651 |
if ( !filenameEntered )
|
|
652 |
{
|
|
653 |
// User pressed cancel, stop here
|
|
654 |
cancelPressed = ETrue;
|
|
655 |
}
|
|
656 |
else
|
|
657 |
{
|
|
658 |
// User entered a file name. Try to open a file store
|
|
659 |
filePath.Append( keyFileNamePtr );
|
|
660 |
filePath.Append( KDevEncKeyFileExtension );
|
|
661 |
TInt openError = fm->OpenFileStore( filePath,
|
|
662 |
file );
|
|
663 |
if ( openError )
|
|
664 |
{
|
|
665 |
DFLOG2( "Error opening file: %d", openError );
|
|
666 |
|
|
667 |
// Notify the user that something went wrong
|
|
668 |
if ( openError == KErrAlreadyExists )
|
|
669 |
{
|
|
670 |
ErrorNoteL( R_DEVENCUI_TEXT_FILE_EXISTS );
|
|
671 |
}
|
|
672 |
else
|
|
673 |
{
|
|
674 |
ErrorNoteL( R_DEVENCUI_TEXT_BAD_NAME );
|
|
675 |
}
|
|
676 |
|
|
677 |
// Remove the file name from the path and try again
|
|
678 |
filePath.Delete( pathLen, filePath.Length() - pathLen );
|
|
679 |
}
|
|
680 |
else
|
|
681 |
{
|
|
682 |
DFLOG( "File opened:" );
|
|
683 |
DFLOGBUF( filePath );
|
|
684 |
keyFileNameOk = ETrue;
|
|
685 |
CleanupStack::PushL( file );
|
|
686 |
}
|
|
687 |
}
|
|
688 |
} // end of while
|
|
689 |
}
|
|
690 |
else
|
|
691 |
{
|
|
692 |
DFLOG( "Password incorrect" );
|
|
693 |
}
|
|
694 |
|
|
695 |
if ( keyFileNameOk )
|
|
696 |
{
|
|
697 |
// Create the encryption key
|
|
698 |
CDevEncKeyUtils* utils = new ( ELeave ) CDevEncKeyUtils;
|
|
699 |
CleanupStack::PushL( utils );
|
|
700 |
// User::LeaveIfError(utils->Connect());
|
|
701 |
|
|
702 |
TRequestStatus status;
|
|
703 |
utils->CreateSetKey( status, pkcs5Key, *password, KEncryptionKeyLength );
|
|
704 |
User::WaitForRequest( status );
|
|
705 |
// utils->Close();
|
|
706 |
CleanupStack::PopAndDestroy( utils );
|
|
707 |
|
|
708 |
if ( status.Int() )
|
|
709 |
{
|
|
710 |
DFLOG2( "Error creating key: %d", status.Int() );
|
|
711 |
}
|
|
712 |
else
|
|
713 |
{
|
|
714 |
keyCreated = ETrue;
|
|
715 |
CleanupStack::PushL( pkcs5Key );
|
|
716 |
// Save the Mmc encryption key status
|
|
717 |
User::LeaveIfError( iCrSettings->Set( KDevEncUserSettingMemoryCard,
|
|
718 |
ETrue ) );
|
|
719 |
}
|
|
720 |
}
|
|
721 |
|
|
722 |
if ( keyCreated )
|
|
723 |
{
|
|
724 |
// Save the key
|
|
725 |
fm->SaveKeyL( file, *pkcs5Key );
|
|
726 |
CleanupStack::PopAndDestroy( pkcs5Key );
|
|
727 |
keySaved = ETrue;
|
|
728 |
}
|
|
729 |
|
|
730 |
if ( keySaved )
|
|
731 |
{
|
|
732 |
// Finally, start the encryption
|
|
733 |
proceed = ETrue;
|
|
734 |
}
|
|
735 |
|
|
736 |
// Cleanup on demand
|
|
737 |
if ( file )
|
|
738 |
{
|
|
739 |
CleanupStack::PopAndDestroy( file );
|
|
740 |
}
|
|
741 |
if ( fm )
|
|
742 |
{
|
|
743 |
CleanupStack::PopAndDestroy( fm );
|
|
744 |
}
|
|
745 |
if ( password )
|
|
746 |
{
|
|
747 |
CleanupStack::PopAndDestroy( password );
|
|
748 |
}
|
|
749 |
if ( keyFileName )
|
|
750 |
{
|
|
751 |
CleanupStack::PopAndDestroy( keyFileName );
|
|
752 |
}
|
|
753 |
|
|
754 |
return proceed;
|
|
755 |
}
|
|
756 |
|
|
757 |
// --------------------------------------------------------------------------
|
|
758 |
// CDevEncUiEncryptionOperator::LoadAndSetKeyL()
|
|
759 |
// --------------------------------------------------------------------------
|
|
760 |
//
|
|
761 |
TBool CDevEncUiEncryptionOperator::LoadAndSetKeyL()
|
|
762 |
{
|
|
763 |
TBool proceed( EFalse );
|
|
764 |
|
|
765 |
TBool keySelected( EFalse );
|
|
766 |
TBool passwordOk( EFalse );
|
|
767 |
TBool askPassword( ETrue );
|
|
768 |
HBufC8* pkcs5Key( NULL );
|
|
769 |
TBuf8<KMaxPasswordLength> password8;
|
|
770 |
|
|
771 |
// Get a list of existing keys in the private directory
|
|
772 |
CDevEncUiFileManager* fm = new ( ELeave ) CDevEncUiFileManager;
|
|
773 |
CleanupStack::PushL( fm );
|
|
774 |
fm->ConstructL();
|
|
775 |
CDir* dir( NULL );
|
|
776 |
fm->GetKeyListL( dir );
|
|
777 |
|
|
778 |
DFLOG2( "Found %d keys", dir->Count() );
|
|
779 |
|
|
780 |
if ( dir->Count() <= 0 )
|
|
781 |
{
|
|
782 |
ErrorNoteL( R_DEVENCUI_TEXT_NO_KEYS_FOUND );
|
|
783 |
User::Leave( KErrNotReady );
|
|
784 |
}
|
|
785 |
|
|
786 |
// Create a list for the query
|
|
787 |
iListQueryItemArray = new ( ELeave ) CDesCArrayFlat( dir->Count() );
|
|
788 |
for ( TInt i = 0; i < dir->Count(); i++ )
|
|
789 |
{
|
|
790 |
TEntry entry( (*dir)[i] );
|
|
791 |
HBufC* tmpFileName = entry.iName.AllocLC();
|
|
792 |
iListQueryItemArray->AppendL( entry.iName );
|
|
793 |
CleanupStack::PopAndDestroy( tmpFileName );
|
|
794 |
}
|
|
795 |
|
|
796 |
// Let the user select which key to load
|
|
797 |
TInt index( 0 ); // the index of the selected item
|
|
798 |
CAknListQueryDialog* query =
|
|
799 |
new ( ELeave ) CAknListQueryDialog( &index );
|
|
800 |
query->PrepareLC( R_DEVENCUI_LIST_QUERY );
|
|
801 |
query->ButtonGroupContainer().SetCommandSetL( R_AVKON_SOFTKEYS_OK_BACK );
|
|
802 |
query->SetItemTextArray( iListQueryItemArray );
|
|
803 |
// Keep ownership of the item array
|
|
804 |
query->SetOwnershipType( ELbmDoesNotOwnItemArray );
|
|
805 |
if ( query->RunLD() )
|
|
806 |
{
|
|
807 |
DFLOG2( "User selected key %d", index );
|
|
808 |
DFLOGBUF( ( *dir )[index].iName );
|
|
809 |
// Load the key file.
|
|
810 |
|
|
811 |
// Construct file path
|
|
812 |
TBuf<KMaxFileName> filePath;
|
|
813 |
DFLOG("Start find key folder");
|
|
814 |
User::LeaveIfError( fm->KeyFolder( filePath ) );
|
|
815 |
DFLOG("Stop find key folder");
|
|
816 |
|
|
817 |
TFileName filename;
|
|
818 |
filename.Append( filePath );
|
|
819 |
filename.Append( ( *dir )[index].iName );
|
|
820 |
fm->LoadKeyL( filename,
|
|
821 |
pkcs5Key );
|
|
822 |
CleanupStack::PushL( pkcs5Key );
|
|
823 |
keySelected = ETrue;
|
|
824 |
DFLOG( "Key loaded" );
|
|
825 |
}
|
|
826 |
else
|
|
827 |
{
|
|
828 |
// User cancelled the query
|
|
829 |
DFLOG( "Key file query cancelled by user, stopping here" );
|
|
830 |
}
|
|
831 |
|
|
832 |
while ( askPassword )
|
|
833 |
{
|
|
834 |
if ( keySelected )
|
|
835 |
{
|
|
836 |
// Get the key password from the user
|
|
837 |
passwordOk = PasswordQueryL( R_DEVENCUI_TEXT_PASSPHRASE_ASK,
|
|
838 |
password8 );
|
|
839 |
}
|
|
840 |
else
|
|
841 |
{
|
|
842 |
//The user pressed back. Do not ask the password
|
|
843 |
askPassword = EFalse;
|
|
844 |
}
|
|
845 |
|
|
846 |
if ( passwordOk )
|
|
847 |
{
|
|
848 |
DFLOG( "Password ok, setting key" );
|
|
849 |
CDevEncKeyUtils* utils = new ( ELeave ) CDevEncKeyUtils;
|
|
850 |
CleanupStack::PushL( utils );
|
|
851 |
// User::LeaveIfError(utils->Connect());
|
|
852 |
|
|
853 |
TRequestStatus status;
|
|
854 |
utils->SetKey( status, *pkcs5Key, password8 );
|
|
855 |
User::WaitForRequest( status );
|
|
856 |
// utils->Close();
|
|
857 |
CleanupStack::PopAndDestroy( utils );
|
|
858 |
if ( status.Int() )
|
|
859 |
{
|
|
860 |
const TInt KErrBadPassphrase( -11000 );
|
|
861 |
DFLOG2( "Error taking key in use: %d", status.Int() );
|
|
862 |
if ( status.Int() == KErrBadPassphrase )
|
|
863 |
{
|
|
864 |
DFLOG( "Invalid password" );
|
|
865 |
ErrorNoteL( R_DEVENCUI_TEXT_INVALID_PASSWORD );
|
|
866 |
}
|
|
867 |
else
|
|
868 |
{
|
|
869 |
DFLOG2( "Key read error %d", status.Int() );
|
|
870 |
ErrorNoteL( R_DEVENCUI_TEXT_KEY_ERROR );
|
|
871 |
askPassword = EFalse;
|
|
872 |
}
|
|
873 |
}
|
|
874 |
else
|
|
875 |
{
|
|
876 |
DFLOG( "New key is now in use" );
|
|
877 |
// Save the Mmc encryption key status
|
|
878 |
User::LeaveIfError( iCrSettings->Set( KDevEncUserSettingMemoryCard,
|
|
879 |
ETrue ) );
|
|
880 |
proceed = ETrue;
|
|
881 |
askPassword = EFalse;
|
|
882 |
}
|
|
883 |
}
|
|
884 |
else
|
|
885 |
{
|
|
886 |
askPassword = EFalse;
|
|
887 |
}
|
|
888 |
}
|
|
889 |
// Cleanup on demand
|
|
890 |
if ( pkcs5Key )
|
|
891 |
{
|
|
892 |
CleanupStack::PopAndDestroy( pkcs5Key );
|
|
893 |
}
|
|
894 |
if ( fm )
|
|
895 |
{
|
|
896 |
CleanupStack::PopAndDestroy( fm );
|
|
897 |
}
|
|
898 |
|
|
899 |
return proceed;
|
|
900 |
}
|
|
901 |
|
|
902 |
|
|
903 |
// --------------------------------------------------------------------------
|
|
904 |
// CDevEncUiEncryptionOperator::PasswordQueryL()
|
|
905 |
// --------------------------------------------------------------------------
|
|
906 |
//
|
|
907 |
TBool CDevEncUiEncryptionOperator::PasswordQueryL( TInt aPromptResourceId,
|
|
908 |
TDes8& aResult )
|
|
909 |
{
|
|
910 |
TBool passwordOk( EFalse );
|
|
911 |
TBuf<KMaxPasswordLength> password;
|
|
912 |
TBuf8<KMaxPasswordLength> password8;
|
|
913 |
CDevEncUiSecretMinMaxCodeQuery* query =
|
|
914 |
new ( ELeave ) CDevEncUiSecretMinMaxCodeQuery( password,
|
|
915 |
KMinPasswordLength,
|
|
916 |
KMaxPasswordLength );
|
|
917 |
|
|
918 |
HBufC* prompt = StringLoader::LoadLC( aPromptResourceId, &iEikEnv );
|
|
919 |
query->SetPromptL( *prompt );
|
|
920 |
CleanupStack::PopAndDestroy( prompt );
|
|
921 |
|
|
922 |
// Prompt the user for the key password
|
|
923 |
if ( ( query->ExecuteLD( R_DEVENCUI_CODE_QUERY ) ) )
|
|
924 |
{
|
|
925 |
// This indicates that the user filled in some password and
|
|
926 |
// pressed OK.
|
|
927 |
passwordOk = ETrue;
|
|
928 |
}
|
|
929 |
else
|
|
930 |
{
|
|
931 |
DFLOG( "Key password dialog cancelled" );
|
|
932 |
}
|
|
933 |
|
|
934 |
if ( passwordOk )
|
|
935 |
{
|
|
936 |
// Convert the password to UTF-8
|
|
937 |
if ( CnvUtfConverter::ConvertFromUnicodeToUtf8( password8,
|
|
938 |
password ) )
|
|
939 |
{
|
|
940 |
DFLOG( "Password conversion failed" );
|
|
941 |
passwordOk = EFalse;
|
|
942 |
}
|
|
943 |
else
|
|
944 |
{
|
|
945 |
aResult.Copy( password8 );
|
|
946 |
}
|
|
947 |
}
|
|
948 |
|
|
949 |
return passwordOk;
|
|
950 |
}
|
|
951 |
|
|
952 |
// --------------------------------------------------------------------------
|
|
953 |
// CDevEncUiEncryptionOperator::HandleMmcDecryptRequestL()
|
|
954 |
// --------------------------------------------------------------------------
|
|
955 |
//
|
|
956 |
void CDevEncUiEncryptionOperator::HandleMmcDecryptRequestL( CDevEncUiMemoryEntity* aMem,
|
|
957 |
TInt aCommand )
|
|
958 |
{
|
|
959 |
// Check the battery level first
|
|
960 |
if ( ! CheckBatteryL() )
|
|
961 |
{
|
|
962 |
// The battery level is too low and no charger is connected.
|
|
963 |
// Show a note to the user.
|
|
964 |
ErrorNoteL( R_DEVENCUI_TEXT_BATTERY_LOW );
|
|
965 |
User::Leave( KErrNotReady );
|
|
966 |
}
|
|
967 |
|
|
968 |
TBool proceed( EFalse );
|
|
969 |
switch ( aCommand )
|
|
970 |
{
|
|
971 |
case EDevEncUiCommandDecrypt:
|
|
972 |
{
|
|
973 |
DFLOG( "Decrypt selected" );
|
|
974 |
// Warn the user about the long decryption process
|
|
975 |
proceed = MessageQueryL( R_DEVENCUI_TEXT_NOTE_DECRYPTING );
|
|
976 |
break;
|
|
977 |
}
|
|
978 |
case EDevEncUiCommandDecryptAndTurnOffEncryption:
|
|
979 |
{
|
|
980 |
DFLOG( "Decrypt and turn off selected" );
|
|
981 |
// Warn the user about the long decryption process,
|
|
982 |
// and that the key will be destroyed
|
|
983 |
proceed = MessageQueryL( R_DEVENCUI_TEXT_NOTE_DECRYPTINGDESTROY );
|
|
984 |
// Save the Mmc encryption key status
|
|
985 |
User::LeaveIfError( iCrSettings->Set( KDevEncUserSettingMemoryCard,
|
|
986 |
EFalse ) );
|
|
987 |
// The key will actually be destroyed in the DevEncStarter
|
|
988 |
// component, because the user may exit from the UI at any time.
|
|
989 |
// By saving the encryption key status in the central repository,
|
|
990 |
// we ensure that the Starter knows that it's supposed to destroy
|
|
991 |
// the key when the operation is complete
|
|
992 |
// TBI: Destroy the key in Starter after decryption is complete.
|
|
993 |
break;
|
|
994 |
}
|
|
995 |
default:
|
|
996 |
{
|
|
997 |
break;
|
|
998 |
}
|
|
999 |
}
|
|
1000 |
|
|
1001 |
if ( aMem->State() == EUnmounted )
|
|
1002 |
{
|
|
1003 |
// Just go back to main view, no decryption operation
|
|
1004 |
iAppUi.ActivateLocalViewL( TUid::Uid( EDevEncUiMainViewId ) );
|
|
1005 |
proceed = EFalse;
|
|
1006 |
DFLOG( "No Mmc present -> no decryption" );
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
if ( proceed )
|
|
1010 |
{
|
|
1011 |
// Start the decryption
|
|
1012 |
DFLOG( "Starting decryption" );
|
|
1013 |
aMem->StartDecryptionL();
|
|
1014 |
// Go back to main view
|
|
1015 |
iAppUi.ActivateLocalViewL( TUid::Uid( EDevEncUiMainViewId ) );
|
|
1016 |
}
|
|
1017 |
else
|
|
1018 |
{
|
|
1019 |
DFLOG( "Decryption cancelled" );
|
|
1020 |
// Stay in the decryption view
|
|
1021 |
}
|
|
1022 |
|
|
1023 |
// Depending on the user's selection, the memory may be in the same
|
|
1024 |
// state as before or in a new state. This call will let all observers
|
|
1025 |
// know what state the memory ended up in.
|
|
1026 |
aMem->UpdateMemoryInfo();
|
|
1027 |
}
|
|
1028 |
|
|
1029 |
// ---------------------------------------------------------------------------
|
|
1030 |
// CDevEncUiEncryptionOperator::CheckBatteryL()
|
|
1031 |
// Checks if there's enough battery power to update
|
|
1032 |
// ---------------------------------------------------------------------------
|
|
1033 |
//
|
|
1034 |
TBool CDevEncUiEncryptionOperator::CheckBatteryL()
|
|
1035 |
{
|
|
1036 |
#ifdef __WINS__
|
|
1037 |
|
|
1038 |
// In the emulator, the battery level is always 0 and the charger is never
|
|
1039 |
// connected, so just return ETrue.
|
|
1040 |
return ETrue;
|
|
1041 |
|
|
1042 |
#else // __WINS__
|
|
1043 |
|
|
1044 |
// Running on target. Check the real battery and charger status
|
|
1045 |
|
|
1046 |
TInt chargingstatus( EChargingStatusError );
|
|
1047 |
TInt batterylevel( 1 );
|
|
1048 |
TBool enoughPower( EFalse );
|
|
1049 |
|
|
1050 |
// Read battery
|
|
1051 |
DFLOG( "CDevEncUiEncryptionOperator::CheckBatteryL" );
|
|
1052 |
RProperty pw;
|
|
1053 |
User::LeaveIfError( pw.Attach( KPSUidHWRMPowerState, KHWRMBatteryLevel ) );
|
|
1054 |
User::LeaveIfError( pw.Get( batterylevel ) );
|
|
1055 |
pw.Close();
|
|
1056 |
|
|
1057 |
User::LeaveIfError( pw.Attach( KPSUidHWRMPowerState, KHWRMChargingStatus ) );
|
|
1058 |
User::LeaveIfError( pw.Get( chargingstatus ));
|
|
1059 |
pw.Close();
|
|
1060 |
|
|
1061 |
// Too low battery, power insufficient
|
|
1062 |
if ( batterylevel >= EBatteryLevelLevel4 )
|
|
1063 |
{
|
|
1064 |
enoughPower = ETrue;
|
|
1065 |
}
|
|
1066 |
// But charger is connected, power sufficient
|
|
1067 |
if ( ( chargingstatus != EChargingStatusError ) &&
|
|
1068 |
( chargingstatus != EChargingStatusNotConnected ) )
|
|
1069 |
{
|
|
1070 |
enoughPower = ETrue;
|
|
1071 |
}
|
|
1072 |
|
|
1073 |
DFLOG3( "Battery level: %d (0..7), chargingstatus %d",
|
|
1074 |
batterylevel, chargingstatus );
|
|
1075 |
DFLOG2( "CheckBatteryL %d", ( enoughPower ? 1 : 0 ) );
|
|
1076 |
return enoughPower;
|
|
1077 |
|
|
1078 |
#endif // __WINS__
|
|
1079 |
}
|
|
1080 |
|
|
1081 |
// --------------------------------------------------------------------------
|
|
1082 |
// CDevEncUiEncryptionOperator::ErrorNoteL()
|
|
1083 |
// --------------------------------------------------------------------------
|
|
1084 |
//
|
|
1085 |
void CDevEncUiEncryptionOperator::ErrorNoteL( TInt aResourceId,
|
|
1086 |
TBool aWaitingNote )
|
|
1087 |
{
|
|
1088 |
HBufC* message = StringLoader::LoadLC( aResourceId );
|
|
1089 |
CAknErrorNote* errorNote = new ( ELeave ) CAknErrorNote( aWaitingNote );
|
|
1090 |
errorNote->ExecuteLD( *message );
|
|
1091 |
CleanupStack::PopAndDestroy( message );
|
|
1092 |
}
|
|
1093 |
|
|
1094 |
// --------------------------------------------------------------------------
|
|
1095 |
// CDevEncUiEncryptionOperator::InfoNoteL()
|
|
1096 |
// --------------------------------------------------------------------------
|
|
1097 |
//
|
|
1098 |
void CDevEncUiEncryptionOperator::InfoNoteL( TInt aResourceId,
|
|
1099 |
TBool aWaitingNote )
|
|
1100 |
{
|
|
1101 |
HBufC* message = StringLoader::LoadLC( aResourceId );
|
|
1102 |
CAknInformationNote* note = new ( ELeave ) CAknInformationNote( aWaitingNote );
|
|
1103 |
note->ExecuteLD( *message );
|
|
1104 |
CleanupStack::PopAndDestroy( message );
|
|
1105 |
}
|
|
1106 |
|
|
1107 |
// --------------------------------------------------------------------------
|
|
1108 |
// CDevEncUiEncryptionOperator::DestroyKeyQueryL()
|
|
1109 |
//
|
|
1110 |
// --------------------------------------------------------------------------
|
|
1111 |
void CDevEncUiEncryptionOperator::DestroyKeyQueryL( TBool aShowMmcNote )
|
|
1112 |
{
|
|
1113 |
TBool destroy = QueryDialogL( R_DEVENCUI_TEXT_NOTE_DECRYPT_NOMEMRYCARD, R_AVKON_SOFTKEYS_YES_NO );
|
|
1114 |
if ( destroy )
|
|
1115 |
{
|
|
1116 |
DestroyKeyL();
|
|
1117 |
if ( aShowMmcNote )
|
|
1118 |
{
|
|
1119 |
InfoNoteL( R_DEVENCUI_TEXT_NOTE_MEMORYCARD_UNENCRYPTED );
|
|
1120 |
}
|
|
1121 |
}
|
|
1122 |
else
|
|
1123 |
{
|
|
1124 |
DFLOG( "User cancelled destroy key query" );
|
|
1125 |
}
|
|
1126 |
}
|
|
1127 |
|
|
1128 |
// --------------------------------------------------------------------------
|
|
1129 |
// CDevEncUiEncryptionOperator::DestroyKeyL()
|
|
1130 |
//
|
|
1131 |
// --------------------------------------------------------------------------
|
|
1132 |
void CDevEncUiEncryptionOperator::DestroyKeyL()
|
|
1133 |
{
|
|
1134 |
DFLOG( "CDevEncUiEncryptionOperator::DestroyKeyL" );
|
|
1135 |
CDevEncKeyUtils* utils = new ( ELeave ) CDevEncKeyUtils;
|
|
1136 |
CleanupStack::PushL( utils );
|
|
1137 |
// User::LeaveIfError(utils->Connect());
|
|
1138 |
|
|
1139 |
TRequestStatus status;
|
|
1140 |
utils->ResetKey( status );
|
|
1141 |
User::WaitForRequest( status );
|
|
1142 |
// utils->Close();
|
|
1143 |
CleanupStack::PopAndDestroy( utils );
|
|
1144 |
if ( status.Int() )
|
|
1145 |
{
|
|
1146 |
DFLOG2( "DestroyKeyL error %d", status.Int() );
|
|
1147 |
}
|
|
1148 |
else
|
|
1149 |
{
|
|
1150 |
DFLOG( "DestroyKeyL done" );
|
|
1151 |
// We no longer have a key in the driver. Update the user setting.
|
|
1152 |
iCrSettings->Set( KDevEncUserSettingMemoryCard, 0 );
|
|
1153 |
}
|
|
1154 |
User::LeaveIfError( status.Int() );
|
|
1155 |
}
|
|
1156 |
|
|
1157 |
// --------------------------------------------------------------------------
|
|
1158 |
// CDevEncUiEncryptionOperator::SuggestMmcEncryptionL()
|
|
1159 |
//
|
|
1160 |
// --------------------------------------------------------------------------
|
|
1161 |
void CDevEncUiEncryptionOperator::SuggestMmcEncryptionL(
|
|
1162 |
CDevEncUiMemoryEntity* aMem )
|
|
1163 |
{
|
|
1164 |
TInt encrypt( 0 );
|
|
1165 |
|
|
1166 |
// Check DM admin status
|
|
1167 |
TInt dmControlSetting( 0 );
|
|
1168 |
iCrSettings->Get( KDevEncUiDmControl, dmControlSetting );
|
|
1169 |
|
|
1170 |
if( dmControlSetting & KDmControlsMemoryCard )
|
|
1171 |
{
|
|
1172 |
//The admin is controlling the encryption, encrypt straight away without questions
|
|
1173 |
encrypt = ETrue;
|
|
1174 |
}
|
|
1175 |
else
|
|
1176 |
{
|
|
1177 |
encrypt = MessageQueryL( R_DEVENCUI_TEXT_NOTE_INSERTUNENCRYPTED,
|
|
1178 |
R_AVKON_SOFTKEYS_YES_NO );
|
|
1179 |
}
|
|
1180 |
|
|
1181 |
if ( encrypt )
|
|
1182 |
{
|
|
1183 |
HandleMmcEncryptRequestL( aMem,
|
|
1184 |
EDevEncUiCommandEncryptWithCurrentKey );
|
|
1185 |
}
|
|
1186 |
else
|
|
1187 |
{
|
|
1188 |
DFLOG( "User selected not to encrypt the card" );
|
|
1189 |
}
|
|
1190 |
}
|
|
1191 |
|
|
1192 |
// --------------------------------------------------------------------------
|
|
1193 |
// CDevEncUiEncryptionOperator::SuggestMmcDecryptionL()
|
|
1194 |
//
|
|
1195 |
// --------------------------------------------------------------------------
|
|
1196 |
void CDevEncUiEncryptionOperator::SuggestMmcDecryptionL( CDevEncUiMemoryEntity* aMem )
|
|
1197 |
{
|
|
1198 |
TBool decrypt = MessageQueryL( R_DEVENCUI_TEXT_NOTE_INSERTENCRYPTED,
|
|
1199 |
R_AVKON_SOFTKEYS_YES_NO );
|
|
1200 |
if ( decrypt )
|
|
1201 |
{
|
|
1202 |
SuggestMmcImportKeyL( aMem, ETrue );
|
|
1203 |
}
|
|
1204 |
else
|
|
1205 |
{
|
|
1206 |
ErrorNoteL( R_DEVENCUI_TEXT_NOTE_INSERTOFF_UNUSEDMEMORYCARD );
|
|
1207 |
}
|
|
1208 |
}
|
|
1209 |
|
|
1210 |
// --------------------------------------------------------------------------
|
|
1211 |
// CDevEncUiEncryptionOperator::SuggestMmcImportKeyL()
|
|
1212 |
//
|
|
1213 |
// --------------------------------------------------------------------------
|
|
1214 |
void CDevEncUiEncryptionOperator::SuggestMmcImportKeyL(
|
|
1215 |
CDevEncUiMemoryEntity* /*aMem*/,
|
|
1216 |
TBool aFirstAttempt )
|
|
1217 |
{
|
|
1218 |
DFLOG( "CDevEncUiEncryptionOperator::SuggestMmcImportKeyL" );
|
|
1219 |
TBool import( ETrue );
|
|
1220 |
if ( aFirstAttempt )
|
|
1221 |
{
|
|
1222 |
DFLOG( "CDevEncUiEncryptionOperator::SuggestMmcImportKeyL => firstAttempt" );
|
|
1223 |
import = MessageQueryL( R_DEVENCUI_TEXT_NOTE_DECRYPT_LOADKEY,
|
|
1224 |
R_AVKON_SOFTKEYS_YES_NO );
|
|
1225 |
}
|
|
1226 |
|
|
1227 |
if ( import )
|
|
1228 |
{
|
|
1229 |
TBool reloadKey = ETrue;
|
|
1230 |
// Loop while user chooses correct key or cancels operation
|
|
1231 |
while ( reloadKey )
|
|
1232 |
{
|
|
1233 |
TBool keySet = LoadAndSetKeyL();
|
|
1234 |
if ( !keySet )
|
|
1235 |
{
|
|
1236 |
ErrorNoteL( R_DEVENCUI_TEXT_NOTE_UNUSEDMEMORYCARD );
|
|
1237 |
reloadKey = EFalse;
|
|
1238 |
}
|
|
1239 |
else
|
|
1240 |
{
|
|
1241 |
// New key is in use, now we need to remount the mmc
|
|
1242 |
RemountMmcL();
|
|
1243 |
|
|
1244 |
// Check that key is valid
|
|
1245 |
TInt err = CheckMMCStatus();
|
|
1246 |
|
|
1247 |
if( err == KErrCorrupt )
|
|
1248 |
{
|
|
1249 |
ErrorNoteL( R_DEVENCUI_TEXT_NOTE_WRONGKEYFILE );
|
|
1250 |
reloadKey = ETrue;
|
|
1251 |
}
|
|
1252 |
else
|
|
1253 |
{
|
|
1254 |
reloadKey = EFalse;
|
|
1255 |
}
|
|
1256 |
}
|
|
1257 |
}
|
|
1258 |
}
|
|
1259 |
}
|
|
1260 |
|
|
1261 |
// --------------------------------------------------------------------------
|
|
1262 |
// CDevEncUiEncryptionOperator::CheckMMCStatus()
|
|
1263 |
//
|
|
1264 |
// --------------------------------------------------------------------------
|
|
1265 |
TInt CDevEncUiEncryptionOperator::CheckMMCStatus()
|
|
1266 |
{
|
|
1267 |
TVolumeInfo volInfo;
|
|
1268 |
RFs fs;
|
|
1269 |
TInt err = fs.Connect();
|
|
1270 |
if (err == KErrNone)
|
|
1271 |
{
|
|
1272 |
fs.Volume( volInfo, EDriveF );
|
|
1273 |
fs.Close();
|
|
1274 |
}
|
|
1275 |
return err;
|
|
1276 |
}
|
|
1277 |
|
|
1278 |
// --------------------------------------------------------------------------
|
|
1279 |
// CDevEncUiEncryptionOperator::RemountMmc()
|
|
1280 |
//
|
|
1281 |
// --------------------------------------------------------------------------
|
|
1282 |
void CDevEncUiEncryptionOperator::RemountMmcL()
|
|
1283 |
{
|
|
1284 |
CDevEncUiFileManager* fm = new ( ELeave ) CDevEncUiFileManager;
|
|
1285 |
CleanupStack::PushL( fm );
|
|
1286 |
fm->ConstructL();
|
|
1287 |
TInt error = fm->RemountMmc();
|
|
1288 |
CleanupStack::PopAndDestroy( fm );
|
|
1289 |
if ( error )
|
|
1290 |
{
|
|
1291 |
DFLOG2( "Mmc remount failed, error %d", error );
|
|
1292 |
User::Leave( error );
|
|
1293 |
}
|
|
1294 |
else
|
|
1295 |
{
|
|
1296 |
DFLOG( "Mmc remounted" );
|
|
1297 |
}
|
|
1298 |
}
|
|
1299 |
|
|
1300 |
// --------------------------------------------------------------------------
|
|
1301 |
// CDevEncUiEncryptionOperator::ShowWrongKeyNoteL()
|
|
1302 |
//
|
|
1303 |
// --------------------------------------------------------------------------
|
|
1304 |
void CDevEncUiEncryptionOperator::ShowWrongKeyNoteL()
|
|
1305 |
{
|
|
1306 |
ErrorNoteL( R_DEVENCUI_TEXT_NOTE_INSERTON_UNUSEDMEMORYCARD );
|
|
1307 |
}
|
|
1308 |
|
|
1309 |
// --------------------------------------------------------------------------
|
|
1310 |
// CDevEncUiEncryptionOperator::CheckNotesWithHeaderL()
|
|
1311 |
//
|
|
1312 |
// --------------------------------------------------------------------------
|
|
1313 |
void CDevEncUiEncryptionOperator::CheckNotesWithHeaderL()
|
|
1314 |
{
|
|
1315 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_DECRYPT_LOADKEY );
|
|
1316 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_DECRYPT_NOMEMRYCARD );
|
|
1317 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_DECRYPTING );
|
|
1318 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_DECRYPTINGDESTROY );
|
|
1319 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_ENCRYPTING );
|
|
1320 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_ENCRYPTIONINTERRUPT );
|
|
1321 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_INSERTENCRYPTED );
|
|
1322 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_INSERTOFF_UNUSEDMEMORYCARD );
|
|
1323 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_INSERTON_UNUSEDMEMORYCARD );
|
|
1324 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_INSERTUNENCRYPTED );
|
|
1325 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_LOCK );
|
|
1326 |
MessageQueryL( R_DEVENCUI_TEXT_NOTE_PHONE_DECRYPTING );
|
|
1327 |
}
|
|
1328 |
|
|
1329 |
// --------------------------------------------------------------------------
|
|
1330 |
// CDevEncUiEncryptionOperator::CheckNotesL()
|
|
1331 |
// --------------------------------------------------------------------------
|
|
1332 |
//
|
|
1333 |
void CDevEncUiEncryptionOperator::CheckNotesL()
|
|
1334 |
{
|
|
1335 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_DECRYPT_LOADKEY );
|
|
1336 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_DECRYPT_NOMEMRYCARD );
|
|
1337 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_DECRYPTING );
|
|
1338 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_DECRYPTINGDESTROY );
|
|
1339 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_ENCRYPTING );
|
|
1340 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_ENCRYPTIONINTERRUPT );
|
|
1341 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_INSERTENCRYPTED );
|
|
1342 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_INSERTOFF_UNUSEDMEMORYCARD );
|
|
1343 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_INSERTON_UNUSEDMEMORYCARD );
|
|
1344 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_INSERTUNENCRYPTED );
|
|
1345 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_LOCK );
|
|
1346 |
QueryDialogL( R_DEVENCUI_TEXT_NOTE_PHONE_DECRYPTING );
|
|
1347 |
}
|
|
1348 |
|
|
1349 |
// END OF FILE
|