rtsecuritymanager/rtsecuritymanagerclient/src/rtsecmanager.cpp
changeset 0 99ef825efeca
equal deleted inserted replaced
-1:000000000000 0:99ef825efeca
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:       Defines CRTSecManager and CRTSecMgrClientProxy classes
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include <coemain.h>
       
    24 #include <rtsecmanager.h>
       
    25 #include <rtsecmgrscriptsession.h>
       
    26 #include "rtsecmgrclient.h"
       
    27 #include "rtsecmgrtracer.h"
       
    28 
       
    29 /**
       
    30  * Proxy delegate class for runtime security manager client-side
       
    31  * session handle.
       
    32  * 
       
    33  * @lib rtsecmgrclient.lib
       
    34  */
       
    35 class CRTSecMgrClientProxy : public CBase
       
    36 	{
       
    37 public:
       
    38 	CRTSecMgrClientProxy()
       
    39 		{
       
    40 		}
       
    41 
       
    42 	void ConstructL()
       
    43 		{
       
    44 		User::LeaveIfError (iSecSession.Connect ());
       
    45 		}
       
    46 
       
    47 	static CRTSecMgrClientProxy* NewL()
       
    48 		{
       
    49 		CRTSecMgrClientProxy* self = CRTSecMgrClientProxy::NewLC ();
       
    50 		CleanupStack::Pop (self);
       
    51 		return self;
       
    52 		}
       
    53 
       
    54 	static CRTSecMgrClientProxy* NewLC()
       
    55 		{
       
    56 		CRTSecMgrClientProxy* self = new (ELeave) CRTSecMgrClientProxy();
       
    57 		CleanupStack::PushL (self);
       
    58 		self->ConstructL ();
       
    59 		return self;
       
    60 		}
       
    61 
       
    62 	virtual ~CRTSecMgrClientProxy()
       
    63 		{
       
    64 		iSecSession.Close ();
       
    65 		}
       
    66 
       
    67 	RSecMgrSession& Session()
       
    68 		{
       
    69 		return iSecSession;
       
    70 		}
       
    71 	RSecMgrSession* operator ->()
       
    72 	{
       
    73 		return &iSecSession;
       
    74 	}
       
    75 private:
       
    76 	RSecMgrSession iSecSession;
       
    77 	};
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Defintiion of default private constructor
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 CRTSecManager::CRTSecManager()
       
    84 	{
       
    85 	}
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Definition of second phase constructor
       
    89 //
       
    90 // Instantiates client proxy object, in turn creating a client-side
       
    91 // session
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CRTSecManager::ConstructL()
       
    95 	{
       
    96 	iClientProxy = CRTSecMgrClientProxy::NewL ();
       
    97 
       
    98 #ifdef _DEBUG
       
    99 	if(CCoeEnv::Static())
       
   100 	{
       
   101 	CCoeEnv::Static()->DisableExitChecks(ETrue); 
       
   102 	}	
       
   103 #endif
       
   104 	}
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Definition of second phase constructor
       
   108 //
       
   109 // Constructs a CRTSecManager instance
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C CRTSecManager* CRTSecManager::NewL()
       
   113 	{
       
   114 	RTSecMgrCreateTraceFile() ;
       
   115 	CRTSecManager* self = CRTSecManager::NewLC();
       
   116 	CleanupStack::Pop(self);
       
   117 	return self;
       
   118 	}
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // Definition of second phase constructor
       
   122 //
       
   123 // Constructs a CRTSecManager instance and leaves the created instance
       
   124 // on the cleanupstack
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 EXPORT_C CRTSecManager* CRTSecManager::NewLC()
       
   128 	{
       
   129 	CRTSecManager* self = new (ELeave) CRTSecManager();
       
   130 	CleanupStack::PushL(self);
       
   131 	self->ConstructL();
       
   132 	return self;
       
   133 	}
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // Destructor
       
   137 //
       
   138 // Closes client-side session in turn closing the peer server
       
   139 // side session
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C CRTSecManager::~CRTSecManager()
       
   143 	{
       
   144 	delete iClientProxy;
       
   145 	}
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Definition of SetPolicy
       
   149 //
       
   150 // This method delegates the actual handling to the client-side session
       
   151 // handle class
       
   152 // ---------------------------------------------------------------------------
       
   153 EXPORT_C TPolicyID CRTSecManager::SetPolicy(const RFile& aSecPolicy)
       
   154 	{
       
   155 	RTSecMgrTraceFunction("CRTSecManager::SetPolicy(const RFile& aSecPolicy)") ;
       
   156 	return (*iClientProxy)->SetPolicy(aSecPolicy);
       
   157 	}
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // Definition of SetPolicy
       
   161 //
       
   162 // This method delegates the actual handling to the client-side session
       
   163 // handle class
       
   164 // ---------------------------------------------------------------------------
       
   165 EXPORT_C TPolicyID CRTSecManager::SetPolicy(const TDesC8& aPolicyBuffer)
       
   166 	{
       
   167 	RTSecMgrTraceFunction("CRTSecManager::SetPolicy(const TDesC8& aPolicyBuffer)") ;
       
   168 	return (*iClientProxy)->SetPolicy(aPolicyBuffer);
       
   169 	}
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // Definition of UnSetPolicy
       
   173 //
       
   174 // This method delegates the actual handling to the client-side session
       
   175 // handle class
       
   176 // ---------------------------------------------------------------------------
       
   177 EXPORT_C TInt CRTSecManager::UnSetPolicy(TPolicyID aPolicyID)
       
   178 	{
       
   179 	RTSecMgrTraceFunction("CRTSecManager::UnSetPolicy(TPolicyID aPolicyID)") ;
       
   180 	return (*iClientProxy)->UnSetPolicy(aPolicyID);
       
   181 	}
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // Definition of UpdatePolicy
       
   185 //
       
   186 // This method delegates the actual handling to the client-side session
       
   187 // handle class
       
   188 // ---------------------------------------------------------------------------
       
   189 EXPORT_C TPolicyID CRTSecManager::UpdatePolicy(TPolicyID aPolicyID,const RFile& aSecPolicy)
       
   190 	{
       
   191 	RTSecMgrTraceFunction("CRTSecManager::UpdatePolicy(TPolicyID aPolicyID,const RFile& aSecPolicy)") ;
       
   192 	return (*iClientProxy)->UpdatePolicy(aPolicyID,aSecPolicy);
       
   193 	}
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // Definition of UpdatePolicy
       
   197 //
       
   198 // This method delegates the actual handling to the client-side session
       
   199 // handle class
       
   200 // ---------------------------------------------------------------------------
       
   201 EXPORT_C TPolicyID CRTSecManager::UpdatePolicy(TPolicyID aPolicyID,const TDesC8& aPolicyBuffer)
       
   202 	{
       
   203 	RTSecMgrTraceFunction("CRTSecManager::UpdatePolicy(TPolicyID aPolicyID,const TDesC8& aPolicyBuffer)") ;
       
   204 	return (*iClientProxy)->UpdatePolicy(aPolicyID,aPolicyBuffer);
       
   205 	}
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // Definition of RegisterScript
       
   209 //
       
   210 // This method delegates the actual handling to the client-side session
       
   211 // handle class
       
   212 // ---------------------------------------------------------------------------
       
   213 EXPORT_C TExecutableID CRTSecManager::RegisterScript(TPolicyID aPolicyID, const CTrustInfo& aTrustInfo)
       
   214 	{
       
   215 	RTSecMgrTraceFunction("CRTSecManager::RegisterScript(TPolicyID aPolicyID, const CTrustInfo& aTrustInfo)") ;
       
   216 	return (*iClientProxy)->RegisterScript(aPolicyID,aTrustInfo);
       
   217 	}
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // Definition of RegisterScript with script having hash value
       
   221 //
       
   222 // This method delegates the actual handling to the client-side session
       
   223 // handle class
       
   224 // ---------------------------------------------------------------------------
       
   225 EXPORT_C TExecutableID CRTSecManager::RegisterScript(TPolicyID aPolicyID, const TDesC& aHashMarker, const CTrustInfo& aTrustInfo)
       
   226 	{
       
   227     RTSecMgrTraceFunction("CRTSecManager::RegisterScript(TPolicyID aPolicyID, const TDesC& aHashMarker, const CTrustInfo& aTrustInfo)") ;
       
   228 	return (*iClientProxy)->RegisterScript(aPolicyID,aHashMarker,aTrustInfo);
       
   229 	}
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // Definition of UnRegisterScript
       
   233 //
       
   234 // This method delegates the actual handling to the client-side session
       
   235 // handle class
       
   236 // ---------------------------------------------------------------------------
       
   237 EXPORT_C TInt CRTSecManager::UnRegisterScript(TExecutableID aExeID, TPolicyID aPolicyID)
       
   238 	{
       
   239     RTSecMgrTraceFunction("CRTSecManager::UnRegisterScript(TExecutableID aExeID, TPolicyID aPolicyID)") ;
       
   240 	return (*iClientProxy)->UnRegisterScript(aExeID,aPolicyID);
       
   241 	}
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // Definition of GetScriptSession
       
   245 //
       
   246 // This method starts a client-side sub-session handle, modelling script
       
   247 // session. This in turn creates a server-side peer sub-session handle
       
   248 // ---------------------------------------------------------------------------
       
   249 /*EXPORT_C CRTSecMgrScriptSession* CRTSecManager::GetScriptSession(TPolicyID aPolicyID,
       
   250 		TExecutableID aExecID,
       
   251 		MSecMgrPromptHandler* aPromptHdlr,const TDesC& aHashValue)
       
   252 	{
       
   253 	if(aExecID<=KAnonymousScript)
       
   254 		return NULL;
       
   255 
       
   256 	CRTSecMgrScriptSession* scriptSession = CRTSecMgrScriptSession::NewLC(aPromptHdlr);
       
   257 
       
   258 	if(KErrNone==scriptSession->Open(iClientProxy->Session(),aPolicyID,aExecID))
       
   259 		{
       
   260 		CleanupStack::Pop(scriptSession);
       
   261 		return scriptSession;
       
   262 		}
       
   263 
       
   264 	if(scriptSession)
       
   265 		CleanupStack::PopAndDestroy(scriptSession);
       
   266 
       
   267 	return NULL;
       
   268 	}*/
       
   269 
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // Definition of GetScriptSession
       
   273 //
       
   274 // This method starts a client-side sub-session handle, modelling script
       
   275 // session. This in turn creates a server-side peer sub-session handle
       
   276 // ---------------------------------------------------------------------------
       
   277 EXPORT_C CRTSecMgrScriptSession* CRTSecManager::GetScriptSessionL(TPolicyID aPolicyID,
       
   278 		const CTrustInfo& aTrustInfo,
       
   279 		MSecMgrPromptHandler* aPromptHdlr)
       
   280 	{
       
   281     RTSecMgrTraceFunction("CRTSecManager::GetScriptSession(TPolicyID aPolicyID,\
       
   282 		                   const CTrustInfo& aTrustInfo,\
       
   283 		                   MSecMgrPromptHandler* aPromptHdlr)") ;
       
   284 	CRTSecMgrScriptSession* scriptSession = CRTSecMgrScriptSession::NewLC(aPromptHdlr);
       
   285 
       
   286 	if(KErrNone==scriptSession->Open(iClientProxy->Session(),aPolicyID,KAnonymousScript,aTrustInfo))
       
   287 		{
       
   288 		CleanupStack::Pop(scriptSession);
       
   289 		return scriptSession;
       
   290 		}
       
   291 
       
   292 	if(scriptSession)
       
   293 		CleanupStack::PopAndDestroy(scriptSession);
       
   294 
       
   295 	return NULL;
       
   296 	}
       
   297 
       
   298 // ---------------------------------------------------------------------------
       
   299 // Definition of GetScriptSession
       
   300 //
       
   301 // This method starts a client-side sub-session handle, modelling script
       
   302 // session. This in turn creates a server-side peer sub-session handle
       
   303 // ---------------------------------------------------------------------------
       
   304 EXPORT_C CRTSecMgrScriptSession* CRTSecManager::GetScriptSessionL(TPolicyID aPolicyID,
       
   305 		TExecutableID aExecID,
       
   306 		MSecMgrPromptHandler* aPromptHdlr,
       
   307 		const TDesC& aHashValue)
       
   308 	{
       
   309 	RTSecMgrTraceFunction("CRTSecManager::GetScriptSession(TPolicyID aPolicyID,\
       
   310 		                   TExecutableID aExecID,MSecMgrPromptHandler* aPromptHdlr,\
       
   311 		                   const TDesC& aHashValue)") ;
       
   312 	if(aExecID<=KAnonymousScript)
       
   313 		return NULL;
       
   314 	
       
   315 	CRTSecMgrScriptSession* scriptSession = CRTSecMgrScriptSession::NewLC(aPromptHdlr);
       
   316 
       
   317 	if(KErrNone==scriptSession->Open(iClientProxy->Session(),aPolicyID,aExecID,aHashValue))
       
   318 		{
       
   319 		CleanupStack::Pop(scriptSession);
       
   320 		return scriptSession;
       
   321 		}
       
   322 
       
   323 	if(scriptSession)
       
   324 		CleanupStack::PopAndDestroy(scriptSession);
       
   325 
       
   326 	return NULL;
       
   327 	}
       
   328