|
1 /* |
|
2 * Copyright (c) 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 * dummy plugin to test post market plugin support. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <f32file.h> |
|
21 |
|
22 #include "tpostmarketramplugin.h" |
|
23 #include <e32svr.h> |
|
24 |
|
25 #ifndef __INIPARSER_H__ |
|
26 #include <cinidata.h> |
|
27 #endif // __INIPARSER_H__ |
|
28 |
|
29 |
|
30 //Implement CAuthPluginInterface definitions |
|
31 CTPostMarketRAMPlugin::~CTPostMarketRAMPlugin() |
|
32 { |
|
33 delete iClientMessage; |
|
34 } |
|
35 |
|
36 CTPostMarketRAMPlugin::CTPostMarketRAMPlugin() |
|
37 { |
|
38 // See ConstructL() for initialisation completion. |
|
39 } |
|
40 |
|
41 /** |
|
42 Safely complete the initialization of the constructed object |
|
43 */ |
|
44 void CTPostMarketRAMPlugin::ConstructL() |
|
45 { |
|
46 iName.Set(KPluginNamePin); |
|
47 iDescription.Set(KPluginDescriptionPin); |
|
48 iMinEntropy = KEntropyPin; |
|
49 iFalsePositiveRate = KFalsePosPin; |
|
50 iFalseNegativeRate = KFalseNegPin; |
|
51 iClientMessage = HBufC::NewL(2048); |
|
52 ReloadAllFromIniFile(); |
|
53 } |
|
54 |
|
55 /** |
|
56 Sets information like iActiveState and iSupportsDefaultData from |
|
57 the TEF ini file to the individual plugin database files |
|
58 */ |
|
59 void CTPostMarketRAMPlugin::ReloadAllFromIniFile() |
|
60 { |
|
61 // Set the file to be read, based on the Id of the plugin |
|
62 |
|
63 _LIT(KFileText, "\\tAuth\\tAuthSvr\\testdata\\Pin"); |
|
64 _LIT(KFileSuffix, "Db.ini"); |
|
65 _LIT(KFormatFileName,"%S%x%S"); |
|
66 |
|
67 TDriveUnit sysDrive (RFs::GetSystemDrive()); |
|
68 TBuf<64> fileText(sysDrive.Name()); |
|
69 fileText.Append(KFileText); |
|
70 iFileToRead.Format(KFormatFileName,&fileText, Id(), &KFileSuffix); |
|
71 |
|
72 //Read data from file to get initialisation information |
|
73 |
|
74 // Open and read in INI file |
|
75 // Default path to look for INI file is in 'c:\system\data' |
|
76 // on target filesystem |
|
77 |
|
78 CIniData* file=NULL; |
|
79 TRAPD(r,file=CIniData::NewL(iFileToRead)); |
|
80 |
|
81 //Put file on the cleanupstack if anything else in this function is going to leave, but nothing does. |
|
82 |
|
83 if(r!=KErrNone) |
|
84 { |
|
85 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &iFileToRead); |
|
86 } |
|
87 |
|
88 else |
|
89 { |
|
90 // Look for a key under a named section, retrieve text value |
|
91 TPtrC result; |
|
92 TBool ret; //return value from FindVar functions |
|
93 ret=file->FindVar(_L("SectionOne"),_L("iSupportsDefaultData"),result); |
|
94 if(!ret) |
|
95 { |
|
96 RDebug::Print(_L("Key or section not found. iSupportsDefaultData default value used.")); |
|
97 iSupportsDefaultData = ETrue; // Default value |
|
98 } |
|
99 else |
|
100 { |
|
101 _LIT(KFalse,"false"); |
|
102 // Create a lower case copy of the data that is read from the file |
|
103 TBuf<10> resultLowerCase; |
|
104 resultLowerCase.Copy(result); |
|
105 resultLowerCase.LowerCase(); |
|
106 iSupportsDefaultData = (resultLowerCase.FindF(KFalse) == KErrNotFound); |
|
107 } |
|
108 |
|
109 // Set the active state of the plugin depending on the contents of the |
|
110 // corresponding file, which has been set as a member variable |
|
111 ret =file->FindVar(_L("SectionOne"),_L("activeState"),result); |
|
112 if(!ret) |
|
113 { |
|
114 RDebug::Print(_L("Key or section not found. iActiveState default value of ETRUE used.")); |
|
115 iActiveState = ETrue; // Default value |
|
116 } |
|
117 else |
|
118 { |
|
119 _LIT(KFalse,"false"); |
|
120 // Create a lower case copy of the data that is read from the file |
|
121 TBuf<10> resultLowerCase; |
|
122 resultLowerCase.Copy(result); |
|
123 resultLowerCase.LowerCase(); |
|
124 |
|
125 // If the string 'false' was not found, we set the value to 'true' -the default value |
|
126 iActiveState = (resultLowerCase.FindF(KFalse) == KErrNotFound); |
|
127 } |
|
128 TRAPD(r,file->WriteToFileL()); |
|
129 |
|
130 if (KErrNone != r) |
|
131 { |
|
132 RDebug::Print(_L("Error occurred while writing to the file.")); |
|
133 TBuf<84> initInfoFile(sysDrive.Name()); |
|
134 initInfoFile.Append(KInitInfoFile); |
|
135 RDebug::Print(_L("Filename = %S, KeyName = iSupportsDefaultData,"), &initInfoFile); |
|
136 RDebug::Print(_L("value = %S."), &result); |
|
137 } |
|
138 |
|
139 delete file; |
|
140 TRAP(r,file=CIniData::NewL(KAuthSvrPolicyFile)); |
|
141 TPtrC displayMessage; |
|
142 ret=file->FindVar(_L("SectionOne"),_L("DisplayMessage"),displayMessage); |
|
143 if(displayMessage.Length() == 0) //Value = 0 |
|
144 { |
|
145 RDebug::Print(_L("DisplayMessage not passed.")); |
|
146 iClientMessage = iClientMessage->ReAllocL(0); // Default value |
|
147 TPtr ptr(iClientMessage->Des()); |
|
148 ptr = KNullDesC(); |
|
149 ret=file->SetValue(_L("SectionOne"),_L("DisplayMessage"),displayMessage); |
|
150 TRAP(r,file->WriteToFileL()); |
|
151 } |
|
152 else |
|
153 { |
|
154 iClientMessage = iClientMessage->ReAllocL(displayMessage.Length()); |
|
155 TPtr ptr(iClientMessage->Des()); |
|
156 ptr = displayMessage; |
|
157 ret=file->SetValue(_L("SectionOne"),_L("DisplayMessage"),displayMessage); |
|
158 TRAP(r,file->WriteToFileL()); |
|
159 } |
|
160 delete file; |
|
161 } |
|
162 |
|
163 } |
|
164 |
|
165 void CTPostMarketRAMPlugin::ReloadActiveStateFromIniFile() const |
|
166 { |
|
167 // Set the file to be read, based on the Id of the plugin |
|
168 |
|
169 _LIT(KFileText, "\\tAuth\\tAuthSvr\\testdata\\Pin"); |
|
170 _LIT(KFileSuffix, "Db.ini"); |
|
171 |
|
172 _LIT(KFormatFileName,"%S%x%S"); |
|
173 |
|
174 TDriveUnit sysDrive (RFs::GetSystemDrive()); |
|
175 TBuf<64> fileText(sysDrive.Name()); |
|
176 fileText.Append(KFileText); |
|
177 iFileToRead.Format(KFormatFileName,&fileText, Id(), &KFileSuffix); |
|
178 |
|
179 //Read data from file to get initialisation information |
|
180 |
|
181 // Open and read in INI file |
|
182 // Default path to look for INI file is in 'c:\system\data' |
|
183 // on target filesystem |
|
184 |
|
185 CIniData* file=NULL; |
|
186 TRAPD(r,file=CIniData::NewL(iFileToRead)); |
|
187 |
|
188 //Put file on the cleanupstack if anything else in this function is going to leave, but nothing does. |
|
189 |
|
190 if(r!=KErrNone) |
|
191 { |
|
192 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &iFileToRead); |
|
193 } |
|
194 |
|
195 else |
|
196 { |
|
197 // Look for a key under a named section, retrieve text value |
|
198 TPtrC result; |
|
199 TBool ret=EFalse; //return value from FindVar functions |
|
200 |
|
201 // Set the active state of the plugin depending on the contents of the |
|
202 // corresponding file, which has been set as a member variable |
|
203 ret =file->FindVar(_L("SectionOne"),_L("activeState"),result); |
|
204 if(!ret) |
|
205 { |
|
206 RDebug::Print(_L("Key or section not found. iActiveState default value of ETRUE used.")); |
|
207 iActiveState = ETrue; // Default value |
|
208 } |
|
209 else |
|
210 { |
|
211 _LIT(KFalse,"false"); |
|
212 // Create a lower case copy of the data that is read from the file |
|
213 TBuf<10> resultLowerCase; |
|
214 resultLowerCase.Copy(result); |
|
215 resultLowerCase.LowerCase(); |
|
216 if (resultLowerCase.FindF(KFalse) == KErrNotFound) |
|
217 iActiveState = ETrue; // The string 'false' was not found, so we set the value to 'true' -the default value |
|
218 else |
|
219 iActiveState = EFalse; |
|
220 } |
|
221 TRAPD(r,file->WriteToFileL()); |
|
222 |
|
223 if (KErrNone != r) |
|
224 { |
|
225 RDebug::Print(_L("Error occurred while writing to the file.")); |
|
226 TBuf<84> initInfoFile(sysDrive.Name()); |
|
227 initInfoFile.Append(KInitInfoFile); |
|
228 RDebug::Print(_L("Filename = %S, KeyName = activeState,"), &initInfoFile); |
|
229 RDebug::Print(_L("value = %S."), &result); |
|
230 } |
|
231 delete file; |
|
232 } |
|
233 } |
|
234 |
|
235 |
|
236 |
|
237 //Implement CAuthPluginInterface definitions |
|
238 |
|
239 /** |
|
240 Normally, this would ask the user to input a 4-digit pin and then compare it to |
|
241 the values that this plugin has been trained with. The result should be the |
|
242 user that this PIN corresponds to. |
|
243 'aResult' should be the 'hash' of the stored PIN (which corresponds to the freshly entered PIN) |
|
244 but in this case, it's returned as it was 'unhashed'. |
|
245 */ |
|
246 |
|
247 void CTPostMarketRAMPlugin::Identify(TIdentityId& aId, const TDesC& aClientMessage, |
|
248 HBufC8*& aResult, TRequestStatus& aRequest) |
|
249 { |
|
250 ASSERT(IsActive()); |
|
251 |
|
252 // We are simulating user input by reading from a file |
|
253 // (The data contained in this file has been freshly written by the 'client part in TestExecute') |
|
254 |
|
255 if(aClientMessage != *ClientMessage()) |
|
256 { |
|
257 TRequestStatus* status = &aRequest; |
|
258 User::RequestComplete(status, KErrGeneral); |
|
259 RDebug::Print(_L("Display String Mismatch !!! ABORTING WITH KERRGENERAL")); |
|
260 return; |
|
261 } |
|
262 else |
|
263 { |
|
264 RDebug::Print(_L("Display String at the plugin matches the string sent !! ")); |
|
265 } |
|
266 aRequest = KRequestPending; |
|
267 |
|
268 TBuf8<32> userInput; |
|
269 TRAPD(result1, IdReadUserInput(userInput)); //Get the data from the AuthSvrPolicy.ini file |
|
270 if (KErrNone != result1) |
|
271 { |
|
272 aRequest = result1; |
|
273 } |
|
274 else |
|
275 { |
|
276 // No errors, carry on |
|
277 //Convert the 8-bit string to a 16-bit string for printing in RDebug |
|
278 HBufC* buf = 0; |
|
279 buf = HBufC::New(32); |
|
280 buf->Des().Copy(userInput); |
|
281 _LIT(KMsgDebug1,"Identifying Userinput read from file = %S"); |
|
282 RDebug::Print(KMsgDebug1, buf); |
|
283 delete buf; //Memory cleanup. This string was only needed for the above Print function |
|
284 |
|
285 // Possibly, to allow for the cancellation or quitting, allow that to be the input string |
|
286 _LIT8(KCancelText, "Cancel"); |
|
287 _LIT8(KQuitText, "Quit"); |
|
288 if (userInput == KCancelText) |
|
289 { |
|
290 TRequestStatus* status = &aRequest; |
|
291 User::RequestComplete(status, KErrAuthServPluginCancelled); |
|
292 //aResult will not be updated, as specified |
|
293 } |
|
294 else if (userInput == KQuitText) |
|
295 { |
|
296 TRequestStatus* status = &aRequest; |
|
297 User::RequestComplete(status, KErrAuthServPluginQuit); |
|
298 //aResult will not be updated, as specified |
|
299 } |
|
300 else |
|
301 { |
|
302 //compare with the known set of inputs and see if this is one of them. |
|
303 TInt result2 = CheckForStringPresence(aId, userInput, aRequest); |
|
304 if (KErrNone == result2) //The above function did not leave |
|
305 { |
|
306 //See if the string was found. |
|
307 TInt length = userInput.Length(); |
|
308 |
|
309 aResult = HBufC8::New(length); |
|
310 aResult->Des().Format(_L8("%S"), &userInput); |
|
311 |
|
312 RDebug::Printf("aResult has been updated. aResult = %S, userInput = %S", |
|
313 aResult, &userInput); |
|
314 TRequestStatus* status = &aRequest; |
|
315 User::RequestComplete(status, result2); |
|
316 |
|
317 //Note: aRequest has been updated by the CheckForStringPresence function |
|
318 } |
|
319 else if (KErrNotFound == result2) |
|
320 { |
|
321 RDebug::Printf("The data that the user input was not found (recognized)" |
|
322 "Error = %d", result2); |
|
323 |
|
324 TRequestStatus* status = &aRequest; |
|
325 aId = KUnknownIdentity; |
|
326 User::RequestComplete(status, KErrNone); |
|
327 } |
|
328 else |
|
329 { |
|
330 //Caters for file access errors etc |
|
331 RDebug::Printf("Error occurred while checking for the presence of the string" |
|
332 "in the list. Error = %d", result2); |
|
333 |
|
334 TRequestStatus* status = &aRequest; |
|
335 aId = KUnknownIdentity; |
|
336 User::RequestComplete(status, KErrNone); |
|
337 } |
|
338 } |
|
339 //End of 'else' where the user did not cancel or quit the 'identify' process |
|
340 } |
|
341 } |
|
342 |
|
343 void CTPostMarketRAMPlugin::Cancel() |
|
344 { |
|
345 } |
|
346 |
|
347 void CTPostMarketRAMPlugin::Train(TIdentityId aId, HBufC8*& aResult, TRequestStatus& aRequest) |
|
348 { |
|
349 |
|
350 //Accept user input and update the list of inputs along with IDs. |
|
351 |
|
352 ASSERT(IsActive()); |
|
353 |
|
354 aRequest = KRequestPending; |
|
355 //TInt result = KErrNone; |
|
356 |
|
357 TBuf8<32> userInput; |
|
358 TRAPD(result1, TrainReadUserInput(userInput)); |
|
359 if (KErrNone != result1) |
|
360 { |
|
361 _LIT(KMsgDebug2,"Training Userinput read Error: result = %d"); |
|
362 RDebug::Print(KMsgDebug2, result1); |
|
363 } |
|
364 else |
|
365 { |
|
366 // No errors, carry on |
|
367 //Convert the 8-bit string to a 16-bit string for printing in RDebug |
|
368 HBufC* buf = 0; |
|
369 buf = HBufC::New(32); |
|
370 buf->Des().Copy(userInput); |
|
371 _LIT(KMsgDebug3, "Training Userinput read from file = %S"); |
|
372 RDebug::Print(KMsgDebug3, buf); |
|
373 delete buf; //Memory cleanup. This string was only needed for the above Print function |
|
374 |
|
375 // To allow for the cancellation or quitting, allow that to be the input string |
|
376 TRequestStatus aRequest2 = KRequestPending; |
|
377 _LIT8(KCancelText, "Cancel"); |
|
378 _LIT8(KQuitText, "Quit"); |
|
379 userInput.Trim(); |
|
380 if (userInput.CompareF(KCancelText) == 0) |
|
381 { aRequest2 = KErrAuthServPluginCancelled; } |
|
382 else if (userInput.CompareF(KQuitText) == 0) |
|
383 { aRequest2 = KErrAuthServPluginQuit; } |
|
384 else |
|
385 { |
|
386 //compare with the present set of inputs and see if this is one of them. |
|
387 // update this list with this new user input, tagged to the aId |
|
388 TRAPD(result2, CheckForNewStringPresenceL(aId, userInput, aRequest2)); |
|
389 if (KErrNone != result2) |
|
390 { |
|
391 _LIT(KMsgDebug4, "Training Userinput read Error: results = %d"); |
|
392 RDebug::Print(KMsgDebug4, result2); |
|
393 } |
|
394 else if(KErrNone == aRequest2.Int()) |
|
395 { |
|
396 // No errors, update aResult. |
|
397 // First allocate space for it since this variable will always be a |
|
398 // null pointer coming into this function |
|
399 |
|
400 aResult = HBufC8::New(userInput.Size()); |
|
401 *aResult = userInput; |
|
402 aRequest2 = KErrNone; |
|
403 } |
|
404 else |
|
405 { |
|
406 _LIT(KMsgDebug5, "Error occurred during training. aRequest.Int() = %d"); |
|
407 RDebug::Print(KMsgDebug5, aRequest2.Int()); |
|
408 //aResult is not updated, nor is aId |
|
409 } |
|
410 } |
|
411 // Complete the asynchronous function |
|
412 TRequestStatus* status = &aRequest; |
|
413 User::RequestComplete(status, aRequest2.Int()); |
|
414 } |
|
415 } |
|
416 |
|
417 TBool CTPostMarketRAMPlugin::IsActive () const |
|
418 { |
|
419 // There is never any user intervention required |
|
420 //return true; |
|
421 // As a future development note, this value may be read from a file (or a section in a file) |
|
422 |
|
423 ReloadActiveStateFromIniFile(); |
|
424 return iActiveState; |
|
425 } |
|
426 |
|
427 TInt CTPostMarketRAMPlugin::Forget(TIdentityId aId) |
|
428 { |
|
429 // Open the list of userInputs that have been stored by this plugin |
|
430 // Then find the one that corresponds to this id |
|
431 // Then remove this string from the list and return the correct status value |
|
432 |
|
433 //Open the file |
|
434 TRAPD(result3, FindStringAndRemoveL(aId)); |
|
435 return result3; |
|
436 |
|
437 } |
|
438 |
|
439 TInt CTPostMarketRAMPlugin::DefaultData(TIdentityId aId, HBufC8*& aOutputBuf) |
|
440 { |
|
441 |
|
442 // This implementation of the PIN plugin does support default data. |
|
443 // There will be cases where i don't want this available. Hence the addition of a |
|
444 // new class member iSupportsDefaultData |
|
445 ReloadAllFromIniFile(); |
|
446 |
|
447 TInt result = KErrNotSupported; |
|
448 TRequestStatus aRequest2 = KRequestPending; |
|
449 |
|
450 if (iSupportsDefaultData) //Class member initialised in the constructor |
|
451 { |
|
452 TBufC8<16> defaultBuf(KDefaultData); |
|
453 //compare with the present set of inputs and see if this is one of them. |
|
454 // update this list with this new user input, tagged to the aId |
|
455 TRAPD(result2, CheckForNewStringPresenceL(aId, defaultBuf, aRequest2)); |
|
456 if (KErrNone != result2) |
|
457 { |
|
458 _LIT(KMsgDebug4, "Training Userinput read Error: results = %d"); |
|
459 RDebug::Print(KMsgDebug4, result2); |
|
460 } |
|
461 else if(KErrNone == aRequest2.Int()) |
|
462 { |
|
463 // No errors, update aOutputBuf. |
|
464 // First allocate space for it since this variable will always be a |
|
465 // null pointer coming into this function |
|
466 |
|
467 TRAPD(resAlloc, (aOutputBuf = HBufC8::NewL(KDefaultData().Size())) ); |
|
468 if (KErrNone != resAlloc) |
|
469 { |
|
470 _LIT(KMsgAllocFailed2,"Failed to allocate memory for updating aOutputBuf"); |
|
471 RDebug::Print(KMsgAllocFailed2); |
|
472 result = resAlloc; |
|
473 } |
|
474 else |
|
475 { |
|
476 *aOutputBuf = KDefaultData; |
|
477 result = KErrNone; |
|
478 } |
|
479 } |
|
480 else |
|
481 { |
|
482 _LIT(KMsgDebug5, "Error occurred during training. aRequest2.Int() = %d"); |
|
483 RDebug::Print(KMsgDebug5, aRequest2.Int()); |
|
484 //aOutputBuf is not updated, nor is aId |
|
485 } |
|
486 } |
|
487 |
|
488 return result; |
|
489 } |
|
490 //-------------------------------------------------------------------------------- |
|
491 |
|
492 /** |
|
493 Utility method to capture the data that the user has input |
|
494 (in the form of data stored in a file) |
|
495 */ |
|
496 TInt CTPostMarketRAMPlugin::IdReadUserInput(TBuf8<32>& aInputValue) |
|
497 { |
|
498 |
|
499 TInt retValue; |
|
500 CIniData* file=NULL; |
|
501 TRAPD(r,file=CIniData::NewL(iFileToRead)); |
|
502 if(r!=KErrNone) |
|
503 { |
|
504 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &iFileToRead); |
|
505 retValue = r; |
|
506 } |
|
507 |
|
508 else |
|
509 { |
|
510 // Look for a key under a named section, retrieve text value |
|
511 TPtrC result; |
|
512 TBool ret=EFalse; //return value from FindVar functions |
|
513 |
|
514 ret=file->FindVar(_L("SectionOne"),_L("IdEnteredPinValue"),result); |
|
515 if(!ret) |
|
516 { |
|
517 RDebug::Print(_L("Unable to find the key in the file %S. IdEnteredPinValue is not known, 9999 used. Error = %d"), &iFileToRead, ret); |
|
518 _LIT8(KEnteredPinValueErr, "9999"); |
|
519 aInputValue = KEnteredPinValueErr; // Default value |
|
520 retValue = KErrNotFound; |
|
521 } |
|
522 else |
|
523 { |
|
524 //Later,include a check to ensure that only digits were entered |
|
525 aInputValue.Copy(result); |
|
526 aInputValue.Trim(); |
|
527 retValue = KErrNone; //Not necessary |
|
528 } |
|
529 delete file; //memory cleanup |
|
530 } |
|
531 |
|
532 return retValue; |
|
533 } |
|
534 |
|
535 TInt CTPostMarketRAMPlugin::TrainReadUserInput(TBuf8<32>& aInputValue) |
|
536 { |
|
537 |
|
538 TInt retValue; |
|
539 CIniData* file=NULL; |
|
540 TRAPD(r,file=CIniData::NewL(iFileToRead)); |
|
541 if(r!=KErrNone) |
|
542 { |
|
543 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &iFileToRead); |
|
544 retValue = r; |
|
545 } |
|
546 |
|
547 else |
|
548 { |
|
549 // Look for a key under a named section, retrieve text value |
|
550 TPtrC result; |
|
551 TBool ret=EFalse; //return value from FindVar functions |
|
552 |
|
553 ret=file->FindVar(_L("SectionOne"),_L("TrainEnteredPinValue"),result); |
|
554 if(!ret) |
|
555 { |
|
556 RDebug::Print(_L("Unable to find the key in the file %S. TrainEnteredPinValue is not known, 9999 used. Error = %d"), &iFileToRead, ret); |
|
557 _LIT8(KEnteredPinValueErr, "9999"); |
|
558 aInputValue = KEnteredPinValueErr; // Default value |
|
559 retValue = KErrNotFound; |
|
560 } |
|
561 else |
|
562 { |
|
563 aInputValue.Copy(result); |
|
564 aInputValue.Trim(); |
|
565 retValue = KErrNone; //Not necessary |
|
566 } |
|
567 delete file; //memory cleanup |
|
568 } |
|
569 |
|
570 return retValue; |
|
571 } |
|
572 |
|
573 TInt CTPostMarketRAMPlugin::Reset(TIdentityId/* aId*/, const TDesC&/* aRegistrationData*/, HBufC8*&/* aResult*/) |
|
574 { |
|
575 return KErrNotSupported; |
|
576 } |
|
577 |
|
578 /** |
|
579 Utility method to compare the data that the user has input |
|
580 with all the data that has been stored for users |
|
581 Called by Identify() |
|
582 @return - success or failure value |
|
583 */ |
|
584 TInt CTPostMarketRAMPlugin::CheckForStringPresence(TIdentityId& aId, TBuf8<32> aInputValue, TRequestStatus& aRequestValue) |
|
585 { |
|
586 |
|
587 TInt retValue = KErrNone; |
|
588 // First format the aInputValue string so that it starts with a ':' and ends with a ','. |
|
589 _LIT8(KFormatValue2, ":%S,"); |
|
590 TBuf8<32> aInputValue2; |
|
591 aInputValue2.Format(KFormatValue2, &aInputValue); |
|
592 |
|
593 //Convert the 8-bit string to a 16-bit string for printing in RDebug |
|
594 HBufC* buf = 0; |
|
595 buf = HBufC::New(32); |
|
596 buf->Des().Copy(aInputValue); |
|
597 RDebug::Print(_L("Formatted string: %S"), buf); |
|
598 delete buf; //Memory cleanup. This string was only needed for the above Print function |
|
599 |
|
600 TBuf8<500> pinFileContents1, pinFileContents2; |
|
601 // Read the contents of the file that contains all the ID/PIN combinations |
|
602 |
|
603 CIniData* file=NULL; |
|
604 TRAPD(r,file=CIniData::NewL(iFileToRead)); |
|
605 if(r!=KErrNone) |
|
606 { |
|
607 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &iFileToRead); |
|
608 retValue = r; |
|
609 } |
|
610 else |
|
611 { |
|
612 // Look for a key under a named section, retrieve text value |
|
613 TPtrC result; |
|
614 TBool ret=EFalse; //return value from FindVar functions |
|
615 |
|
616 ret=file->FindVar(_L("SectionOne"),_L("Identity&PinValues"),result); |
|
617 if(!ret) |
|
618 { |
|
619 RDebug::Print(_L("Unable to find the Identity&PinValues key in the file %S."), &iFileToRead); |
|
620 retValue = KErrNotFound; |
|
621 aRequestValue =KErrNotFound; |
|
622 } |
|
623 else |
|
624 { |
|
625 pinFileContents1.Copy(result); |
|
626 |
|
627 TInt searchResult; |
|
628 searchResult = pinFileContents1.Find(aInputValue2); |
|
629 |
|
630 if (KErrNotFound == searchResult) |
|
631 { |
|
632 RDebug::Print(_L("Userinput not found in the pinFile %S. Identification error"), &iFileToRead); |
|
633 aRequestValue= KErrAuthServIdentityNotFound; |
|
634 retValue = searchResult; |
|
635 } |
|
636 else if (searchResult) // a positive value |
|
637 { |
|
638 // Now find the userID by searching back through the string for the "," marker |
|
639 pinFileContents2 = pinFileContents1.Left(searchResult); |
|
640 TInt userIdStartPos = pinFileContents2.LocateReverse(','); |
|
641 |
|
642 //Extract this userId for use by the calling function |
|
643 TBuf8<50> p1 = pinFileContents2.Right(searchResult - userIdStartPos - 1); |
|
644 TLex8 input (p1); |
|
645 TRadix aRadix = EDecimal; |
|
646 input.Val(aId, aRadix); |
|
647 RDebug::Print(_L("UserId that is stored = %u"), aId); |
|
648 aRequestValue = KErrNone; |
|
649 retValue = KErrNone; |
|
650 } |
|
651 else |
|
652 { |
|
653 RDebug::Print(_L("Unexpected error in the 'Find' function. Searchresult = %d"), searchResult); |
|
654 aRequestValue = searchResult; |
|
655 retValue = searchResult; |
|
656 }//End check for key§ion search in file |
|
657 }//End check for safe file access |
|
658 delete file; |
|
659 } |
|
660 |
|
661 return retValue; |
|
662 } |
|
663 |
|
664 /** |
|
665 Utility method to compare the data that the user has input |
|
666 with all the data that has been stored for users |
|
667 Used to find out if the input is unique. |
|
668 -since KIdAmbiguous is no longer used, KIdCancel will be returned if the input is non-unique |
|
669 Called by Train() and DefaultData() |
|
670 */ |
|
671 TInt CTPostMarketRAMPlugin::CheckForNewStringPresenceL(TIdentityId aId, TBuf8<32> aInputValue, TRequestStatus& aRequestValue) |
|
672 { |
|
673 TBuf8<500> pinFileContents, pinFileContents2; |
|
674 TInt retValue = KErrNone; |
|
675 |
|
676 CIniData* file=NULL; |
|
677 TRAPD(r,file=CIniData::NewL(iFileToRead)); |
|
678 |
|
679 if(r!=KErrNone) |
|
680 { |
|
681 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &iFileToRead); |
|
682 return r; |
|
683 } |
|
684 |
|
685 // Look for a key under a named section, retrieve text value |
|
686 TPtrC result; |
|
687 TBool ret=EFalse; //return value from FindVar functions |
|
688 aRequestValue = KErrAuthServIdentityNotFound; //Initialisation |
|
689 |
|
690 ret=file->FindVar(KPluginIniSection, KPinDbTag,result); |
|
691 if(!ret) |
|
692 { |
|
693 RDebug::Print(_L("Unable to find the %S key in the file %S."), &KPinDbTag, &iFileToRead); |
|
694 delete file; |
|
695 return KErrNotFound; |
|
696 } |
|
697 |
|
698 //Copy the data from the named section in the file, and see if any previous user has used this input string |
|
699 pinFileContents.Copy(result); |
|
700 |
|
701 TInt searchResultPin; |
|
702 TBuf8<50> searchStringPin; |
|
703 _LIT8(KFormat3, ":%S,"); |
|
704 searchStringPin.Format(KFormat3, &aInputValue); |
|
705 searchResultPin = pinFileContents.Find(searchStringPin); |
|
706 |
|
707 if (KErrNotFound == searchResultPin) |
|
708 { |
|
709 //check that the identity is unique, if so, update the Db |
|
710 // with the new Id-PIN pair, as is done already |
|
711 // else update the PIN only, ie training data for that identity |
|
712 TInt searchResultId; |
|
713 TBuf8<50> searchStringId; |
|
714 _LIT8(KFormat4, ",%u:"); |
|
715 searchStringId.Format(KFormat4, aId); |
|
716 |
|
717 searchResultId = pinFileContents.Find(searchStringId); |
|
718 |
|
719 TDriveUnit sysDrive (RFs::GetSystemDrive()); |
|
720 TBuf<80> policyFile; |
|
721 if (KErrNotFound == searchResultId) |
|
722 { |
|
723 // Add this entry to the file |
|
724 // This is a simple system, expecting a format as below: |
|
725 // ",aId:inputPin,aId:inputPin,aId:inputPin," |
|
726 |
|
727 _LIT8(KFormat2, "%S%u:%S,"); |
|
728 if (pinFileContents.Size() == 0) |
|
729 { |
|
730 pinFileContents.Append(','); //Initialisation |
|
731 } |
|
732 pinFileContents2.Format(KFormat2, &pinFileContents, aId, &aInputValue); |
|
733 |
|
734 //For the purpose of writing the data to a file, i'll create a 16-bit version of pinFileContents |
|
735 TInt ret2 = 0; |
|
736 HBufC* buf = 0; |
|
737 buf = HBufC::NewL(pinFileContents2.Length()); |
|
738 buf->Des().Copy(pinFileContents2); |
|
739 ret2 = file->SetValue(_L("SectionOne"),_L("Identity&PinValues"), *buf); |
|
740 |
|
741 TRAPD(r,file->WriteToFileL()); |
|
742 |
|
743 |
|
744 if (KErrNone != r) |
|
745 { |
|
746 policyFile.Copy(sysDrive.Name()); |
|
747 policyFile.Append(KPolicyFile); |
|
748 RDebug::Print(_L("Error occurred while writing to the file. Filename = %S, KeyName = AllUserID&PinValues, value = %S."), &policyFile, buf); |
|
749 } |
|
750 delete buf; //Memory cleanup. This string was only needed for the above Print function |
|
751 |
|
752 if(KErrNone == ret2) |
|
753 { |
|
754 aRequestValue = KErrNone; |
|
755 |
|
756 //Update the global database |
|
757 AddToGlobalDb(aId, aInputValue); |
|
758 } |
|
759 else |
|
760 { |
|
761 RDebug::Print(_L("Error occurred while writing data to file. Error = %d"), ret2); |
|
762 aRequestValue = ret2; |
|
763 } |
|
764 |
|
765 } |
|
766 |
|
767 else |
|
768 { |
|
769 //The Identity has already been trained with this plugin, |
|
770 // update the PIN (training data) |
|
771 |
|
772 //extract the string to the right of the end of the aId |
|
773 pinFileContents2 = pinFileContents.Mid(searchResultId + searchStringId.Size()); |
|
774 |
|
775 //Find the end of the PIN (Training data) |
|
776 _LIT8(KPinEndMarker, ","); |
|
777 TBufC8<5> bufPinEndMarker(KPinEndMarker); |
|
778 TInt pinEndPos = pinFileContents2.Find(bufPinEndMarker); |
|
779 |
|
780 //Replace this with the new PIN |
|
781 pinFileContents.Replace((searchResultId + searchStringId.Size()), |
|
782 pinEndPos, aInputValue); |
|
783 |
|
784 //For the purpose of writing the data to a file, i'll create a 16-bit version of pinFileContents |
|
785 TInt ret2 = 0; |
|
786 HBufC* buf = 0; |
|
787 buf = HBufC::NewL(pinFileContents.Length()); |
|
788 buf->Des().Copy(pinFileContents); |
|
789 |
|
790 ret2 = file->SetValue(_L("SectionOne"),_L("Identity&PinValues"), *buf); |
|
791 |
|
792 TRAPD(r,file->WriteToFileL()); |
|
793 |
|
794 if (KErrNone != r) |
|
795 { |
|
796 policyFile.Copy(sysDrive.Name()); |
|
797 policyFile.Append(KPolicyFile); |
|
798 RDebug::Print(_L("Error occurred while writing to the file. Filename = %S, KeyName = AllUserID&PinValues, value = %S."), &policyFile, buf); |
|
799 } |
|
800 delete buf; //Memory cleanup. This string was only needed for the above Print function |
|
801 |
|
802 if(KErrNone ==ret2) |
|
803 { |
|
804 aRequestValue = KErrNone; |
|
805 |
|
806 //Update the global database |
|
807 AddToGlobalDb(aId, aInputValue); |
|
808 } |
|
809 else |
|
810 { |
|
811 RDebug::Print(_L("Error occurred while writing data to file. Error = %d"), ret2); |
|
812 aRequestValue = ret2; |
|
813 } |
|
814 } |
|
815 delete file; |
|
816 return ret; |
|
817 } |
|
818 if (searchResultPin) // a positive value |
|
819 { |
|
820 // A user has already tried to train this plugin using the given data. |
|
821 // The pinFileContents are not updated, to avoid duplication |
|
822 |
|
823 aRequestValue = KErrAuthServPluginCancelled; |
|
824 delete file; |
|
825 return searchResultPin; |
|
826 } |
|
827 |
|
828 RDebug::Print(_L("Unexpected error in the 'Find' function. SearchresultPin = %d"), searchResultPin); |
|
829 retValue = searchResultPin; |
|
830 |
|
831 delete file; |
|
832 |
|
833 return retValue; |
|
834 } |
|
835 |
|
836 |
|
837 /** |
|
838 Utility function to remove the training data that is associated with a given Id |
|
839 Called by the Forget function |
|
840 @return - KIdSuccess, KIdUnknown or some error code |
|
841 */ |
|
842 TInt CTPostMarketRAMPlugin::FindStringAndRemoveL (TIdentityId aId) |
|
843 { |
|
844 TBuf8<500> pinFileContents, pinFileContents2; |
|
845 TInt retValue = KErrAuthServNoSuchIdentity; //init |
|
846 CIniData* file=NULL; |
|
847 //First read the list of userId and PIN combinations from a file |
|
848 TRAPD(r,file=CIniData::NewL(iFileToRead)); |
|
849 if(r!=KErrNone) |
|
850 { |
|
851 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &iFileToRead); |
|
852 retValue = r; |
|
853 } |
|
854 else |
|
855 { |
|
856 // Look for a key under a named section, retrieve text value |
|
857 TPtrC result; |
|
858 TBool ret=EFalse; //return value from FindVar functions |
|
859 |
|
860 ret=file->FindVar(KPluginIniSection, KPinDbTag,result); |
|
861 if(!ret) |
|
862 { |
|
863 RDebug::Print(_L("Config error: Unable to find the %S key in the file %S."), &KPinDbTag, &iFileToRead); |
|
864 retValue = KErrNotFound; |
|
865 } |
|
866 else |
|
867 { |
|
868 //Copy the data from the named section in the file, and see if any previous user has used this input string |
|
869 pinFileContents.Copy(result); |
|
870 |
|
871 //Format the searchstring as defined in the file so that it starts with a ',' and ends with a ':'. |
|
872 _LIT8(KFormatValue3, ",%u:"); |
|
873 |
|
874 TBuf8<32> searchString; |
|
875 searchString.Format(KFormatValue3, aId); |
|
876 |
|
877 //For the purpose of printing the data to a file, i'll create a 16-bit version of pinFileContents |
|
878 HBufC* buf = 0; |
|
879 buf = HBufC::NewL(searchString.Length()); |
|
880 buf->Des().Copy(searchString); |
|
881 RDebug::Print(_L("Formatted searchString used in 'FindStringAndRemove(): %S"), buf); |
|
882 delete buf; |
|
883 |
|
884 TInt userIdStartPos; //The offset of the searchString within pinFileContents |
|
885 //i.e the position of the '.' just before the identityId |
|
886 userIdStartPos = pinFileContents.Find(searchString); |
|
887 if (KErrNotFound == userIdStartPos) |
|
888 { |
|
889 RDebug::Print(_L("FindStringAndRemoveL: The specified ID was not found in the pinFile")); |
|
890 retValue = KErrAuthServNoSuchIdentity; //KIdUnknown; |
|
891 } |
|
892 else |
|
893 { |
|
894 |
|
895 //Find where the string (including PIN) ends |
|
896 TLex8 aLex = TLex8(pinFileContents); |
|
897 TInt length(0); |
|
898 aLex.Inc(userIdStartPos+1); |
|
899 while(aLex.Peek() != ',') |
|
900 { |
|
901 aLex.Inc(); |
|
902 length++; |
|
903 } |
|
904 |
|
905 //remove the found (total) string from the list (including the starting ',') |
|
906 pinFileContents.Delete(userIdStartPos,length+1); |
|
907 |
|
908 //Update the file |
|
909 //For the purpose of writing the data to a file, i'll create a 16-bit version of pinFileContents |
|
910 TInt ret2 = 0; |
|
911 HBufC* buf; |
|
912 buf = HBufC::NewL(pinFileContents.Length()); |
|
913 buf->Des().Copy(pinFileContents); |
|
914 |
|
915 ret2 = file->SetValue(KPluginIniSection, KPinDbTag, *buf); |
|
916 |
|
917 TRAPD(r,file->WriteToFileL()); |
|
918 TDriveUnit sysDrive (RFs::GetSystemDrive()); |
|
919 TBuf<2> sysDriveName (sysDrive.Name()); |
|
920 TBuf<84> policyFile; |
|
921 |
|
922 if (KErrNone != r) |
|
923 { |
|
924 policyFile.Copy(sysDriveName); |
|
925 policyFile.Append(KPolicyFile); |
|
926 RDebug::Print(_L("Error occurred while writing to the file. Filename = %S, KeyName = AllUserID&PinValues, value = %S."), &policyFile, buf); |
|
927 } |
|
928 delete buf; //Memory cleanup. This string was only needed for the above Print function |
|
929 |
|
930 if (KErrNone !=ret2) |
|
931 { |
|
932 policyFile .Copy(sysDriveName); |
|
933 policyFile.Append(KAuthSvrPolicyFile); |
|
934 RDebug::Print(_L("Error occurred in WriteToFileL(). Error = %d. Filename= %S"), ret2, &policyFile); |
|
935 retValue = ret2; |
|
936 } |
|
937 else |
|
938 { |
|
939 retValue = KErrNone; |
|
940 } |
|
941 } |
|
942 }//End check for key§ion search in file |
|
943 delete file; |
|
944 }//End check for safe file access |
|
945 |
|
946 return retValue; |
|
947 } |
|
948 |
|
949 |
|
950 /** |
|
951 Utility function to Update the Global Db with the training data |
|
952 that is associated with a given Id. The update will not happen if |
|
953 the identity is already present in this list, i.e. it's been pu in |
|
954 by another plugin |
|
955 Called by the CheckForNewStringPresence function |
|
956 @return - KErrNone, or some error code |
|
957 */ |
|
958 TInt CTPostMarketRAMPlugin::AddToGlobalDb (TIdentityId aId, TBuf8<32> aInputValue) |
|
959 { |
|
960 |
|
961 TBuf8<500> totalDbFileContents, totalDbFileContents2; |
|
962 TInt retValue = KErrNone; |
|
963 CIniData* file=NULL; |
|
964 |
|
965 TDriveUnit sysDrive (RFs::GetSystemDrive()); |
|
966 TDriveName sysDriveName (sysDrive.Name()); |
|
967 TBuf<128> authSvrPolicyFile(sysDriveName); |
|
968 authSvrPolicyFile.Append(KAuthSvrPolicyFile); |
|
969 |
|
970 TRAPD(r,file=CIniData::NewL(authSvrPolicyFile)); |
|
971 if(r!=KErrNone) |
|
972 { |
|
973 RDebug::Print(_L("Unable to create CIniData object. Error = %d, File = %S"), r, &authSvrPolicyFile); |
|
974 retValue = r; |
|
975 } |
|
976 else |
|
977 { |
|
978 // Look for a key under a named section, retrieve text value |
|
979 TPtrC result; |
|
980 TBool ret=EFalse; //return value from FindVar functions |
|
981 |
|
982 ret=file->FindVar(KPluginIniSection, KTotalDbTag,result); |
|
983 if(!ret) |
|
984 { |
|
985 RDebug::Print(_L("Unable to find the %S key in the file %S."), &KTotalDbTag, &authSvrPolicyFile); |
|
986 retValue = KErrNotFound; |
|
987 } |
|
988 else |
|
989 { |
|
990 //Copy the data from the named section in the file, and see if any previous user has used this input string |
|
991 totalDbFileContents.Copy(result); |
|
992 TBuf8<20> aidString; |
|
993 aidString.Num(aId, EDecimal); |
|
994 TInt searchResult; |
|
995 searchResult = totalDbFileContents.Find(aidString); |
|
996 |
|
997 if (KErrNotFound == searchResult) |
|
998 { |
|
999 // Add this entry to the file |
|
1000 // This is a simple system, expecting a format as below: |
|
1001 // ",aId:inputPin,aId:inputPin,aId:inputPin," |
|
1002 _LIT8(KFormat2, "%S%u:%S,"); |
|
1003 if (totalDbFileContents.Size() == 0) |
|
1004 { |
|
1005 totalDbFileContents.Append(','); //Initialisation |
|
1006 } |
|
1007 totalDbFileContents2.Format(KFormat2, &totalDbFileContents, aId, &aInputValue); |
|
1008 |
|
1009 //For the purpose of writing the data to a file, i'll create a 16-bit version of pinFileContents |
|
1010 TInt ret2 = 0; |
|
1011 HBufC* buf = 0; |
|
1012 buf = HBufC::New(totalDbFileContents2.Length()); |
|
1013 buf->Des().Copy(totalDbFileContents2); |
|
1014 ret2 = file->SetValue(KPluginIniSection, KTotalDbTag, *buf); |
|
1015 |
|
1016 TRAPD(r,file->WriteToFileL()); |
|
1017 |
|
1018 if (KErrNone != r) |
|
1019 { |
|
1020 TBuf<80> policyFile(sysDriveName); |
|
1021 policyFile.Append(KPolicyFile); |
|
1022 RDebug::Print(_L("Error occurred while writing to the file. Filename = %S, KeyName = AllUserID&PinValues, value = %S."), &policyFile, buf); |
|
1023 } |
|
1024 delete buf; //Memory cleanup. This string was only needed for the above Print function |
|
1025 |
|
1026 if (KErrNone !=ret2) |
|
1027 { |
|
1028 RDebug::Print(_L("Error occurred in SetValue(). Error = %d. Filename= %S"), ret2, &authSvrPolicyFile); |
|
1029 retValue = ret2; |
|
1030 } |
|
1031 } |
|
1032 else |
|
1033 { |
|
1034 // A user has already tried to train this plugin using the given data. |
|
1035 // The pinFileContents are not updated, to avoid duplication |
|
1036 retValue = KErrNone; |
|
1037 }//End aidString search in the totalDbFileContents string (Find()) |
|
1038 }//End check for key§ion search in file (FindVar()) |
|
1039 delete file; |
|
1040 }//End check for safe file access |
|
1041 return retValue; |
|
1042 } |
|
1043 |
|
1044 const HBufC* CTPostMarketRAMPlugin::ClientMessage() |
|
1045 { |
|
1046 return iClientMessage; |
|
1047 } |
|
1048 |
|
1049 const TPtrC& CTPostMarketRAMPlugin::Name() const |
|
1050 { |
|
1051 return iName; |
|
1052 } |
|
1053 const TPtrC& CTPostMarketRAMPlugin::Description() const |
|
1054 { |
|
1055 return iDescription; |
|
1056 } |
|
1057 AuthServer::TAuthPluginType CTPostMarketRAMPlugin::Type() const |
|
1058 { |
|
1059 return iType; |
|
1060 } |
|
1061 |
|
1062 AuthServer::TEntropy CTPostMarketRAMPlugin::MinEntropy() const |
|
1063 { |
|
1064 return iMinEntropy; |
|
1065 } |
|
1066 |
|
1067 AuthServer::TPercentage CTPostMarketRAMPlugin::FalsePositiveRate() const |
|
1068 { |
|
1069 return iFalsePositiveRate; |
|
1070 } |
|
1071 |
|
1072 AuthServer::TPercentage CTPostMarketRAMPlugin::FalseNegativeRate() const |
|
1073 { |
|
1074 return iFalseNegativeRate; |
|
1075 } |
|
1076 |