os/kernelhwsrv/kerneltest/e32test/secure/t_capsup.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\secure\t_capsup.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test support of platform security capabilities.
sl@0
    17
// API Information:
sl@0
    18
// TCapabilitySet, TSecurityInfo, TSecurityPolicy and various other methods.
sl@0
    19
// Details:
sl@0
    20
// - Verify the enumeration of each of the capability names.
sl@0
    21
// - Test the TCapabilitySet class methods by setting and checking various
sl@0
    22
// capabilities. Verify results are as expected.
sl@0
    23
// - Test the TSecurityInfo class methods and verify results.
sl@0
    24
// - Test the RProcess, RThread and RMessage2 SecureId() methods along with
sl@0
    25
// User::CreatorSecureId(). Verify results are as expected.
sl@0
    26
// - Test the RProcess, RThread and RMessage2 VendorId() methods along with
sl@0
    27
// User::CreatorVendorId(). Verify results are as expected.
sl@0
    28
// - Test the RProcess, RThread and RMessage2 HasCapability() methods along
sl@0
    29
// with User::CreatorHasCapability(). Verify results are as expected.
sl@0
    30
// - Test TSecurityPolicy constructors including macros for compile-time
sl@0
    31
// construction. Verify results are as expected.
sl@0
    32
// - Test kernel APIs.  Verify results are as expected.
sl@0
    33
// - Test setting KernelConfigFlags.  Ensure that, if __PLATSEC_UNLOCKED__
sl@0
    34
// is not set, the PlatSec flags cannot be unset.
sl@0
    35
// - Test the use of platform security diagnostic strings.
sl@0
    36
// Platforms/Drives/Compatibility:
sl@0
    37
// All.
sl@0
    38
// Assumptions/Requirement/Pre-requisites:
sl@0
    39
// Failures and causes:
sl@0
    40
// Base Port information:
sl@0
    41
// 
sl@0
    42
//
sl@0
    43
sl@0
    44
#define __INCLUDE_CAPABILITY_NAMES__
sl@0
    45
#define __E32TEST_EXTENSION__
sl@0
    46
sl@0
    47
#include <e32cmn.h>
sl@0
    48
#include <e32cmn_private.h>
sl@0
    49
#include <u32exec.h>
sl@0
    50
#include <e32test.h>
sl@0
    51
#include <e32def.h>
sl@0
    52
#include <e32def_private.h>
sl@0
    53
#include "d_sldd.h"
sl@0
    54
sl@0
    55
TBool PlatSecEnforcement;
sl@0
    56
sl@0
    57
_LIT_SECURE_ID(KTestSecureId,0x101f534d);
sl@0
    58
_LIT_SECURE_ID(KTestSecureId2,0x101f534e);
sl@0
    59
_LIT_VENDOR_ID(KTestVendorId,0x01234567);
sl@0
    60
_LIT_VENDOR_ID(KTestVendorId2,0x01234568);
sl@0
    61
sl@0
    62
const TUint32 KTestCapabilities =(1<<ECapabilityTCB)
sl@0
    63
								|(1<<ECapabilityPowerMgmt)
sl@0
    64
								|(1<<ECapabilityReadDeviceData)
sl@0
    65
								|(1<<ECapabilityDRM)
sl@0
    66
								|(1<<ECapabilityProtServ)
sl@0
    67
								|(1<<ECapabilityNetworkControl)
sl@0
    68
								|(1<<ECapabilitySwEvent)
sl@0
    69
								|(1<<ECapabilityLocalServices)
sl@0
    70
								|(1<<ECapabilityWriteUserData)
sl@0
    71
								|(1<<ECapabilitySurroundingsDD);
sl@0
    72
sl@0
    73
LOCAL_D RTest test(_L("T_CAPSUP"));
sl@0
    74
sl@0
    75
enum TTestProcessFunctions
sl@0
    76
	{
sl@0
    77
	ETestProcessServer,
sl@0
    78
	};
sl@0
    79
sl@0
    80
#include "testprocess.h"
sl@0
    81
sl@0
    82
TInt StartServer();
sl@0
    83
sl@0
    84
TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
sl@0
    85
	{
sl@0
    86
	(void)aArg1;
sl@0
    87
	(void)aArg2;
sl@0
    88
sl@0
    89
	switch(aTestNum)
sl@0
    90
		{
sl@0
    91
sl@0
    92
	case ETestProcessServer:
sl@0
    93
		return StartServer();
sl@0
    94
sl@0
    95
	default:
sl@0
    96
		User::Panic(_L("T_CAPSUP"),1);
sl@0
    97
		}
sl@0
    98
sl@0
    99
	return KErrNone;
sl@0
   100
	}
sl@0
   101
sl@0
   102
sl@0
   103
sl@0
   104
//
sl@0
   105
// RTestThread
sl@0
   106
//
sl@0
   107
sl@0
   108
class RTestThread : public RThread
sl@0
   109
	{
sl@0
   110
public:
sl@0
   111
	void Create(TThreadFunction aFunction,TAny* aArg=0);
sl@0
   112
	};
sl@0
   113
sl@0
   114
void RTestThread::Create(TThreadFunction aFunction,TAny* aArg)
sl@0
   115
	{
sl@0
   116
	TInt r=RThread::Create(_L(""),aFunction,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,aArg);
sl@0
   117
	test(r==KErrNone);
sl@0
   118
	}
sl@0
   119
sl@0
   120
sl@0
   121
//
sl@0
   122
// CTestSession
sl@0
   123
//
sl@0
   124
sl@0
   125
class CTestSession : public CSession2
sl@0
   126
	{
sl@0
   127
public:
sl@0
   128
	enum {EShutdown,
sl@0
   129
		ETestProcessSecurityInfo,ETestThreadSecurityInfo,ETestMessageSecurityInfo,ETestCreatorSecurityInfo,
sl@0
   130
		ETestProcessSecureId,ETestThreadSecureId,ETestMessageSecureId,ETestCreatorSecureId,
sl@0
   131
		ETestProcessVendorId,ETestThreadVendorId,ETestMessageVendorId,ETestCreatorVendorId,
sl@0
   132
		ETestProcessHasCapability1,ETestProcessHasCapability2,
sl@0
   133
		ETestThreadHasCapability1,ETestThreadHasCapability2,
sl@0
   134
		ETestMessageHasCapability1,ETestMessageHasCapability2,
sl@0
   135
		ETestMessageHasCapabilityL1,ETestMessageHasCapabilityL2,
sl@0
   136
		ETestCreatorHasCapability1,ETestCreatorHasCapability2,
sl@0
   137
		ETestSecurityPolicyAgainstMessage,
sl@0
   138
		ETestSecurityPolicyAgainstCreator
sl@0
   139
		};
sl@0
   140
	enum {EPolicyCheckPassed = 15, EPolicyCheckFailed = 16};
sl@0
   141
public:
sl@0
   142
	CTestSession();
sl@0
   143
	virtual void ServiceL(const RMessage2& aMessage);
sl@0
   144
public:
sl@0
   145
	};
sl@0
   146
sl@0
   147
CTestSession::CTestSession()
sl@0
   148
	: CSession2()
sl@0
   149
	{}
sl@0
   150
sl@0
   151
