|
1 /* |
|
2 * Copyright (c) 2001-2006 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: EAP and WLAN authentication protocols. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // This is enumeration of EAPOL source code. |
|
20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
21 #undef EAP_FILE_NUMBER_ENUM |
|
22 #define EAP_FILE_NUMBER_ENUM 426 |
|
23 #undef EAP_FILE_NUMBER_DATE |
|
24 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
26 |
|
27 |
|
28 // INCLUDE FILES |
|
29 #include <e32base.h> |
|
30 #include "EapTlsPeapUtils.h" |
|
31 #include "EapTlsPeapDbParameterNames.h" |
|
32 #include "EapTlsPeapDbDefaults.h" |
|
33 #include <EapTlsPeapUiConnection.h> |
|
34 #include <EapTlsPeapUiCipherSuites.h> |
|
35 #include <EapTlsPeapUiCipherSuite.h> |
|
36 |
|
37 const TUint KMaxSqlQueryLength = 256; |
|
38 |
|
39 CEapTlsPeapUiCipherSuites::CEapTlsPeapUiCipherSuites(CEapTlsPeapUiConnection * const aUiConn) |
|
40 : iIsOpened(EFalse) |
|
41 , iUiConn(aUiConn) |
|
42 , iDataPtr(NULL) |
|
43 { |
|
44 } |
|
45 |
|
46 |
|
47 CEapTlsPeapUiCipherSuites::~CEapTlsPeapUiCipherSuites() |
|
48 { |
|
49 if (iUiConn) |
|
50 { |
|
51 Close(); |
|
52 iUiConn = NULL; |
|
53 } |
|
54 } |
|
55 |
|
56 |
|
57 TInt CEapTlsPeapUiCipherSuites::Open() |
|
58 { |
|
59 if (iIsOpened) |
|
60 { |
|
61 return KErrAlreadyExists; |
|
62 } |
|
63 |
|
64 TInt err = iUiConn->GetDatabase(iDatabase); |
|
65 if (err != KErrNone) |
|
66 { |
|
67 return err; |
|
68 } |
|
69 |
|
70 iIsOpened = ETrue; |
|
71 |
|
72 return KErrNone; |
|
73 } |
|
74 |
|
75 |
|
76 TInt CEapTlsPeapUiCipherSuites::GetCipherSuites(CArrayFixFlat<TEapTlsPeapUiCipherSuite> ** aDataPtr) |
|
77 { |
|
78 if (aDataPtr == NULL) |
|
79 { |
|
80 return KErrArgument; |
|
81 } |
|
82 if (iIsOpened == EFalse) |
|
83 { |
|
84 return KErrSessionClosed; |
|
85 } |
|
86 |
|
87 if (iDataPtr != 0) |
|
88 { |
|
89 *aDataPtr = iDataPtr; |
|
90 return KErrNone; |
|
91 } |
|
92 iDataPtr = new CArrayFixFlat<TEapTlsPeapUiCipherSuite>(8); |
|
93 if (!iDataPtr) |
|
94 { |
|
95 return KErrNoMemory; |
|
96 } |
|
97 |
|
98 TInt i(0); |
|
99 while (available_cipher_suites[i] != 0) |
|
100 { |
|
101 TEapTlsPeapUiCipherSuite tmp; |
|
102 tmp.iCipherSuite = available_cipher_suites[i]; |
|
103 tmp.iIsEnabled = EFalse; |
|
104 |
|
105 TRAPD(err, iDataPtr->AppendL(tmp)); |
|
106 if (err != KErrNone) |
|
107 { |
|
108 return err; |
|
109 } |
|
110 |
|
111 i++; |
|
112 } |
|
113 |
|
114 |
|
115 |
|
116 TRAPD(err, FetchDataL()); |
|
117 |
|
118 if (err != KErrNone) |
|
119 { |
|
120 delete iDataPtr; |
|
121 return err; |
|
122 } |
|
123 |
|
124 *aDataPtr = iDataPtr; |
|
125 |
|
126 return KErrNone; |
|
127 } |
|
128 |
|
129 |
|
130 TInt CEapTlsPeapUiCipherSuites::Update() |
|
131 { |
|
132 TRAPD(err, UpdateL()); |
|
133 return err; |
|
134 } |
|
135 |
|
136 void CEapTlsPeapUiCipherSuites::UpdateL() |
|
137 { |
|
138 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
139 TPtr sqlStatement = buf->Des(); |
|
140 |
|
141 // Form the query. Query everything. |
|
142 _LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
143 |
|
144 if (iUiConn->GetEapType() == eap_type_tls) |
|
145 { |
|
146 sqlStatement.Format(KSQLQuery, |
|
147 &KTlsAllowedCipherSuitesDatabaseTableName, |
|
148 &KServiceType, |
|
149 iUiConn->GetIndexType(), |
|
150 &KServiceIndex, |
|
151 iUiConn->GetIndex(), |
|
152 &KTunnelingType, |
|
153 iUiConn->GetTunnelingType()); |
|
154 } |
|
155 else if (iUiConn->GetEapType() == eap_type_peap) |
|
156 { |
|
157 sqlStatement.Format(KSQLQuery, |
|
158 &KPeapAllowedCipherSuitesDatabaseTableName, |
|
159 &KServiceType, |
|
160 iUiConn->GetIndexType(), |
|
161 &KServiceIndex, |
|
162 iUiConn->GetIndex(), |
|
163 &KTunnelingType, |
|
164 iUiConn->GetTunnelingType()); |
|
165 } |
|
166 else if (iUiConn->GetEapType() == eap_type_ttls || iUiConn->GetEapType() == eap_type_ttls_plain_pap) |
|
167 { |
|
168 sqlStatement.Format(KSQLQuery, |
|
169 &KTtlsAllowedCipherSuitesDatabaseTableName, |
|
170 &KServiceType, |
|
171 iUiConn->GetIndexType(), |
|
172 &KServiceIndex, |
|
173 iUiConn->GetIndex(), |
|
174 &KTunnelingType, |
|
175 iUiConn->GetTunnelingType()); |
|
176 } |
|
177 |
|
178 #ifdef USE_FAST_EAP_TYPE |
|
179 else if (iUiConn->GetEapType() == eap_type_fast) |
|
180 { |
|
181 sqlStatement.Format(KSQLQuery, |
|
182 &KFastAllowedCipherSuitesDatabaseTableName, |
|
183 &KServiceType, |
|
184 iUiConn->GetIndexType(), |
|
185 &KServiceIndex, |
|
186 iUiConn->GetIndex(), |
|
187 &KTunnelingType, |
|
188 iUiConn->GetTunnelingType()); |
|
189 } |
|
190 #endif //#ifdef USE_FAST_EAP_TYPE |
|
191 |
|
192 // Evaluate view |
|
193 RDbView view; |
|
194 User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(sqlStatement))); |
|
195 CleanupClosePushL(view); |
|
196 User::LeaveIfError(view.EvaluateAll()); |
|
197 |
|
198 // Delete old rows |
|
199 if (view.FirstL()) |
|
200 { |
|
201 do { |
|
202 view.DeleteL(); |
|
203 } while (view.NextL() != EFalse); |
|
204 } |
|
205 |
|
206 // Get column set so we get the correct column numbers |
|
207 CDbColSet* colSet = view.ColSetL(); |
|
208 CleanupStack::PushL(colSet); |
|
209 |
|
210 TInt i(0); |
|
211 |
|
212 for (i = 0; i < iDataPtr->Count(); i++) |
|
213 { |
|
214 if (iDataPtr->At(i).iIsEnabled) |
|
215 { |
|
216 view.InsertL(); |
|
217 view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(iUiConn->GetIndexType())); |
|
218 view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(iUiConn->GetIndex())); |
|
219 view.SetColL(colSet->ColNo(KTunnelingType), static_cast<TUint>(iUiConn->GetTunnelingType())); |
|
220 view.SetColL(colSet->ColNo(KCipherSuite), static_cast<TUint>(iDataPtr->At(i).iCipherSuite)); |
|
221 view.PutL(); |
|
222 } |
|
223 } |
|
224 CleanupStack::PopAndDestroy(colSet); |
|
225 CleanupStack::PopAndDestroy(); // view |
|
226 CleanupStack::PopAndDestroy(buf); |
|
227 } |
|
228 |
|
229 TInt CEapTlsPeapUiCipherSuites::Close() |
|
230 { |
|
231 if (iIsOpened == EFalse) |
|
232 { |
|
233 return KErrNone; |
|
234 } |
|
235 |
|
236 delete iDataPtr; |
|
237 iDataPtr = 0; |
|
238 |
|
239 iUiConn = NULL; |
|
240 return KErrNone; |
|
241 } |
|
242 |
|
243 |
|
244 void CEapTlsPeapUiCipherSuites::FetchDataL() |
|
245 { |
|
246 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
247 TPtr sqlStatement = buf->Des(); |
|
248 |
|
249 // Form the query. Query everything. |
|
250 _LIT(KSQLQuery, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
251 |
|
252 if (iUiConn->GetEapType() == eap_type_tls) |
|
253 { |
|
254 sqlStatement.Format(KSQLQuery, |
|
255 &KCipherSuite, |
|
256 &KTlsAllowedCipherSuitesDatabaseTableName, |
|
257 &KServiceType, |
|
258 iUiConn->GetIndexType(), |
|
259 &KServiceIndex, |
|
260 iUiConn->GetIndex(), |
|
261 &KTunnelingType, |
|
262 iUiConn->GetTunnelingType()); |
|
263 } |
|
264 else if (iUiConn->GetEapType() == eap_type_peap) |
|
265 { |
|
266 sqlStatement.Format(KSQLQuery, |
|
267 &KCipherSuite, |
|
268 &KPeapAllowedCipherSuitesDatabaseTableName, |
|
269 &KServiceType, |
|
270 iUiConn->GetIndexType(), |
|
271 &KServiceIndex, |
|
272 iUiConn->GetIndex(), |
|
273 &KTunnelingType, |
|
274 iUiConn->GetTunnelingType()); |
|
275 } |
|
276 else if (iUiConn->GetEapType() == eap_type_ttls || iUiConn->GetEapType() == eap_type_ttls_plain_pap) |
|
277 { |
|
278 sqlStatement.Format(KSQLQuery, |
|
279 &KCipherSuite, |
|
280 &KTtlsAllowedCipherSuitesDatabaseTableName, |
|
281 &KServiceType, |
|
282 iUiConn->GetIndexType(), |
|
283 &KServiceIndex, |
|
284 iUiConn->GetIndex(), |
|
285 &KTunnelingType, |
|
286 iUiConn->GetTunnelingType()); |
|
287 } |
|
288 |
|
289 #ifdef USE_FAST_EAP_TYPE |
|
290 else if (iUiConn->GetEapType() == eap_type_fast) |
|
291 { |
|
292 sqlStatement.Format(KSQLQuery, |
|
293 &KCipherSuite, |
|
294 &KFastAllowedCipherSuitesDatabaseTableName, |
|
295 &KServiceType, |
|
296 iUiConn->GetIndexType(), |
|
297 &KServiceIndex, |
|
298 iUiConn->GetIndex(), |
|
299 &KTunnelingType, |
|
300 iUiConn->GetTunnelingType()); |
|
301 } |
|
302 #endif //#ifdef USE_FAST_EAP_TYPE |
|
303 |
|
304 // Evaluate view |
|
305 RDbView view; |
|
306 User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(sqlStatement))); |
|
307 CleanupClosePushL(view); |
|
308 User::LeaveIfError(view.EvaluateAll()); |
|
309 |
|
310 // Get column set so we get the correct column numbers |
|
311 CDbColSet* colSet = view.ColSetL(); |
|
312 CleanupStack::PushL(colSet); |
|
313 |
|
314 if (view.FirstL()) |
|
315 { |
|
316 do { |
|
317 view.GetL(); |
|
318 |
|
319 switch (view.ColType(colSet->ColNo(KCipherSuite))) |
|
320 { |
|
321 case EDbColUint32: |
|
322 { |
|
323 // Find the corresponding cipher suite in the list |
|
324 TInt j(0); |
|
325 TUint id = view.ColUint(colSet->ColNo(KCipherSuite)); |
|
326 for (j = 0; j < iDataPtr->Count(); j++) |
|
327 { |
|
328 if (iDataPtr->At(j).iCipherSuite == id) |
|
329 { |
|
330 iDataPtr->At(j).iIsEnabled = ETrue; |
|
331 break; |
|
332 } |
|
333 } |
|
334 } |
|
335 break; |
|
336 default: |
|
337 User::Leave(KErrArgument); |
|
338 } |
|
339 } while (view.NextL() != EFalse); |
|
340 } |
|
341 |
|
342 CleanupStack::PopAndDestroy(colSet); |
|
343 |
|
344 CleanupStack::PopAndDestroy(); // view |
|
345 CleanupStack::PopAndDestroy(buf); |
|
346 } |
|
347 |
|
348 // End of file |