os/security/cryptoservices/filebasedcertificateandkeystores/source/generic/client/clientsession.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/source/generic/client/clientsession.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,191 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "clientsession.h"
    1.23 +#include <e32std.h>
    1.24 +#include <e32uid.h>
    1.25 +#include "clientutils.h"
    1.26 +#include "fstokenservername.h"
    1.27 +
    1.28 +#ifdef SYMBIAN_AUTH_SERVER
    1.29 +
    1.30 +#ifdef __WINS__
    1.31 +#include <u32hal.h>
    1.32 +#endif //__WINS__
    1.33 +
    1.34 +#include <e32svr.h>
    1.35 +#endif // SYMBIAN_AUTH_SERVER
    1.36 +
    1.37 +//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	
    1.38 +//	Tokentype session class for file based certificate store
    1.39 +//	Connects and passes messages to the file store tokentype server
    1.40 +//	Coded specifically for file store token type
    1.41 +//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	
    1.42 +
    1.43 +_LIT(KFSTokenServerImg,"fstokenserver");
    1.44 +#ifdef SYMBIAN_AUTH_SERVER
    1.45 +#ifdef __WINS__
    1.46 +_LIT(KFSNewTokenServerImg,"fstokenserver_useauth");
    1.47 +#endif // __WINS__
    1.48 +#endif // SYMBIAN_AUTH_SERVER
    1.49 +
    1.50 +RFileStoreClientSession::RFileStoreClientSession()
    1.51 +{}
    1.52 +
    1.53 +TInt RFileStoreClientSession::SendRequest(TFSTokenMessages aRequest, const TIpcArgs& aArgs) const
    1.54 +{
    1.55 +	return SendReceive(aRequest, aArgs);
    1.56 +}
    1.57 +
    1.58 +void RFileStoreClientSession::SendAsyncRequest(TFSTokenMessages aRequest, const TIpcArgs& aArgs, TRequestStatus* aStatus) const
    1.59 +{
    1.60 +	__ASSERT_ALWAYS(aStatus, FSTokenPanic(EBadArgument));
    1.61 +
    1.62 +	if (aStatus)
    1.63 +	{
    1.64 +		*aStatus = KRequestPending;
    1.65 +		SendReceive(aRequest, aArgs, *aStatus);
    1.66 +	}
    1.67 +}
    1.68 +
    1.69 +
    1.70 +//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	
    1.71 +//	Client-server startup code
    1.72 +//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	//	\\	
    1.73 +
    1.74 +static TInt StartServer();	//	Forward declaration
    1.75 +//
    1.76 +// Connect to the server, attempting to start it if necessary
    1.77 +//
    1.78 +
    1.79 +#ifdef SYMBIAN_AUTH_SERVER
    1.80 +#ifdef __WINS__
    1.81 +
    1.82 +static bool UseAuthServer(void);
    1.83 +
    1.84 +#endif // SYMBIAN_AUTH_SERVER
    1.85 +#endif // __WINS__
    1.86 +
    1.87 +TInt RFileStoreClientSession::Connect(ETokenEnum aToken)
    1.88 +	{
    1.89 +	// The version is made up of three pieces of information:
    1.90 +	// 1. iMajor - The token we want to talk to
    1.91 +	// 2. iMinor - The protocol version number
    1.92 +	// 3. iBuild - unused
    1.93 +	TVersion version(aToken, KFSProtolVersion, 0);
    1.94 +	
    1.95 +	TInt retry=2;
    1.96 +	for (;;)
    1.97 +		{
    1.98 +		TInt err = KErrNone;
    1.99 +#ifdef SYMBIAN_AUTH_SERVER
   1.100 +#ifdef __WINS__
   1.101 +		if(UseAuthServer())
   1.102 +			{
   1.103 +			err = CreateSession(KFSNewTokenServerName, version, 1);
   1.104 +			}
   1.105 +		else
   1.106 +#endif // __WINS__
   1.107 +#endif // SYMBIAN_AUTH_SERVER
   1.108 +			{
   1.109 +			err = CreateSession(KFSTokenServerName, version, 1);
   1.110 +			}
   1.111 +		
   1.112 +		if (err!=KErrNotFound && err!=KErrServerTerminated)
   1.113 +			return err;
   1.114 +		if (--retry==0)
   1.115 +			return err;
   1.116 +		err=StartServer();
   1.117 +		if (err!=KErrNone && err!=KErrAlreadyExists)
   1.118 +			return err;
   1.119 +		}
   1.120 +	}
   1.121 +
   1.122 +#ifdef SYMBIAN_AUTH_SERVER
   1.123 +#ifdef __WINS__
   1.124 +
   1.125 +/*static*/ bool UseAuthServer(void)
   1.126 +	{
   1.127 +	bool useAuthServer = false;
   1.128 +	
   1.129 +	TUint32 useAuth = 0;
   1.130 +	// For the emulator allow the constant to be patched via epoc.ini
   1.131 +	UserSvr::HalFunction(EHalGroupEmulator, EEmulatorHalIntProperty,
   1.132 +	(TAny*)"KKeyStoreUseAuthServer", &useAuth); // read emulator property (if present)
   1.133 +	if(useAuth)
   1.134 +		{
   1.135 +		useAuthServer = true;
   1.136 +		}
   1.137 +	return useAuthServer; 
   1.138 +	}
   1.139 +#endif // __WINS__
   1.140 +#endif // SYMBIAN_AUTH_SERVER
   1.141 +
   1.142 +TInt StartServer()
   1.143 +	{
   1.144 +	// Server startup is different for WINS in EKA1 mode ONLY (lack of process
   1.145 +	// emulation - we load the library in this instance
   1.146 +	const TUidType serverUid(KNullUid, KNullUid, KUidFSTokenServer);
   1.147 +
   1.148 +	RProcess server;
   1.149 +	TInt error = KErrNone;
   1.150 +	
   1.151 +#ifdef SYMBIAN_AUTH_SERVER
   1.152 +#ifdef __WINS__
   1.153 +	if(UseAuthServer())
   1.154 +		{
   1.155 +		error = server.Create(KFSNewTokenServerImg, KNullDesC, serverUid);
   1.156 +		}
   1.157 +	else
   1.158 +#endif // __WINS__
   1.159 +#endif // SYMBIAN_AUTH_SERVER
   1.160 +		{
   1.161 +		error = server.Create(KFSTokenServerImg, KNullDesC, serverUid);
   1.162 +		}
   1.163 +	
   1.164 +	if (error != KErrNone)
   1.165 +		{
   1.166 +		return error;
   1.167 +		}
   1.168 +
   1.169 +	// Synchronise with the process to make sure it hasn't died straight away
   1.170 +	TRequestStatus stat;
   1.171 +	server.Rendezvous(stat);
   1.172 +	if (stat != KRequestPending)
   1.173 +		{
   1.174 +		// logon failed - server is not yet running, so cannot have terminated
   1.175 +		server.Kill(0);				// Abort startup
   1.176 +		}
   1.177 +	else
   1.178 +		{
   1.179 +		// logon OK - start the server
   1.180 +		server.Resume();
   1.181 +		}
   1.182 +
   1.183 +	// Wait to synchronise with server - if it dies in the meantime, it
   1.184 +	// also gets completed
   1.185 +	User::WaitForRequest(stat);	
   1.186 +
   1.187 +	// We can't use the 'exit reason' if the server panicked as this
   1.188 +	// is the panic 'reason' and may be '0' which cannot be distinguished
   1.189 +	// from KErrNone
   1.190 +	error = (server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
   1.191 +	server.Close();
   1.192 +	return (error);
   1.193 +	}
   1.194 +