void CTestSession::ServiceL(const RMessage2& aMessage)
sl@0
   152
	{
sl@0
   153
	const RMessagePtr2 m(aMessage);
sl@0
   154
	switch (aMessage.Function())
sl@0
   155
		{
sl@0
   156
		case CTestSession::ETestProcessSecureId:
sl@0
   157
			{
sl@0
   158
			RProcess process;
sl@0
   159
			TInt r=process.Open(aMessage.Int0());
sl@0
   160
			if(r==KErrNone)
sl@0
   161
				{
sl@0
   162
				r = process.SecureId();
sl@0
   163
				process.Close();
sl@0
   164
				}
sl@0
   165
			else
sl@0
   166
				r = KErrGeneral;
sl@0
   167
			m.Complete(r);
sl@0
   168
			}
sl@0
   169
			break;
sl@0
   170
sl@0
   171
		case CTestSession::ETestThreadSecureId:
sl@0
   172
			{
sl@0
   173
			RThread thread;
sl@0
   174
			TInt r=thread.Open(aMessage.Int0());
sl@0
   175
			if(r==KErrNone)
sl@0
   176
				{
sl@0
   177
				r = thread.SecureId();
sl@0
   178
				thread.Close();
sl@0
   179
				}
sl@0
   180
			else
sl@0
   181
				r = KErrGeneral;
sl@0
   182
			m.Complete(r);
sl@0
   183
			}
sl@0
   184
			break;
sl@0
   185
sl@0
   186
		case CTestSession::ETestMessageSecureId:
sl@0
   187
			{
sl@0
   188
			TInt32 id = m.SecureId();
sl@0
   189
			m.Complete(id);
sl@0
   190
			}
sl@0
   191
			break;
sl@0
   192
sl@0
   193
		case CTestSession::ETestCreatorSecureId:
sl@0
   194
			{
sl@0
   195
			m.Complete(User::CreatorSecureId());
sl@0
   196
			}
sl@0
   197
			break;
sl@0
   198
sl@0
   199
		case CTestSession::ETestProcessVendorId:
sl@0
   200
			{
sl@0
   201
			RProcess process;
sl@0
   202
			TInt r=process.Open(aMessage.Int0());
sl@0
   203
			if(r==KErrNone)
sl@0
   204
				{
sl@0
   205
				r = process.VendorId();
sl@0
   206
				process.Close();
sl@0
   207
				}
sl@0
   208
			else
sl@0
   209
				r = KErrGeneral;
sl@0
   210
			m.Complete(r);
sl@0
   211
			}
sl@0
   212
			break;
sl@0
   213
sl@0
   214
		case CTestSession::ETestThreadVendorId:
sl@0
   215
			{
sl@0
   216
			RThread thread;
sl@0
   217
			TInt r=thread.Open(aMessage.Int0());
sl@0
   218
			if(r==KErrNone)
sl@0
   219
				{
sl@0
   220
				r = thread.VendorId();
sl@0
   221
				thread.Close();
sl@0
   222
				}
sl@0
   223
			else
sl@0
   224
				r = KErrGeneral;
sl@0
   225
			m.Complete(r);
sl@0
   226
			}
sl@0
   227
			break;
sl@0
   228
sl@0
   229
		case CTestSession::ETestMessageVendorId:
sl@0
   230
			{
sl@0
   231
			TInt32 id = m.VendorId();
sl@0
   232
			m.Complete(id);
sl@0
   233
			}
sl@0
   234
			break;
sl@0
   235
sl@0
   236
		case CTestSession::ETestCreatorVendorId:
sl@0
   237
			{
sl@0
   238
			m.Complete(User::CreatorVendorId());
sl@0
   239
			}
sl@0
   240
			break;
sl@0
   241
sl@0
   242
		case CTestSession::ETestProcessSecurityInfo:
sl@0
   243
			{
sl@0
   244
			RProcess process;
sl@0
   245
			TInt r=process.Open(aMessage.Int0());
sl@0
   246
			if(r==KErrNone)
sl@0
   247
				{
sl@0
   248
				TSecurityInfo info;
sl@0
   249
				info.Set(process);
sl@0
   250
				r = m.Write(1,TPtrC8((TUint8*)&info,sizeof(info)));
sl@0
   251
				process.Close();
sl@0
   252
				}
sl@0
   253
			else
sl@0
   254
				r = KErrGeneral;
sl@0
   255
			m.Complete(r);
sl@0
   256
			}
sl@0
   257
			break;
sl@0
   258
sl@0
   259
		case CTestSession::ETestThreadSecurityInfo:
sl@0
   260
			{
sl@0
   261
			RThread thread;
sl@0
   262
			TInt r=thread.Open(aMessage.Int0());
sl@0
   263
			if(r==KErrNone)
sl@0
   264
				{
sl@0
   265
				TSecurityInfo info;
sl@0
   266
				info.Set(thread);
sl@0
   267
				r = m.Write(1,TPtrC8((TUint8*)&info,sizeof(info)));
sl@0
   268
				thread.Close();
sl@0
   269
				}
sl@0
   270
			else
sl@0
   271
				r = KErrGeneral;
sl@0
   272
			m.Complete(r);
sl@0
   273
			}
sl@0
   274
			break;
sl@0
   275
sl@0
   276
		case CTestSession::ETestMessageSecurityInfo:
sl@0
   277
			{
sl@0
   278
			TSecurityInfo info;
sl@0
   279
			info.Set(m);
sl@0
   280
			TInt r = m.Write(0,TPtrC8((TUint8*)&info,sizeof(info)));
sl@0
   281
			m.Complete(r);
sl@0
   282
			}
sl@0
   283
			break;
sl@0
   284
sl@0
   285
		case CTestSession::ETestCreatorSecurityInfo:
sl@0
   286
			{
sl@0
   287
			TSecurityInfo info;
sl@0
   288
			info.SetToCreatorInfo();
sl@0
   289
			TInt r = m.Write(0,TPtrC8((TUint8*)&info,sizeof(info)));
sl@0
   290
			m.Complete(r);
sl@0
   291
			}
sl@0
   292
			break;
sl@0
   293
sl@0
   294
		case CTestSession::ETestProcessHasCapability1:
sl@0
   295
			{
sl@0
   296
			RProcess process;
sl@0
   297
			TInt r=process.Open(aMessage.Int0());
sl@0
   298
			if(r==KErrNone)
sl@0
   299
				{
sl@0
   300
				r = process.HasCapability((TCapability)aMessage.Int1(),__PLATSEC_DIAGNOSTIC_STRING("ETestProcessHasCapability1"));
sl@0
   301
				process.Close();
sl@0
   302
				}
sl@0
   303
			else
sl@0
   304
				r = KErrGeneral;
sl@0
   305
			m.Complete(r);
sl@0
   306
			}
sl@0
   307
			break;
sl@0
   308
sl@0
   309
		case CTestSession::ETestProcessHasCapability2:
sl@0
   310
			{
sl@0
   311
			RProcess process;
sl@0
   312
			TInt r=process.Open(aMessage.Int0());
sl@0
   313
			if(r==KErrNone)
sl@0
   314
				{
sl@0
   315
				r = process.HasCapability((TCapability)aMessage.Int1(),(TCapability)aMessage.Int2(),__PLATSEC_DIAGNOSTIC_STRING("ETestProcessHasCapability2"));
sl@0
   316
				process.Close();
sl@0
   317
				}
sl@0
   318
			else
sl@0
   319
				r = KErrGeneral;
sl@0
   320
			m.Complete(r);
sl@0
   321
			}
sl@0
   322
			break;
sl@0
   323
sl@0
   324
		case CTestSession::ETestThreadHasCapability1:
sl@0
   325
			{
sl@0
   326
			RThread thread;
sl@0
   327
			TInt r=thread.Open(aMessage.Int0());
sl@0
   328
			if(r==KErrNone)
sl@0
   329
				{
sl@0
   330
				r = thread.HasCapability((TCapability)aMessage.Int1(),__PLATSEC_DIAGNOSTIC_STRING("ETestThreadHasCapability1"));
sl@0
   331
				thread.Close();
sl@0
   332
				}
sl@0
   333
			else
sl@0
   334
				r = KErrGeneral;
sl@0
   335
			m.Complete(r);
sl@0
   336
			}
sl@0
   337
			break;
sl@0
   338
sl@0
   339
		case CTestSession::ETestThreadHasCapability2:
sl@0
   340
			{
sl@0
   341
			RThread thread;
sl@0
   342
			TInt r=thread.Open(aMessage.Int0());
sl@0
   343
			if(r==KErrNone)
sl@0
   344
				{
sl@0
   345
				r = thread.HasCapability((TCapability)aMessage.Int1(),(TCapability)aMessage.Int2(),__PLATSEC_DIAGNOSTIC_STRING("ETestThreadHasCapability2"));
sl@0
   346
				thread.Close();
sl@0
   347
				}
sl@0
   348
			else
sl@0
   349
				r = KErrGeneral;
sl@0
   350
			m.Complete(r);
sl@0
   351
			}
sl@0
   352
			break;
sl@0
   353
sl@0
   354
		case CTestSession::ETestMessageHasCapability1:
sl@0
   355
			{
sl@0
   356
			TInt r = m.HasCapability((TCapability)aMessage.Int0(),__PLATSEC_DIAGNOSTIC_STRING("ETestMessageHasCapability1"));
sl@0
   357
			m.Complete(r);
sl@0
   358
			}
sl@0
   359
			break;
sl@0
   360
sl@0
   361
		case CTestSession::ETestMessageHasCapabilityL1:
sl@0
   362
			{
sl@0
   363
			TRAPD(r,m.HasCapabilityL((TCapability)aMessage.Int0(),__PLATSEC_DIAGNOSTIC_STRING("ETestMessageHasCapabilityL1")))
sl@0
   364
			m.Complete(r);
sl@0
   365
			}
sl@0
   366
			break;
sl@0
   367
sl@0
   368
		case CTestSession::ETestMessageHasCapability2:
sl@0
   369
			{
sl@0
   370
			TInt r = m.HasCapability((TCapability)aMessage.Int0(),(TCapability)aMessage.Int1(),__PLATSEC_DIAGNOSTIC_STRING("ETestMessageHasCapability2"));
sl@0
   371
			m.Complete(r);
sl@0
   372
			}
sl@0
   373
			break;
sl@0
   374
sl@0
   375
		case CTestSession::ETestMessageHasCapabilityL2:
sl@0
   376
			{
sl@0
   377
			TRAPD(r,m.HasCapabilityL((TCapability)aMessage.Int0(),(TCapability)aMessage.Int1(),__PLATSEC_DIAGNOSTIC_STRING("ETestMessageHasCapabilityL2")))
sl@0
   378
			m.Complete(r);
sl@0
   379
			}
sl@0
   380
			break;
sl@0
   381
sl@0
   382
		case CTestSession::ETestCreatorHasCapability1:
sl@0
   383
			{
sl@0
   384
			TInt r = User::CreatorHasCapability((TCapability)aMessage.Int0(),__PLATSEC_DIAGNOSTIC_STRING("ETestCreatorHasCapability1"));
sl@0
   385
			m.Complete(r);
sl@0
   386
			}
sl@0
   387
			break;
sl@0
   388
sl@0
   389
		case CTestSession::ETestCreatorHasCapability2:
sl@0
   390
			{
sl@0
   391
			TInt r = User::CreatorHasCapability((TCapability)aMessage.Int0(),(TCapability)aMessage.Int1(),__PLATSEC_DIAGNOSTIC_STRING("ETestCreatorHasCapability2"));
sl@0
   392
			m.Complete(r);
sl@0
   393
			}
sl@0
   394
			break;
sl@0
   395
sl@0
   396
		case CTestSession::ETestSecurityPolicyAgainstMessage:
sl@0
   397
			{
sl@0
   398
			TBuf8<sizeof(TSecurityPolicy)> buf(0);
sl@0
   399
			TInt len = m.GetDesLength(0);
sl@0
   400
			TInt r = KErrArgument;
sl@0
   401
			if(len>0 && len <=buf.MaxSize())
sl@0
   402
				{
sl@0
   403
				r = m.Read(0, buf, 0);
sl@0
   404
				if(r==KErrNone)
sl@0
   405
					{
sl@0
   406
					TSecurityPolicy policy;
sl@0
   407
					r = policy.Set(buf);
sl@0
   408
					if(r == KErrNone)
sl@0
   409
						{
sl@0
   410
						r = policy.CheckPolicy(m, __PLATSEC_DIAGNOSTIC_STRING("Testing message against policy -- sample additional diagnostic."));
sl@0
   411
						if(r)
sl@0
   412
							r = EPolicyCheckPassed;
sl@0
   413
						else
sl@0
   414
							r = EPolicyCheckFailed;
sl@0
   415
						}
sl@0
   416
					}
sl@0
   417
				}
sl@0
   418
			m.Complete(r);
sl@0
   419
			break;
sl@0
   420
			}
sl@0
   421
sl@0
   422
		case CTestSession::ETestSecurityPolicyAgainstCreator:
sl@0
   423
			{
sl@0
   424
			TBuf8<sizeof(TSecurityPolicy)> buf(0);
sl@0
   425
			TInt len = m.GetDesLength(0);
sl@0
   426
			TInt r = KErrArgument;
sl@0
   427
			if(len>0 && len <=buf.MaxSize())
sl@0
   428
				{
sl@0
   429
				r = m.Read(0, buf, 0);
sl@0
   430
				if(r==KErrNone)
sl@0
   431
					{
sl@0
   432
					TSecurityPolicy policy;
sl@0
   433
					r = policy.Set(buf);
sl@0
   434
					if(r == KErrNone)
sl@0
   435
						{
sl@0
   436
						r = policy.CheckPolicyCreator(__PLATSEC_DIAGNOSTIC_STRING("Testing creator against policy -- sample additional diagnostic."));
sl@0
   437
						if(r)
sl@0
   438
							r = EPolicyCheckPassed;
sl@0
   439
						else
sl@0
   440
							r = EPolicyCheckFailed;
sl@0
   441
						}
sl@0
   442
					}
sl@0
   443
				}
sl@0
   444
			m.Complete(r);
sl@0
   445
			break;
sl@0
   446
			}
sl@0
   447
sl@0
   448
		case CTestSession::EShutdown:
sl@0
   449
			CActiveScheduler::Stop();
sl@0
   450
			break;
sl@0
   451
sl@0
   452
		default:
sl@0
   453
			m.Complete(KErrNotSupported);
sl@0
   454
			break;
sl@0
   455
		}
sl@0
   456
	}
sl@0
   457
sl@0
   458
sl@0
   459
sl@0
   460
//
sl@0
   461
// CTestServer
sl@0
   462
//
sl@0
   463
sl@0
   464
class CTestServer : public CServer2
sl@0
   465
	{
sl@0
   466
public:
sl@0
   467
	CTestServer(TInt aPriority);
sl@0
   468
	virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
sl@0
   469
	};
sl@0
   470
sl@0
   471
CTestServer::CTestServer(TInt aPriority)
sl@0
   472
	: CServer2(aPriority)
sl@0
   473
	{
sl@0
   474
	}
sl@0
   475
sl@0
   476
CSession2* CTestServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const
sl@0
   477
	{
sl@0
   478
	return new (ELeave) CTestSession();
sl@0
   479
	}
sl@0
   480
sl@0
   481
sl@0
   482
sl@0
   483
//
sl@0
   484
// CTestActiveScheduler
sl@0
   485
//
sl@0
   486
sl@0
   487
class CTestActiveScheduler : public CActiveScheduler
sl@0
   488
	{
sl@0
   489
public:
sl@0
   490
	virtual void Error(TInt anError) const;
sl@0
   491
	};
sl@0
   492
sl@0
   493
void CTestActiveScheduler::Error(TInt anError) const
sl@0
   494
	{
sl@0
   495
	User::Panic(_L("TestServer Error"),anError);
sl@0
   496
	}
sl@0
   497
sl@0
   498
sl@0
   499
sl@0
   500
//
sl@0
   501
// Server thread
sl@0
   502
//
sl@0
   503
sl@0
   504
_LIT(KServerName,"T_CAPSUP-server");
sl@0
   505
const TInt KServerRendezvous = KRequestPending+1;
sl@0
   506
sl@0
   507
void DoStartServer()
sl@0
   508
	{
sl@0
   509
	CTestActiveScheduler* activeScheduler = new (ELeave) CTestActiveScheduler;
sl@0
   510
	CActiveScheduler::Install(activeScheduler);
sl@0
   511
	CleanupStack::PushL(activeScheduler);
sl@0
   512
sl@0
   513
	CTestServer* server = new (ELeave) CTestServer(0);
sl@0
   514
	CleanupStack::PushL(server);
sl@0
   515
sl@0
   516
	User::LeaveIfError(server->Start(KServerName));
sl@0
   517
sl@0
   518
	RProcess::Rendezvous(KServerRendezvous);
sl@0
   519
sl@0
   520
	CActiveScheduler::Start();
sl@0
   521
sl@0
   522
	CleanupStack::PopAndDestroy(2);
sl@0
   523
	}
