|
1 /* |
|
2 * Copyright (c) 2010 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: Basic PIN query operation in secui dialog |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "secuidialogoperbasicpinquery.h" // CBasicPinQueryOperation |
|
19 #include "secuidialogoperationobserver.h" // MSecuiDialogOperationObserver |
|
20 #include <hb/hbcore/hbtextresolversymbian.h> // HbTextResolverSymbian |
|
21 #include "secuidialogstrace.h" // TRACE macro |
|
22 |
|
23 // TODO: fix this |
|
24 #include "../../../securitydialogs/SecUi/Inc/SecQueryUi.h" // CSecQueryUi |
|
25 |
|
26 #include <secui.h> |
|
27 #include <secuisecurityhandler.h> |
|
28 #include <gsmerror.h> |
|
29 #include <etelmm.h> |
|
30 #include <rmmcustomapi.h> |
|
31 #include <startupdomainpskeys.h> |
|
32 #include <featmgr.h> |
|
33 |
|
34 const TInt KPhoneIndex( 0 ); |
|
35 const TInt KTriesToConnectServer( 2 ); |
|
36 const TInt KTimeBeforeRetryingServerConnection( 50000 ); |
|
37 |
|
38 _LIT( KMmTsyModuleName, "PhoneTsy"); |
|
39 |
|
40 // Descriptors for different password queries |
|
41 _LIT( KBasicPinQueryKeyStorePassphrase, "Key store passphrase" ); |
|
42 _LIT( KBasicPinQueryNewKeyStorePassphrase, "New key store passphrase" ); |
|
43 _LIT( KBasicPinQueryImportedKeyFilePassphrase, "Passphrase of the imported key file" ); |
|
44 _LIT( KBasicPinQueryExportedKeyFilePassphrase, "Passphrase of the exported key file" ); |
|
45 _LIT( KBasicPinQueryPKCS12, "PKCS12"); |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 // ======== MEMBER FUNCTIONS ======== |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CBasicPinQueryOperation::NewL() |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CBasicPinQueryOperation* CBasicPinQueryOperation::NewL( |
|
57 MSecuiDialogOperationObserver& aObserver, const RMessage2& aMessage, |
|
58 TInt aReplySlot ) |
|
59 { |
|
60 TRACE( "CBasicPinQueryOperation::NewL, aMessage 0x%08x", aMessage.Handle() ); |
|
61 TRACE( "CBasicPinQueryOperation::NewL, aMessage.Function = 0x%08x", aMessage.Function() ); |
|
62 return new( ELeave ) CBasicPinQueryOperation( aObserver, aMessage, aReplySlot ); |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CBasicPinQueryOperation::~CBasicPinQueryOperation() |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CBasicPinQueryOperation::~CBasicPinQueryOperation() |
|
70 { |
|
71 TRACE( "CBasicPinQueryOperation::~CBasicPinQueryOperation" ); |
|
72 Cancel(); |
|
73 iPinInput = NULL; // not owned |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CBasicPinQueryOperation::StartL() |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CBasicPinQueryOperation::StartL( const TDesC8& aBuffer ) |
|
81 { |
|
82 TRACE( "CBasicPinQueryOperation::StartL" ); |
|
83 iPinInput = reinterpret_cast< const TPINInput* >( aBuffer.Ptr() ); |
|
84 ASSERT( iPinInput != NULL ); |
|
85 |
|
86 iStatus = KRequestPending; |
|
87 TRequestStatus* status = &iStatus; |
|
88 User::RequestComplete( status, KErrNone ); |
|
89 SetActive(); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CBasicPinQueryOperation::CancelOperation() |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CBasicPinQueryOperation::CancelOperation() |
|
97 { |
|
98 TRACE( "CBasicPinQueryOperation::CancelOperation" ); |
|
99 // nothing to do |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CBasicPinQueryOperation::RunL() |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void CBasicPinQueryOperation::RunL() |
|
107 { |
|
108 TRACE( "CBasicPinQueryOperation::RunL, iStatus.Int()=%d", iStatus.Int() ); |
|
109 User::LeaveIfError( iStatus.Int() ); |
|
110 |
|
111 TBool isRetry = ( iPinInput->iOperation & EPINValueIncorrect ); |
|
112 if( isRetry ) |
|
113 { |
|
114 // Show "Invalid PIN code" error note, as previous attempt was failed. |
|
115 // TODO: localized UI string needed |
|
116 _LIT( KInvalidPinCode, "Invalid PIN code" ); |
|
117 ShowWarningNoteL( KInvalidPinCode ); |
|
118 } |
|
119 TRACE( "CBasicPinQueryOperation::RunL, iPinInput->iOperation=%d", iPinInput->iOperation ); |
|
120 |
|
121 HBufC* caption = NULL; |
|
122 if( iPinInput->iPIN.iPINLabel == KBasicPinQueryKeyStorePassphrase ) |
|
123 { |
|
124 TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryKeyStorePassphrase =%d", 1 ); |
|
125 |
|
126 // TODO: localized UI string needed |
|
127 _LIT( KText, "Keystore password:" ); |
|
128 caption = KText().AllocLC(); |
|
129 } |
|
130 else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryNewKeyStorePassphrase ) |
|
131 { |
|
132 TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryNewKeyStorePassphrase =%d", 1 ); |
|
133 |
|
134 // "Keystore password must be created for using private keys." |
|
135 // SecUi creates two input fields when caption contains two labels |
|
136 // separated with a vertical bar. SecUi verifies that user types the |
|
137 // same passphrase in both fields. |
|
138 // TODO: localized UI strings needed |
|
139 _LIT( KText, "Create keystore password:|Verify:" ); |
|
140 caption = KText().AllocLC(); |
|
141 } |
|
142 else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryImportedKeyFilePassphrase ) |
|
143 { |
|
144 TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryImportedKeyFilePassphrase =%d", 1 ); |
|
145 |
|
146 // "Enter code for imported key:" |
|
147 // TODO: localized UI strings needed |
|
148 _LIT( KText, "Enter code for imported key:|Verify:" ); |
|
149 caption = KText().AllocLC(); |
|
150 } |
|
151 else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryExportedKeyFilePassphrase ) |
|
152 { |
|
153 TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryExportedKeyFilePassphrase =%d", 1 ); |
|
154 |
|
155 // "Enter new code for exported key:" |
|
156 // TODO: localized UI strings needed |
|
157 _LIT( KText, "Enter new code for exported key:|Verify:" ); |
|
158 caption = KText().AllocLC(); |
|
159 } |
|
160 else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryPKCS12 ) |
|
161 { |
|
162 TRACE( "CBasicPinQueryOperation::RunL, KBasicPinQueryPKCS12 =%d", 1 ); |
|
163 |
|
164 // "Password for %U:", PKCS#12 password query prompt |
|
165 // TODO: localized UI string needed |
|
166 _LIT( KText, "Password for PKCS#12 file:" ); |
|
167 caption = KText().AllocLC(); |
|
168 } |
|
169 else |
|
170 { |
|
171 TRACE( "CBasicPinQueryOperation::RunL, else =%d", 1 ); |
|
172 |
|
173 // "Enter code for %0U in %1U" |
|
174 // Data query for PIN request in keystore where %0U is the PIN's name %1U is the keystore's name. |
|
175 // TODO: EEnterPinNR |
|
176 _LIT( KText, "86" ); |
|
177 caption = KText().AllocLC(); |
|
178 } |
|
179 iPinValue.Copy(_L("0")); |
|
180 TRACE( "CBasicPinQueryOperation::RunL, 1 =%d", 1 ); |
|
181 |
|
182 TInt resultVerif = KErrNone; |
|
183 TRACE( "CBasicPinQueryOperation::RunL, 1 =%d", 1 ); |
|
184 |
|
185 { |
|
186 RMobilePhone iPhone; |
|
187 |
|
188 TInt err( KErrGeneral); |
|
189 TRACE( "CBasicPinQueryOperation::RunL, ESecurityQueryActive =%d", ESecurityQueryActive ); |
|
190 err = RProperty::Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryActive); |
|
191 TRACE( "CBasicPinQueryOperation::RunL, err =%d", err ); |
|
192 |
|
193 TInt thisTry( 0); |
|
194 RTelServer iTelServer; |
|
195 RMmCustomAPI iCustomPhone; |
|
196 while ( ( err = iTelServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer ) |
|
197 { |
|
198 User::After( KTimeBeforeRetryingServerConnection ); |
|
199 } |
|
200 err = iTelServer.LoadPhoneModule( KMmTsyModuleName ); |
|
201 RTelServer::TPhoneInfo PhoneInfo; |
|
202 err = iTelServer.SetExtendedErrorGranularity( RTelServer::EErrorExtended ) ; |
|
203 err = iTelServer.GetPhoneInfo( KPhoneIndex, PhoneInfo ) ; |
|
204 err = iPhone.Open( iTelServer, PhoneInfo.iName ) ; |
|
205 err = iCustomPhone.Open( iPhone ) ; |
|
206 TRACE( "CBasicPinQueryOperation::RunL, err =%d", err ); |
|
207 CSecurityHandler* handler = new(ELeave) CSecurityHandler(iPhone); |
|
208 CleanupStack::PushL(handler); |
|
209 // TSecUi::InitializeLibL(); |
|
210 TRACE( "CBasicPinQueryOperation::RunL, TMobilePhoneSecurityEvent 1 =%d", 1 ); |
|
211 RMobilePhone::TMobilePhoneSecurityEvent iEvent; |
|
212 TInt lEvent = iPinInput->iOperation; |
|
213 TRACE( "CBasicPinQueryOperation::RunL, lEvent =%d", lEvent ); |
|
214 if( lEvent >= 0x1000 ) // flag for iStartUp |
|
215 { |
|
216 lEvent-=0x1000; |
|
217 } |
|
218 iEvent = static_cast<RMobilePhone::TMobilePhoneSecurityEvent>(lEvent); |
|
219 TRACE( "CBasicPinQueryOperation::RunL, iEvent =%d", iEvent ); |
|
220 TRACE( "CBasicPinQueryOperation::RunL, TBool iStartUp =%d", iStartUp ); |
|
221 TRAPD( resultHandler, handler->HandleEventL( iEvent, iStartUp, resultVerif ) ); |
|
222 TRACE( "CBasicPinQueryOperation::RunL, resultHandler =%d", resultHandler ); |
|
223 TRACE( "CBasicPinQueryOperation::RunL, resultVerif =%d", resultVerif ); |
|
224 |
|
225 // if something went wrong cancel the code request |
|
226 if (resultHandler) |
|
227 { |
|
228 if(resultVerif==KErrNone) // if the process failed, then the result shoud also indicate the failure (unless it does it already) |
|
229 resultVerif = resultHandler; |
|
230 TRACE( "CBasicPinQueryOperation::RunL, iEvent =%d", iEvent ); |
|
231 TBool wcdmaSupported(FeatureManager::FeatureSupported( KFeatureIdProtocolWcdma )); |
|
232 TBool upinSupported(FeatureManager::FeatureSupported( KFeatureIdUpin )); |
|
233 switch (iEvent) |
|
234 { |
|
235 case RMobilePhone::EUniversalPinRequired: |
|
236 if(wcdmaSupported || upinSupported) |
|
237 { |
|
238 iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPin); |
|
239 } |
|
240 break; |
|
241 case RMobilePhone::EUniversalPukRequired: |
|
242 if(wcdmaSupported || upinSupported) |
|
243 { |
|
244 iPhone.AbortSecurityCode(RMobilePhone::ESecurityUniversalPuk); |
|
245 } |
|
246 break; |
|
247 case RMobilePhone::EPin1Required: |
|
248 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin1); |
|
249 break; |
|
250 case RMobilePhone::EPuk1Required: |
|
251 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk1); |
|
252 break; |
|
253 case RMobilePhone::EPin2Required: |
|
254 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePin2); |
|
255 break; |
|
256 case RMobilePhone::EPuk2Required: |
|
257 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePuk2); |
|
258 break; |
|
259 case RMobilePhone::EPhonePasswordRequired: |
|
260 iPhone.AbortSecurityCode(RMobilePhone::ESecurityCodePhonePassword); |
|
261 break; |
|
262 default: |
|
263 TRACE( "CBasicPinQueryOperation::RunL, default iEvent =%d", iEvent ); |
|
264 break; |
|
265 } |
|
266 } |
|
267 |
|
268 // uninitialize security ui |
|
269 TRACE( "CBasicPinQueryOperation::RunL, PopAndDestroy(handler) =%d", 0 ); |
|
270 CleanupStack::PopAndDestroy(handler); // handler |
|
271 TRACE( "CBasicPinQueryOperation::RunL, UnInitializeLib =%d", 1 ); |
|
272 TSecUi::UnInitializeLib(); |
|
273 TRACE( "CBasicPinQueryOperation::RunL, ESecurityQueryNotActive =%d", ESecurityQueryNotActive ); |
|
274 err = RProperty::Set(KPSUidStartup, KStartupSecurityCodeQueryStatus, ESecurityQueryNotActive); |
|
275 TRACE( "CBasicPinQueryOperation::RunL, err =%d", err ); |
|
276 //close ETel connection |
|
277 if (iTelServer.Handle()) |
|
278 { |
|
279 TRACE( "CBasicPinQueryOperation::RunL, iPhone.Close =%d", 0 ); |
|
280 iPhone.Close(); |
|
281 iTelServer.UnloadPhoneModule(KMmTsyModuleName); |
|
282 iTelServer.Close(); |
|
283 TRACE( "CBasicPinQueryOperation::RunL, iTelServer.Close =%d", 1 ); |
|
284 } |
|
285 } |
|
286 |
|
287 |
|
288 ReturnResultL( resultVerif ); |
|
289 |
|
290 if( caption ) |
|
291 { |
|
292 CleanupStack::PopAndDestroy( caption ); |
|
293 caption = NULL; |
|
294 } |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // CBasicPinQueryOperation::DoCancel() |
|
299 // --------------------------------------------------------------------------- |
|
300 // |
|
301 void CBasicPinQueryOperation::DoCancel() |
|
302 { |
|
303 TRACE( "CBasicPinQueryOperation::DoCancel" ); |
|
304 } |
|
305 |
|
306 // --------------------------------------------------------------------------- |
|
307 // CBasicPinQueryOperation::CBasicPinQueryOperation() |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 CBasicPinQueryOperation::CBasicPinQueryOperation( |
|
311 MSecuiDialogOperationObserver& aObserver, const RMessage2& aMessage, |
|
312 TInt aReplySlot ) : CSecuiDialogOperation( aObserver, aMessage, aReplySlot ) |
|
313 { |
|
314 TRACE( "CBasicPinQueryOperation::CBasicPinQueryOperation, aMessage 0x%08x", aMessage.Handle() ); |
|
315 TRACE( "CBasicPinQueryOperation::CBasicPinQueryOperation, aMessage.Function = 0x%08x", aMessage.Function() ); |
|
316 iStartUp=EFalse; |
|
317 if(aMessage.Function()>=0x1000) |
|
318 iStartUp=ETrue; |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // CBasicPinQueryOperation::ReturnResultL() |
|
323 // --------------------------------------------------------------------------- |
|
324 // |
|
325 void CBasicPinQueryOperation::ReturnResultL( TInt aErrorCode ) |
|
326 { |
|
327 TRACE( "CBasicPinQueryOperation::ReturnResultL, begin, aErrorCode=%d", aErrorCode ); |
|
328 if( aErrorCode <= KErrNone ) // TODO should skip WriteL is error? |
|
329 { |
|
330 TPINValueBuf output( iPinValue ); |
|
331 iMessage.WriteL( iReplySlot, output ); |
|
332 } |
|
333 TRACE( "CBasicPinQueryOperation::ReturnResultL, completing msg 0x%08x", iMessage.Handle() ); |
|
334 iMessage.Complete( aErrorCode ); |
|
335 TRACE( "CBasicPinQueryOperation::ReturnResultL, informing observer" ); |
|
336 iObserver.OperationComplete(); |
|
337 TRACE( "CBasicPinQueryOperation::ReturnResultL, end" ); |
|
338 } |
|
339 |