authenticationservices/authenticationserver/source/client/authclient.cpp
changeset 102 deec7e509f66
parent 94 0e6c5a9328b5
child 108 ca9a0fc2f082
equal deleted inserted replaced
94:0e6c5a9328b5 102:deec7e509f66
     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 * authclient - exported authentication client session  implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22 */
       
    23 
       
    24 #include <e32debug.h>
       
    25 #include <s32mem.h>
       
    26 #include "authclient_impl.h"
       
    27 #include "authrepository.h"
       
    28 
       
    29 namespace AuthServer
       
    30 {
       
    31 
       
    32 /**
       
    33 	Helper function for Authenticate.  This allocates
       
    34 	a buffer to hold the externalized authentication expression.
       
    35 	
       
    36 	@param	aExpr			Expression to externalize.
       
    37 	@return					Descriptor containing externalized expression.
       
    38 							The memory must be freed by the caller.
       
    39  */
       
    40 HBufC8* ExternalizeExpressionL(const CAuthExpression* aExpr)
       
    41 	{
       
    42 	AuthServer::TSizeStream ss;
       
    43 	RWriteStream ws(&ss);
       
    44 	aExpr->ExternalizeL(ws);
       
    45 	
       
    46 	TInt len = ss.Size();
       
    47 	HBufC8* buf = HBufC8::NewLC(len);
       
    48 	TPtr8 bufDes(buf->Des());
       
    49 	
       
    50 	RDesWriteStream dws(bufDes);
       
    51 	aExpr->ExternalizeL(dws);
       
    52 	dws.CommitL();
       
    53 		
       
    54 	CleanupStack::Pop(buf);
       
    55 	return buf;
       
    56 	}
       
    57 }
       
    58 
       
    59 using namespace AuthServer;
       
    60 
       
    61 
       
    62 /**
       
    63  * Connect to the server, attempt to start it if it is not yet running
       
    64  *
       
    65  * @return KErrNone if successful or an error code
       
    66  */
       
    67 EXPORT_C TInt RAuthClient::Connect()
       
    68 	{
       
    69 	const TUidType serverUid(KNullUid, KNullUid, KAuthServerSecureId);
       
    70 
       
    71 	TInt err = RScsClientBase::Connect(AuthServer::KAuthServerName, TVersion(1, 0, 0), 
       
    72 									   AuthServer::KAuthServerImg, serverUid );
       
    73 	return err;
       
    74 	}
       
    75 
       
    76 EXPORT_C RAuthClient::RAuthClient() : 
       
    77 	RScsClientBase(), iAsyncResponseDecoder(0)
       
    78     {
       
    79 	
       
    80     }
       
    81     
       
    82  
       
    83     
       
    84 /**
       
    85   Authenticate the current device holder using a specified combination of
       
    86   authentication methods. The ownership of the heap allocated CIdentity
       
    87   object is passed to the caller. Requesting a user specific key
       
    88   requires ReadUserData capability.
       
    89  
       
    90   @capability None/ReadUserData
       
    91  
       
    92   @param aExpression An authentication expression specifying which 
       
    93   combination of methods to use to authenticate the device holder.
       
    94  
       
    95   @param aTimeout If an authentication has previously been performed 
       
    96   within this period then a cached identity is returned.
       
    97  
       
    98   @param aClientSpecificKey If this value is true then the key returned
       
    99   by this server will be unique to the calling client. This is achieved
       
   100   by combining the identity protection key with the client process UID.
       
   101   If this value is set to false then the call requires ReadUserData.
       
   102  
       
   103   @param aWithString If this value is true then the identity object returned
       
   104   by the server will contain the identities string. If this value is set to
       
   105   true then the call requires ReadUserData.
       
   106  
       
   107   @return CIdentity object corresponding to the authenticated device
       
   108   holder. It is possible for the identity to be 'unknown'.
       
   109   
       
   110   @leave KErrServerTerminated, if the server no longer present
       
   111   @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   112   @leave KErrNoMemory, if there is insufficient memory available.
       
   113   @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   114   @leave ...			One of the AuthServer error codes defined in 
       
   115   						auth_srv_errs.h or one of the system-wide error codes.
       
   116  **/
       
   117 EXPORT_C CIdentity* RAuthClient::AuthenticateL(
       
   118 	const CAuthExpression& aExpression,
       
   119 	TTimeIntervalSeconds   aTimeout,
       
   120 	TBool                  aClientSpecificKey,
       
   121 	TBool                  aWithString)
       
   122 	{
       
   123 	TUid clientSid = {0};
       
   124 		
       
   125 	CIdentity* identity = AuthenticateL(aExpression, aTimeout,
       
   126 										aClientSpecificKey, clientSid, 
       
   127 										aWithString, KNullDesC());
       
   128 		
       
   129 	return identity;
       
   130 	
       
   131     }
       
   132 
       
   133     
       
   134 
       
   135 /**
       
   136   Authenticate the current device holder using a specified combination of
       
   137   authentication methods. The ownership of the heap allocated CIdentity
       
   138   object is passed to the caller. Requesting a user specific key
       
   139   requires ReadUserData capability.
       
   140  
       
   141   @capability None/ReadUserData
       
   142  
       
   143   @param aExpression An authentication expression specifying which 
       
   144   combination of methods to use to authenticate the device holder.
       
   145  
       
   146   @param aTimeout If an authentication has previously been performed 
       
   147   within this period then a cached identity is returned.
       
   148  
       
   149   @param aClientSpecificKey If this value is true then the key returned
       
   150   by this server will be unique to the calling client. This is achieved
       
   151   by combining the identity protection key with the client process UID.
       
   152   If this value is set to false then the call requires ReadUserData.
       
   153  
       
   154   @param aWithString If this value is true then the identity object returned
       
   155   by the server will contain the identities string. If this value is set to
       
   156   true then the call requires ReadUserData.
       
   157  
       
   158   @param aIdentityResult The returned identity will be placed in this
       
   159   parameter when the asynchronous request completes.  
       
   160  
       
   161   @param aStatus The request status for this asynchronous request.
       
   162  
       
   163   @leave KErrServerTerminated, if the server no longer present
       
   164   @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   165   @leave KErrNoMemory, if there is insufficient memory available.
       
   166   @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   167   @leave ...			One of the AuthServer error codes defined in 
       
   168   						auth_srv_errs.h or one of the system-wide error codes.
       
   169 
       
   170  **/
       
   171 EXPORT_C void RAuthClient::AuthenticateL(
       
   172 	const CAuthExpression& 	aExpression,
       
   173 	TTimeIntervalSeconds   	aTimeout,
       
   174 	TBool                  	aClientSpecificKey,
       
   175 	TBool                  	aWithString, 
       
   176 	CIdentity*&            	aIdentityResult, 
       
   177 	TRequestStatus&        	aStatus)
       
   178 	{
       
   179 	TUid clientSid = {0};
       
   180 	AuthenticateL(aExpression, aTimeout, aClientSpecificKey,
       
   181 				  clientSid, aWithString, KNullDesC(),
       
   182 			      aIdentityResult, aStatus);	
       
   183 	
       
   184 	}
       
   185 
       
   186 
       
   187 /**
       
   188    Authenticate the current device holder using a specified combination of
       
   189   authentication methods. The ownership of the heap allocated CIdentity 
       
   190   object is passed to the caller. Requesting a user specific key requires 
       
   191   ReadUserData capability.
       
   192  
       
   193    @capability None/ReadUserData
       
   194  
       
   195    @param aAuthStrength Descriptor specifying the authentication strength, 
       
   196    which inturn maps to a combination of methods to be used to authenticate 
       
   197    the device holder.
       
   198  
       
   199    @param aTimeout If an authentication has previously been performed 
       
   200    within this period then a cached identity is returned.
       
   201  
       
   202    @param aClientSpecificKey If this value is true then the key returned
       
   203    by this server will be unique to the calling client. This is achieved
       
   204    by combining the identity protection key with the client process UID.
       
   205    If this value is set to false then the call requires ReadUserData.
       
   206           
       
   207    @param aClientSid Sid of the client application from where the authentication
       
   208    request originated and is used to generate protection key.This value is ignored 
       
   209    when aClientSpecificKey is set to false. If aClientSid is non-zero and is not 
       
   210    the calling application's sid, then the call requires ReadUserData.
       
   211   
       
   212    @param aWithString If this value is true then the identity object returned
       
   213    by the server will contain the identities string. If this value is set to
       
   214    true then the call requires ReadUserData.
       
   215  
       
   216    @param aClientMessage A displayable text string parameter for authentication
       
   217    requests.It shall be passed to plug-ins to display to the users.
       
   218 
       
   219    @return the CIdentity object corresponding to the authenticated device
       
   220    holder. It is possible for the identity to be 'unknown'.
       
   221   
       
   222    @leave KErrServerTerminated, if the server no longer present
       
   223    @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   224    @leave KErrNoMemory, if there is insufficient memory available.
       
   225    @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   226    @leave ...			One of the AuthServer error codes defined in 
       
   227   						auth_srv_errs.h or one of the system-wide error codes.
       
   228 
       
   229  **/	
       
   230 
       
   231 EXPORT_C CIdentity* RAuthClient::AuthenticateL(
       
   232 		const CAuthExpression& aAuthExpression,
       
   233 	    TTimeIntervalSeconds   aTimeout,
       
   234 		TBool                  aClientSpecificKey,
       
   235 		TUid 				   aClientSid,
       
   236 		TBool                  aWithString,
       
   237 		const TDesC&		   aClientMessage)
       
   238 	{
       
   239 	
       
   240 	//Create a flat buffer
       
   241 	CBufFlat* flatBuffer = CBufFlat::NewL(KDefaultBufferSize);
       
   242 	CleanupStack::PushL(flatBuffer);
       
   243 	
       
   244 	//Initialize the CAuthParams object
       
   245 	CAuthParams* params = CAuthParams::NewL(aTimeout,
       
   246 											aClientSpecificKey,
       
   247 											aClientSid,
       
   248 											aWithString,
       
   249 											aClientMessage);
       
   250 	CleanupStack::PushL(params);
       
   251 	//Externalize params
       
   252 	RBufWriteStream stream(*flatBuffer);
       
   253 	CleanupClosePushL(stream);
       
   254 	params->ExternalizeL(stream);
       
   255 	CleanupStack::PopAndDestroy(2, params);
       
   256 	
       
   257 	HBufC8* paramsBuffer = HBufC8::NewLC(flatBuffer->Size());
       
   258 	TPtr8 paramsPtr(paramsBuffer->Des());
       
   259 	flatBuffer->Read(0, paramsPtr, flatBuffer->Size());
       
   260 		
       
   261 	//Externalize the expression
       
   262 	HBufC8* exprBuf = ExternalizeExpressionL(&aAuthExpression);
       
   263 	CleanupStack::PushL(exprBuf);
       
   264 		
       
   265 	// allocate buffer for identity result
       
   266 	HBufC8* identityResultbuf = HBufC8::NewLC(KDefaultBufferSize);
       
   267 	TPtr8 bufDes(identityResultbuf->Des());
       
   268 		
       
   269 	TIpcArgs args(exprBuf, &paramsPtr, &bufDes); 
       
   270 	User::LeaveIfError(CallSessionFunction(EAuthenticate, args));
       
   271 		
       
   272 
       
   273 		
       
   274 	RDesReadStream readStream(*identityResultbuf);
       
   275 	CIdentity* identity = CIdentity::InternalizeL(readStream);
       
   276 	    
       
   277 	CleanupStack::PopAndDestroy(4,flatBuffer);//identityResultbuf, exprBuf,
       
   278 											  //paramsBuffer, flatBuffer	
       
   279 	return identity;
       
   280 	}
       
   281 
       
   282 /**
       
   283   Authenticate the current device holder using a specified combination of
       
   284   authentication methods. The ownership of the heap allocated CIdentity 
       
   285   object is passed to the caller. Requesting a user specific key requires 
       
   286   ReadUserData capability.
       
   287  
       
   288   @capability None/ReadUserData
       
   289  
       
   290   @param aAuthStrength	Descriptor specifying the authentication strength, 
       
   291   which inturn maps to a combination of methods to be used to authenticate the device holder.
       
   292  
       
   293   @param aTimeout If an authentication has previously been performed 
       
   294   within this period then a cached identity is returned.
       
   295  
       
   296   @param aClientSpecificKey If this value is true then the key returned
       
   297   by this server will be unique to the calling client. This is achieved
       
   298   by combining the identity protection key with the client process UID.
       
   299   If this value is set to false then the call requires ReadUserData.
       
   300   
       
   301   @param aClientSid Sid of the client application from where the authentication
       
   302   request originated and is used to generate protection key.This value is ignored 
       
   303   when aClientSpecificKey is set to false. If aClientSid is non-zero and is not 
       
   304   the calling application's sid, then the call requires ReadUserData.
       
   305  
       
   306   @param aWithString If this value is true then the identity object returned
       
   307   by the server will contain the identities string. If this value is set to
       
   308   true then the call requires ReadUserData.
       
   309  
       
   310   @param aClientMessage A displayable text string parameter for authentication
       
   311   requests.It shall be passed to plug-ins to display to the users.
       
   312    
       
   313   @param aIdentityResult The returned identity will be placed in this
       
   314   parameter when the asynchronous request completes.  
       
   315  
       
   316   @param aStatus The request status for this asynchronous request.
       
   317  
       
   318   @leave KErrServerTerminated, if the server no longer present
       
   319   @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   320   @leave KErrNoMemory, if there is insufficient memory available.
       
   321   @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   322   @leave ...			One of the AuthServer error codes defined in 
       
   323   						auth_srv_errs.h or one of the system-wide error codes.
       
   324 
       
   325  **/
       
   326  	
       
   327 EXPORT_C void RAuthClient::AuthenticateL(
       
   328 	const CAuthExpression& aExpression,
       
   329 	TTimeIntervalSeconds   aTimeout,
       
   330 	TBool                  aClientSpecificKey,
       
   331 	TUid 				   aClientSid,	
       
   332 	TBool                  aWithString, 
       
   333 	const TDesC&		   aClientMessage,
       
   334 	CIdentity*&            aIdentityResult,
       
   335 	TRequestStatus&        aStatus
       
   336 	)
       
   337 	{
       
   338 	
       
   339 	CheckAsyncDecoderL();
       
   340 	iAsyncResponseDecoder->AuthenticateL(aExpression,
       
   341 										 aTimeout,
       
   342 										 aClientSpecificKey,
       
   343 										 aClientSid,
       
   344 										 aWithString,
       
   345 										 aClientMessage,
       
   346 										 aIdentityResult,
       
   347 										 aStatus);
       
   348 										 
       
   349 	
       
   350 	}
       
   351 
       
   352 /**
       
   353  * creates the async decoder if it's not already been created. 
       
   354  */
       
   355 void RAuthClient::CheckAsyncDecoderL()
       
   356     {
       
   357     if (iAsyncResponseDecoder == 0)
       
   358 	    {
       
   359 	    iAsyncResponseDecoder = new (ELeave) CAsyncResponseDecoder(*this);
       
   360 	    }
       
   361     }
       
   362     
       
   363 	    
       
   364 
       
   365 
       
   366 /**
       
   367  * Retrieves all plugin descriptions. 
       
   368  *
       
   369  * @param aPluginList will be filled with  the full list of plugins available on the device. 
       
   370  *
       
   371  * @leave KErrServerTerminated, if the server no longer present
       
   372  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   373  * @leave KErrNoMemory, if there is insufficient memory available.
       
   374  **/
       
   375 EXPORT_C void RAuthClient::PluginsL(RPluginDescriptions& aPluginList)
       
   376     {
       
   377 	HBufC8* buffer = SendReceiveBufferLC(EPlugins);
       
   378 	// create a stream based on the buffer
       
   379 	RDesReadStream stream(*buffer);
       
   380 	CleanupClosePushL(stream);
       
   381 	
       
   382 	// reassemble the array from the stream
       
   383 	InternalizePointerArrayL(aPluginList, stream);
       
   384 	
       
   385 	CleanupStack::PopAndDestroy(2, buffer);// buffer, stream
       
   386     }
       
   387 	
       
   388 /**
       
   389  * @param aPluginList the list of active plugins available on the device. 
       
   390  *
       
   391  * @leave KErrServerTerminated, if the server no longer present
       
   392  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   393  * @leave KErrNoMemory, if there is insufficient memory available.
       
   394  **/
       
   395 EXPORT_C void RAuthClient::ActivePluginsL(RPluginDescriptions& aPluginList)
       
   396     {
       
   397  	HBufC8* buffer = SendReceiveBufferLC(EActivePlugins);
       
   398 	// create a stream based on the buffer
       
   399 	RDesReadStream stream(*buffer);
       
   400 	CleanupClosePushL(stream);
       
   401 	
       
   402 	// reassemble the array from the stream
       
   403 	InternalizePointerArrayL(aPluginList, stream);
       
   404 	
       
   405 	CleanupStack::PopAndDestroy(2, buffer);// buffer, stream
       
   406 	}
       
   407 	
       
   408 /**
       
   409  *
       
   410  * Retrieves plugin descriptions for plugins matching the specified
       
   411  * type.
       
   412  *
       
   413  * @param aType the plugin type for which the method should return 
       
   414  * the list of plugins. 
       
   415  *
       
   416  * @param aPluginList the list of plugins with the specified type available
       
   417  * on the device. 
       
   418  *
       
   419  * @leave KErrServerTerminated, if the server no longer present
       
   420  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   421  * @leave KErrNoMemory, if there is insufficient memory available.
       
   422  *
       
   423  * @see TAuthPluginType
       
   424  **/
       
   425 EXPORT_C void RAuthClient::PluginsOfTypeL(
       
   426     TAuthPluginType aType,
       
   427     RPluginDescriptions& aPluginList)
       
   428     {
       
   429 	TIpcArgs args(TIpcArgs::ENothing, aType);
       
   430 	HBufC8* buffer = SendReceiveBufferLC(EPluginsByType, args);
       
   431 	// create a stream based on the buffer
       
   432 	RDesReadStream stream(*buffer);
       
   433 	CleanupClosePushL(stream);
       
   434 	
       
   435 	// reassemble the array from the stream
       
   436 	InternalizePointerArrayL(aPluginList, stream);
       
   437 	
       
   438 	CleanupStack::PopAndDestroy(2, buffer);// buffer, stream
       
   439     }
       
   440 	
       
   441 /**
       
   442  * Retrieves plugin descriptions for plugins matching the specified
       
   443  * training status.
       
   444  *
       
   445  * @param aStatus the training status for which the method should 
       
   446  * return the list of plugins. 
       
   447  *
       
   448  * @param aPluginList the list of plugins with the specified type available
       
   449  * on the device.
       
   450  *
       
   451  * @leave KErrServerTerminated, if the server no longer present
       
   452  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   453  * @leave KErrNoMemory, if there is insufficient memory available.
       
   454  *
       
   455  * @see TAuthTrainingStatus
       
   456  **/
       
   457 EXPORT_C void RAuthClient::PluginsWithTrainingStatusL(
       
   458     TAuthTrainingStatus aStatus,
       
   459     RPluginDescriptions& aPluginList)
       
   460     {
       
   461 	TIpcArgs args(TIpcArgs::ENothing, aStatus);
       
   462 	HBufC8* buffer = SendReceiveBufferLC(EPluginsByTraining, args);
       
   463 	// create a stream based on the buffer
       
   464 	RDesReadStream stream(*buffer);
       
   465 	CleanupClosePushL(stream);
       
   466 	
       
   467 	// reassemble the array from the stream
       
   468 	InternalizePointerArrayL(aPluginList, stream);
       
   469 	
       
   470 	CleanupStack::PopAndDestroy(2, buffer);// buffer, stream
       
   471     }
       
   472 	
       
   473 /**
       
   474  * @param aIdList populated with the list of identities known by the 
       
   475  * phone.
       
   476  *
       
   477  * @capability ReadDeviceData
       
   478  *
       
   479  * @leave KErrServerTerminated, if the server no longer present
       
   480  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   481  * @leave KErrNoMemory, if there is insufficient memory available.
       
   482  * @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   483  **/
       
   484 EXPORT_C void RAuthClient::IdentitiesL(RIdentityIdArray& aIdList)
       
   485     {
       
   486 	HBufC8* buffer = SendReceiveBufferLC(EIdentities);
       
   487 	// create a stream based on the buffer
       
   488 	RDesReadStream stream(*buffer);
       
   489 	CleanupClosePushL(stream);
       
   490 	
       
   491 	// reassemble the array from the stream
       
   492 	InternalizeArrayL(aIdList, stream);
       
   493 	
       
   494 	CleanupStack::PopAndDestroy(2, buffer);// buffer, stream
       
   495     }
       
   496 
       
   497 /**
       
   498  * @param aIdList populated with the list of identities and their strings
       
   499  * known by the phone.
       
   500  *
       
   501  * @capability ReadDeviceData
       
   502  * @capability ReadUserData
       
   503  *
       
   504  * @leave KErrServerTerminated, if the server no longer present
       
   505  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   506  * @leave KErrNoMemory, if there is insufficient memory available.
       
   507  * @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   508  **/
       
   509 EXPORT_C void RAuthClient::IdentitiesWithStringL(RIdAndStringArray& aIdList)
       
   510     {
       
   511 	HBufC8* buffer = SendReceiveBufferLC(EIdentitiesWithString);
       
   512 	// create a stream based on the buffer
       
   513 	RDesReadStream stream(*buffer);
       
   514 	CleanupClosePushL(stream);
       
   515 	
       
   516 	// reassemble the array from the stream
       
   517 	InternalizePointerArrayL(aIdList, stream);
       
   518 	
       
   519 	CleanupStack::PopAndDestroy(2, buffer);// buffer, stream
       
   520     }
       
   521 
       
   522 /**
       
   523  * @param aId the Id number of the identity for which to set the
       
   524  * string.
       
   525  *
       
   526  * @param aId the identity who's string to set.
       
   527  * @param aString the string to use
       
   528  *
       
   529  * @capability WriteUserData
       
   530  *
       
   531  * @leave KErrServerTerminated, if the server no longer present
       
   532  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   533  * @leave KErrNoMemory, if there is insufficient memory available.
       
   534  * @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   535  * @leave KErrAuthServIdentityNotFound, if the id does not exist.
       
   536  **/
       
   537 EXPORT_C void RAuthClient::SetIdentityStringL(TIdentityId aId,
       
   538 											  const TDesC& aString)
       
   539   {
       
   540   TIpcArgs args(aId, &aString);
       
   541 
       
   542   User::LeaveIfError(CallSessionFunction(ESetIdentityString, args));
       
   543   }
       
   544 
       
   545 /**
       
   546  * Deauthenticates the current user. This means that clients requesting an
       
   547  * authentication will always cause a plug-in to be called regardless of
       
   548  * any timeout value specified.
       
   549  *
       
   550  * @leave KErrServerTerminated, if the server no longer present
       
   551  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   552  * @leave KErrNoMemory, if there is insufficient memory available.
       
   553  *
       
   554  **/
       
   555 EXPORT_C void RAuthClient::DeauthenticateL()
       
   556   {
       
   557   User::LeaveIfError(CallSessionFunction(EDeauthenticate));
       
   558   }
       
   559 
       
   560 /**
       
   561  * @param aId the Id number of the identity for which to return the
       
   562  * string.
       
   563  * 
       
   564  * @return the string associated with the specified identity.
       
   565  *
       
   566  * @capability ReadUserData
       
   567  *
       
   568  * @leave KErrServerTerminated, if the server no longer present
       
   569  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   570  * @leave KErrNoMemory, if there is insufficient memory available.
       
   571  * @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   572  * @leave KErrAuthServIdentityNotFound, if the id does not exist.
       
   573  **/
       
   574 EXPORT_C HBufC* RAuthClient::IdentityStringL(TIdentityId aId)
       
   575     {
       
   576     HBufC* buffer = HBufC::NewLC(KDefaultBufferSize);
       
   577 	TPtr ptr = buffer->Des();
       
   578 	User::LeaveIfError(CallSessionFunction(EIdentityString, TIpcArgs(&ptr, aId)));
       
   579 	CleanupStack::Pop(buffer);
       
   580 	return buffer;
       
   581     }
       
   582 
       
   583 
       
   584 /**
       
   585  */
       
   586 HBufC8* RAuthClient::SendReceiveBufferLC(TInt aMessage) 
       
   587 	{
       
   588 	HBufC8* output = HBufC8::NewLC(KDefaultBufferSize);
       
   589 	
       
   590 	TPtr8 pOutput(output->Des());
       
   591 	
       
   592 	TInt result = CallSessionFunction(aMessage, TIpcArgs(&pOutput));
       
   593 	
       
   594 	if (result == KErrOverflow)
       
   595 		{
       
   596 		TInt sizeNeeded = 0;
       
   597 		TPckg<TInt> sizeNeededPackage(sizeNeeded);
       
   598 		sizeNeededPackage.Copy(*output);
       
   599 		
       
   600 		// Re-allocate buffer after reclaiming memory
       
   601 		CleanupStack::PopAndDestroy(output);
       
   602 		output = HBufC8::NewLC(sizeNeeded);
       
   603 
       
   604 		TPtr8 pResizedOutput(output->Des());
       
   605 		
       
   606 		result=CallSessionFunction(aMessage, TIpcArgs(&pResizedOutput));
       
   607 		}
       
   608 	User::LeaveIfError(result);
       
   609 	return output;
       
   610 	}
       
   611 
       
   612 /**
       
   613  * aArgs[0] is set to the buffer to be sent/received
       
   614  */
       
   615 HBufC8* RAuthClient::SendReceiveBufferLC(
       
   616 	TInt aMessage,
       
   617 	TIpcArgs& aArgs) 
       
   618 	{
       
   619 	HBufC8* output = HBufC8::NewLC(KDefaultBufferSize);
       
   620 	
       
   621 	TPtr8 pOutput(output->Des());
       
   622 
       
   623 	aArgs.Set(0, &pOutput);
       
   624 		  
       
   625 	TInt result = CallSessionFunction(aMessage, aArgs);
       
   626 	
       
   627 	if (result == KErrOverflow)
       
   628 		{
       
   629 		TInt sizeNeeded;
       
   630 		TPckg<TInt> sizeNeededPackage(sizeNeeded);
       
   631 		sizeNeededPackage.Copy(*output);
       
   632 		
       
   633 		// Re-allocate buffer
       
   634 		CleanupStack::PopAndDestroy(output);
       
   635 		output = HBufC8::NewLC(sizeNeeded);
       
   636 
       
   637 		TPtr8 pResizedOutput(output->Des());
       
   638 		aArgs.Set(0, &pResizedOutput);
       
   639 		result=CallSessionFunction(aMessage, aArgs);
       
   640 		}
       
   641 	User::LeaveIfError(result);
       
   642 	return output;
       
   643 	}
       
   644 
       
   645 /**
       
   646  * @param aPluginType the type of plugin for which to return the preferred
       
   647  * plugin id
       
   648  * 
       
   649  * @return the id of the preferred plugin for the specified type
       
   650  *
       
   651  * @leave KErrServerTerminated, if the server no longer present
       
   652  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   653  * @leave KErrNoMemory, if there is insufficient memory available.
       
   654  * @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   655  **/
       
   656 EXPORT_C TPluginId RAuthClient::PreferredTypePluginL(TAuthPluginType aPluginType)
       
   657 	{
       
   658 	TPluginId id = KUnknownPluginId;
       
   659 	TPckg<TPluginId> idPckg(id);
       
   660 	
       
   661 	User::LeaveIfError(CallSessionFunction(EGetAuthPreferences, TIpcArgs(aPluginType, &idPckg)));
       
   662 
       
   663 	return id;
       
   664 	}
       
   665 	
       
   666 /**
       
   667  * Cancel any operation in progress.
       
   668  * 
       
   669  * @return KErrNone, if the send operation is successful or no operation
       
   670  * is in effect.
       
   671  * @return KErrServerTerminated, if the server no longer present
       
   672  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
   673  * @return KErrNoMemory, if there is insufficient memory available.
       
   674  **/
       
   675 EXPORT_C TUint RAuthClient::Cancel()
       
   676     {
       
   677     CallSessionFunction(ECancel);
       
   678     if(iAsyncResponseDecoder)
       
   679     	{
       
   680     	iAsyncResponseDecoder->Cancel();
       
   681     	}
       
   682     
       
   683     return KErrNone;
       
   684 	}
       
   685 	
       
   686 
       
   687 EXPORT_C void RAuthClient::Close()
       
   688     {
       
   689     delete iAsyncResponseDecoder;
       
   690     iAsyncResponseDecoder = 0;
       
   691      
       
   692     RScsClientBase::Close();
       
   693     }
       
   694 
       
   695 /**
       
   696   Lists the authentication aliases.
       
   697   
       
   698   @return An array of authentication strength aliases.
       
   699  
       
   700   @leave KErrServerTerminated, if the server no longer present
       
   701   @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   702   @leave KErrNoMemory, if there is insufficient memory available.
       
   703   @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   704  **/
       
   705  
       
   706 EXPORT_C void RAuthClient::ListAuthAliasesL(RPointerArray<HBufC>& aAuthAliasesList)
       
   707     {
       
   708 	HBufC8* buffer = SendReceiveBufferLC(EListAuthAliases);
       
   709 	
       
   710 	// create a stream based on the buffer
       
   711 	RDesReadStream stream(*buffer);
       
   712 	CleanupClosePushL(stream);
       
   713 	
       
   714 	// reassemble the array from the stream
       
   715 	TInt strengthAliasCount = stream.ReadInt32L();
       
   716 	for(TInt i = 0; i < strengthAliasCount; ++i)
       
   717 		{
       
   718 		HBufC* strengthAlias = HBufC::NewLC(stream, KMaxTInt);
       
   719 		aAuthAliasesList.AppendL(strengthAlias);
       
   720 		CleanupStack::Pop(strengthAlias);
       
   721 		}
       
   722 	
       
   723 	CleanupStack::PopAndDestroy(2, buffer);// buffer, stream
       
   724     }
       
   725 
       
   726 /**
       
   727    Returns a CAuthExpression object from a free form expression
       
   728    which can be a combination of plugin Ids, plugin types and alias names.
       
   729    This can be used for calling the authentication APIs.
       
   730    
       
   731  
       
   732    @capability None
       
   733  
       
   734    @param aAuthString Descriptor specifying a free form expression
       
   735    which can be a combination of plugin Ids, plugin types and alias names.
       
   736    
       
   737  
       
   738    @return the CAuthExpression object which can be used to call the 
       
   739    authentication APIs.
       
   740   
       
   741    @leave KErrServerTerminated, if the server no longer present
       
   742    @leave KErrServerBusy, if the request cannot be handled at this time. 
       
   743    @leave KErrNoMemory, if there is insufficient memory available.
       
   744    @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
   745    @leave ...			One of the AuthServer error codes defined in 
       
   746   						auth_srv_errs.h or one of the system-wide error codes.
       
   747 
       
   748  **/	
       
   749 
       
   750 EXPORT_C CAuthExpression* RAuthClient::CreateAuthExpressionL(const TDesC& aAuthString) const
       
   751 	{
       
   752 	CAuthExpression* authExpr(0);
       
   753 	
       
   754 	if(aAuthString == KNullDesC)
       
   755 		{
       
   756 		authExpr = AuthExpr();
       
   757 		return authExpr;
       
   758 		}
       
   759 	HBufC* buffer = HBufC::NewLC(KDefaultBufferSize);
       
   760 	TPtr bufDes(buffer->Des());
       
   761 		
       
   762 	// get the string in combination of plugin ID and plugin type.
       
   763 	User::LeaveIfError(CallSessionFunction(EResolveExpression, TIpcArgs(&bufDes, &aAuthString)));
       
   764 		
       
   765 	// create an auth expression from alias string.
       
   766 	authExpr = CAuthExpressionImpl::CreateAuthExprObjectL(*buffer);
       
   767 	CleanupStack::PopAndDestroy(buffer);
       
   768 	
       
   769 	return authExpr;
       
   770 	}
       
   771 
       
   772  
       
   773 
       
   774