sl@0
   524
sl@0
   525
TInt StartServer()
sl@0
   526
	{
sl@0
   527
	CTrapCleanup* cleanupStack = CTrapCleanup::New();
sl@0
   528
	if(!cleanupStack)
sl@0
   529
		return KErrNoMemory;
sl@0
   530
	TRAPD(leaveError,DoStartServer())
sl@0
   531
	delete cleanupStack;
sl@0
   532
	return leaveError;
sl@0
   533
	}
sl@0
   534
sl@0
   535
sl@0
   536
sl@0
   537
//
sl@0
   538
// RTestSession
sl@0
   539
//
sl@0
   540
sl@0
   541
class RTestSession : public RSessionBase
sl@0
   542
	{
sl@0
   543
public:
sl@0
   544
	inline TInt Connect()
sl@0
   545
		{ return CreateSession(KServerName,TVersion());}
sl@0
   546
	inline TInt Send(TInt aFunction)
sl@0
   547
		{ return RSessionBase::SendReceive(aFunction); }
sl@0
   548
	inline TInt Send(TInt aFunction,const TIpcArgs& aArgs)
sl@0
   549
		{ return RSessionBase::SendReceive(aFunction,aArgs); }
sl@0
   550
	inline void Send(TInt aFunction,TRequestStatus& aStatus)
sl@0
   551
		{ RSessionBase::SendReceive(aFunction,aStatus); }
sl@0
   552
	inline void Send(TInt aFunction,const TIpcArgs& aArgs,TRequestStatus& aStatus)
sl@0
   553
		{ RSessionBase::SendReceive(aFunction,aArgs,aStatus); }
sl@0
   554
	};
sl@0
   555
sl@0
   556
sl@0
   557
sl@0
   558
RTestSession Session;
sl@0
   559
sl@0
   560
void CheckCapabilitySetEqual(const TCapabilitySet& a1,const TCapabilitySet& a2)
sl@0
   561
	{
sl@0
   562
	TInt i;
sl@0
   563
	for(i=0; i<ECapability_Limit; i++)
sl@0
   564
		test((!a1.HasCapability((TCapability)i))==(!a2.HasCapability((TCapability)i)));
sl@0
   565
	}
sl@0
   566
sl@0
   567
