installationservices/swcomponentregistry/source/server/scrserver.cpp
changeset 25 98b66e4fb0be
parent 24 84a16765cd86
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "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".
    30 #include "scrhelperclient.h"
    30 #include "scrhelperclient.h"
    31 #include <scs/securityutils.h>
    31 #include <scs/securityutils.h>
    32 
    32 
    33 using namespace Usif;
    33 using namespace Usif;
    34 
    34 
    35 _LIT_SECURE_ID(KSisRegistryServerSid, 0x10202DCA); 
    35 static const TUint scrRangeCount = 13;
    36 
       
    37 static const TUint scrRangeCount = 11;
       
    38 
    36 
    39 static const TInt scrRanges[scrRangeCount] =
    37 static const TInt scrRanges[scrRangeCount] =
    40 	{
    38 	{
    41 	0,							 // Range-0 - 0 to EBaseSession-1. Not used.
    39 	0,							 // Range-0 - 0 to EBaseSession-1. Not used.
    42 	CScsServer::EBaseSession,	 // Range-1 - EBaseSession to EBaseMustAllow exclusive.
    40 	CScsServer::EBaseSession,	 // Range-1 - EBaseSession to EBaseMustAllow exclusive.
    43 	CScsServer::EBaseSession | EGetSingleComponentSize, // Modification and transaction APIs have custom checks
    41 	CScsServer::EBaseSession | EGetSingleComponentSize, // Modification and transaction APIs have custom checks
    44 	CScsServer::EBaseSession | EGetComponentIdListSize, // Component-specific APIs are free for all
    42 	CScsServer::EBaseSession | EGetComponentIdListSize, // Component-specific APIs are free for all
    45 	CScsServer::EBaseSession | EGetIsMediaPresent, // Getting all component IDs is restricted to ReadUserData
    43 	CScsServer::EBaseSession | EGetApplicationLaunchersSize, // Getting all component IDs is restricted to ReadUserData
    46 	CScsServer::EBaseSession | ESetScomoState, // Component-specific APIs are free for all
    44 	CScsServer::EBaseSession | EGetIsMediaPresent, // Only allowed by apparc
    47 	CScsServer::EBaseSession | EGetPluginUidWithMimeType, // SetScomoState has custom checks (as with the rest of modification APIs)
    45 	CScsServer::EBaseSession | EAddApplicationEntry, // Component-specific APIs are free for all
    48 	CScsServer::EBaseSession | EAddSoftwareType, // File filter sub-sessions and plugin-fetching APIs are free for all
    46 	CScsServer::EBaseSession | EGetPluginUidWithMimeType, // Custom checks (as with the rest of modification APIs)
       
    47 	CScsServer::EBaseSession | EAddSoftwareType, // File filter sub-sessions and plugin-fetching APIs are free for all	
    49 	CScsServer::EBaseSubSession | EOpenComponentsView, // Software Type management APIs are only allowed for SWI 
    48 	CScsServer::EBaseSubSession | EOpenComponentsView, // Software Type management APIs are only allowed for SWI 
    50 	CScsServer::EBaseSubSession | EOpenFileList, // Component filter sub-sessions require ReadUserData	
    49 	CScsServer::EBaseSubSession | EOpenFileList, // Component filter sub-sessions require ReadUserData	
    51 	CScsServer::EBaseMustAllow // File filter sub-session are free for all, the rest of the range is reserved for SCS, and must be allowed( EBaseMustAllow to KMaxTInt inclusive)
    50 	CScsServer::EBaseSubSession | EOpenApplicationRegistrationInfoView, // Always pass
       
    51 	CScsServer::EBaseMustAllow // Application Registration view to be only allowed by apparc, the rest of the range is reserved for SCS, and must be allowed( EBaseMustAllow to KMaxTInt inclusive)	
    52 	};
    52 	};
    53 
    53 
    54 static const TUint8 scrElementsIndex[scrRangeCount] =
    54 static const TUint8 scrElementsIndex[scrRangeCount] =
    55 	{
    55 	{
    56 	CPolicyServer::ENotSupported, // Range 0 is not supported.
    56 	CPolicyServer::ENotSupported, // Range 0 is not supported.
    57 	CPolicyServer::ECustomCheck,
    57 	CPolicyServer::ECustomCheck,
    58 	CPolicyServer::EAlwaysPass,
    58 	CPolicyServer::EAlwaysPass,
    59 	0, // Require ReadUserData
    59 	0, // Require ReadUserData
       
    60 	2, // Only Apparc process can invoke	
    60 	CPolicyServer::EAlwaysPass,
    61 	CPolicyServer::EAlwaysPass,
    61 	CPolicyServer::ECustomCheck,
    62 	CPolicyServer::ECustomCheck,
    62 	CPolicyServer::EAlwaysPass,
    63 	CPolicyServer::EAlwaysPass,	
    63 	1, // Only SWI process can invoke
    64 	1, // Only SWI process can invoke	
    64 	0, // Require ReadUserData
    65 	0, // Require ReadUserData
    65 	CPolicyServer::EAlwaysPass,
    66 	CPolicyServer::EAlwaysPass,
       
    67 	2, // Only Apparc process can invoke
    66 	CPolicyServer::EAlwaysPass 
    68 	CPolicyServer::EAlwaysPass 
    67 	};							
    69 	};							
    68 
    70 
    69 static const CPolicyServer::TPolicyElement scrElements[] =
    71 static const CPolicyServer::TPolicyElement scrElements[] =
    70 	{
    72 	{
    71 	{_INIT_SECURITY_POLICY_C1(ECapabilityReadUserData), CPolicyServer::EFailClient},
    73 	{_INIT_SECURITY_POLICY_C1(ECapabilityReadUserData), CPolicyServer::EFailClient},
    72 	{_INIT_SECURITY_POLICY_S0(KSisRegistryServerSid.iId), CPolicyServer::EFailClient}
    74 	{_INIT_SECURITY_POLICY_S0(KSisRegistryServerSid.iId), CPolicyServer::EFailClient},
       
    75 	{_INIT_SECURITY_POLICY_S0(KApparcServerSid.iId), CPolicyServer::EFailClient}	
    73 	};
    76 	};
    74 
    77 
    75 static const CPolicyServer::TPolicy scrPolicy =
    78 static const CPolicyServer::TPolicy scrPolicy =
    76 	{
    79 	{
    77 	CPolicyServer::EAlwaysPass, // Allow all connections
    80 	CPolicyServer::EAlwaysPass, // Allow all connections
   185 	{
   188 	{
   186 	DEBUG_PRINTF(_L8("SCR session creation!"));
   189 	DEBUG_PRINTF(_L8("SCR session creation!"));
   187 	return CScrSession::NewL(*this, aMessage);
   190 	return CScrSession::NewL(*this, aMessage);
   188 	}
   191 	}
   189 
   192 
   190 CPolicyServer::TCustomResult CScrServer::CheckComponentIdMatchingEnvironmentL(const RMessage2& aMsg)
   193 CPolicyServer::TCustomResult CScrServer::CheckComponentIdMatchingEnvironmentL(const RMessage2& aMsg, TBool aCheckForSingleApp)
   191 	{	
   194 	{	
   192 	TComponentId componentId = CScrRequestImpl::GetComponentIdFromMsgL(aMsg); 
   195 	TComponentId componentId = 0;
       
   196 	if(aCheckForSingleApp)
       
   197 	    {
       
   198         // Get the application uid from RMessage2
       
   199         TInt applicationUid = aMsg.Int0();        
       
   200         // Get the component id for the application            
       
   201         if(!iRequestImpl->GetComponentIdForAppInternalL(TUid::Uid(applicationUid), componentId))
       
   202             return EFail;
       
   203 	    }
       
   204 	else
       
   205 	    {
       
   206 	    componentId = CScrRequestImpl::GetComponentIdFromMsgL(aMsg);
       
   207 	    }
       
   208 	
   193 	TSecureId clientSid = aMsg.SecureId();
   209 	TSecureId clientSid = aMsg.SecureId();
   194 	
   210 
   195 	TSecureId installerSid (0);
   211     if (componentId == 0)
   196 	if(iRequestImpl->GetInstallerSidForComponentL(componentId, installerSid))
   212         {
   197 		{
   213         if (clientSid == KSisRegistryServerSid)
   198 		if (clientSid == installerSid)
   214             return EPass;
   199 			return EPass;
   215         }   
   200 		}
   216     
   201 	
   217     TBool vaildSid = EFalse;
   202 	// Minor optimisation - in most legal cases, the installer is the one which should be doing operations,
   218 	RArray<TSecureId> installerSids;
   203 	// so we check it first to reduce the second query
   219 	CleanupClosePushL(installerSids);
   204 	TSecureId executionEnvironmentSid (0);
   220 	if (iRequestImpl->GetInstallerOrExecutionEnvSidsForComponentL(componentId, installerSids))
   205 	if(iRequestImpl->GetExecutionEnvSidForComponentL(componentId, executionEnvironmentSid))	
   221 	    {
   206 		{
   222         TInt count = installerSids.Count();
   207 		if (clientSid == executionEnvironmentSid)
   223         for (TInt i = 0; i < count; i++)
   208 			return EPass;
   224             {
   209 		}
   225             if (clientSid == installerSids[i])
       
   226                 {
       
   227                 vaildSid = ETrue;
       
   228                 break;
       
   229                 }
       
   230             }
       
   231 	    }
       
   232 	CleanupStack::PopAndDestroy(&installerSids);
       
   233 	
       
   234 	if (vaildSid)
       
   235 		return EPass;
   210 			
   236 			
   211 	DEBUG_PRINTF5(_L("Neither installer nor execution environment matched the client while checking for component-matching environment. Installer SID %d, execution environment SID %d, client SID %d, component ID %d"), 
   237 	DEBUG_PRINTF3(_L("Neither installer nor execution environment matched the client while checking for component-matching environment. Client SID %d, Component ID %d"), 
   212 			TUint32(installerSid), TUint32(executionEnvironmentSid), TUint32(clientSid), componentId);
   238 			TUint32(clientSid), componentId);
   213 	return EFail;
   239 	return EFail;
   214 	}
   240 	}
   215 	
   241 	
   216 CPolicyServer::TCustomResult CScrServer::CheckDeleteComponentAllowedL(const RMessage2& aMsg)	
   242 CPolicyServer::TCustomResult CScrServer::CheckDeleteComponentAllowedL(const RMessage2& aMsg)	
   217 	{
   243 	{
   233 	}
   259 	}
   234 
   260 
   235 CPolicyServer::TCustomResult CScrServer::CheckSoftwareNameMatchingEnvironmentL(const RMessage2& aMsg)
   261 CPolicyServer::TCustomResult CScrServer::CheckSoftwareNameMatchingEnvironmentL(const RMessage2& aMsg)
   236 	{
   262 	{
   237 	HBufC* softwareTypeName = CScrRequestImpl::GetSoftwareTypeNameFromMsgLC(aMsg);
   263 	HBufC* softwareTypeName = CScrRequestImpl::GetSoftwareTypeNameFromMsgLC(aMsg);
   238 	
       
   239 	TSecureId installerSid, executionEnvSid;	
       
   240 	if(!iRequestImpl->GetSidsForSoftwareTypeL(softwareTypeName, installerSid, executionEnvSid))
       
   241 		{
       
   242 		DEBUG_PRINTF2(_L("SID couldn't be found for software type (%S)!"), softwareTypeName);
       
   243 		CleanupStack::PopAndDestroy(softwareTypeName);
       
   244 		return EFail;
       
   245 		}
       
   246 	CleanupStack::PopAndDestroy(softwareTypeName);
       
   247 	
       
   248 	TSecureId clientSid = aMsg.SecureId();
   264 	TSecureId clientSid = aMsg.SecureId();
   249 	if (clientSid == installerSid || clientSid == executionEnvSid)
   265 	
       
   266 	TBool vaildSid = EFalse;
       
   267     RArray<TSecureId> installerSids;
       
   268     CleanupClosePushL(installerSids);
       
   269     if (iRequestImpl->GetSidsForSoftwareTypeL(softwareTypeName, installerSids))
       
   270         {
       
   271         TInt count = installerSids.Count();
       
   272         for (TInt i = 0; i < count; i++)
       
   273             {
       
   274             if (clientSid == installerSids[i])
       
   275                 {
       
   276                 vaildSid = ETrue;
       
   277                 break;
       
   278                 }
       
   279             }
       
   280         }
       
   281     CleanupStack::PopAndDestroy(2, softwareTypeName);
       
   282 	
       
   283 	if (vaildSid)	
   250 		return EPass;	
   284 		return EPass;	
   251 
   285 
   252 	DEBUG_PRINTF4(_L("Neither installer nor execution environment matched the client while checking for component-matching environment. Installer SID %d, execution environment SID %d, client SID %d"), 
   286 	DEBUG_PRINTF(_L("Client Sid is not a valid one software type!"));	
   253 			TUint32(installerSid), TUint32(executionEnvSid), TUint32(clientSid));	
       
   254 	return EFail;
   287 	return EFail;
   255 	}
   288 	}
   256 
   289 
   257 CPolicyServer::TCustomResult CScrServer::CheckAllowedFilePathL(const RMessage2& aMsg)
   290 CPolicyServer::TCustomResult CScrServer::CheckAllowedFilePathL(const RMessage2& aMsg)
   258 	{
   291 	{
   335 		case ESetIsComponentDrmProtected:
   368 		case ESetIsComponentDrmProtected:
   336 		case ESetIsComponentHidden:
   369 		case ESetIsComponentHidden:
   337 		case ESetIsComponentKnownRevoked:
   370 		case ESetIsComponentKnownRevoked:
   338 		case ESetIsComponentOriginVerified:		
   371 		case ESetIsComponentOriginVerified:		
   339 			return CheckCommonComponentPropertySettableL(aMsg, ECapabilityWriteDeviceData);
   372 			return CheckCommonComponentPropertySettableL(aMsg, ECapabilityWriteDeviceData);
       
   373 		case EAddApplicationEntry:
       
   374 		case EDeleteApplicationEntries:
       
   375 			return CheckComponentIdMatchingEnvironmentL(aMsg);
       
   376 		case EDeleteApplicationEntry:
       
   377 		    return CheckComponentIdMatchingEnvironmentL(aMsg, ETrue);
   340 		default:
   378 		default:
   341 			DEBUG_PRINTF2(_L("Unknown function was invoked in CustomSecurityCheck - %d"), functionId);							
   379 			DEBUG_PRINTF2(_L("Unknown function was invoked in CustomSecurityCheck - %d"), functionId);							
   342 			__ASSERT_DEBUG(0, User::Invariant());
   380 			__ASSERT_DEBUG(0, User::Invariant());
   343 			return EFail;
   381 			return EFail;
   344 		}
   382 		}