|
1 /* |
|
2 * Copyright (c) 2006-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 * CPinPlugin implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 |
|
24 |
|
25 #include "pinplugin.h" |
|
26 #include <bautils.h> |
|
27 #include <barsread.h> |
|
28 #include <e32math.h> |
|
29 #include <pinpluginconfig.rsg> |
|
30 #include <ecom/ecom.h> |
|
31 #include <ecom/implementationproxy.h> |
|
32 #include <f32file.h> |
|
33 |
|
34 using namespace AuthServer; |
|
35 |
|
36 _LIT(KPinPluginResourceFile, "z:\\Resource\\pinplugin\\pinpluginconfig.rsc"); |
|
37 |
|
38 const TPluginId KPinPluginImplementationUid = 0x200032E5; |
|
39 |
|
40 CPinPlugin* CPinPlugin::NewL() |
|
41 { |
|
42 CPinPlugin* self = CPinPlugin::NewLC(); |
|
43 CleanupStack::Pop(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CPinPlugin* CPinPlugin::NewLC() |
|
48 { |
|
49 CPinPlugin* self = new(ELeave) CPinPlugin(); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CPinPlugin::~CPinPlugin() |
|
56 { |
|
57 delete iPinPluginAO; |
|
58 delete iPinName; |
|
59 delete iPinDescription; |
|
60 } |
|
61 |
|
62 CPinPlugin::CPinPlugin() |
|
63 { |
|
64 iActive = ETrue; |
|
65 } |
|
66 |
|
67 void CPinPlugin::ConstructL() |
|
68 { |
|
69 TInt retryCount, pinSize, pinMinSize, pinMaxSize; |
|
70 TReal val; |
|
71 |
|
72 // Verifies the UID/SID of the Authentication server |
|
73 // to make sure pinplugin is loaded from Authentication server. |
|
74 RProcess process; |
|
75 |
|
76 ReadResourceL(retryCount, pinSize, pinMinSize, pinMaxSize); |
|
77 |
|
78 __ASSERT_ALWAYS(retryCount >= 0 && pinSize >= 0 && pinMinSize >= 0 && |
|
79 pinMaxSize >= 0 && pinSize >= pinMinSize && pinSize <= pinMaxSize, |
|
80 User::Panic(KPinPluginPanicString(), EPinPanicInvalidConfigValues)); |
|
81 |
|
82 iName.Set(iPinName->Des()); |
|
83 iDescription.Set(iPinDescription->Des()); |
|
84 Math::Pow10(val, pinMinSize); |
|
85 // since pinMinSize is always a Int value, val never have a floating point |
|
86 // in future if entropy is changed to have real value also, it will work |
|
87 // now in our case, compiler do the default truncation. |
|
88 iMinEntropy = val; |
|
89 iFalsePositiveRate = 0; |
|
90 iFalseNegativeRate = 0; |
|
91 iType = AuthServer::EAuthKnowledge; |
|
92 |
|
93 //Create a new implementation object |
|
94 iPinPluginAO = CPinPluginAO::NewL(pinSize, pinMinSize, pinMaxSize, retryCount); |
|
95 |
|
96 SetPluginStateL(); |
|
97 |
|
98 } |
|
99 |
|
100 |
|
101 //Implement CAuthPluginInterface definitions |
|
102 |
|
103 void CPinPlugin::Identify(TIdentityId& aId,const TDesC& aClientMessage, |
|
104 HBufC8*& aResult, TRequestStatus& aRequest) |
|
105 { |
|
106 iPinPluginAO->Identify(aId, aClientMessage, aResult, aRequest); |
|
107 } |
|
108 |
|
109 void CPinPlugin::Cancel() |
|
110 { |
|
111 iPinPluginAO->Cancel(); |
|
112 } |
|
113 |
|
114 void CPinPlugin::Train(TIdentityId aId, HBufC8*& aResult, TRequestStatus& aRequest) |
|
115 { |
|
116 iPinPluginAO->Train(aId, aResult, aRequest); |
|
117 } |
|
118 |
|
119 TInt CPinPlugin::Forget(TIdentityId aId) |
|
120 { |
|
121 return iPinPluginAO->Forget(aId); |
|
122 } |
|
123 |
|
124 TBool CPinPlugin::IsActive() const |
|
125 { |
|
126 return iActive; |
|
127 } |
|
128 |
|
129 TInt CPinPlugin::DefaultData(TIdentityId aId, HBufC8*& aOutputBuf) |
|
130 { |
|
131 return iPinPluginAO->DefaultData(aId, aOutputBuf); |
|
132 } |
|
133 |
|
134 TInt CPinPlugin::Reset(TIdentityId aIdentityId, const TDesC& aRegistrationData, HBufC8*& aResult) |
|
135 { |
|
136 TRAPD(err, iPinPluginAO->ResetL(aIdentityId, aRegistrationData, aResult)); |
|
137 return err; |
|
138 } |
|
139 |
|
140 TPluginId CPinPlugin::Id() const |
|
141 { |
|
142 return KPinPluginImplementationUid; |
|
143 } |
|
144 |
|
145 void CPinPlugin::ReadResourceL(TInt& aRetryCount, TInt& aPinSize, TInt& aPinMinSize, |
|
146 TInt& aPinMaxSize) |
|
147 { |
|
148 RFs fs; |
|
149 TFileName fileName(KPinPluginResourceFile); |
|
150 User::LeaveIfError(fs.Connect()); |
|
151 CleanupClosePushL(fs); |
|
152 BaflUtils::NearestLanguageFile(fs,fileName); |
|
153 RResourceFile resourceFile; |
|
154 resourceFile.OpenL(fs,fileName); |
|
155 CleanupClosePushL(resourceFile); |
|
156 resourceFile.ConfirmSignatureL(0); |
|
157 resourceFile.Offset(); |
|
158 |
|
159 aRetryCount = ResourceValueL(resourceFile, R_IDENTIFY_DIALOG_RETRY_COUNT); |
|
160 aPinSize = ResourceValueL(resourceFile, R_PIN_SIZE); |
|
161 aPinMinSize = ResourceValueL(resourceFile, R_PIN_MIN_SIZE); |
|
162 aPinMaxSize = ResourceValueL(resourceFile, R_PIN_MAX_SIZE); |
|
163 |
|
164 HBufC8* res = resourceFile.AllocReadLC(R_PLUGIN_INFO); |
|
165 TResourceReader reader; |
|
166 reader.SetBuffer(res); |
|
167 iPinName = reader.ReadTPtrC().AllocL(); |
|
168 iPinDescription = reader.ReadTPtrC().AllocL(); |
|
169 CleanupStack::PopAndDestroy(3, &fs); |
|
170 } |
|
171 |
|
172 TInt CPinPlugin::ResourceValueL(RResourceFile& aResFile, const TInt aResourceID) |
|
173 { |
|
174 TResourceReader reader; |
|
175 HBufC8* res = aResFile.AllocReadLC(aResourceID); |
|
176 reader.SetBuffer(res); |
|
177 TInt val = reader.ReadInt8(); |
|
178 CleanupStack::PopAndDestroy(res); |
|
179 return val; |
|
180 } |
|
181 |
|
182 void CPinPlugin::SetPluginStateL() |
|
183 { |
|
184 // identifies the pinplugins state by looking for a file |
|
185 // in system drive. |
|
186 _LIT(KPinPlugin,"pinplugin_inactive.txt"); |
|
187 TFileName filename; |
|
188 filename.Copy(KPinPlugin); // convert from 8 -> 16 bit descriptor |
|
189 |
|
190 TDriveUnit sysDrive = RFs::GetSystemDrive(); |
|
191 TDriveName sysDriveName (sysDrive.Name()); |
|
192 filename.Insert(0,sysDriveName); |
|
193 filename.Insert(2,_L("\\")); |
|
194 |
|
195 RFs fs; |
|
196 User::LeaveIfError(fs.Connect()); |
|
197 TEntry entry; |
|
198 TInt err = fs.Entry(filename, entry); |
|
199 if(err == KErrNone) |
|
200 { |
|
201 iActive = EFalse; |
|
202 } |
|
203 else if( err == KErrNotFound ) |
|
204 { |
|
205 iActive = ETrue; |
|
206 } |
|
207 else |
|
208 { |
|
209 User::LeaveIfError(err); |
|
210 } |
|
211 } |
|
212 |
|
213 // Map the interface UIDs to implementation factory functions |
|
214 const TImplementationProxy ImplementationTable[] = |
|
215 { |
|
216 IMPLEMENTATION_PROXY_ENTRY(KPinPluginImplementationUid, CPinPlugin::NewL) |
|
217 }; |
|
218 |
|
219 // Exported proxy function to resolve intstantiation methods for an ECOM plugin dll |
|
220 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
221 { |
|
222 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
223 return ImplementationTable; |
|
224 } |
|
225 |
|
226 |
|
227 const TPtrC& CPinPlugin::Name() const |
|
228 { |
|
229 return iName; |
|
230 } |
|
231 const TPtrC& CPinPlugin::Description() const |
|
232 { |
|
233 return iDescription; |
|
234 } |
|
235 TAuthPluginType CPinPlugin::Type() const |
|
236 { |
|
237 return iType; |
|
238 } |
|
239 |
|
240 TEntropy CPinPlugin::MinEntropy() const |
|
241 { |
|
242 return iMinEntropy; |
|
243 } |
|
244 |
|
245 TPercentage CPinPlugin::FalsePositiveRate() const |
|
246 { |
|
247 return iFalsePositiveRate; |
|
248 } |
|
249 |
|
250 TPercentage CPinPlugin::FalseNegativeRate() const |
|
251 { |
|
252 return iFalseNegativeRate; |
|
253 } |
|
254 |
|
255 |
|
256 |
|
257 |