void TestCapabilitySet()
sl@0
   568
	{
sl@0
   569
	TCapabilitySet s;
sl@0
   570
	TCapabilitySet all;
sl@0
   571
	TCapabilitySet empty;
sl@0
   572
	TInt i,j,k;
sl@0
   573
sl@0
   574
	test.Start(_L("Each test stage also implicity tests HasCapability()"));
sl@0
   575
sl@0
   576
	test.Next(_L("Test SetEmpty()"));
sl@0
   577
	memset(&empty,-1,sizeof(empty));
sl@0
   578
	empty.SetEmpty();
sl@0
   579
	for(i=0; i<ECapability_HardLimit; i++)
sl@0
   580
		test(!empty.HasCapability((TCapability)i));
sl@0
   581
	// test memory cleared - assumes knowledge of internal representation
sl@0
   582
	for(i=0; i<(TInt)sizeof(empty); ++i)
sl@0
   583
		test(((TUint8*)&empty)[i] == 0);
sl@0
   584
sl@0
   585
	test.Next(_L("Test SetAllSupported()"));
sl@0
   586
	all.SetAllSupported();
sl@0
   587
	// This code makes the assumption that there are no gaps in the TCapability enumeration
sl@0
   588
	for(i=0; i<ECapability_Limit; i++)
sl@0
   589
		test(all.HasCapability((TCapability)i));
sl@0
   590
	for(; i<ECapability_HardLimit; i++)
sl@0
   591
		test(!all.HasCapability((TCapability)i));
sl@0
   592
sl@0
   593
	test.Next(_L("Test Set(TCapability)"));
sl@0
   594
	for(j=-2; j<ECapability_HardLimit; j++)
sl@0
   595
		{
sl@0
   596
		if(j&1)
sl@0
   597
			s.SetAllSupported();
sl@0
   598
		else
sl@0
   599
			s.SetEmpty();
sl@0
   600
		s.Set((TCapability)j);
sl@0
   601
		for(i=0; i<=ECapability_HardLimit; i++)
sl@0
   602
			{
sl@0
   603
			if(i==j)
sl@0
   604
				test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   605
			else
sl@0
   606
				test(!s.HasCapability((TCapability)i));
sl@0
   607
			
sl@0
   608
			}
sl@0
   609
		test(!s.HasCapability(ECapability_Denied));
sl@0
   610
		test(s.HasCapability(ECapability_None));
sl@0
   611
		}
sl@0
   612
sl@0
   613
	test.Next(_L("Test Set(TCapability,TCapability)"));
sl@0
   614
	for(k=-2; k<ECapability_HardLimit; k++)
sl@0
   615
		{
sl@0
   616
		for(j=-2; j<ECapability_HardLimit; j++)
sl@0
   617
			{
sl@0
   618
			if((j^k)&1)
sl@0
   619
				s.SetAllSupported();
sl@0
   620
			else
sl@0
   621
				s.SetEmpty();
sl@0
   622
			s.Set((TCapability)j,(TCapability)k);
sl@0
   623
			for(i=0; i<=ECapability_HardLimit; i++)
sl@0
   624
				{
sl@0
   625
				if(i==j || i==k)
sl@0
   626
					test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   627
				else
sl@0
   628
					test(!s.HasCapability((TCapability)i));
sl@0
   629
sl@0
   630
				}
sl@0
   631
			test(!s.HasCapability(ECapability_Denied));
sl@0
   632
			test(s.HasCapability(ECapability_None));
sl@0
   633
			}
sl@0
   634
		}
sl@0
   635
sl@0
   636
	test.Next(_L("Test TCapability(TCapability)"));
sl@0
   637
	for(j=-2; j<ECapability_HardLimit; j++)
sl@0
   638
		{
sl@0
   639
		TCapabilitySet t((TCapability)j);
sl@0
   640
		for(i=0; i<=ECapability_HardLimit; i++)
sl@0
   641
			{
sl@0
   642
			if(i==j)
sl@0
   643
				test(!t.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   644
			else
sl@0
   645
				test(!t.HasCapability((TCapability)i));
sl@0
   646
sl@0
   647
			}
sl@0
   648
		test(!s.HasCapability(ECapability_Denied));
sl@0
   649
		test(s.HasCapability(ECapability_None));
sl@0
   650
		}
sl@0
   651
sl@0
   652
	test.Next(_L("Test TCapability(TCapability,TCapability)"));
sl@0
   653
	for(k=-2; k<ECapability_HardLimit; k++)
sl@0
   654
		{
sl@0
   655
		for(j=-2; j<ECapability_HardLimit; j++)
sl@0
   656
			{
sl@0
   657
			TCapabilitySet t((TCapability)j,(TCapability)k);
sl@0
   658
			for(i=0; i<=ECapability_HardLimit; i++)
sl@0
   659
				{
sl@0
   660
				if(i==j || i==k)
sl@0
   661
					test(!t.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   662
				else
sl@0
   663
					test(!t.HasCapability((TCapability)i));
sl@0
   664
sl@0
   665
				}
sl@0
   666
			test(!s.HasCapability(ECapability_Denied));
sl@0
   667
			test(s.HasCapability(ECapability_None));
sl@0
   668
			}
sl@0
   669
		}
sl@0
   670
sl@0
   671
	test.Next(_L("Test AddCapability(TCapability)"));
sl@0
   672
	s.SetEmpty();
sl@0
   673
	for(j=-2; j<ECapability_HardLimit; j++) // Add each capability in sequence
sl@0
   674
		{
sl@0
   675
		s.AddCapability((TCapability)j);
sl@0
   676
		for(i=0; i<=j; i++)
sl@0
   677
			test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   678
		for(; i<ECapability_HardLimit; i++)
sl@0
   679
			test(!s.HasCapability((TCapability)i));
sl@0
   680
		test(!s.HasCapability(ECapability_Denied));
sl@0
   681
		test(s.HasCapability(ECapability_None));
sl@0
   682
		}
sl@0
   683
	s.SetEmpty();
sl@0
   684
	for(j=ECapability_HardLimit-1; j>=-2; j--) // Add each capability in reverse sequence
sl@0
   685
		{
sl@0
   686
		s.AddCapability((TCapability)j);
sl@0
   687
		for(i=ECapability_HardLimit-1; i>=j && i>=0; i--)
sl@0
   688
			test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   689
		for(; i>=0; i--)
sl@0
   690
			test(!s.HasCapability((TCapability)i));
sl@0
   691
		test(!s.HasCapability(ECapability_Denied));
sl@0
   692
		test(s.HasCapability(ECapability_None));
sl@0
   693
		}
sl@0
   694
sl@0
   695
	test.Next(_L("Test RemoveCapability(TCapability)"));
sl@0
   696
	s.SetAllSupported();
sl@0
   697
	for(j=-2; j<ECapability_HardLimit; j++) // Remove each capability in sequence
sl@0
   698
		{
sl@0
   699
		s.RemoveCapability((TCapability)j);
sl@0
   700
		for(i=0; i<=j; i++)
sl@0
   701
			test(!s.HasCapability((TCapability)i));
sl@0
   702
		for(; i<ECapability_HardLimit; i++)
sl@0
   703
			test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   704
		test(!s.HasCapability(ECapability_Denied));
sl@0
   705
		test(s.HasCapability(ECapability_None));
sl@0
   706
		}
sl@0
   707
	s.SetAllSupported();
sl@0
   708
	for(j=ECapability_HardLimit-1; j>=-2; j--) // Remove each capability reverse sequence
sl@0
   709
		{
sl@0
   710
		s.RemoveCapability((TCapability)j);
sl@0
   711
		for(i=ECapability_HardLimit-1; i>=j && i >=0; i--)
sl@0
   712
			test(!s.HasCapability((TCapability)i));
sl@0
   713
		for(; i>=0; i--)
sl@0
   714
			test(!s.HasCapability((TCapability)i) == !all.HasCapability((TCapability)i)); // Should have capability (if in set of All capabilities)
sl@0
   715
		test(!s.HasCapability(ECapability_Denied));
sl@0
   716
		test(s.HasCapability(ECapability_None));
sl@0
   717
		}
sl@0
   718
sl@0
   719
	test.Next(_L("Building test sets"));
sl@0
   720
	TCapabilitySet even;
sl@0
   721
	even.SetEmpty();
sl@0
   722
	for(i=0; i<ECapability_Limit; i+=2) even.AddCapability((TCapability)i);
sl@0
   723
	TCapabilitySet odd;
sl@0
   724
	odd.SetEmpty();
sl@0
   725
	for(i=1; i<ECapability_Limit; i+=2) odd.AddCapability((TCapability)i);
sl@0
   726
sl@0
   727
	test.Next(_L("Test Union(TCapabilitySet)"));
sl@0
   728
	s.SetEmpty();
sl@0
   729
	CheckCapabilitySetEqual(s,empty);
sl@0
   730
	s.Union(odd);
sl@0
   731
	CheckCapabilitySetEqual(s,odd);
sl@0
   732
	s.Union(odd);
sl@0
   733
	CheckCapabilitySetEqual(s,odd);
sl@0
   734
	s.Union(empty);
sl@0
   735
	CheckCapabilitySetEqual(s,odd);
sl@0
   736
	s.Union(even);
sl@0
   737
	CheckCapabilitySetEqual(s,all);
sl@0
   738
	s.Union(even);
sl@0
   739
	CheckCapabilitySetEqual(s,all);
sl@0
   740
	s.SetEmpty();
sl@0
   741
	CheckCapabilitySetEqual(s,empty);
sl@0
   742
	s.Union(even);
sl@0
   743
	CheckCapabilitySetEqual(s,even);
sl@0
   744
	s.Union(even);
sl@0
   745
	CheckCapabilitySetEqual(s,even);
sl@0
   746
	s.Union(empty);
sl@0
   747
	CheckCapabilitySetEqual(s,even);
sl@0
   748
	s.Union(odd);
sl@0
   749
	CheckCapabilitySetEqual(s,all);
sl@0
   750
	s.Union(odd);
sl@0
   751
	CheckCapabilitySetEqual(s,all);
sl@0
   752
sl@0
   753
	test.Next(_L("Test Intersection(TCapabilitySet)"));
sl@0
   754
	s.SetAllSupported();
sl@0
   755
	CheckCapabilitySetEqual(s,all);
sl@0
   756
	s.Intersection(odd);
sl@0
   757
	CheckCapabilitySetEqual(s,odd);
sl@0
   758
	s.Intersection(odd);
sl@0
   759
	CheckCapabilitySetEqual(s,odd);
sl@0
   760
	s.Intersection(even);
sl@0
   761
	CheckCapabilitySetEqual(s,empty);
sl@0
   762
	s.Intersection(even);
sl@0
   763
	CheckCapabilitySetEqual(s,empty);
sl@0
   764
	s.SetAllSupported();
sl@0
   765
	CheckCapabilitySetEqual(s,all);
sl@0
   766
	s.Intersection(even);
sl@0
   767
	CheckCapabilitySetEqual(s,even);
sl@0
   768
	s.Intersection(even);
sl@0
   769
	CheckCapabilitySetEqual(s,even);
sl@0
   770
	s.Intersection(odd);
sl@0
   771
	CheckCapabilitySetEqual(s,empty);
sl@0
   772
	s.Intersection(odd);
sl@0
   773
	CheckCapabilitySetEqual(s,empty);
sl@0
   774
sl@0
   775
	test.Next(_L("Test Remove(TCapabilitySet)"));
sl@0
   776
	s.SetAllSupported();
sl@0
   777
	CheckCapabilitySetEqual(s,all);
sl@0
   778
	s.Remove(odd);
sl@0
   779
	CheckCapabilitySetEqual(s,even);
sl@0
   780
	s.Remove(odd);
sl@0
   781
	CheckCapabilitySetEqual(s,even);
sl@0
   782
	s.Remove(empty);
sl@0
   783
	CheckCapabilitySetEqual(s,even);
sl@0
   784
	s.Remove(even);
sl@0
   785
	CheckCapabilitySetEqual(s,empty);
sl@0
   786
	s.Remove(even);
sl@0
   787
	CheckCapabilitySetEqual(s,empty);
sl@0
   788
	s.SetAllSupported();
sl@0
   789
	CheckCapabilitySetEqual(s,all);
sl@0
   790
	s.Remove(even);
sl@0
   791
	CheckCapabilitySetEqual(s,odd);
sl@0
   792
	s.Remove(even);
sl@0
   793
	CheckCapabilitySetEqual(s,odd);
sl@0
   794
	s.Remove(empty);
sl@0
   795
	CheckCapabilitySetEqual(s,odd);
sl@0
   796
	s.Remove(odd);
sl@0
   797
	CheckCapabilitySetEqual(s,empty);
sl@0
   798
	s.Remove(odd);
sl@0
   799
	CheckCapabilitySetEqual(s,empty);
sl@0
   800
sl@0
   801
	test.Next(_L("Test HasCapabilities(TCapabilitySet)"));
sl@0
   802
	for(i=0; i<ECapability_Limit; i++)
sl@0
   803
		{
sl@0
   804
		if(!all.HasCapability((TCapability)i))
sl@0
   805
			continue;
sl@0
   806
		TCapabilitySet t((TCapability)i);
sl@0
   807
		test(t.HasCapabilities(t));
sl@0
   808
		test(all.HasCapabilities(t));
sl@0
   809
		test(!empty.HasCapabilities(t));
sl@0
   810
		if(i&1)
sl@0
   811
			{
sl@0
   812
			test(odd.HasCapabilities(t));
sl@0
   813
			test(!even.HasCapabilities(t));
sl@0
   814
			}
sl@0
   815
		else
sl@0
   816
			{
sl@0
   817
			test(!odd.HasCapabilities(t));
sl@0
   818
			test(even.HasCapabilities(t));
sl@0
   819
			}
sl@0
   820
		test(!t.HasCapabilities(all));
sl@0
   821
		test(!t.HasCapabilities(even));
sl@0
   822
		test(!t.HasCapabilities(odd));
sl@0
   823
		test(t.HasCapabilities(empty));
sl@0
   824
		}
sl@0
   825
sl@0
   826
	test(all.HasCapabilities(all));
sl@0
   827
	test(all.HasCapabilities(even));
sl@0
   828
	test(all.HasCapabilities(odd));
sl@0
   829
	test(all.HasCapabilities(empty));
sl@0
   830
sl@0
   831
	test(!even.HasCapabilities(all));
sl@0
   832
	test(even.HasCapabilities(even));
sl@0
   833
	test(!even.HasCapabilities(odd));
sl@0
   834
	test(even.HasCapabilities(empty));
sl@0
   835
sl@0
   836
	test(!odd.HasCapabilities(all));
sl@0
   837
	test(!odd.HasCapabilities(even));
sl@0
   838
	test(odd.HasCapabilities(odd));
sl@0
   839
	test(odd.HasCapabilities(empty));
sl@0
   840
sl@0
   841
	test(!empty.HasCapabilities(all));
sl@0
   842
	test(!empty.HasCapabilities(even));
sl@0
   843
	test(!empty.HasCapabilities(odd));
sl@0
   844
	test(empty.HasCapabilities(empty));
sl@0
   845
sl@0
   846
	test.End();
sl@0
   847
	}
sl@0
   848
sl@0
   849
void CheckSecurityInfo(const TSecurityInfo& a1,const TSecurityInfo& a2)
sl@0
   850
	{
sl@0
   851
	test(a1.iSecureId==a2.iSecureId);
sl@0
   852
	test(a1.iVendorId==a2.iVendorId);
sl@0
   853
	TInt i;
sl@0
   854
	for(i=0; i<ECapability_Limit; i++)
sl@0
   855
		test((!a1.iCaps.HasCapability((TCapability)i))==(!a2.iCaps.HasCapability((TCapability)i)));
sl@0
   856
	}
sl@0
   857
sl@0
   858
void TestSecurityInfo()
sl@0
   859
	{
sl@0
   860
	TSecurityInfo self;
sl@0
   861
	TSecurityInfo info;
sl@0
   862
	TPckg<TSecurityInfo> infoPtr(info);
sl@0
   863
	TInt i;
sl@0
   864
sl@0
   865
	test.Start(_L("Test TSecurityInfo::SetToCurrentInfo"));
sl@0
   866
	self.SetToCurrentInfo();
sl@0
   867
	test(self.iSecureId==KTestSecureId);
sl@0
   868
	test(self.iVendorId==KTestVendorId);
sl@0
   869
	for(i=0; i<ECapability_Limit; i++)
sl@0
   870
		test((TUint32)(self.iCaps.HasCapability((TCapability)i)!=0)==((KTestCapabilities>>i)&1));
sl@0
   871
sl@0
   872
	test.Next(_L("Test TSecurityInfo::Set(RProcess)"));
sl@0
   873
	Mem::FillZ(&info,sizeof(info));
sl@0
   874
	TInt32 r = Session.Send(CTestSession::ETestProcessSecurityInfo,TIpcArgs(TUint(RProcess().Id()),&infoPtr));
sl@0
   875
	test(r==KErrNone);
sl@0
   876
	CheckSecurityInfo(self,info);
sl@0
   877
sl@0
   878
	test.Next(_L("Test TSecurityInfo::Set(RThread)"));
sl@0
   879
	Mem::FillZ(&info,sizeof(info));
sl@0
   880
	r = Session.Send(CTestSession::ETestThreadSecurityInfo,TIpcArgs(TUint(RThread().Id()),&infoPtr));
sl@0
   881
	test(r==KErrNone);
sl@0
   882
	CheckSecurityInfo(self,info);
sl@0
   883
sl@0
   884
	test.Next(_L("Test TSecurityInfo::Set(RMessagePtr2)"));
sl@0
   885
	Mem::FillZ(&info,sizeof(info));
sl@0
   886
	r = Session.Send(CTestSession::ETestMessageSecurityInfo,TIpcArgs(&infoPtr));
sl@0
   887
	test(r==KErrNone);
sl@0
   888
	CheckSecurityInfo(self,info);
sl@0
   889
sl@0
   890
	test.Next(_L("Test TSecurityInfo::SetToCreatorInfo"));
sl@0
   891
	Mem::FillZ(&info,sizeof(info));
sl@0
   892
	r = Session.Send(CTestSession::ETestCreatorSecurityInfo,TIpcArgs(&infoPtr));
sl@0
   893
	test(r==KErrNone);
sl@0
   894
	CheckSecurityInfo(self,info);
sl@0
   895
sl@0
   896
	test.End();
sl@0
   897
	}
sl@0
   898
sl@0
   899
void TestSecureId()
sl@0
   900
	{
sl@0
   901
	test.Start(_L("Test RProcess::SecureId()"));
sl@0
   902
	TInt r = Session.Send(CTestSession::ETestProcessSecureId,TIpcArgs(TUint(RProcess().Id())));
sl@0
   903
	test((TUint32)r==KTestSecureId);
sl@0
   904
sl@0
   905
	test.Next(_L("Test RThread::SecureId()"));
sl@0
   906
	r = Session.Send(CTestSession::ETestThreadSecureId,TIpcArgs(TUint(RThread().Id())));
sl@0
   907
	test((TUint32)r==KTestSecureId);
sl@0
   908
sl@0
   909
	test.Next(_L("Test RMessage2::SecureId()"));
sl@0
   910
	r = Session.Send(CTestSession::ETestMessageSecureId);
sl@0
   911
	test((TUint32)r==KTestSecureId);
sl@0
   912
sl@0
   913
	test.Next(_L("Test User::CreatorSecureId()"));
sl@0
   914
	r = Session.Send(CTestSession::ETestCreatorSecureId);
sl@0
   915
	test((TUint32)r==KTestSecureId);
sl@0
   916
sl@0
   917
	test.End();
sl@0
   918
	}
sl@0
   919
sl@0
   920
void TestVendorId()
sl@0
   921
	{
sl@0
   922
	test.Start(_L("Test RProcess::VendorId()"));
sl@0
   923
	TInt r = Session.Send(CTestSession::ETestProcessVendorId,TIpcArgs(TUint(RProcess().Id())));
sl@0
   924
	test((TUint32)r==KTestVendorId);
sl@0
   925
sl@0
   926
	test.Next(_L("Test RThread::VendorId()"));
sl@0
   927
	r = Session.Send(CTestSession::ETestThreadVendorId,TIpcArgs(TUint(RThread().Id())));
sl@0
   928
	test((TUint32)r==KTestVendorId);
sl@0
   929
sl@0
   930
	test.Next(_L("Test RMessage2::VendorId()"));
sl@0
   931
	r = Session.Send(CTestSession::ETestMessageVendorId);
sl@0
   932
	test((TUint32)r==KTestVendorId);
sl@0
   933
sl@0
   934
	test.Next(_L("Test User::CreatorVendorId()"));
sl@0
   935
	r = Session.Send(CTestSession::ETestCreatorVendorId);
sl@0
   936
	test((TUint32)r==KTestVendorId);
sl@0
   937
sl@0
   938
	test.End();
sl@0
   939
	}
sl@0
   940
sl@0
   941
void TestHasCapability()
sl@0
   942
	{
sl@0
   943
	TInt failResult=PlatSecEnforcement ? 0 : 1;
sl@0
   944
	TInt failResultL=PlatSecEnforcement ? KErrPermissionDenied : KErrNone;
sl@0
   945
sl@0
   946
	test.Start(_L("Test RProcess::HasCapability(TCapability)"));
sl@0
   947
	TInt r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapabilityLocalServices));
sl@0
   948
	test(r);
sl@0
   949
	r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapabilityNetworkServices));
