5 * under the terms of the "Eclipse Public License v1.0" |
5 * under the terms of the "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html" |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html" |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Pritam Roy Biswas, Sasken Communication Technologies Ltd - Initial contribution |
10 * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Pritam Roy Biswas, Sasken Communication Technologies Ltd |
11 * |
14 * |
12 * Description: |
15 * Description: |
13 * Header file for Credential Manager Server Session. |
16 * Header file for Credential Manager Server Session. |
14 */ |
17 */ |
15 |
18 |
20 #include <random.h> |
23 #include <random.h> |
21 #include <smfcredmgrcommon.h> |
24 #include <smfcredmgrcommon.h> |
22 #include <smfcredmgrclientdatastruct.h> |
25 #include <smfcredmgrclientdatastruct.h> |
23 #include <smfutils.h> |
26 #include <smfutils.h> |
24 |
27 |
25 |
|
26 #include "smfcredmgrserversession.h" |
28 #include "smfcredmgrserversession.h" |
27 #include "smfcredmgrserver.h" |
29 #include "smfcredmgrserver.h" |
28 #include "smfcredmgrdbuser.h" |
30 #include "smfcredmgrdbuser.h" |
29 |
31 |
|
32 /** |
|
33 * NewL Method |
|
34 * @param aServer the server object |
|
35 * @return The constructed CSmfCredMgrServerSession instance |
|
36 */ |
|
37 CSmfCredMgrServerSession* CSmfCredMgrServerSession::NewL( |
|
38 CSmfCredMgrServer& aServer) |
|
39 { |
|
40 CSmfCredMgrServerSession* self = CSmfCredMgrServerSession::NewLC(aServer); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 /** |
|
46 * NewLC Method |
|
47 * @param aServer the server object |
|
48 * @return The constructed CSmfCredMgrServerSession instance |
|
49 */ |
30 CSmfCredMgrServerSession* CSmfCredMgrServerSession::NewLC( |
50 CSmfCredMgrServerSession* CSmfCredMgrServerSession::NewLC( |
31 CSmfCredMgrServer& aServer) |
51 CSmfCredMgrServer& aServer) |
32 { |
52 { |
33 CSmfCredMgrServerSession* self = new (ELeave) CSmfCredMgrServerSession( |
53 CSmfCredMgrServerSession* self = new (ELeave) CSmfCredMgrServerSession(aServer); |
34 aServer); |
|
35 CleanupStack::PushL(self); |
54 CleanupStack::PushL(self); |
36 self->ConstructL(); |
55 self->ConstructL(); |
37 return self; |
56 return self; |
38 } |
57 } |
39 |
58 |
40 CSmfCredMgrServerSession* CSmfCredMgrServerSession::NewL( |
59 /** |
41 CSmfCredMgrServer& aServer) |
60 * Constructor |
42 { |
61 * @param aServer The server object |
43 CSmfCredMgrServerSession* self = CSmfCredMgrServerSession::NewLC(aServer); |
62 */ |
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 CSmfCredMgrServerSession::CSmfCredMgrServerSession(CSmfCredMgrServer& aServer) : |
63 CSmfCredMgrServerSession::CSmfCredMgrServerSession(CSmfCredMgrServer& aServer) : |
49 iServer(aServer) |
64 iServer(aServer) |
50 { |
65 { |
51 RDebug::Printf("in constructor CSmfCredMgrServerSession"); |
66 RDebug::Printf("in constructor CSmfCredMgrServerSession"); |
52 } |
67 } |
53 |
68 |
|
69 /** |
|
70 * Two-Phase constructor |
|
71 */ |
54 void CSmfCredMgrServerSession::ConstructL() |
72 void CSmfCredMgrServerSession::ConstructL() |
55 { |
73 { |
56 iDbUser = CSmfCredMgrDbUser::NewL(this); |
74 iDbUser = CSmfCredMgrDbUser::NewL(this); |
57 iKeyStore = CSmfKeyStoreManager::NewL(); |
75 iKeyStore = CSmfKeyStoreManager::NewL(); |
58 } |
76 } |
59 |
77 |
|
78 /** |
|
79 * Destructor |
|
80 */ |
60 CSmfCredMgrServerSession::~CSmfCredMgrServerSession() |
81 CSmfCredMgrServerSession::~CSmfCredMgrServerSession() |
61 { |
82 { |
62 RDebug::Printf("in destructor CSmfCredMgrServerSession"); |
83 RDebug::Printf("in destructor CSmfCredMgrServerSession"); |
63 delete iDbUser; |
84 delete iDbUser; |
64 delete iKeyStore; |
85 delete iKeyStore; |
65 } |
86 } |
66 |
87 |
|
88 /** |
|
89 * Handles the servicing of a client request that has been |
|
90 * passed to the server |
|
91 * @param aMessage The message containing the details of the client request |
|
92 */ |
67 void CSmfCredMgrServerSession::ServiceL(const RMessage2& aMessage) |
93 void CSmfCredMgrServerSession::ServiceL(const RMessage2& aMessage) |
68 { |
94 { |
69 TInt err = KErrNone; |
95 TInt err = KErrNone; |
70 switch (aMessage.Function()) |
96 switch (aMessage.Function()) |
71 { |
97 { |
72 |
|
73 case ESendAuthDataSet: |
98 case ESendAuthDataSet: |
74 { |
99 { |
75 //create buffer to read the received data |
100 //create buffer to read the received data |
76 RBuf8 dataBuf; |
101 RBuf8 dataBuf; |
77 CleanupClosePushL(dataBuf); |
102 CleanupClosePushL(dataBuf); |
82 |
107 |
83 CleanupStack::PushL(fetchAuthTokenSetParams); |
108 CleanupStack::PushL(fetchAuthTokenSetParams); |
84 |
109 |
85 fetchAuthTokenSetParams->InternalizeL(dataBuf); |
110 fetchAuthTokenSetParams->InternalizeL(dataBuf); |
86 |
111 |
87 getTokenArray(fetchAuthTokenSetParams); |
112 getTokenArrayL(fetchAuthTokenSetParams); |
88 |
113 |
89 //create buffer to serialize the data to be sent |
114 //create buffer to serialize the data to be sent |
90 CBufFlat* buf = CBufFlat::NewL(512); |
115 CBufFlat* buf = CBufFlat::NewL(512); |
91 CleanupStack::PushL(buf); |
116 CleanupStack::PushL(buf); |
92 RBufWriteStream stream(*buf); |
117 RBufWriteStream stream(*buf); |
144 new (ELeave) CSmfURLListParams; |
169 new (ELeave) CSmfURLListParams; |
145 CleanupStack::PushL(fetchURLListParams); |
170 CleanupStack::PushL(fetchURLListParams); |
146 |
171 |
147 fetchURLListParams->InternalizeL(dataBuf); |
172 fetchURLListParams->InternalizeL(dataBuf); |
148 |
173 |
149 fetchURLs(fetchURLListParams); |
174 fetchUrlL(fetchURLListParams); |
150 |
175 |
151 //to serialize data we need a buffer |
176 //to serialize data we need a buffer |
152 CBufFlat* buf = CBufFlat::NewL(512); |
177 CBufFlat* buf = CBufFlat::NewL(512); |
153 CleanupStack::PushL(buf); |
178 CleanupStack::PushL(buf); |
154 RBufWriteStream stream(*buf); |
179 RBufWriteStream stream(*buf); |
181 CSmfPluginIDListParams* fetchPluginListParams = |
206 CSmfPluginIDListParams* fetchPluginListParams = |
182 new (ELeave) CSmfPluginIDListParams; |
207 new (ELeave) CSmfPluginIDListParams; |
183 CleanupStack::PushL(fetchPluginListParams); |
208 CleanupStack::PushL(fetchPluginListParams); |
184 fetchPluginListParams->InternalizeL(dataBuf); |
209 fetchPluginListParams->InternalizeL(dataBuf); |
185 |
210 |
186 fetchPluginIDs(fetchPluginListParams); |
211 fetchPluginIDsL(fetchPluginListParams); |
187 |
212 |
188 //to serialize data we need a buffer |
213 //to serialize data we need a buffer |
189 CBufFlat* buf = CBufFlat::NewL(512); |
214 CBufFlat* buf = CBufFlat::NewL(512); |
190 CleanupStack::PushL(buf); |
215 CleanupStack::PushL(buf); |
191 RBufWriteStream stream(*buf); |
216 RBufWriteStream stream(*buf); |
258 new (ELeave) CSmfStoreAuthParams; |
283 new (ELeave) CSmfStoreAuthParams; |
259 CleanupStack::PushL(authenticationProcessData); |
284 CleanupStack::PushL(authenticationProcessData); |
260 |
285 |
261 authenticationProcessData->InternalizeL(dataBuf); |
286 authenticationProcessData->InternalizeL(dataBuf); |
262 |
287 |
263 |
288 //generate cryptographically secure random number. |
264 TBuf8<56> regToken; |
289 TRandom generator; |
265 regToken.SetLength(regToken.MaxLength()); |
290 TBuf8<KMaxRegistrationTokenLength> randNum; |
266 TRandom::RandomL(regToken); |
291 randNum.SetLength(randNum.MaxLength()); |
267 authenticationProcessData->iRegistrationToken = HBufC::NewL(KMaxRegistrationTokenLength); |
292 generator.RandomL(randNum); |
268 TPtr tokenPtr(authenticationProcessData->iRegistrationToken->Des()); |
293 |
269 tokenPtr.Copy(regToken); |
294 //assign it to iRegistrationToken |
|
295 authenticationProcessData->iRegistrationToken = HBufC::NewL(/*regToken.Length()*/KMaxRegistrationTokenLength);; |
|
296 |
|
297 TPtr regTokenPtr(authenticationProcessData->iRegistrationToken->Des()); |
|
298 regTokenPtr.Copy(randNum); |
|
299 |
270 storeInDb(authenticationProcessData); |
300 storeInDb(authenticationProcessData); |
271 |
301 |
272 aMessage.WriteL(1, regToken); |
302 //to serialize data we need a buffer |
|
303 CBufFlat* buf = CBufFlat::NewL(KMaxBufSize); |
|
304 CleanupStack::PushL(buf); |
|
305 RBufWriteStream stream(*buf); |
|
306 CleanupClosePushL(stream); |
|
307 |
|
308 authenticationProcessData->ExternalizeL(stream); |
|
309 |
|
310 stream.CommitL(); |
|
311 |
|
312 TPtr8 bufPtr = buf->Ptr(0); |
|
313 |
|
314 TInt err = aMessage.Write(1, bufPtr); |
|
315 |
|
316 CleanupStack::PopAndDestroy(&stream); |
|
317 CleanupStack::PopAndDestroy(buf); |
273 |
318 |
274 CleanupStack::PopAndDestroy(authenticationProcessData->iRegistrationToken); |
|
275 CleanupStack::PopAndDestroy(authenticationProcessData); |
319 CleanupStack::PopAndDestroy(authenticationProcessData); |
276 CleanupStack::PopAndDestroy(&dataBuf); |
320 CleanupStack::PopAndDestroy(&dataBuf); |
277 aMessage.Complete(err); |
321 aMessage.Complete(err); |
278 } |
322 } |
279 break; |
323 break; |
|
324 |
280 case ESmfHMACSHA1SignMessage: |
325 case ESmfHMACSHA1SignMessage: |
281 case ESmfRSASignMessage: |
326 case ESmfRSASignMessage: |
282 case ESmfStoreRSAKey: |
327 case ESmfStoreRSAKey: |
283 case ESmfDeleteKeys: |
328 case ESmfDeleteKeys: |
284 { |
329 { |
289 //todo -panic client |
334 //todo -panic client |
290 break; |
335 break; |
291 } |
336 } |
292 } |
337 } |
293 |
338 |
|
339 /** |
|
340 * Stores data to Db during Authentication process |
|
341 * @param aParams class containg the data to be stored at Db |
|
342 */ |
294 void CSmfCredMgrServerSession::storeInDb( |
343 void CSmfCredMgrServerSession::storeInDb( |
295 CSmfStoreAuthParams* aAuthenticationProcessData) |
344 CSmfStoreAuthParams* aAuthenticationProcessData) |
296 { |
345 { |
297 TBuf<KMaxBufSize> authAppIDbuf( |
346 TBuf<KMaxBufSize> authAppIDbuf( |
298 aAuthenticationProcessData->iAuthAppID->Des()); |
347 aAuthenticationProcessData->iAuthAppID->Des()); |
299 |
348 TBuf<KMaxBufSize> regTokenBuf(aAuthenticationProcessData->iRegistrationToken->Des()); |
300 iDbUser->RegTokenValidityTableInsert( |
349 iDbUser->RegTokenValidityTableInsert( |
301 aAuthenticationProcessData->iRegistrationToken->Des(), |
350 regTokenBuf, |
302 authAppIDbuf, aAuthenticationProcessData->iValidity); |
351 authAppIDbuf, aAuthenticationProcessData->iValidity); |
303 |
352 |
304 for (int i = 0; i < aAuthenticationProcessData->iAuthTokenArray.Count(); i++) |
353 for (int i = 0; i < aAuthenticationProcessData->iAuthTokenArray.Count(); i++) |
305 { |
354 { |
306 iDbUser->AuthParamsTableInsert( |
355 iDbUser->AuthParamsTableInsert( |
323 HBufC* buf = aAuthenticationProcessData->iURLList[i]; |
372 HBufC* buf = aAuthenticationProcessData->iURLList[i]; |
324 iDbUser->URLTableInsert(authAppIDbuf, buf->Des()); |
373 iDbUser->URLTableInsert(authAppIDbuf, buf->Des()); |
325 } |
374 } |
326 } |
375 } |
327 |
376 |
328 void CSmfCredMgrServerSession::fetchPluginIDs(CSmfPluginIDListParams* aParams) |
377 /** |
|
378 * Retrieves the plugin ids from Db |
|
379 * @param aParams class object to be updated |
|
380 */ |
|
381 void CSmfCredMgrServerSession::fetchPluginIDsL(CSmfPluginIDListParams* aParams) |
329 { |
382 { |
330 TBuf<KMaxBufSize> tokenBuf(aParams->iRegistrationToken->Des()); |
383 TBuf<KMaxBufSize> tokenBuf(aParams->iRegistrationToken->Des()); |
331 iDbUser->fetchPluginList(tokenBuf, aParams->iPluginList); |
384 iDbUser->fetchPluginListL(tokenBuf, aParams->iPluginList); |
332 } |
385 } |
333 |
386 |
334 void CSmfCredMgrServerSession::fetchURLs(CSmfURLListParams* aArg) |
387 /** |
|
388 * Retrieves the URLs from Db |
|
389 * @param aArg class object to be updated |
|
390 */ |
|
391 void CSmfCredMgrServerSession::fetchUrlL(CSmfURLListParams* aArg) |
335 { |
392 { |
336 TBuf<KMaxBufSize> authAppIDBuf; |
393 TBuf<KMaxBufSize> authAppIDBuf; |
337 iDbUser->readAuthAppIdInPluginIdTable(aArg->iPluginID->Des(), authAppIDBuf); |
394 iDbUser->readAuthAppIdInPluginIdTable(aArg->iPluginID->Des(), authAppIDBuf); |
338 iDbUser->readURL(authAppIDBuf, aArg->iURLList); |
395 iDbUser->readUrlL(authAppIDBuf, aArg->iURLList); |
339 } |
396 } |
340 |
397 |
341 |
398 /** |
342 void CSmfCredMgrServerSession::getTokenArray(CSmfFetchAuthTokenSet* aParams) |
399 * Retrieves each token set from Db and updates the array of CSmfFetchAuthTokenSet |
|
400 * @param aParams class containg the array to be filled |
|
401 */ |
|
402 void CSmfCredMgrServerSession::getTokenArrayL(CSmfFetchAuthTokenSet* aParams) |
343 { |
403 { |
344 TBuf<KMaxBufSize> authAppIDBuf; |
404 TBuf<KMaxBufSize> authAppIDBuf; |
345 iDbUser->readAuthAppIdInRegTokenTable(aParams->iRegistrationToken->Des(), |
405 iDbUser->readAuthAppIdInRegTokenTable(aParams->iRegistrationToken->Des(), |
346 authAppIDBuf); |
406 authAppIDBuf); |
347 iDbUser->readAuthTokens(authAppIDBuf, aParams->iAuthTokenArray); |
407 iDbUser->readAuthTokensL(authAppIDBuf, aParams->iAuthTokenArray); |
348 } |
408 } |
349 |
|