|
1 /* |
|
2 * Copyright (c) 2005-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 * tMiscAuthPlugin.cpp |
|
16 * Improvements: |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #include <f32file.h> |
|
23 |
|
24 |
|
25 #ifndef __INIPARSER_H__ |
|
26 #include <cinidata.h> |
|
27 #endif // __INIPARSER_H__ |
|
28 |
|
29 #include "tPluginBase.h" |
|
30 #include <e32svr.h> |
|
31 #include <authserver/auth_srv_errs.h> |
|
32 |
|
33 TBool E32Dll() |
|
34 { |
|
35 |
|
36 return ETrue; |
|
37 } |
|
38 |
|
39 |
|
40 // Construction and destruction functions |
|
41 //CTPluginUnknown* CTPluginUnknown::NewL(const TPluginId aPluginId) |
|
42 CTPluginUnknown* CTPluginUnknown::NewL() |
|
43 { |
|
44 CTPluginUnknown* self = new (ELeave) CTPluginUnknown(); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 CTPluginUnknown::~CTPluginUnknown() |
|
52 {} |
|
53 |
|
54 //CTPluginUnknown::CTPluginUnknown(const TPluginId aPluginId) |
|
55 CTPluginUnknown::CTPluginUnknown() |
|
56 { // See ConstructL() for initialisation completion. |
|
57 } |
|
58 |
|
59 void CTPluginUnknown::ConstructL() |
|
60 // Safely complete the initialization of the constructed object |
|
61 { |
|
62 |
|
63 //TUid iDtor_ID_Key; |
|
64 |
|
65 // Initialise member data |
|
66 /* |
|
67 iName = "Pin1"; |
|
68 iDescription = "PIN Plugin"; |
|
69 iMinEntropy = 0.8; |
|
70 iFalsePositiveRate = 1; |
|
71 iFalseNegativeRate = 1; |
|
72 iType = EAuthKnowledge; |
|
73 |
|
74 // TPtrC iName; |
|
75 // TPtrC iDescription; |
|
76 // TEntropy iMinEntropy; |
|
77 // TPercentage iFalsePositiveRate; |
|
78 // TPercentage iFalseNegativeRate; |
|
79 // TPluginType iType; |
|
80 */ |
|
81 |
|
82 iSupportsDefaultData = true; |
|
83 iNumTimesTrained = 0; |
|
84 } |
|
85 |
|
86 |
|
87 //Implement CAuthPluginInterface definitions |
|
88 void CTPluginUnknown::Identify(TIdentityId& aId, HBufC8*& aResult, TRequestStatus& aRequest) |
|
89 { |
|
90 // We are simulating user input by reading from a file |
|
91 // (The data contained in this file has been freshly written by the 'client part in TestExecute') |
|
92 |
|
93 aRequest = KRequestPending; |
|
94 //aId = USER; |
|
95 aId = KUnknownIdentity; //Unknown Id |
|
96 aResult = HBufC8::New(16); |
|
97 |
|
98 TRequestStatus* status = &aRequest; |
|
99 |
|
100 if(aResult == NULL) |
|
101 { |
|
102 User::RequestComplete(status, KErrNoMemory); |
|
103 return; |
|
104 } |
|
105 |
|
106 aResult->Des().Format(_L8("%x"), aId); |
|
107 |
|
108 |
|
109 |
|
110 //aRequest = AuthServer::KIdCancel; //KIdCancel not defined yet |
|
111 //aResult will not be updated, as specified |
|
112 |
|
113 |
|
114 //aRequest = AuthServer::KIdQuit; //KIdQuit not defined yet |
|
115 //aResult will not be updated, as specified |
|
116 |
|
117 |
|
118 //aRequest = AuthServer::KIdUnknown; |
|
119 |
|
120 //return aRequest.Int(); |
|
121 |
|
122 User::RequestComplete(status, KErrNone); |
|
123 } |
|
124 |
|
125 void CTPluginUnknown::Cancel() |
|
126 { |
|
127 } |
|
128 |
|
129 void CTPluginUnknown::Train(TIdentityId /*aId*/, HBufC8*& /*aResult*/, TRequestStatus& aRequest) |
|
130 { |
|
131 |
|
132 aRequest = KRequestPending; |
|
133 iNumTimesTrained++; |
|
134 //Possibly update aResult here, later for now we'll pretend that the plugin was cancelled |
|
135 |
|
136 TRequestStatus* status = &aRequest; |
|
137 User::RequestComplete(status, KErrAuthServPluginCancelled); |
|
138 } |
|
139 |
|
140 |
|
141 TBool CTPluginUnknown::IsActive() const |
|
142 { |
|
143 // There is never any user intervention required |
|
144 return true; |
|
145 |
|
146 // As a future development note, this value may be read from a file (or a section in a file) |
|
147 } |
|
148 |
|
149 TInt CTPluginUnknown::Forget(TIdentityId /*aId*/) |
|
150 { |
|
151 |
|
152 //Dummy implementation |
|
153 return KErrNone; |
|
154 } |
|
155 |
|
156 TInt CTPluginUnknown::DefaultData(TIdentityId /*aId*/, HBufC8*& aOutputBuf) |
|
157 { |
|
158 |
|
159 // This implementation of the PIN plugin does support default data. |
|
160 // There will be cases where i don't want this available. Hence the addition of a |
|
161 // new class member iSupportsDefaultData |
|
162 |
|
163 TInt result = KErrNone; |
|
164 |
|
165 if (iSupportsDefaultData) //Class member initialised in the constructor |
|
166 { |
|
167 //_LIT(KDefaultData, "0000"); // in tPluginBase.h |
|
168 aOutputBuf = HBufC8::New(KDefaultData().Size()); |
|
169 if(aOutputBuf == NULL) |
|
170 { |
|
171 return KErrNoMemory; |
|
172 } |
|
173 *aOutputBuf = KDefaultData; |
|
174 } |
|
175 else |
|
176 result = KErrNotSupported; |
|
177 |
|
178 return result; |
|
179 } |
|
180 |
|
181 TPluginId CTPluginUnknown::Id() const |
|
182 { |
|
183 return 0x11112FFF; |
|
184 } |
|
185 |
|
186 |
|
187 |
|
188 //========================================================================= |
|
189 |
|
190 //========================================================================= |
|
191 |
|
192 // Construction and destruction functions |
|
193 /*CTPluginBase* CTPluginBase::NewL() |
|
194 { |
|
195 CTPluginBase* self = new (ELeave) TMyType(); |
|
196 CleanupStack::PushL(self); |
|
197 self->ConstructL(); |
|
198 CleanupStack::Pop(); |
|
199 return self; |
|
200 } |
|
201 */ |
|
202 |
|
203 CTPluginBase::~CTPluginBase() |
|
204 {} |
|
205 |
|
206 CTPluginBase::CTPluginBase() |
|
207 { |
|
208 // See ConstructL() for initialisation completion. |
|
209 } |
|
210 |
|
211 void CTPluginBase::ConstructL() |
|
212 // Safely complete the initialization of the constructed object |
|
213 { |
|
214 |
|
215 //TUid iDtor_ID_Key; |
|
216 |
|
217 |
|
218 /* |
|
219 iName = "Pin1"; |
|
220 iDescription = "PIN Plugin"; |
|
221 iMinEntropy = 0.8; |
|
222 iFalsePositiveRate = 1; |
|
223 iFalseNegativeRate = 1; |
|
224 iType = EAuthKnowledge; |
|
225 |
|
226 // TPtrC iName; |
|
227 // TPtrC iDescription; |
|
228 // TEntropy iMinEntropy; |
|
229 // TPercentage iFalsePositiveRate; |
|
230 // TPercentage iFalseNegativeRate; |
|
231 // TPluginType iType; |
|
232 */ |
|
233 |
|
234 iType = GetType(); |
|
235 |
|
236 iSupportsDefaultData = true; |
|
237 iNumTimesTrained = 0; |
|
238 } |
|
239 |
|
240 |
|
241 //Implement CAuthPluginInterface definitions |
|
242 |
|
243 void CTPluginBase::Identify(TIdentityId& aId, HBufC8*& aResult, TRequestStatus& aRequest) |
|
244 { |
|
245 // We are simulating user input by reading from a file |
|
246 // (The data contained in this file has been freshly written by the 'client part in TestExecute') |
|
247 |
|
248 // aRequest = KRequestPending; |
|
249 // aId = USER; |
|
250 //delete aResult; |
|
251 // aResult = HBufC8::NewL(16); |
|
252 |
|
253 //aResult->Des().Format(_L8("%x"), aResult); |
|
254 // aResult->Des().Format(_L8("%d"), aId); |
|
255 |
|
256 |
|
257 //aRequest = AuthServer::KIdCancel; //KIdCancel not defined yet |
|
258 //aResult will not be updated, as specified |
|
259 |
|
260 |
|
261 //aRequest = AuthServer::KIdQuit; //KIdQuit not defined yet |
|
262 //aResult will not be updated, as specified |
|
263 |
|
264 |
|
265 //aRequest = AuthServer::KIdUnknown; |
|
266 |
|
267 // aRequest = KIdSuccess; |
|
268 //return aRequest.Int(); |
|
269 |
|
270 aRequest = KRequestPending; |
|
271 aId = GetId(); |
|
272 aResult = HBufC8::New(16); |
|
273 |
|
274 TRequestStatus* status = &aRequest; |
|
275 if(aResult == NULL) |
|
276 { |
|
277 User::RequestComplete(status, KErrNoMemory); |
|
278 return; |
|
279 } |
|
280 |
|
281 aResult->Des().Format(_L8("%x"), aId); |
|
282 User::RequestComplete(status, KErrNone); |
|
283 } |
|
284 |
|
285 |
|
286 void CTPluginBase::Cancel() |
|
287 { |
|
288 } |
|
289 |
|
290 void CTPluginBase::Train(TIdentityId aId, HBufC8*& aResult, TRequestStatus& aRequest) |
|
291 { |
|
292 |
|
293 aRequest = KRequestPending; |
|
294 iNumTimesTrained++; |
|
295 aResult = HBufC8::New(16); |
|
296 TRequestStatus* status = &aRequest; |
|
297 if(aResult == NULL) |
|
298 { |
|
299 User::RequestComplete(status, KErrNoMemory); |
|
300 return; |
|
301 } |
|
302 TInt number = iNumTimesTrained*GetId(); |
|
303 aResult->Des().Format(_L8("%x"), aId); |
|
304 |
|
305 User::RequestComplete(status, KErrNone); |
|
306 } |
|
307 |
|
308 |
|
309 TBool CTPluginBase::IsActive() const |
|
310 { |
|
311 // There is never any user intervention required |
|
312 return true; |
|
313 |
|
314 // As a future development note, this value may be read from a file (or a section in a file) |
|
315 } |
|
316 |
|
317 TInt CTPluginBase::Forget(TIdentityId /*aId*/) |
|
318 { |
|
319 |
|
320 //Dummy implementation |
|
321 return KErrNone; |
|
322 |
|
323 //Improvement |
|
324 // If (NumTimesTrained == 0) |
|
325 // return AuthServer::KIdUnknown; // This is what is returned for the CTUnknownPlugin class |
|
326 |
|
327 } |
|
328 |
|
329 TInt CTPluginBase::DefaultData(TIdentityId /*aId*/, HBufC8*& aOutputBuf) |
|
330 { |
|
331 |
|
332 // This implementation of the PIN plugin does support default data. |
|
333 // There will be cases where i don't want this available. Hence the addition of a |
|
334 // new class member iSupportsDefaultData |
|
335 |
|
336 TInt result = KErrNone; |
|
337 |
|
338 if (iSupportsDefaultData) //Class member initialised in the constructor |
|
339 { |
|
340 //_LIT(KDefaultData, "0000"); // in tPinAuthPlugin.h |
|
341 aOutputBuf = HBufC8::New(KDefaultData().Size()); |
|
342 if(aOutputBuf == NULL) |
|
343 { |
|
344 return KErrNoMemory; |
|
345 } |
|
346 *aOutputBuf = KDefaultData; |
|
347 } |
|
348 else |
|
349 result = KErrNotSupported; |
|
350 |
|
351 return result; |
|
352 } |
|
353 |
|
354 TPluginId CTPluginBase::Id() const |
|
355 { |
|
356 return GetId(); |
|
357 } |