sl@0
   950
	test(r==failResult);
sl@0
   951
	r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapability_None));
sl@0
   952
	test(r);
sl@0
   953
	r = Session.Send(CTestSession::ETestProcessHasCapability1,TIpcArgs(TUint(RProcess().Id()),ECapability_Denied));
sl@0
   954
	test(r==failResult);
sl@0
   955
sl@0
   956
	test.Next(_L("Test RProcess::HasCapability(TCapability,TCapability)"));
sl@0
   957
	r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityLocalServices,ECapabilityWriteUserData));
sl@0
   958
	test(r);
sl@0
   959
	r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityNetworkServices,ECapabilityWriteUserData));
sl@0
   960
	test(r==failResult);
sl@0
   961
	r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityLocalServices,ECapabilityReadUserData));
sl@0
   962
	test(r==failResult);
sl@0
   963
	r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapabilityNetworkServices,ECapabilityReadUserData));
sl@0
   964
	test(r==failResult);
sl@0
   965
	r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapability_None,ECapabilityWriteUserData));
sl@0
   966
	test(r);
sl@0
   967
	r = Session.Send(CTestSession::ETestProcessHasCapability2,TIpcArgs(TUint(RProcess().Id()),ECapability_Denied,ECapabilityWriteUserData));
sl@0
   968
	test(r==failResult);
sl@0
   969
sl@0
   970
	test.Next(_L("Test RThread::HasCapability(TCapability)"));
sl@0
   971
	r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapabilityLocalServices));
sl@0
   972
	test(r);
sl@0
   973
	r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapabilityNetworkServices));
sl@0
   974
	test(r==failResult);
sl@0
   975
	r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapability_None));
sl@0
   976
	test(r);
sl@0
   977
	r = Session.Send(CTestSession::ETestThreadHasCapability1,TIpcArgs(TUint(RThread().Id()),ECapability_Denied));
sl@0
   978
	test(r==failResult);
sl@0
   979
sl@0
   980
	test.Next(_L("Test RThread::HasCapability(TCapability,TCapability)"));
sl@0
   981
	r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityLocalServices,ECapabilityWriteUserData));
sl@0
   982
	test(r);
sl@0
   983
	r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityNetworkServices,ECapabilityWriteUserData));
sl@0
   984
	test(r==failResult);
sl@0
   985
	r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityLocalServices,ECapabilityReadUserData));
sl@0
   986
	test(r==failResult);
sl@0
   987
	r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapabilityNetworkServices,ECapabilityReadUserData));
sl@0
   988
	test(r==failResult);
sl@0
   989
	r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapability_None,ECapabilityWriteUserData));
sl@0
   990
	test(r);
sl@0
   991
	r = Session.Send(CTestSession::ETestThreadHasCapability2,TIpcArgs(TUint(RThread().Id()),ECapability_Denied,ECapabilityWriteUserData));
sl@0
   992
	test(r==failResult);
sl@0
   993
sl@0
   994
	test.Next(_L("Test RMessagePtr2::HasCapability(TCapability)"));
sl@0
   995
	r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapabilityLocalServices));
sl@0
   996
	test(r);
sl@0
   997
	r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapabilityNetworkServices));
sl@0
   998
	test(r==failResult);
sl@0
   999
	r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapability_None));
sl@0
  1000
	test(r);
sl@0
  1001
	r = Session.Send(CTestSession::ETestMessageHasCapability1,TIpcArgs(ECapability_Denied));
sl@0
  1002
	test(r==failResult);
sl@0
  1003
sl@0
  1004
	test.Next(_L("Test RMessagePtr2::HasCapabilityL(TCapability)"));
sl@0
  1005
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapabilityLocalServices));
sl@0
  1006
	test(r==KErrNone);
sl@0
  1007
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapabilityNetworkServices));
sl@0
  1008
	test(r==failResultL);
sl@0
  1009
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapability_None));
sl@0
  1010
	test(r==KErrNone);
sl@0
  1011
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL1,TIpcArgs(ECapability_Denied));
sl@0
  1012
	test(r==failResultL);
sl@0
  1013
sl@0
  1014
	test.Next(_L("Test RMessagePtr2::HasCapability(TCapability,TCapability)"));
sl@0
  1015
	r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityWriteUserData));
sl@0
  1016
	test(r);
sl@0
  1017
	r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityWriteUserData));
sl@0
  1018
	test(r==failResult);
sl@0
  1019
	r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityReadUserData));
sl@0
  1020
	test(r==failResult);
sl@0
  1021
	r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityReadUserData));
sl@0
  1022
	test(r==failResult);
sl@0
  1023
	r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapability_None,ECapabilityWriteUserData));
sl@0
  1024
	test(r);
sl@0
  1025
	r = Session.Send(CTestSession::ETestMessageHasCapability2,TIpcArgs(ECapability_Denied,ECapabilityWriteUserData));
sl@0
  1026
	test(r==failResult);
sl@0
  1027
sl@0
  1028
	test.Next(_L("Test RMessagePtr2::HasCapabilityL(TCapability,TCapability)"));
sl@0
  1029
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityLocalServices,ECapabilityWriteUserData));
sl@0
  1030
	test(r==KErrNone);
sl@0
  1031
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityNetworkServices,ECapabilityWriteUserData));
sl@0
  1032
	test(r==failResultL);
sl@0
  1033
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityLocalServices,ECapabilityReadUserData));
sl@0
  1034
	test(r==failResultL);
sl@0
  1035
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapabilityNetworkServices,ECapabilityReadUserData));
sl@0
  1036
	test(r==failResultL);
sl@0
  1037
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapability_None,ECapabilityWriteUserData));
sl@0
  1038
	test(r==KErrNone);
sl@0
  1039
	r = Session.Send(CTestSession::ETestMessageHasCapabilityL2,TIpcArgs(ECapability_Denied,ECapabilityWriteUserData));
sl@0
  1040
	test(r==failResultL);
sl@0
  1041
sl@0
  1042
	test.Next(_L("Test User::CreatorHasCapability(TCapability)"));
sl@0
  1043
	r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapabilityLocalServices));
sl@0
  1044
	test(r);
sl@0
  1045
	r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapabilityNetworkServices));
sl@0
  1046
	test(r==failResult);
sl@0
  1047
	r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapability_None));
sl@0
  1048
	test(r);
sl@0
  1049
	r = Session.Send(CTestSession::ETestCreatorHasCapability1,TIpcArgs(ECapability_Denied));
sl@0
  1050
	test(r==failResult);
sl@0
  1051
sl@0
  1052
	test.Next(_L("Test User::CreatorHasCapability(TCapability,TCapability)"));
sl@0
  1053
	r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityWriteUserData));
sl@0
  1054
	test(r);
sl@0
  1055
	r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityWriteUserData));
sl@0
  1056
	test(r==failResult);
sl@0
  1057
	r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityLocalServices,ECapabilityReadUserData));
sl@0
  1058
	test(r==failResult);
sl@0
  1059
	r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapabilityNetworkServices,ECapabilityReadUserData));
sl@0
  1060
	test(r==failResult);
sl@0
  1061
	r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapability_None,ECapabilityWriteUserData));
sl@0
  1062
	test(r);
sl@0
  1063
	r = Session.Send(CTestSession::ETestCreatorHasCapability2,TIpcArgs(ECapability_Denied,ECapabilityWriteUserData));
sl@0
  1064
	test(r==failResult);
sl@0
  1065
sl@0
  1066
	test.End();
sl@0
  1067
	}
sl@0
  1068
sl@0
  1069
TBool SecurityPoliciesEqual(const TSecurityPolicy& a,const TSecurityPolicy& b)
sl@0
  1070
	{
sl@0
  1071
	return Mem::Compare((TUint8*)&a, sizeof(TSecurityPolicy), (TUint8*)&b, sizeof(TSecurityPolicy))==0;
sl@0
  1072
	}
sl@0
  1073
sl@0
  1074
