26 #undef EAP_FILE_NUMBER_DATE |
26 #undef EAP_FILE_NUMBER_DATE |
27 #define EAP_FILE_NUMBER_DATE 1127594498 |
27 #define EAP_FILE_NUMBER_DATE 1127594498 |
28 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
28 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
29 |
29 |
30 #include <e32base.h> |
30 #include <e32base.h> |
31 //#include "EapTlsPeapUtils.h" |
31 #include "EapTlsPeapUtils.h" |
32 #include "EapTlsPeapDbDefaults.h" |
32 #include "EapTlsPeapDbDefaults.h" |
33 #include "EapTlsPeapDbParameterNames.h" |
33 #include "EapTlsPeapDbParameterNames.h" |
34 #include <EapTlsPeapUiConnection.h> |
34 #include <EapTlsPeapUiConnection.h> |
35 #include <EapTlsPeapUiCertificates.h> |
35 #include <EapTlsPeapUiCertificates.h> |
36 #include <EapGeneralSettings.h> |
36 #include <EapTlsPeapUiCertificate.h> |
|
37 #include "EapTlsPeapCertFetcher.h" |
37 #include <AbsEapTlsPeapUiCertificates.h> |
38 #include <AbsEapTlsPeapUiCertificates.h> |
38 #include <EapTraceSymbian.h> |
39 #include "eap_am_trace_symbian.h" |
39 #include "EapConversion.h" |
|
40 #include <EapType.h> |
|
41 |
40 |
42 #include <unifiedcertstore.h> |
41 #include <unifiedcertstore.h> |
43 #include <mctwritablecertstore.h> |
42 #include <mctwritablecertstore.h> |
44 |
43 |
|
44 const TUint KMaxSqlQueryLength = 256; |
45 const TUint KCertArrayGranularity = 16; |
45 const TUint KCertArrayGranularity = 16; |
46 |
|
47 // ---------------------------------------------------------- |
|
48 |
46 |
49 CEapTlsPeapUiCertificates::CEapTlsPeapUiCertificates( |
47 CEapTlsPeapUiCertificates::CEapTlsPeapUiCertificates( |
50 CEapTlsPeapUiConnection * const aUiConn, |
48 CEapTlsPeapUiConnection * const aUiConn, |
51 MEapTlsPeapUiCertificates * const aParent) |
49 MEapTlsPeapUiCertificates * const aParent) |
52 : iIsOpened(EFalse) |
50 : iIsOpened(EFalse) |
53 , iUiConn(aUiConn) |
51 , iUiConn(aUiConn) |
54 , iUserCerts(0) |
52 , iUserCerts(0) |
55 , iCACerts(0) |
53 , iCACerts(0) |
56 , iEapGeneralSettings(0) |
|
57 , iParent(aParent) |
54 , iParent(aParent) |
58 , iEapTypeConnection(0) |
55 { |
59 { |
56 } |
60 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::CEapTlsPeapUiCertificates()\n"))); |
57 |
61 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::CEapTlsPeapUiCertificates()\n")); |
|
62 |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------- |
|
66 |
58 |
67 CEapTlsPeapUiCertificates::~CEapTlsPeapUiCertificates() |
59 CEapTlsPeapUiCertificates::~CEapTlsPeapUiCertificates() |
68 { |
60 { |
69 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::~CEapTlsPeapUiCertificates()\n"))); |
61 if (iUiConn) |
70 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::~CEapTlsPeapUiCertificates()\n")); |
62 { |
71 |
63 Close(); |
72 Close(); |
64 iUiConn = NULL; |
73 } |
65 } |
74 |
66 } |
75 // ---------------------------------------------------------- |
67 |
76 |
68 |
77 TInt CEapTlsPeapUiCertificates::Open() |
69 TInt CEapTlsPeapUiCertificates::Open() |
78 { |
70 { |
79 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::Open()\n"))); |
|
80 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::Open()\n")); |
|
81 |
|
82 if (iIsOpened) |
71 if (iIsOpened) |
83 { |
72 { |
84 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::Open(): KErrAlreadyExists\n"))); |
|
85 return KErrAlreadyExists; |
73 return KErrAlreadyExists; |
86 } |
74 } |
87 |
75 |
88 TEapExpandedType aEapType(iUiConn->GetEapType()); |
76 TInt err = iUiConn->GetDatabase(iDatabase); |
89 |
77 if (err != KErrNone) |
90 TRAPD(error, iEapTypeConnection = CEapType::NewL(iUiConn->GetIndexType(), iUiConn->GetIndex(), aEapType)); |
78 { |
91 if (error != KErrNone) |
79 return err; |
92 { |
80 } |
93 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::Open(): CEapType::NewL() error=%d\n"),error)); |
81 |
94 return error; |
82 TRAP(err, iCertFetcher = CEapTlsPeapCertFetcher::NewL(this)); |
95 } |
83 if (err != KErrNone) |
|
84 { |
|
85 return err; |
|
86 } |
|
87 |
|
88 iIsOpened = ETrue; |
|
89 |
|
90 return KErrNone; |
|
91 } |
|
92 |
|
93 |
|
94 TInt CEapTlsPeapUiCertificates::Close() |
|
95 { |
|
96 if (iIsOpened == EFalse) |
|
97 { |
|
98 return KErrNone; |
|
99 } |
|
100 |
|
101 delete iUserCerts; |
|
102 iUserCerts = 0; |
96 |
103 |
97 iEapTypeConnection->SetTunnelingType(iUiConn->GetTunnelingType()); |
104 delete iCACerts; |
98 |
105 iCACerts = 0; |
99 TRAP(error, iEapGeneralSettings = CEapGeneralSettings::NewL(iUiConn->GetIndexType(), iUiConn->GetIndex())); |
106 |
100 if (error != KErrNone) |
107 delete iCertFetcher; |
101 { |
108 iCertFetcher = 0; |
102 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::Open(): CEapGeneralSettings::NewL() error=%d\n"),error)); |
109 |
103 return error; |
110 iUiConn = NULL; |
104 } |
|
105 |
|
106 iIsOpened = ETrue; |
|
107 |
|
108 return KErrNone; |
111 return KErrNone; |
109 } |
112 } |
110 |
113 |
111 // ---------------------------------------------------------- |
114 TInt CEapTlsPeapUiCertificates::GetCertificates(CArrayFixFlat<TEapTlsPeapUiCertificate> ** aUserCerts, |
112 |
115 CArrayFixFlat<TEapTlsPeapUiCertificate> ** aCACerts) |
113 TInt CEapTlsPeapUiCertificates::Close() |
116 { |
114 { |
|
115 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::Close()\n"))); |
|
116 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::Close()\n")); |
|
117 |
|
118 if (iIsOpened == EFalse) |
|
119 { |
|
120 return KErrNone; |
|
121 } |
|
122 |
|
123 delete iUserCerts; |
|
124 iUserCerts = 0; |
|
125 |
|
126 delete iCACerts; |
|
127 iCACerts = 0; |
|
128 |
|
129 delete iEapGeneralSettings; |
|
130 iEapGeneralSettings = 0; |
|
131 |
|
132 iUiConn = NULL; |
|
133 |
|
134 iIsOpened = EFalse; |
|
135 |
|
136 return KErrNone; |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------- |
|
140 |
|
141 TInt CEapTlsPeapUiCertificates::GetCertificates( |
|
142 RPointerArray<EapCertificateEntry> ** aUserCerts, |
|
143 RPointerArray<EapCertificateEntry> ** aCACerts) |
|
144 { |
|
145 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::GetCertificates()\n"))); |
|
146 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::GetCertificates()\n")); |
|
147 |
|
148 if (aUserCerts == NULL |
117 if (aUserCerts == NULL |
149 || aCACerts == NULL) |
118 || aCACerts == NULL) |
150 { |
119 { |
151 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::GetCertificates(): KErrArgument\n"))); |
|
152 return KErrArgument; |
120 return KErrArgument; |
153 } |
121 } |
154 |
|
155 if (iIsOpened == EFalse) |
122 if (iIsOpened == EFalse) |
156 { |
123 { |
157 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::GetCertificates(): KErrSessionClosed\n"))); |
|
158 return KErrSessionClosed; |
124 return KErrSessionClosed; |
159 } |
125 } |
160 |
|
161 if (iUserCerts == 0) |
126 if (iUserCerts == 0) |
162 { |
127 { |
163 iUserCerts = new RPointerArray<EapCertificateEntry>(KCertArrayGranularity); |
128 iUserCerts = new CArrayFixFlat<TEapTlsPeapUiCertificate>(KCertArrayGranularity); |
164 if (!iUserCerts) |
129 if (!iUserCerts) |
165 { |
130 { |
166 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::GetCertificates(): iUserCerts, KErrNoMemory\n"))); |
|
167 return KErrNoMemory; |
131 return KErrNoMemory; |
168 } |
132 } |
169 } |
133 } |
170 |
134 |
171 *aUserCerts = iUserCerts; |
135 *aUserCerts = iUserCerts; |
172 |
136 |
173 if (iCACerts == 0) |
137 if (iCACerts == 0) |
174 { |
138 { |
175 iCACerts = new RPointerArray<EapCertificateEntry>(KCertArrayGranularity); |
139 iCACerts = new CArrayFixFlat<TEapTlsPeapUiCertificate>(KCertArrayGranularity); |
176 if (!iUserCerts) |
140 if (!iUserCerts) |
177 { |
141 { |
178 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::GetCertificates(): iCACerts, KErrNoMemory\n"))); |
|
179 return KErrNoMemory; |
142 return KErrNoMemory; |
180 } |
143 } |
181 } |
144 } |
182 *aCACerts = iCACerts; |
145 *aCACerts = iCACerts; |
183 |
146 |
184 TInt error(KErrNone); |
147 TRAPD(err, iCertFetcher->GetCertificatesL()); |
185 |
148 |
186 error = iEapGeneralSettings->GetCertificateLists( |
149 return err; |
187 *iUserCerts, |
150 } |
188 *iCACerts); |
151 |
189 |
152 |
190 if (error != KErrNone) |
153 void CEapTlsPeapUiCertificates::CompleteReadCertificatesL( |
191 { |
154 const RArray<SCertEntry>& aAvailableUserCerts, |
192 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::GetCertificates(): GetCertificateLists() error=%d\n"), |
155 const RArray<SCertEntry>& aAvailableCACerts) |
193 error)); |
156 { |
194 iParent->CompleteReadCertificates(error); |
157 |
195 return error; |
158 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::CompleteReadCertificatesL - Available cert count in device - USER=%d, CA=%d \n"), |
196 } |
159 aAvailableUserCerts.Count(), aAvailableCACerts.Count())); |
197 |
|
198 TRAP(error, SelectActiveCertificatesL()); |
|
199 |
|
200 return error; |
|
201 } |
|
202 |
|
203 // ---------------------------------------------------------- |
|
204 |
|
205 void CEapTlsPeapUiCertificates::SelectCertificatesL( |
|
206 const EapCertificateEntry::TCertType aCertType, |
|
207 const EAPSettings & aSettings, |
|
208 RPointerArray<EapCertificateEntry>& aAvailableCerts) |
|
209 { |
|
210 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::SelectCertificatesL(): - Available cert count in device aAvailableCerts.Count()=%d, aSettings.iCertificates.Count()=%d\n"), |
|
211 aAvailableCerts.Count(), |
|
212 aSettings.iCertificates.Count())); |
|
213 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::SelectCertificatesL()\n")); |
|
214 |
|
215 // Loop through available certs |
|
216 TInt avail_ind(0); |
|
217 |
|
218 for (avail_ind = 0; avail_ind < aAvailableCerts.Count(); ++avail_ind) |
|
219 { |
|
220 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::SelectCertificatesL(): loops aAvailableCerts avail_ind=%d, aAvailableCerts.Count()=%d, aSettings.iCertificates.Count()=%d\n"), |
|
221 avail_ind, |
|
222 aAvailableCerts.Count(), |
|
223 aSettings.iCertificates.Count()) ); |
|
224 |
|
225 EapCertificateEntry * const avail_cert = aAvailableCerts[avail_ind]; |
|
226 |
|
227 EAP_TRACE_SETTINGS(avail_cert); |
|
228 |
|
229 avail_cert->SetIsEnabled(EFalse); |
|
230 |
|
231 if (aSettings.iCertificatesPresent) |
|
232 { |
|
233 TInt select_ind(0); |
|
234 |
|
235 for (select_ind = 0; select_ind < aSettings.iCertificates.Count(); ++select_ind) |
|
236 { |
|
237 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::SelectCertificatesL(): loops aSettings.iCertificates select_ind=%d\n"), |
|
238 select_ind ) ); |
|
239 |
|
240 EapCertificateEntry * const conf_cert = aSettings.iCertificates[select_ind]; |
|
241 |
|
242 EAP_TRACE_SETTINGS(conf_cert); |
|
243 |
|
244 if (aCertType == conf_cert->GetCertType() |
|
245 && avail_cert->GetSubjectKeyId() == conf_cert->GetSubjectKeyId()) |
|
246 { |
|
247 avail_cert->SetIsEnabled(ETrue); |
|
248 |
|
249 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::SelectCertificatesL(): - Reading certificate details from the DB - Label=%S \n"), |
|
250 avail_cert->GetLabel() ) ); |
|
251 |
|
252 EAP_TRACE_DATA_DEBUG_SYMBIAN(("Subject Key Id:", |
|
253 avail_cert->GetSubjectKeyId().Ptr(), |
|
254 avail_cert->GetSubjectKeyId().Length())); |
|
255 } |
|
256 } |
|
257 } |
|
258 } |
|
259 } |
|
260 |
|
261 // ---------------------------------------------------------- |
|
262 |
|
263 void CEapTlsPeapUiCertificates::SelectActiveCertificatesL() |
|
264 { |
|
265 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::SelectActiveCertificatesL(): - Available cert count in device - USER=%d, CA=%d \n"), |
|
266 iUserCerts->Count(), iCACerts->Count())); |
|
267 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::SelectActiveCertificatesL()\n")); |
|
268 |
160 |
269 // Now all available certificates have been read. |
161 // Now all available certificates have been read. |
270 // Get the allowed certs from the server and set their iIsEnabled flag -> ETrue. |
162 // Get the allowed certs from the database and set their iIsEnabled flag -> ETrue. |
271 |
163 TInt err(KErrNone); |
272 EAPSettings aSettings; |
164 if (iUiConn->GetEapType() == eap_type_tls) |
273 |
165 { |
274 TRAPD(error, iEapTypeConnection->GetConfigurationL(aSettings)); |
166 TRAP(err, FetchDataL(KTlsAllowedUserCertsDatabaseTableName, aAvailableUserCerts, iUserCerts)); |
275 if (error) |
167 if (err != KErrNone) |
276 { |
168 { |
277 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::SelectActiveCertificatesL(): GetConfigurationL(): failed %d\n"), error)); |
169 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::CompleteReadCertificatesL -TLS- USER cert - LEAVE from FetchDataL err=%d\n"), |
278 iParent->CompleteReadCertificates(error); |
170 err)); |
279 User::Leave(error); |
171 |
280 } |
172 iParent->CompleteReadCertificates(err); |
281 |
173 return; |
282 TRAP(error, SelectCertificatesL(EapCertificateEntry::EUser, aSettings, *iUserCerts)); |
174 } |
283 if (error) |
175 TRAP(err, FetchDataL(KTlsAllowedCACertsDatabaseTableName, aAvailableCACerts, iCACerts)); |
284 { |
176 if (err != KErrNone) |
285 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::SelectActiveCertificatesL(): SelectCertificatesL(iUserCerts): failed %d\n"), error)); |
177 { |
286 iParent->CompleteReadCertificates(error); |
178 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::CompleteReadCertificatesL -TLS- CA cert - LEAVE from FetchDataL err=%d\n"), |
287 User::Leave(error); |
179 err)); |
288 } |
180 |
289 |
181 iParent->CompleteReadCertificates(err); |
290 TRAP(error, SelectCertificatesL(EapCertificateEntry::ECA, aSettings, *iCACerts)); |
182 return; |
291 if (error) |
183 } |
292 { |
184 |
293 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::SelectActiveCertificatesL(): SelectCertificatesL(iCACerts): failed %d\n"), error)); |
185 } |
294 iParent->CompleteReadCertificates(error); |
186 else if (iUiConn->GetEapType() == eap_type_peap) |
295 User::Leave(error); |
187 { |
296 } |
188 |
297 |
189 TRAP(err, FetchDataL(KPeapAllowedUserCertsDatabaseTableName, aAvailableUserCerts, iUserCerts)); |
|
190 if (err != KErrNone) |
|
191 { |
|
192 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::CompleteReadCertificatesL -PEAP- USER cert - LEAVE from FetchDataL err=%d\n"), |
|
193 err)); |
|
194 |
|
195 iParent->CompleteReadCertificates(err); |
|
196 return; |
|
197 } |
|
198 TRAP(err, FetchDataL(KPeapAllowedCACertsDatabaseTableName, aAvailableCACerts, iCACerts)); |
|
199 if (err != KErrNone) |
|
200 { |
|
201 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::CompleteReadCertificatesL -PEAP- CA cert - LEAVE from FetchDataL err=%d\n"), |
|
202 err)); |
|
203 |
|
204 iParent->CompleteReadCertificates(err); |
|
205 return; |
|
206 } |
|
207 } |
|
208 else if (iUiConn->GetEapType() == eap_type_ttls || iUiConn->GetEapType() == eap_type_ttls_plain_pap) |
|
209 { |
|
210 |
|
211 TRAP(err, FetchDataL(KTtlsAllowedUserCertsDatabaseTableName, aAvailableUserCerts, iUserCerts)); |
|
212 if (err != KErrNone) |
|
213 { |
|
214 EAP_TRACE_DEBUG_SYMBIAN((_L( |
|
215 "CEapTlsPeapUiCertificates::CompleteReadCertificatesL -TTLS- USER cert - LEAVE from FetchDataL err=%d\n"), |
|
216 err)); |
|
217 |
|
218 iParent->CompleteReadCertificates(err); |
|
219 return; |
|
220 } |
|
221 TRAP(err, FetchDataL(KTtlsAllowedCACertsDatabaseTableName, aAvailableCACerts, iCACerts)); |
|
222 if (err != KErrNone) |
|
223 { |
|
224 EAP_TRACE_DEBUG_SYMBIAN((_L( |
|
225 "CEapTlsPeapUiCertificates::CompleteReadCertificatesL -TTLS- CA cert - LEAVE from FetchDataL err=%d\n"), |
|
226 err)); |
|
227 |
|
228 iParent->CompleteReadCertificates(err); |
|
229 return; |
|
230 } |
|
231 } |
|
232 |
|
233 #ifdef USE_FAST_EAP_TYPE |
|
234 else if (iUiConn->GetEapType() == eap_type_fast) |
|
235 { |
|
236 |
|
237 TRAP(err, FetchDataL(KFastAllowedUserCertsDatabaseTableName, aAvailableUserCerts, iUserCerts)); |
|
238 if (err != KErrNone) |
|
239 { |
|
240 EAP_TRACE_DEBUG_SYMBIAN((_L( |
|
241 "CEapTlsPeapUiCertificates::CompleteReadCertificatesL -FAST- USER cert - LEAVE from FetchDataL err=%d\n"), |
|
242 err)); |
|
243 |
|
244 iParent->CompleteReadCertificates(err); |
|
245 return; |
|
246 } |
|
247 TRAP(err, FetchDataL(KFastAllowedCACertsDatabaseTableName, aAvailableCACerts, iCACerts)); |
|
248 if (err != KErrNone) |
|
249 { |
|
250 EAP_TRACE_DEBUG_SYMBIAN((_L( |
|
251 "CEapTlsPeapUiCertificates::CompleteReadCertificatesL -FAST- CA cert - LEAVE from FetchDataL err=%d\n"), |
|
252 err)); |
|
253 |
|
254 iParent->CompleteReadCertificates(err); |
|
255 return; |
|
256 } |
|
257 } |
|
258 #endif //#ifdef USE_FAST_EAP_TYPE |
|
259 |
|
260 else |
|
261 { |
|
262 iParent->CompleteReadCertificates(KErrNotSupported); |
|
263 return; |
|
264 } |
|
265 |
298 // Operation was successful |
266 // Operation was successful |
299 iParent->CompleteReadCertificates(KErrNone); |
267 iParent->CompleteReadCertificates(KErrNone); |
300 } |
268 } |
301 |
269 |
302 // ---------------------------------------------------------- |
270 void CEapTlsPeapUiCertificates::FetchDataL( |
303 |
271 const TDesC& aTableName, |
304 void CEapTlsPeapUiCertificates::SaveCertificatesL( |
272 const RArray<SCertEntry>& aAvailableCerts, |
305 const EapCertificateEntry::TCertType /* aCertType */, |
273 CArrayFixFlat<TEapTlsPeapUiCertificate>* const aArray) |
306 const RPointerArray<EapCertificateEntry>* const aAvailableCerts, |
274 { |
307 EAPSettings & aSettings) |
275 |
308 { |
276 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::FetchDataL - Fetching & comparing cert details from table:%S\n"), |
309 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::SaveCertificatesL(): - Available cert count %d \n"), |
277 &aTableName)); |
310 aAvailableCerts->Count())); |
278 |
311 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::SaveCertificatesL()\n")); |
279 aArray->Reset(); |
312 |
280 |
313 TInt avail_ind(0); |
281 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
314 for (avail_ind = 0; avail_ind < aAvailableCerts->Count(); avail_ind++) |
282 TPtr sqlStatement = buf->Des(); |
315 { |
283 |
316 if ((*aAvailableCerts)[avail_ind]->GetIsEnabled()) |
284 // Form the query. Query everything. |
317 { |
285 _LIT(KSQLQuery, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
318 EAP_TRACE_SETTINGS((*aAvailableCerts)[avail_ind]); |
286 |
319 |
287 sqlStatement.Format(KSQLQuery, |
|
288 &aTableName, |
|
289 &KServiceType, |
|
290 iUiConn->GetIndexType(), |
|
291 &KServiceIndex, |
|
292 iUiConn->GetIndex(), |
|
293 &KTunnelingType, |
|
294 iUiConn->GetTunnelingType()); |
|
295 |
|
296 // Evaluate view |
|
297 RDbView view; |
|
298 User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(sqlStatement))); |
|
299 CleanupClosePushL(view); |
|
300 User::LeaveIfError(view.EvaluateAll()); |
|
301 |
|
302 // Get column set so we get the correct column numbers |
|
303 CDbColSet* colSet = view.ColSetL(); |
|
304 CleanupStack::PushL(colSet); |
|
305 |
|
306 TEapTlsPeapUiCertificate tmp; |
|
307 |
|
308 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::FetchDataL - Available certs=%d\n"), |
|
309 aAvailableCerts.Count())); |
|
310 |
|
311 // Loop through available certs |
|
312 TInt i(0); |
|
313 for (i = 0; i < aAvailableCerts.Count(); i++) |
|
314 { |
|
315 SCertEntry cert = aAvailableCerts[i]; |
|
316 |
|
317 tmp.iCertEntry = cert; |
|
318 tmp.iIsEnabled = EFalse; |
|
319 |
|
320 // Try to find the cert from the database rows |
|
321 if (view.FirstL()) |
|
322 { |
|
323 do |
|
324 { |
|
325 view.GetL(); |
|
326 if ((view.ColDes(colSet->ColNo(KCertLabel)) == cert.iLabel |
|
327 || view.IsColNull(colSet->ColNo(KCertLabel))) |
|
328 && view.ColDes8(colSet->ColNo(KSubjectKeyIdentifier)) == cert.iSubjectKeyId) |
|
329 { |
|
330 tmp.iIsEnabled = ETrue; |
|
331 |
|
332 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::FetchDataL - Reading certificate details from the DB - Label=%S \n"), |
|
333 &(cert.iLabel) ) ); |
|
334 |
|
335 EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "Subject Key Id:", cert.iSubjectKeyId.Ptr(), |
|
336 cert.iSubjectKeyId.Size() ) ); |
|
337 break; |
|
338 } |
|
339 } while (view.NextL() != EFalse); |
|
340 } |
|
341 |
|
342 aArray->AppendL(tmp); |
|
343 } |
|
344 CleanupStack::PopAndDestroy(); // colset |
|
345 CleanupStack::PopAndDestroy(); // view |
|
346 CleanupStack::PopAndDestroy(buf); |
|
347 } |
|
348 |
|
349 TInt CEapTlsPeapUiCertificates::Update() |
|
350 { |
|
351 TRAPD(err, UpdateL()); |
|
352 |
|
353 if(KErrNone != err) |
|
354 { |
|
355 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::Update - UpdateL LEAVES with error =%d \n"), |
|
356 err)); |
|
357 } |
|
358 |
|
359 return err; |
|
360 } |
|
361 |
|
362 |
|
363 void CEapTlsPeapUiCertificates::UpdateL() |
|
364 { |
|
365 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
366 TPtr sqlStatement = buf->Des(); |
|
367 |
|
368 // USER CERTIFICATES |
|
369 _LIT(KSQL, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
370 |
|
371 if (iUiConn->GetEapType() == eap_type_tls) |
|
372 { |
|
373 sqlStatement.Format( |
|
374 KSQL, |
|
375 &KTlsAllowedUserCertsDatabaseTableName, |
|
376 &KServiceType, |
|
377 iUiConn->GetIndexType(), |
|
378 &KServiceIndex, |
|
379 iUiConn->GetIndex(), |
|
380 &KTunnelingType, |
|
381 iUiConn->GetTunnelingType()); |
|
382 } |
|
383 else if (iUiConn->GetEapType() == eap_type_peap) |
|
384 { |
|
385 sqlStatement.Format( |
|
386 KSQL, |
|
387 &KPeapAllowedUserCertsDatabaseTableName, |
|
388 &KServiceType, |
|
389 iUiConn->GetIndexType(), |
|
390 &KServiceIndex, |
|
391 iUiConn->GetIndex(), |
|
392 &KTunnelingType, |
|
393 iUiConn->GetTunnelingType()); |
|
394 } |
|
395 else if (iUiConn->GetEapType() == eap_type_ttls || iUiConn->GetEapType() == eap_type_ttls_plain_pap) |
|
396 { |
|
397 sqlStatement.Format( |
|
398 KSQL, |
|
399 &KTtlsAllowedUserCertsDatabaseTableName, |
|
400 &KServiceType, |
|
401 iUiConn->GetIndexType(), |
|
402 &KServiceIndex, |
|
403 iUiConn->GetIndex(), |
|
404 &KTunnelingType, |
|
405 iUiConn->GetTunnelingType()); |
|
406 } |
|
407 |
|
408 #ifdef USE_FAST_EAP_TYPE |
|
409 else if (iUiConn->GetEapType() == eap_type_fast) |
|
410 { |
|
411 sqlStatement.Format( |
|
412 KSQL, |
|
413 &KFastAllowedUserCertsDatabaseTableName, |
|
414 &KServiceType, |
|
415 iUiConn->GetIndexType(), |
|
416 &KServiceIndex, |
|
417 iUiConn->GetIndex(), |
|
418 &KTunnelingType, |
|
419 iUiConn->GetTunnelingType()); |
|
420 } |
|
421 #endif //#ifdef USE_FAST_EAP_TYPE |
|
422 |
|
423 RDbView view; |
|
424 User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
425 CleanupClosePushL(view); |
|
426 User::LeaveIfError(view.EvaluateAll()); |
|
427 |
|
428 // Get column set so we get the correct column numbers |
|
429 CDbColSet* colSet; |
|
430 colSet = view.ColSetL(); |
|
431 CleanupStack::PushL(colSet); |
|
432 |
|
433 // Delete old rows |
|
434 if (view.FirstL()) |
|
435 { |
|
436 do { |
|
437 view.DeleteL(); |
|
438 } while (view.NextL() != EFalse); |
|
439 } |
|
440 |
|
441 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::UpdateL - About to update cert details in the DB - User cert count=%d \n"), |
|
442 iUserCerts->Count())); |
|
443 |
|
444 TInt i(0); |
|
445 for (i = 0; i < iUserCerts->Count(); i++) |
|
446 { |
|
447 if ((*iUserCerts)[i].iIsEnabled) |
|
448 { |
320 // Validate data lengths. |
449 // Validate data lengths. |
321 if((*aAvailableCerts)[avail_ind]->GetLabel()->Length() > KMaxCertLabelLengthInDB |
450 if((*iUserCerts)[i].iCertEntry.iLabel.Length() > KMaxCertLabelLengthInDB |
322 || (*aAvailableCerts)[avail_ind]->GetSubjectKeyId().Length() > KMaxSubjectKeyIdLengthInDB) |
451 || (*iUserCerts)[i].iCertEntry.iSubjectKeyId.Length() > KMaxSubjectKeyIdLengthInDB) |
323 { |
452 { |
324 // Too long data. Can not be stored in DB. |
453 // Too long data. Can not be stored in DB. |
325 |
454 |
326 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::UpdateL(): User : Too long Label or SubjectKeyId. Length: Label=%d, SubjectKeyId=%d \n"), |
455 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::UpdateL: User : Too long Label or SubjectKeyId. Length: Label=%d, SubjectKeyId=%d \n"), |
327 (*aAvailableCerts)[avail_ind]->GetLabel()->Length(), |
456 (*iUserCerts)[i].iCertEntry.iLabel.Length(), (*iUserCerts)[i].iCertEntry.iSubjectKeyId.Length())); |
328 (*aAvailableCerts)[avail_ind]->GetSubjectKeyId().Length())); |
|
329 |
457 |
330 User::Leave(KErrArgument); |
458 User::Leave(KErrArgument); |
331 } |
459 } |
332 |
460 |
333 #if 1 |
461 view.InsertL(); |
334 |
462 // Set the default values. The other three tables (certs, ca certs & cipher suites) are empty by default. |
335 EapCertificateEntry * const aCertEntry = (*aAvailableCerts)[avail_ind]->Copy(); |
463 view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(iUiConn->GetIndexType())); |
336 if (aCertEntry == 0) |
464 view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(iUiConn->GetIndex())); |
|
465 view.SetColL(colSet->ColNo(KTunnelingType), static_cast<TUint>(iUiConn->GetTunnelingType())); |
|
466 view.SetColL(colSet->ColNo(KCertLabel), (*iUserCerts)[i].iCertEntry.iLabel); |
|
467 view.SetColL(colSet->ColNo(KSubjectKeyIdentifier), (*iUserCerts)[i].iCertEntry.iSubjectKeyId); |
|
468 view.SetColL(colSet->ColNo(KActualSubjectKeyIdentifier), (*iUserCerts)[i].iCertEntry.iSubjectKeyId); |
|
469 view.PutL(); |
|
470 |
|
471 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::UpdateL - Wrote User cert details to the DB - Label=%S \n"), |
|
472 &((*iUserCerts)[i].iCertEntry.iLabel) ) ); |
|
473 |
|
474 EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "Subject Key Id:", (*iUserCerts)[i].iCertEntry.iSubjectKeyId.Ptr(), |
|
475 (*iUserCerts)[i].iCertEntry.iSubjectKeyId.Size() ) ); |
|
476 } |
|
477 } |
|
478 |
|
479 CleanupStack::PopAndDestroy(colSet); |
|
480 CleanupStack::PopAndDestroy(); // view |
|
481 |
|
482 // CA CERTIFICATES |
|
483 _LIT(KSQL2, "SELECT * FROM %S WHERE %S=%d AND %S=%d AND %S=%d"); |
|
484 |
|
485 if (iUiConn->GetEapType() == eap_type_tls) |
|
486 { |
|
487 sqlStatement.Format( |
|
488 KSQL2, |
|
489 &KTlsAllowedCACertsDatabaseTableName, |
|
490 &KServiceType, |
|
491 iUiConn->GetIndexType(), |
|
492 &KServiceIndex, |
|
493 iUiConn->GetIndex(), |
|
494 &KTunnelingType, |
|
495 iUiConn->GetTunnelingType()); |
|
496 } |
|
497 else if (iUiConn->GetEapType() == eap_type_peap) |
|
498 { |
|
499 sqlStatement.Format( |
|
500 KSQL2, |
|
501 &KPeapAllowedCACertsDatabaseTableName, |
|
502 &KServiceType, |
|
503 iUiConn->GetIndexType(), |
|
504 &KServiceIndex, |
|
505 iUiConn->GetIndex(), |
|
506 &KTunnelingType, |
|
507 iUiConn->GetTunnelingType()); |
|
508 } |
|
509 else if (iUiConn->GetEapType() == eap_type_ttls || iUiConn->GetEapType() == eap_type_ttls_plain_pap) |
|
510 { |
|
511 sqlStatement.Format( |
|
512 KSQL2, |
|
513 &KTtlsAllowedCACertsDatabaseTableName, |
|
514 &KServiceType, |
|
515 iUiConn->GetIndexType(), |
|
516 &KServiceIndex, |
|
517 iUiConn->GetIndex(), |
|
518 &KTunnelingType, |
|
519 iUiConn->GetTunnelingType()); |
|
520 } |
|
521 |
|
522 #ifdef USE_FAST_EAP_TYPE |
|
523 else if (iUiConn->GetEapType() == eap_type_fast) |
|
524 { |
|
525 sqlStatement.Format( |
|
526 KSQL2, |
|
527 &KFastAllowedCACertsDatabaseTableName, |
|
528 &KServiceType, |
|
529 iUiConn->GetIndexType(), |
|
530 &KServiceIndex, |
|
531 iUiConn->GetIndex(), |
|
532 &KTunnelingType, |
|
533 iUiConn->GetTunnelingType()); |
|
534 } |
|
535 #endif // #ifdef USE_FAST_EAP_TYPE |
|
536 |
|
537 User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
538 CleanupClosePushL(view); |
|
539 User::LeaveIfError(view.EvaluateAll()); |
|
540 |
|
541 // Get column set so we get the correct column numbers |
|
542 colSet = view.ColSetL(); |
|
543 CleanupStack::PushL(colSet); |
|
544 |
|
545 // Delete old rows |
|
546 if (view.FirstL()) |
|
547 { |
|
548 do { |
|
549 view.DeleteL(); |
|
550 } while (view.NextL() != EFalse); |
|
551 } |
|
552 |
|
553 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::UpdateL - About to update cert details in the DB - CA cert count=%d \n"), |
|
554 iCACerts->Count())); |
|
555 |
|
556 for (i = 0; i < iCACerts->Count(); i++) |
|
557 { |
|
558 if ((*iCACerts)[i].iIsEnabled) |
|
559 { |
|
560 // Validate data lengths. |
|
561 if((*iCACerts)[i].iCertEntry.iLabel.Length() > KMaxCertLabelLengthInDB |
|
562 || (*iCACerts)[i].iCertEntry.iSubjectKeyId.Length() > KMaxSubjectKeyIdLengthInDB) |
337 { |
563 { |
338 User::Leave(KErrNoMemory); |
564 // Too long data. Can not be stored in DB. |
|
565 |
|
566 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::UpdateL: CA : Too long Label or SubjectKeyId. Length: Label=%d, SubjectKeyId=%d \n"), |
|
567 (*iCACerts)[i].iCertEntry.iLabel.Length(), (*iCACerts)[i].iCertEntry.iSubjectKeyId.Length())); |
|
568 |
|
569 User::Leave(KErrArgument); |
339 } |
570 } |
340 CleanupStack::PushL(aCertEntry); |
571 |
341 |
572 view.InsertL(); |
342 #else |
573 // Set the default values. The other three tables (certs, ca certs & cipher suites) are empty by default. |
343 |
574 view.SetColL(colSet->ColNo(KServiceType), static_cast<TUint>(iUiConn->GetIndexType())); |
344 EapCertificateEntry * const aCertEntry = new EapCertificateEntry; |
575 view.SetColL(colSet->ColNo(KServiceIndex), static_cast<TUint>(iUiConn->GetIndex())); |
345 if (aCertEntry == 0) |
576 view.SetColL(colSet->ColNo(KTunnelingType), static_cast<TUint>(iUiConn->GetTunnelingType())); |
346 { |
577 view.SetColL(colSet->ColNo(KCertLabel), (*iCACerts)[i].iCertEntry.iLabel); |
347 User::Leave(KErrNoMemory); |
578 view.SetColL(colSet->ColNo(KSubjectKeyIdentifier), (*iCACerts)[i].iCertEntry.iSubjectKeyId); |
348 } |
579 view.SetColL(colSet->ColNo(KActualSubjectKeyIdentifier), (*iCACerts)[i].iCertEntry.iSubjectKeyId); |
349 CleanupStack::PushL(aCertEntry); |
580 view.PutL(); |
350 |
581 |
351 aCertEntry->SetCertType(aCertType); |
582 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::UpdateL - Wrote CA cert details to the DB - Label=%S \n"), |
352 aCertEntry->GetSubjectKeyIdWritable()->Copy(*((*aAvailableCerts)[avail_ind]->GetSubjectKeyId())); |
583 &((*iCACerts)[i].iCertEntry.iLabel) ) ); |
353 |
|
354 #endif |
|
355 |
|
356 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::UpdateL(): - Wrote User cert details to the DB - Label=%S \n"), |
|
357 aCertEntry->GetLabel() ) ); |
|
358 |
584 |
359 EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "Subject Key Id:", |
585 EAP_TRACE_DATA_DEBUG_SYMBIAN( ( "Subject Key Id:", (*iCACerts)[i].iCertEntry.iSubjectKeyId.Ptr(), |
360 aCertEntry->GetSubjectKeyId().Ptr(), |
586 (*iCACerts)[i].iCertEntry.iSubjectKeyId.Size() ) ); |
361 aCertEntry->GetSubjectKeyId().Length() ) ); |
587 } |
362 |
588 } |
363 EAP_TRACE_SETTINGS(aCertEntry); |
589 CleanupStack::PopAndDestroy(colSet); |
364 |
590 CleanupStack::PopAndDestroy(); // view |
365 aSettings.iCertificates.AppendL(aCertEntry); |
591 |
366 |
592 CleanupStack::PopAndDestroy(buf); |
367 aSettings.iCertificatesPresent = ETrue; |
593 } |
368 |
594 |
369 CleanupStack::Pop(aCertEntry); |
|
370 } |
|
371 } |
|
372 } |
|
373 |
|
374 // ---------------------------------------------------------- |
|
375 |
|
376 TInt CEapTlsPeapUiCertificates::Update() |
|
377 { |
|
378 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::Update()\n"))); |
|
379 EAP_TRACE_RETURN_STRING_SYMBIAN(_L("returns: CEapTlsPeapUiCertificates::Update()\n")); |
|
380 |
|
381 EAPSettings aSettings; |
|
382 |
|
383 TRAPD(error, SaveCertificatesL(EapCertificateEntry::EUser, iUserCerts, aSettings)); |
|
384 if (error) |
|
385 { |
|
386 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::Update() SaveCertificatesL(iUserCerts): failed %d\n"), error)); |
|
387 iParent->CompleteReadCertificates(error); |
|
388 return error; |
|
389 } |
|
390 |
|
391 TRAP(error, SaveCertificatesL(EapCertificateEntry::ECA, iCACerts, aSettings)); |
|
392 if (error) |
|
393 { |
|
394 EAP_TRACE_DEBUG_SYMBIAN((_L("ERROR: CEapTlsPeapUiCertificates::Update() SaveCertificatesL(iCACerts): failed %d\n"), error)); |
|
395 iParent->CompleteReadCertificates(error); |
|
396 return error; |
|
397 } |
|
398 |
|
399 TRAP(error,iEapTypeConnection->SetConfigurationL(aSettings)); |
|
400 |
|
401 EAP_TRACE_DEBUG_SYMBIAN((_L("CEapTlsPeapUiCertificates::Update(): error = %d\n"),error)); |
|
402 |
|
403 return error; |
|
404 } |
|
405 |
|
406 // ---------------------------------------------------------- |
|
407 // End of file |
595 // End of file |