void TestSecurityPolicy()
sl@0
  1075
	{
sl@0
  1076
	test.Start(_L("Test TSecurityPolicy Constructors"));
sl@0
  1077
sl@0
  1078
	TBool failResult=!PlatSecEnforcement;
sl@0
  1079
sl@0
  1080
	test.Next(_L("Empty Constructor"));
sl@0
  1081
		{
sl@0
  1082
		TSecurityPolicy empty;
sl@0
  1083
		TPtrC8 ptr = empty.Package();
sl@0
  1084
		TSecurityPolicy empty2;
sl@0
  1085
		test(empty2.Set(ptr) == KErrNone);
sl@0
  1086
		test(SecurityPoliciesEqual(empty, empty2));
sl@0
  1087
sl@0
  1088
		test(failResult!=!empty.CheckPolicy(RProcess()));
sl@0
  1089
		test(failResult!=!empty.CheckPolicy(RThread()));
sl@0
  1090
		test(failResult!=!empty2.CheckPolicy(RProcess()));
sl@0
  1091
		test(failResult!=!empty2.CheckPolicy(RThread()));
sl@0
  1092
sl@0
  1093
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1094
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1095
sl@0
  1096
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1097
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1098
		}
sl@0
  1099
sl@0
  1100
	test.Next(_L("Always Fail Constructor"));
sl@0
  1101
		{
sl@0
  1102
		TSecurityPolicy fail(TSecurityPolicy::EAlwaysFail);
sl@0
  1103
		TPtrC8 ptr = fail.Package();
sl@0
  1104
		TSecurityPolicy fail2;
sl@0
  1105
		test(fail2.Set(ptr) == KErrNone);
sl@0
  1106
		test(SecurityPoliciesEqual(fail, fail2));
sl@0
  1107
sl@0
  1108
		test(failResult!=!fail.CheckPolicy(RProcess()));
sl@0
  1109
		test(failResult!=!fail.CheckPolicy(RThread()));
sl@0
  1110
		test(failResult!=!fail2.CheckPolicy(RProcess()));
sl@0
  1111
		test(failResult!=!fail2.CheckPolicy(RThread()));
sl@0
  1112
sl@0
  1113
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1114
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1115
sl@0
  1116
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1117
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1118
		}
sl@0
  1119
sl@0
  1120
	test.Next(_L("Always Pass Constructor"));
sl@0
  1121
		{
sl@0
  1122
		TSecurityPolicy pass(TSecurityPolicy::EAlwaysPass);
sl@0
  1123
		TPtrC8 ptr = pass.Package();
sl@0
  1124
		TSecurityPolicy pass2;
sl@0
  1125
		test(pass2.Set(ptr) == KErrNone);
sl@0
  1126
		test(SecurityPoliciesEqual(pass, pass2));
sl@0
  1127
sl@0
  1128
		test(pass.CheckPolicy(RProcess()));
sl@0
  1129
		test(pass.CheckPolicy(RThread()));
sl@0
  1130
		test(pass2.CheckPolicy(RProcess()));
sl@0
  1131
		test(pass2.CheckPolicy(RThread()));
sl@0
  1132
sl@0
  1133
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1134
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1135
sl@0
  1136
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1137
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1138
		}
sl@0
  1139
sl@0
  1140
	test.Next(_L("3 Capability Constructor"));
sl@0
  1141
		{
sl@0
  1142
		TSecurityPolicy threeCaps(ECapabilityTCB,ECapabilityDRM,ECapabilityProtServ);
sl@0
  1143
		//Current process has these three
sl@0
  1144
		test(threeCaps.CheckPolicy(RProcess()));
sl@0
  1145
		test(threeCaps.CheckPolicy(RThread()));
sl@0
  1146
		TPtrC8 ptr = threeCaps.Package();
sl@0
  1147
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1148
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1149
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1150
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1151
		}
sl@0
  1152
sl@0
  1153
		{
sl@0
  1154
		TSecurityPolicy threeCaps(ECapabilityTCB,ECapabilityProtServ,ECapabilityCommDD);
sl@0
  1155
		//Current process doesn't have ECapabilityCommDD
sl@0
  1156
		test(failResult!=!(threeCaps.CheckPolicy(RProcess())));
sl@0
  1157
		test(failResult!=!(threeCaps.CheckPolicy(RThread())));
sl@0
  1158
		TPtrC8 ptr = threeCaps.Package();
sl@0
  1159
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1160
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1161
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1162
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1163
		}
sl@0
  1164
sl@0
  1165
		{
sl@0
  1166
		TSecurityPolicy threeCaps(ECapabilityCommDD);
sl@0
  1167
		//Current process doesn't have ECapabilityCommDD
sl@0
  1168
		test(failResult!=!(threeCaps.CheckPolicy(RProcess())));
sl@0
  1169
		test(failResult!=!(threeCaps.CheckPolicy(RThread())));
sl@0
  1170
		TPtrC8 ptr = threeCaps.Package();
sl@0
  1171
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1172
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1173
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1174
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1175
		}
sl@0
  1176
sl@0
  1177
		{
sl@0
  1178
		TSecurityPolicy threeCaps(ECapabilityTCB);
sl@0
  1179
		//Current process has TCB + 2 * ECapability_None
sl@0
  1180
		test(threeCaps.CheckPolicy(RProcess()));
sl@0
  1181
		test(threeCaps.CheckPolicy(RThread()));
sl@0
  1182
sl@0
  1183
		TPtrC8 ptr = threeCaps.Package();
sl@0
  1184
		TSecurityPolicy threeCaps2;
sl@0
  1185
		TBuf8<sizeof(TSecurityPolicy)> invalid;
sl@0
  1186
		for(TInt i=4; i<=7; i++)
sl@0
  1187
			{
sl@0
  1188
			invalid=ptr;
sl@0
  1189
			invalid[i] = 0; // Set unused capability to be invalid
sl@0
  1190
			test(threeCaps2.Set(invalid)==KErrArgument);
sl@0
  1191
			}
sl@0
  1192
		test(threeCaps2.Set(ptr)==KErrNone);
sl@0
  1193
		test(SecurityPoliciesEqual(threeCaps, threeCaps2));
sl@0
  1194
sl@0
  1195
		test(threeCaps2.CheckPolicy(RProcess()));
sl@0
  1196
		test(threeCaps2.CheckPolicy(RThread()));
sl@0
  1197
sl@0
  1198
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1199
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1200
sl@0
  1201
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1202
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1203
		}
sl@0
  1204
sl@0
  1205
	test.Next(_L("7 Capability Constructor"));
sl@0
  1206
		{
sl@0
  1207
		TSecurityPolicy sevenCaps(ECapabilityTCB,ECapabilityWriteUserData,ECapabilitySwEvent,ECapabilityProtServ,ECapabilityNetworkControl,ECapabilityDRM,ECapabilityReadDeviceData);
sl@0
  1208
		//Current process has all 7 of these.
sl@0
  1209
		test(sevenCaps.CheckPolicy(RProcess()));
sl@0
  1210
		test(sevenCaps.CheckPolicy(RThread()));
sl@0
  1211
		TPtrC8 ptr = sevenCaps.Package();
sl@0
  1212
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1213
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1214
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1215
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1216
		}
sl@0
  1217
		
sl@0
  1218
		{
sl@0
  1219
		TSecurityPolicy sevenCaps(ECapabilityTCB,ECapabilityWriteUserData,ECapabilityMultimediaDD,ECapabilityProtServ,ECapabilityNetworkControl,ECapabilityDRM,ECapabilityReadDeviceData);
sl@0
  1220
		//Current process doesn't have MultimediaDD
sl@0
  1221
		test(failResult!=!(sevenCaps.CheckPolicy(RProcess())));
sl@0
  1222
		test(failResult!=!(sevenCaps.CheckPolicy(RThread())));
sl@0
  1223
		TPtrC8 ptr = sevenCaps.Package();
sl@0
  1224
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1225
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1226
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1227
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1228
		}
sl@0
  1229
sl@0
  1230
		{
sl@0
  1231
		TSecurityPolicy sevenCaps(ECapabilityTCB,ECapabilityWriteUserData,ECapabilityMultimediaDD,ECapabilityProtServ,ECapabilityTrustedUI,ECapabilityDRM,ECapabilityReadDeviceData);
sl@0
  1232
		//Current process doesn't have MultiMediaDD or TrustedUI
sl@0
  1233
		test(failResult!=!(sevenCaps.CheckPolicy(RProcess())));
sl@0
  1234
		test(failResult!=!(sevenCaps.CheckPolicy(RThread())));
sl@0
  1235
sl@0
  1236
		TPtrC8 ptr = sevenCaps.Package();
sl@0
  1237
		TSecurityPolicy sevenCaps2;
sl@0
  1238
		test(sevenCaps2.Set(ptr)==KErrNone);
sl@0
  1239
		test(SecurityPoliciesEqual(sevenCaps,sevenCaps2));
sl@0
  1240
		test(failResult!=!(sevenCaps2.CheckPolicy(RProcess())));
sl@0
  1241
		test(failResult!=!(sevenCaps2.CheckPolicy(RThread())));
sl@0
  1242
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1243
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);;
sl@0
  1244
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1245
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);;
sl@0
  1246
		}
sl@0
  1247
sl@0
  1248
	test.Next(_L("SID + 3 constructor"));
sl@0
  1249
		{
sl@0
  1250
		TSecurityPolicy sid(KTestSecureId, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData);
sl@0
  1251
		//Current process has all three + sid
sl@0
  1252
		test(sid.CheckPolicy(RProcess()));
sl@0
  1253
		test(sid.CheckPolicy(RThread()));
sl@0
  1254
sl@0
  1255
		TPtrC8 ptr = sid.Package();
sl@0
  1256
		TSecurityPolicy sid2;
sl@0
  1257
		test(sid2.Set(ptr)==KErrNone);
sl@0
  1258
		test(SecurityPoliciesEqual(sid,sid2));
sl@0
  1259
		test(sid2.CheckPolicy(RProcess()));
sl@0
  1260
		test(sid2.CheckPolicy(RThread()));
sl@0
  1261
sl@0
  1262
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1263
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1264
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1265
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1266
		}
sl@0
  1267
sl@0
  1268
		{
sl@0
  1269
		TSecurityPolicy sid(KTestSecureId2, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData);
sl@0
  1270
		//Current process has all three caps but not sid
sl@0
  1271
		test(failResult!=!(sid.CheckPolicy(RProcess())));
sl@0
  1272
		test(failResult!=!(sid.CheckPolicy(RThread())));
sl@0
  1273
		TPtrC8 ptr = sid.Package();
sl@0
  1274
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1275
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1276
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1277
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1278
		}
sl@0
  1279
sl@0
  1280
		{
sl@0
  1281
		TSecurityPolicy sid(KTestSecureId, ECapabilityProtServ, ECapabilityWriteDeviceData);
sl@0
  1282
		//Current process has sid but missing ECapabilityWriteDeviceData
sl@0
  1283
		test(failResult!=!(sid.CheckPolicy(RProcess())));
sl@0
  1284
		test(failResult!=!(sid.CheckPolicy(RThread())));
sl@0
  1285
		TPtrC8 ptr = sid.Package();
sl@0
  1286
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1287
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1288
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1289
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1290
		}
sl@0
  1291
sl@0
  1292
		{
sl@0
  1293
		TSecurityPolicy sid(KTestSecureId2, ECapabilityProtServ, ECapabilityWriteDeviceData);
sl@0
  1294
		//Current process is missing sid and ECapabilityWriteDeviceData
sl@0
  1295
		test(failResult!=!(sid.CheckPolicy(RProcess())));
sl@0
  1296
		test(failResult!=!(sid.CheckPolicy(RThread())));
sl@0
  1297
		TPtrC8 ptr = sid.Package();
sl@0
  1298
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1299
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1300
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1301
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1302
		}
sl@0
  1303
sl@0
  1304
	test.Next(_L("VID + 3 constructor"));
sl@0
  1305
		{
sl@0
  1306
		TSecurityPolicy vid(KTestVendorId, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData);
sl@0
  1307
		//Current process has all three + vid
sl@0
  1308
		test(vid.CheckPolicy(RProcess()));
sl@0
  1309
		test(vid.CheckPolicy(RThread()));
sl@0
  1310
sl@0
  1311
		TPtrC8 ptr = vid.Package();
sl@0
  1312
		TSecurityPolicy vid2;
sl@0
  1313
		test(vid2.Set(ptr)==KErrNone);
sl@0
  1314
		test(SecurityPoliciesEqual(vid,vid2));
sl@0
  1315
		test(vid2.CheckPolicy(RProcess()));
sl@0
  1316
		test(vid2.CheckPolicy(RThread()));
sl@0
  1317
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1318
		test(r==CTestSession::EPolicyCheckPassed);
sl@0
  1319
		}
sl@0
  1320
sl@0
  1321
		{
sl@0
  1322
		TSecurityPolicy vid(KTestVendorId2, ECapabilityProtServ, ECapabilityDRM, ECapabilityReadDeviceData);
sl@0
  1323
		//Current process has all three caps but not vid
sl@0
  1324
		test(failResult!=!(vid.CheckPolicy(RProcess())));
sl@0
  1325
		test(failResult!=!(vid.CheckPolicy(RThread())));
sl@0
  1326
		TPtrC8 ptr = vid.Package();
sl@0
  1327
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1328
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1329
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1330
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1331
		}
sl@0
  1332
sl@0
  1333
		{
sl@0
  1334
		TSecurityPolicy vid(KTestVendorId, ECapabilityProtServ, ECapabilityWriteDeviceData);
sl@0
  1335
		//Current process has vid but missing ECapabilityWriteDeviceData
sl@0
  1336
		test(failResult!=!(vid.CheckPolicy(RProcess())));
sl@0
  1337
		test(failResult!=!(vid.CheckPolicy(RThread())));
sl@0
  1338
		TPtrC8 ptr = vid.Package();
sl@0
  1339
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1340
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1341
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1342
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1343
		}
sl@0
  1344
sl@0
  1345
		{
sl@0
  1346
		TSecurityPolicy vid(KTestVendorId2, ECapabilityProtServ, ECapabilityWriteDeviceData);
sl@0
  1347
		//Current process is missing vid and ECapabilityWriteDeviceData
sl@0
  1348
		test(failResult!=!(vid.CheckPolicy(RProcess())));
sl@0
  1349
		test(failResult!=!(vid.CheckPolicy(RThread())));
sl@0
  1350
		TPtrC8 ptr = vid.Package();
sl@0
  1351
		TInt r = Session.Send(CTestSession::ETestSecurityPolicyAgainstMessage,TIpcArgs(&ptr));
sl@0
  1352
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1353
		r = Session.Send(CTestSession::ETestSecurityPolicyAgainstCreator,TIpcArgs(&ptr));
sl@0
  1354
		test(r==failResult?CTestSession::EPolicyCheckFailed:CTestSession::EPolicyCheckPassed);
sl@0
  1355
		}
sl@0
  1356
sl@0
  1357
	test.Next(_L("Macros for compile-time construction"));
sl@0
  1358
		{
sl@0
  1359
		static _LIT_SECURITY_POLICY_C7(pc7,1,2,3,4,5,6,7);
sl@0
  1360
		static _LIT_SECURITY_POLICY_C6(pc6,1,2,3,4,5,6);
sl@0
  1361
		static _LIT_SECURITY_POLICY_C5(pc5,1,2,3,4,5);
sl@0
  1362
		static _LIT_SECURITY_POLICY_C4(pc4,1,2,3,4);
sl@0
  1363
		static _LIT_SECURITY_POLICY_C3(pc3,1,2,3);
sl@0
  1364
		static _LIT_SECURITY_POLICY_C2(pc2,1,2);
sl@0
  1365
		static _LIT_SECURITY_POLICY_C1(pc1,1);
sl@0
  1366
		test(SecurityPoliciesEqual(pc7,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6,(TCapability)7)));
sl@0
  1367
		test(SecurityPoliciesEqual(pc6,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6)));
sl@0
  1368
		test(SecurityPoliciesEqual(pc5,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5)));
sl@0
  1369
		test(SecurityPoliciesEqual(pc4,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4)));
sl@0
  1370
		test(SecurityPoliciesEqual(pc3,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3)));
sl@0
  1371
		test(SecurityPoliciesEqual(pc2,TSecurityPolicy((TCapability)1,(TCapability)2)));
sl@0
  1372
		test(SecurityPoliciesEqual(pc1,TSecurityPolicy((TCapability)1)));
sl@0
  1373
		
sl@0
  1374
		static _LIT_SECURITY_POLICY_S3(ps3,0x12345678,1,2,3);
sl@0
  1375
		static _LIT_SECURITY_POLICY_S2(ps2,0x12345678,1,2);
sl@0
  1376
		static _LIT_SECURITY_POLICY_S1(ps1,0x12345678,1);
sl@0
  1377
		static _LIT_SECURITY_POLICY_S0(ps0,0x12345678);
sl@0
  1378
		test(SecurityPoliciesEqual(ps3,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3)));
sl@0
  1379
		test(SecurityPoliciesEqual(ps2,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2)));
sl@0
  1380
		test(SecurityPoliciesEqual(ps1,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1)));
sl@0
  1381
		test(SecurityPoliciesEqual(ps0,TSecurityPolicy(TSecureId(0x12345678))));
sl@0
  1382
sl@0
  1383
		static _LIT_SECURITY_POLICY_V3(pv3,0x12345678,1,2,3);
sl@0
  1384
		static _LIT_SECURITY_POLICY_V2(pv2,0x12345678,1,2);
sl@0
  1385
		static _LIT_SECURITY_POLICY_V1(pv1,0x12345678,1);
sl@0
  1386
		static _LIT_SECURITY_POLICY_V0(pv0,0x12345678);
sl@0
  1387
		test(SecurityPoliciesEqual(pv3,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3)));
sl@0
  1388
		test(SecurityPoliciesEqual(pv2,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2)));
sl@0
  1389
		test(SecurityPoliciesEqual(pv1,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1)));
sl@0
  1390
		test(SecurityPoliciesEqual(pv0,TSecurityPolicy(TVendorId(0x12345678))));
sl@0
  1391
sl@0
  1392
		static _LIT_SECURITY_POLICY_FAIL(fail);
sl@0
  1393
		static _LIT_SECURITY_POLICY_PASS(pass);
sl@0
  1394
		test(SecurityPoliciesEqual(fail,TSecurityPolicy(TSecurityPolicy::EAlwaysFail)));
sl@0
  1395
		test(SecurityPoliciesEqual(pass,TSecurityPolicy(TSecurityPolicy::EAlwaysPass)));
sl@0
  1396
		}
sl@0
  1397
sl@0
  1398
	test.Next(_L("Macros for compile-time initialisation"));
sl@0
  1399
		{
sl@0
  1400
		const TStaticSecurityPolicy pc7 = _INIT_SECURITY_POLICY_C7(1,2,3,4,5,6,7);
sl@0
  1401
		const TStaticSecurityPolicy pc6 = _INIT_SECURITY_POLICY_C6(1,2,3,4,5,6);
sl@0
  1402
		const TStaticSecurityPolicy pc5 = _INIT_SECURITY_POLICY_C5(1,2,3,4,5);
sl@0
  1403
		const TStaticSecurityPolicy pc4 = _INIT_SECURITY_POLICY_C4(1,2,3,4);
sl@0
  1404
		const TStaticSecurityPolicy pc3 = _INIT_SECURITY_POLICY_C3(1,2,3);
sl@0
  1405
		const TStaticSecurityPolicy pc2 = _INIT_SECURITY_POLICY_C2(1,2);
sl@0
  1406
		const TStaticSecurityPolicy pc1 = _INIT_SECURITY_POLICY_C1(1);
sl@0
  1407
		test(SecurityPoliciesEqual(pc7,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6,(TCapability)7)));
sl@0
  1408
		test(SecurityPoliciesEqual(pc6,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5,(TCapability)6)));
sl@0
  1409
		test(SecurityPoliciesEqual(pc5,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4,(TCapability)5)));
sl@0
  1410
		test(SecurityPoliciesEqual(pc4,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3,(TCapability)4)));
sl@0
  1411
		test(SecurityPoliciesEqual(pc3,TSecurityPolicy((TCapability)1,(TCapability)2,(TCapability)3)));
sl@0
  1412
		test(SecurityPoliciesEqual(pc2,TSecurityPolicy((TCapability)1,(TCapability)2)));
sl@0
  1413
		test(SecurityPoliciesEqual(pc1,TSecurityPolicy((TCapability)1)));
sl@0
  1414
		
sl@0
  1415
		const TStaticSecurityPolicy ps3 = _INIT_SECURITY_POLICY_S3(0x12345678,1,2,3);
sl@0
  1416
		const TStaticSecurityPolicy ps2 = _INIT_SECURITY_POLICY_S2(0x12345678,1,2);
sl@0
  1417
		const TStaticSecurityPolicy ps1 = _INIT_SECURITY_POLICY_S1(0x12345678,1);
sl@0
  1418
		const TStaticSecurityPolicy ps0 = _INIT_SECURITY_POLICY_S0(0x12345678);
sl@0
  1419
		test(SecurityPoliciesEqual(ps3,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3)));
sl@0
  1420
		test(SecurityPoliciesEqual(ps2,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1,(TCapability)2)));
sl@0
  1421
		test(SecurityPoliciesEqual(ps1,TSecurityPolicy(TSecureId(0x12345678),(TCapability)1)));
sl@0
  1422
		test(SecurityPoliciesEqual(ps0,TSecurityPolicy(TSecureId(0x12345678))));
sl@0
  1423
sl@0
  1424
		const TStaticSecurityPolicy pv3 = _INIT_SECURITY_POLICY_V3(0x12345678,1,2,3);
sl@0
  1425
		const TStaticSecurityPolicy pv2 = _INIT_SECURITY_POLICY_V2(0x12345678,1,2);
sl@0
  1426
		const TStaticSecurityPolicy pv1 = _INIT_SECURITY_POLICY_V1(0x12345678,1);
sl@0
  1427
		const TStaticSecurityPolicy pv0 = _INIT_SECURITY_POLICY_V0(0x12345678);
sl@0
  1428
		test(SecurityPoliciesEqual(pv3,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2,(TCapability)3)));
sl@0
  1429
		test(SecurityPoliciesEqual(pv2,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1,(TCapability)2)));
sl@0
  1430
		test(SecurityPoliciesEqual(pv1,TSecurityPolicy(TVendorId(0x12345678),(TCapability)1)));
sl@0
  1431
		test(SecurityPoliciesEqual(pv0,TSecurityPolicy(TVendorId(0x12345678))));
sl@0
  1432
sl@0
  1433
		const TStaticSecurityPolicy fail = _INIT_SECURITY_POLICY_FAIL;
sl@0
  1434
		const TStaticSecurityPolicy pass = _INIT_SECURITY_POLICY_PASS;
sl@0
  1435
		test(SecurityPoliciesEqual(fail,TSecurityPolicy(TSecurityPolicy::EAlwaysFail)));
sl@0
  1436
		test(SecurityPoliciesEqual(pass,TSecurityPolicy(TSecurityPolicy::EAlwaysPass)));
sl@0
  1437
sl@0
  1438
		}
sl@0
  1439
sl@0
  1440
	test.End();
sl@0
  1441
	}
sl@0
  1442
sl@0
  1443
#define CHECK_NAME(name)	\
sl@0
  1444
	test(0==TPtrC8((TUint8*)#name).Compare(TPtrC8((TUint8*)CapabilityNames[ECapability##name])));
sl@0
  1445
sl@0
  1446
void TestCapabilityNames()
sl@0
  1447
	{
sl@0
  1448
	CHECK_NAME(TCB);
sl@0
  1449
	CHECK_NAME(CommDD);
sl@0
  1450
	CHECK_NAME(PowerMgmt);
sl@0
  1451
	CHECK_NAME(MultimediaDD);
sl@0
  1452
	CHECK_NAME(ReadDeviceData);
sl@0
  1453
	CHECK_NAME(WriteDeviceData);
sl@0
  1454
	CHECK_NAME(DRM);
sl@0
  1455
	CHECK_NAME(TrustedUI);
sl@0
  1456
	CHECK_NAME(ProtServ);
sl@0
  1457
	CHECK_NAME(DiskAdmin);
sl@0
  1458
	CHECK_NAME(NetworkControl);
sl@0
  1459
	CHECK_NAME(AllFiles);
sl@0
  1460
	CHECK_NAME(SwEvent);
sl@0
  1461
	CHECK_NAME(NetworkServices);
sl@0
  1462
	CHECK_NAME(LocalServices);
sl@0
  1463
	CHECK_NAME(ReadUserData);
sl@0
  1464
	CHECK_NAME(WriteUserData);
sl@0
  1465
	CHECK_NAME(Location);
sl@0
  1466
	CHECK_NAME(SurroundingsDD);
sl@0
  1467
	CHECK_NAME(UserEnvironment);
sl@0
  1468
	}
sl@0
  1469
sl@0
  1470
sl@0
  1471
void TestKernelAPIs()
sl@0
  1472
	{
sl@0
  1473
	RLddTest ldd;
sl@0
  1474
	TInt r=User::LoadLogicalDevice(_L("D_SLDD.LDD"));
sl@0
  1475
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
  1476
	r=ldd.OpenLocal();
sl@0
  1477
	test(r==KErrNone);
sl@0
  1478
sl@0
  1479
	RLddTest::TIds ids;
sl@0
  1480
	memclr(&ids,sizeof(ids));
sl@0
  1481
	ldd.GetIds(ids);
sl@0
  1482
	test.Printf(_L("Thread VID,SID = %08x,%08x\n\r"),ids.iThreadVID.iId,ids.iThreadSID.iId);
sl@0
  1483
	test.Printf(_L("Process VID,SID = %08x,%08x\n\r"),ids.iProcessVID.iId,ids.iProcessSID.iId);
sl@0
  1484
	test(ids.iThreadVID==KTestVendorId);
sl@0
  1485
	test(ids.iThreadSID==KTestSecureId);
sl@0
  1486
	test(ids.iProcessVID==KTestVendorId);
sl@0
  1487
	test(ids.iProcessSID==KTestSecureId);
sl@0
  1488
sl@0
  1489
	// Test kernel-mode TSecurityInfo-getting APIs
sl@0
  1490
	TSecurityInfo infoProcess, infoThread;
sl@0
  1491
	ldd.GetSecureInfos(&infoThread, &infoProcess);
sl@0
  1492
	// Check the vendor & secure IDs are what's expected
sl@0
  1493
	test(infoThread.iVendorId==KTestVendorId);
sl@0
  1494
	test(infoThread.iSecureId==KTestSecureId);
sl@0
  1495
	test(infoProcess.iVendorId==KTestVendorId);
sl@0
  1496
	test(infoProcess.iSecureId==KTestSecureId);
sl@0
  1497
	// Check process caps == thread caps
sl@0
  1498
	TUint32* capsT = (TUint32*)&infoThread.iCaps;
sl@0
  1499
	TUint32* capsP = (TUint32*)&infoProcess.iCaps;
sl@0
  1500
	test(capsT[0]==capsP[0]);
sl@0
  1501
	test(capsT[1]==capsP[1]);
sl@0
  1502
	// Check the caps match what the user API gives
sl@0
  1503
	RProcess this_process;
sl@0
  1504
	for (TInt i=0 ; i<64 ; i++) {
sl@0
  1505
		TCapability cap = (TCapability)i;
sl@0
  1506
		test(infoProcess.iCaps.HasCapability(cap) == this_process.HasCapability(cap));
sl@0
  1507
	}
sl@0
  1508
sl@0
  1509
sl@0
  1510
	ldd.Close();
sl@0
  1511
	}
sl@0
  1512
sl@0
  1513
sl@0
  1514
void TestPlatSecUnlocked()
sl@0
  1515
	{
sl@0
  1516
	RLddTest ldd;
sl@0
  1517
	TInt r = User::LoadLogicalDevice(_L("D_SLDD.LDD"));
sl@0
  1518
	test(r == KErrNone || r == KErrAlreadyExists);
sl@0
  1519
	r = ldd.OpenLocal();
sl@0
  1520
	test_KErrNone(r);
sl@0
  1521
sl@0
  1522
	TUint32 flags0, flags;
sl@0
  1523
	TInt enforced;
sl@0
  1524
sl@0
  1525
	flags0 = ldd.GetKernelConfigFlags();
sl@0
  1526
sl@0
  1527
	const TUint32 bits = (TUint32)(EKernelConfigTest | EKernelConfigPlatSecEnforcement);
sl@0
  1528
sl@0
  1529
	// Different test cases depending on whether __PLATSEC_UNLOCKED__ defined.
sl@0
  1530
	// Ask the kernel whether EKernelConfigPlatSecLocked is set, and hope that
sl@0
  1531
	// it's not lying to us!
sl@0
  1532
	//
sl@0
  1533
	// Best thing to do is to check the log and verify the printf() output.
sl@0
  1534
	//
sl@0
  1535
sl@0
  1536
	if (PlatSec::ConfigSetting(PlatSec::EPlatSecLocked))
sl@0
  1537
		{
sl@0
  1538
		/*
sl@0
  1539
		 * Tests for __PLATSEC_UNLOCKED__ not defined
sl@0
  1540
		 *
sl@0
  1541
		 * The device driver is built with __PLATSEC_FORCED_FLAGS__ set to 0, so we can't use
sl@0
  1542
		 * its GetKernelConfigFlags() interface (the accessor functions are inlines) when we're
sl@0
  1543
		 * testing for PlatSec locked.  Instead, use PlatSec::ConfigSetting(), which makes an
sl@0
  1544
		 * exec call to get iKernelConfigFlags.
sl@0
  1545
		 */
sl@0
  1546
		test.Printf(_L("__PLATSEC_UNLOCKED_ does NOT appear to have been used\n"));
sl@0
  1547
sl@0
  1548
		/* Check that PlatSecEnforcement is set */
sl@0
  1549
		enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
sl@0
  1550
		test(enforced != 0);
sl@0
  1551
sl@0
  1552
		/* Check that the device driver is able to set our test bit */
sl@0
  1553
		ldd.SetKernelConfigFlags(flags0 | EKernelConfigTest);
sl@0
  1554
sl@0
  1555
		flags = ldd.GetKernelConfigFlags();
sl@0
  1556
		test((flags & EKernelConfigTest) == EKernelConfigTest);
sl@0
  1557
sl@0
  1558
		/* Check that the device driver is able to clear our test bit, but not able to clear enforcement bit */
sl@0
  1559
		ldd.SetKernelConfigFlags(flags0 & ~bits);
sl@0
  1560
sl@0
  1561
		enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
sl@0
  1562
		test(enforced != 0);
sl@0
  1563
		}
sl@0
  1564
	else
sl@0
  1565
		{
sl@0
  1566
		/*
sl@0
  1567
		 * Tests for __PLATSEC_UNLOCKED__ defined
sl@0
  1568
		 */
sl@0
  1569
		test.Printf(_L("__PLATSEC_UNLOCKED_ DOES appear to have been used\n"));
sl@0
  1570
sl@0
  1571
		/* Check that the device driver is able to set our test bit and PlatSecEnforcement */
sl@0
  1572
		ldd.SetKernelConfigFlags(flags0 | bits);
sl@0
  1573
sl@0
  1574
		flags = ldd.GetKernelConfigFlags();
sl@0
  1575
		test((flags & bits) == bits);
sl@0
  1576
sl@0
  1577
		/* And verify that the kernel sees the same result */
sl@0
  1578
		enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
sl@0
  1579
		test(enforced != 0);			// (yes, "!= 0" is redundant)
sl@0
  1580
sl@0
  1581
		/* Check that the device driver is able to clear our test bit and PlatSecEnforcement */
sl@0
  1582
		ldd.SetKernelConfigFlags(flags0 & ~bits);
sl@0
  1583
sl@0
  1584
		flags = ldd.GetKernelConfigFlags();
sl@0
  1585
		test((flags & bits) == 0);
sl@0
  1586
sl@0
  1587
		/* Verify that the kernel sees the same result */
sl@0
  1588
		enforced = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
sl@0
  1589
		test(enforced == 0);
sl@0
  1590
		}
sl@0
  1591
sl@0
  1592
	/* Restore original flags value */
sl@0
  1593
	ldd.SetKernelConfigFlags(flags0);
sl@0
  1594
sl@0
  1595
	// Now test handling of iDisabledCapabilities
sl@0
  1596
sl@0
  1597
	const TUint32 test_value = 0x31415926;						// Just some random number
sl@0
  1598
sl@0
  1599
	TCapabilitySet disabled0, disabled;
sl@0
  1600
	disabled0.SetDisabled();
sl@0
  1601
sl@0
  1602
	SCapabilitySet *caps0 = (SCapabilitySet *)&disabled0;
sl@0
  1603
	SCapabilitySet *caps = (SCapabilitySet *)&disabled;
sl@0
  1604
sl@0
  1605
	if (PlatSec::ConfigSetting(PlatSec::EPlatSecLocked))
sl@0
  1606
		{
sl@0
  1607
		/*
sl@0
  1608
		 * Tests for __PLATSEC_UNLOCKED__ not defined
sl@0
  1609
		 */
sl@0
  1610
sl@0
  1611
		/* Check that the capability set is 0 */
sl@0
  1612
		int i;
sl@0
  1613
sl@0
  1614
		for (i = 0; i < SCapabilitySet::ENCapW; i++)
sl@0
  1615
			{
sl@0
  1616
			test_Equal(0, caps0->iCaps[i]);
sl@0
  1617
			}
sl@0
  1618
sl@0
  1619
		/* Check that the device driver is not able to set word 0 of disabled capabilities */
sl@0
  1620
		ldd.SetDisabledCapabilities0(test_value);
sl@0
  1621
sl@0
  1622
		/*
sl@0
  1623
		 * It's okay to use SetDisabled() here, since this makes an exec call to get the
sl@0
  1624
		 * set of disabled capabilities.
sl@0
  1625
		 */
sl@0
  1626
		disabled.SetDisabled();
sl@0
  1627
		test_Equal(0, caps->iCaps[0]);
sl@0
  1628
		}
sl@0
  1629
	else
sl@0
  1630
		{
sl@0
  1631
		/*
sl@0
  1632
		 * Tests for __PLATSEC_UNLOCKED__ defined
sl@0
  1633
		 */
sl@0
  1634
sl@0
  1635
		/* Check that the device driver is able to set word 0 of disabled capabilities */
sl@0
  1636
		ldd.SetDisabledCapabilities0(test_value);
sl@0
  1637
sl@0
  1638
		disabled.SetDisabled();
sl@0
  1639
		test_Equal(test_value, caps->iCaps[0]);
sl@0
  1640
		}
sl@0
  1641
sl@0
  1642
	/* Restore original value */
sl@0
  1643
	ldd.SetDisabledCapabilities0(caps0->iCaps[0]);
sl@0
  1644
sl@0
  1645
	ldd.Close();
sl@0
  1646
	}
sl@0
  1647
sl@0
  1648
#include <e32svr.h>
sl@0
  1649
sl@0
  1650
GLDEF_C TInt E32Main()
sl@0
  1651
    {
sl@0
  1652
	PlatSecEnforcement = PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement);
sl@0
  1653
sl@0
  1654
	TBuf16<512> cmd;
sl@0
  1655
	User::CommandLine(cmd);
sl@0
  1656
	if(cmd.Length() && TChar(cmd[0]).IsDigit())
sl@0
  1657
		{
sl@0
  1658
		TInt function = -1;
sl@0
  1659
		TInt arg1 = -1;
sl@0
  1660
		TInt arg2 = -1;
sl@0
  1661
		TLex lex(cmd);
sl@0
  1662
sl@0
  1663
		lex.Val(function);
sl@0
  1664
		lex.SkipSpace();
sl@0
  1665
		lex.Val(arg1);
sl@0
  1666
		lex.SkipSpace();
sl@0
  1667
		lex.Val(arg2);
sl@0
  1668
		return DoTestProcess(function,arg1,arg2);
sl@0
  1669
		}
sl@0
  1670
sl@0
  1671
	test.Title();
sl@0
  1672
sl@0
  1673
	if(PlatSecEnforcement)
sl@0
  1674
		test.Printf(_L("PlatSecConfig appears to be ON\n"));
sl@0
  1675
	else
sl@0
  1676
		test.Printf(_L("PlatSecConfig appears to be OFF\n"));
sl@0
  1677
sl@0
  1678
	test.Start(_L("Starting test server"));
sl@0
  1679
	RTestProcess server;
sl@0
  1680
	TRequestStatus rendezvous;
sl@0
  1681
	server.Create(~KTestCapabilities,ETestProcessServer,0,0);
sl@0
  1682
	server.Rendezvous(rendezvous);
sl@0
  1683
	server.Resume();
sl@0
  1684
	User::WaitForRequest(rendezvous);
sl@0
  1685
	test(rendezvous==KServerRendezvous);
sl@0
  1686
sl@0
  1687
	test.Next(_L("Openning server session"));
sl@0
  1688
	TInt r = Session.Connect();
sl@0
  1689
	RDebug::Print(_L("%d"),r);
sl@0
  1690
	test(r==KErrNone);
sl@0
  1691
sl@0
  1692
	test.Next(_L("Test Capability Names"));
sl@0
  1693
	TestCapabilityNames();
sl@0
  1694
sl@0
  1695
	test.Next(_L("Test TCapabilitySet"));
sl@0
  1696
	TestCapabilitySet();
sl@0
  1697
sl@0
  1698
	test.Next(_L("Test TSecurityInfo"));
sl@0
  1699
	TestSecurityInfo();
sl@0
  1700
sl@0
  1701
	test.Next(_L("Test SecureId functions"));
sl@0
  1702
	TestSecureId();
sl@0
  1703
sl@0
  1704
	test.Next(_L("Test VendorId functions"));
sl@0
  1705
	TestVendorId();
sl@0
  1706
sl@0
  1707
	test.Next(_L("Test HasCapability functions"));
sl@0
  1708
	TestHasCapability();
sl@0
  1709
sl@0
  1710
	test.Next(_L("Test TSecurityPolicy"));
sl@0
  1711
	TestSecurityPolicy();
sl@0
  1712
sl@0
  1713
	test.Next(_L("Test Kernel APIs"));
sl@0
  1714
	TestKernelAPIs();
sl@0
  1715
sl@0
  1716
	test.Next(_L("Test __PLATSEC_UNLOCKED__"));
sl@0
  1717
	TestPlatSecUnlocked();
sl@0
  1718
sl@0
  1719
	test.Next(_L("Test diagnostic message suppression"));
sl@0
  1720
	RThread().HasCapability(ECapabilityReadUserData,0);
sl@0
  1721
	test.Printf(_L("There should be a diagnostic message just before this\n"));
sl@0
  1722
	RThread().HasCapability(ECapabilityReadUserData,__PLATSEC_DIAGNOSTIC_STRING("You should see this"));
sl@0
  1723
	test.Printf(_L("There should be a diagnostic message just before this\n"));
sl@0
  1724
	RThread().HasCapability(ECapabilityReadUserData,KSuppressPlatSecDiagnostic);
sl@0
  1725
	test.Printf(_L("There should NOT be a diagnostic message just before this\n"));
sl@0
  1726
sl@0
  1727
	test.Next(_L("Closing server session"));
sl@0
  1728
	Session.Send(CTestSession::EShutdown);
sl@0
  1729
	Session.Close();
sl@0
  1730
	server.Close();
sl@0
  1731
sl@0
  1732
	test.End();
sl@0
  1733
	return(0);
sl@0
  1734
    }
sl@0
  1735