pkiutilities/ocsp/test/command.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "command.h"
       
    17 #include "engine.h"
       
    18 #include "panic.h"
       
    19 #include "logger.h"
       
    20 #include "result.h"
       
    21 
       
    22 #include "TEFparser.h"
       
    23 #include <f32file.h>
       
    24 #include <utf.h>
       
    25 
       
    26 // Define the commands the user can use in the input script
       
    27 
       
    28 // *****************  General  ************************
       
    29 
       
    30 // Comment prefix for input file
       
    31 _LIT(KTOCSPCommandComment,		"REM");
       
    32 
       
    33 // Print remaining text to console
       
    34 _LIT(KTOCSPCommandPrint,		"PRINT");
       
    35 
       
    36 // Bail out at this point
       
    37 _LIT(KTOCSPCommandAbort,		"ABORT");
       
    38 
       
    39 // NOTE: Skips CAN be nested
       
    40 // Skip everything unil KTOCSPCommandEndSkip
       
    41 _LIT(KTOCSPCommandSkip,			"SKIP");
       
    42 
       
    43 // Stop skipping - does nothing if not skipping
       
    44 _LIT(KTOCSPCommandEndSkip,		"ENDSKIP");
       
    45 
       
    46 // ************ Configuring the request ***************
       
    47 
       
    48 // Start a new OCSP request/response transaction
       
    49 // Has exactly one parameter - the name of the test (which must not include spaces)
       
    50 _LIT(KTOCSPCommandStart,		"START");
       
    51 
       
    52 // Set the URI of the server
       
    53 _LIT(KTOCSPCommandSetURI,		"SETURI");
       
    54 
       
    55 
       
    56 // Parameter is a file from which to read a cert
       
    57 _LIT(KTOCSPCommandCert,			"REQUESTCERT");
       
    58 
       
    59 // Parameter is ON or OFF
       
    60 _LIT(KTOCSPCommandNonce,        "NONCE");
       
    61 
       
    62 // ************ Handling the communication *************
       
    63 
       
    64 // Set transport scheme for communication
       
    65 // Parameter DEFAULT means let the OCSP module deal with the transport
       
    66 // Parameter TEST means use the test harness server
       
    67 _LIT(KTOCSPCommandSetTransport,	"TRANSPORT");
       
    68 
       
    69 // ******* Configuring + performing the validation ********
       
    70 
       
    71 // Set transport retry count
       
    72 // Takes one parameter, the retry count (1 means no retry)
       
    73 // NOTE: This command must appear after the TRANSPORT command
       
    74 _LIT(KTOCSPCommandSetTransportRetry, "TRANSPORTRETRY");
       
    75 
       
    76 // Set transport timeout
       
    77 // Takes one parameter, the timeout value in milliseconds
       
    78 // NOTE: This command must appear after the TRANSPORT command
       
    79 _LIT(KTOCSPCommandSetTransportTimeout, "TRANSPORTTIMEOUT");
       
    80 
       
    81 // Set validation date, parameters are YYYY MM DD HH MM - optional
       
    82 _LIT(KTOCSPCommandValidationDate, "VALIDATIONDATE");
       
    83 
       
    84 // Parameter is a file containing a cert to be set as valid for authorisation of
       
    85 // the response.  Can call more than once.
       
    86 _LIT(KTOCSPCommandDirectAuthorisation, "AUTHORISATIONCERT");
       
    87 
       
    88 // No parameters - tells test client to use ca delegate authorisation.
       
    89 // (See RFC2560 S2.2, S4.2.2.2)
       
    90 _LIT(KTOCSPCommandCADelegateAuthorisation, "CADELEGATE");
       
    91 
       
    92 // No parameters - tells test client to use direct signing by ca.
       
    93 // see (RFC 2560 S2.2)
       
    94 _LIT(KTOCSPCommandCADirectAuthorisation, "CADIRECT");
       
    95 
       
    96 // No parameters - tells test client to use all schemes
       
    97 // see (RFC 2560 S2.2)
       
    98 _LIT(KTOCSPCommandAllAuthorisationSchemes, "ALLSCHEMES");
       
    99 
       
   100 // Set the maximum allowable age of the status returned.  Parameter is in
       
   101 // seconds, or "OFF" to disable checking.
       
   102 _LIT(KTOCSPCommandSetMaxStatusAge, "SETMAXSTATUSAGE");
       
   103 
       
   104 // Set http filter parameters
       
   105 // The parameters to FILTERPARAMS command are:
       
   106 // numDelayResp countDropResp countCorruptHTTPDataHeader countCorruptHTTPDataBodySizeLarge countCorruptHTTPDataBodySizeSmall countCorruptOCSPData countInternalErrorResp countTryLaterResp
       
   107 // where:
       
   108 // 		numDelayResp - Delays response by specified number of milliseconds
       
   109 //		countDropResp - Drops specified number of responses
       
   110 //		countCorruptHTTPDataHeader - Corrupts specified number of responses (content-type in header is corrupted)
       
   111 //		countCorruptHTTPDataBodySizeLarge - Corrupts specified number of responses (body is of larger size than expected)
       
   112 //		countCorruptHTTPDataBodySizeSmall - Corrupts specified number of responses (body is of smaller size than expected)
       
   113 //		countCorruptOCSPData - Corrupts specified number of responses (OCSPResponse data is corrupted)
       
   114 //		countInternalErrorResp - Returns an "internalError" response for specified number of requests
       
   115 //		countTryLaterResp - Returns a "tryLater" response for specified number of requests
       
   116 //		countSigValidateFailure - Causes a signature validation failure by corrupting the Responder ID
       
   117 // NOTE: This command must appear after the TRANSPORT command
       
   118 _LIT(KTOCSPCommandSetFilterParams, "FILTERPARAMS");
       
   119 
       
   120 
       
   121 // Cancel the OCSP check after its issued
       
   122 // The parameter is the time in milliseconds to wait before issuing the cancel
       
   123 // Note that this command must appear before the CHECK command
       
   124 _LIT(KTOCSPCommandCancel, "CANCEL");
       
   125 
       
   126 // Run the OCSP check
       
   127 _LIT(KTOCSPCommandCheck, "CHECK");
       
   128 
       
   129 // Tests that the revocation check was cancelled
       
   130 _LIT(KTOCSPCommandTestCancel, "TESTCANCEL");
       
   131 
       
   132 // Tests that the summary result is as expected.  Takes one parameter, the
       
   133 // expected result.
       
   134 _LIT(KTOCSPCommandTestSummary, "TESTSUMMARY");
       
   135 
       
   136 // Tests that the outcome for a certificate is as expected.  Takes three
       
   137 // paramters, the certificate index, the expected status and the expected result
       
   138 _LIT(KTOCSPCommandTestOutcome, "TESTOUTCOME");
       
   139 
       
   140 // Tests that the outcome for the tranport is as expected. Takes four
       
   141 // paramters, the retry count number (0 means first attempt), the expected HTTP method, 
       
   142 // and the range of time in milliseconds (min max) within which each request should complete
       
   143 // NOTE: The usage of this command assumes only one certificate is being
       
   144 // checked for revocation per test case! (also means CHECKRESPONDERCERT command cannot be used with this)
       
   145 _LIT(KTOCSPCommandTestTransport, "TESTTRANSPORT");
       
   146 
       
   147 // Tests that the outcome for the retry attempts is as expected. 
       
   148 // Takes one paramter, the retry count (1 means single attempt ie. no retry)
       
   149 // NOTE: The usage of this command assumes only one certificate is being
       
   150 // checked for revocation per test case! (also means CHECKRESPONDERCERT command cannot be used with this)
       
   151 _LIT(KTOCSPCommandTestTransportRetry, "TESTTRANSPORTRETRY");
       
   152 
       
   153 // Log the reponses to a file.  The filename is the only parameter.
       
   154 // This command must be placed after the CHECK command
       
   155 _LIT(KTOCSPCommandLogResponse, "LOGRESPONSE");
       
   156 
       
   157 // Log the requests to a file.  The filename is the only parameter.
       
   158 // This command must be placed before the TRANSPORT command
       
   159 _LIT(KTOCSPCommandLogRequest, "LOGREQUEST");
       
   160 
       
   161 // End a test
       
   162 _LIT(KTOCSPCommandEnd, "END");
       
   163 
       
   164 // parameter for setting whether the ocsp status check 
       
   165 // for responder certificate should be done or not.
       
   166 _LIT(KTOCSPCheckResponderCert, "CHECKRESPONDERCERT");
       
   167 
       
   168 _LIT(KTOCSPAddCertToStore, "ADDCERTTOSTORE");
       
   169 
       
   170 _LIT(KTOCSPUseAIA, "USEAIA");
       
   171 
       
   172 _LIT(KTOCSPCheckCertsWithAiaOnly, "CHECKCERTSWITHAIAONLY");
       
   173 
       
   174 _LIT(KTOCSPExpectedError, "EXPECTEDERROR");
       
   175 
       
   176 // ************* Parameter definitions *****************
       
   177 
       
   178 // Default transport (currently only HTTP)
       
   179 _LIT(KTOCSPDefaultTransport,		"DEFAULT");
       
   180 
       
   181 _LIT(KTOCSPTestTransport,			"TEST");
       
   182 
       
   183 _LIT(KTOCSPOcspSupportTransport,	"OCSPSUPPORT");
       
   184 
       
   185 // Generic parameter for toggle of settings.
       
   186 _LIT(KTOCSPOn,  "ON");
       
   187 _LIT(KTOCSPOff, "OFF");
       
   188 
       
   189 _LIT(KTOCSPEnable,  "ENABLE");
       
   190 _LIT(KTOCSPDisable, "DISABLE");
       
   191 _LIT(KTOCSPEnableDisable,"ENABLE|DISABLE");
       
   192 
       
   193 
       
   194 CTOCSPCommand* CTOCSPCommand::NewL(CTOCSPLogger& aLog,
       
   195 								   CTOCSPResult& aResult,	
       
   196 								   TInt aTransaction)
       
   197 	{
       
   198 	CTOCSPCommand* self = new (ELeave) CTOCSPCommand(aLog, aResult, aTransaction);
       
   199 	CleanupStack::PushL(self);
       
   200 	self->ConstructL();
       
   201 	CleanupStack::Pop(self);
       
   202 	return self;
       
   203 	}
       
   204 
       
   205  
       
   206 CTOCSPCommand::CTOCSPCommand(CTOCSPLogger& aLog,
       
   207 							 CTOCSPResult& aResult,
       
   208 							 TInt aTransaction) :
       
   209 	CActive(EPriorityNormal),
       
   210 	iResult(aResult),
       
   211 	iLog(aLog),
       
   212 	iTestToProcess(aTransaction)
       
   213 	{
       
   214 	CActiveScheduler::Add(this);
       
   215 	}
       
   216 
       
   217 
       
   218 void CTOCSPCommand::ConstructL()
       
   219 	{
       
   220 	iEngine = CTOCSPEngine::NewL(iLog);
       
   221 	}
       
   222 
       
   223 
       
   224 CTOCSPCommand::~CTOCSPCommand()
       
   225 	{
       
   226     Cancel();
       
   227 	delete iEngine;
       
   228 	iTokens.Close();
       
   229 	}
       
   230 
       
   231 
       
   232 void CTOCSPCommand::ResetL()
       
   233     {
       
   234 	FinishedTestL();
       
   235     iTestIndex = 0;
       
   236     iTestToProcess = 0;
       
   237     }
       
   238 
       
   239 
       
   240 TInt CTOCSPCommand::CurrentTransaction() const
       
   241     {
       
   242     return iTestIndex;
       
   243     }
       
   244 
       
   245 
       
   246 TBool CTOCSPCommand::ProcessCommand(const TDesC& aLine, TRequestStatus& aStatus)
       
   247 	{
       
   248 	iOriginalRequestStatus = &aStatus;
       
   249 
       
   250     TBool result = ETrue;
       
   251     TRAPD(err, result = DoProcessCommandL(aLine));
       
   252     if (err != KErrNone)
       
   253         {
       
   254         Cancel();
       
   255         User::RequestComplete(iOriginalRequestStatus, err);
       
   256         }
       
   257 
       
   258     return result;
       
   259     }
       
   260 
       
   261 
       
   262 TBool CTOCSPCommand::DoProcessCommandL(const TDesC& aLine)
       
   263 	{
       
   264 	*iOriginalRequestStatus = KRequestPending;
       
   265 
       
   266 	if (!iVerbose)
       
   267 		{
       
   268 		iLog.LogL(_L("."), ETrue);
       
   269 		}
       
   270 
       
   271 	TLex lex(aLine);
       
   272 
       
   273     // Empty line
       
   274     if (lex.Eos())
       
   275         {
       
   276         User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   277         return ETrue;
       
   278         }
       
   279 
       
   280     TPtrC command = lex.NextToken();
       
   281 
       
   282     // Handle skipping commands
       
   283 	if (command == KTOCSPCommandSkip)
       
   284 		{
       
   285 		++iSkipping;
       
   286 		}
       
   287 	else if (command == KTOCSPCommandEndSkip)
       
   288 		{
       
   289         --iSkipping;
       
   290 		if (iSkipping < 0)
       
   291 			{
       
   292             User::RequestComplete(iOriginalRequestStatus, KErrCorrupt);
       
   293 			return ETrue;
       
   294 			}
       
   295 		}
       
   296 
       
   297 	LogCommandL(aLine);
       
   298 
       
   299 	if (iSkipping)
       
   300 		{
       
   301 		User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   302         return ETrue;
       
   303 		}
       
   304 
       
   305 	if (command == KTOCSPCommandSkip || command == KTOCSPCommandEndSkip)
       
   306 		{
       
   307 		User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   308         return ETrue;
       
   309 		}
       
   310 
       
   311 	if (command == KTOCSPCommandStart)
       
   312 		{
       
   313 		++iTestIndex;
       
   314 		}
       
   315 
       
   316     // Don't process any tests except the ones we're interested in
       
   317     if (iTestToProcess != 0 && iTestToProcess != iTestIndex)
       
   318         {   
       
   319 		User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   320         return ETrue;
       
   321         }
       
   322 
       
   323 	// Handle comment and print commands
       
   324 	if (command == KTOCSPCommandComment)
       
   325 		{
       
   326 		// Remark - nothing to do except move on to next line
       
   327 		User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   328         return ETrue;
       
   329 		}
       
   330 	else if (command == KTOCSPCommandPrint)
       
   331 		{
       
   332 		lex.SkipSpace();
       
   333 		PrintCommandL(lex.Remainder());
       
   334         return ETrue;
       
   335 		}
       
   336 
       
   337     // Now split the rest of the command into tokens
       
   338 	iTokens.Reset();
       
   339 	while (!lex.Eos())
       
   340 		{
       
   341 		User::LeaveIfError(iTokens.Append(lex.NextToken()));
       
   342 		}
       
   343     
       
   344     // Check commands that don't have to occur in tests
       
   345 	if (command == KTOCSPCommandAbort)
       
   346 		{
       
   347 		User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   348 		return EFalse;
       
   349 		}
       
   350 	else if (command == KTOCSPCommandStart)
       
   351         {
       
   352 		StartCommandL();
       
   353 		}
       
   354 	else if (command == KTOCSPCommandEnd)
       
   355         {
       
   356 		EndCommandL();
       
   357 		}
       
   358 	else
       
   359 		{
       
   360 		return ProcessTestCommandL(command);
       
   361 		}
       
   362 
       
   363 	return ETrue;
       
   364 	}
       
   365 
       
   366 
       
   367 TBool CTOCSPCommand::ProcessTestCommandL(const TDesC& command)
       
   368 	{
       
   369 	if (!iInsideTest)
       
   370 		{
       
   371 		iLog.LogL(_L("Command cannot occur outside test: "));
       
   372 		iLog.LogL(command);
       
   373 		iLog.NewLineL();
       
   374 		User::Leave(KErrCorrupt);
       
   375 		}
       
   376 
       
   377     // Check the other commands that can only occur in tests
       
   378 	if (command == KTOCSPCommandSetURI)
       
   379 		{
       
   380 		SetURICommandL();
       
   381 		}
       
   382 	else if (command == KTOCSPCommandSetTransport)
       
   383 		{
       
   384 		SetTransportCommandL();
       
   385 		}
       
   386 	else if (command == KTOCSPCommandSetTransportRetry)
       
   387 		{
       
   388 		SetTransportRetryCommandL();
       
   389 		}
       
   390 	else if (command == KTOCSPCommandSetTransportTimeout)
       
   391 		{
       
   392 		SetTransportTimeoutCommandL();
       
   393 		}
       
   394 	else if (command == KTOCSPCommandCert)
       
   395 		{
       
   396 		CertCommandL();
       
   397 		}
       
   398 	else if (command == KTOCSPCommandValidationDate)
       
   399 		{
       
   400 		ValidationDateCommandL();
       
   401 		}
       
   402 	else if (command == KTOCSPCommandDirectAuthorisation)
       
   403 		{
       
   404 		DirectAuthorisationCommandL();
       
   405 		}
       
   406 	else if (command == KTOCSPCommandCADelegateAuthorisation)
       
   407 		{
       
   408 		CADelegateAuthorisationCommandL();
       
   409 		}
       
   410 	else if (command == KTOCSPCommandCADirectAuthorisation)
       
   411 		{
       
   412 		CADirectAuthorisationCommandL();
       
   413 		}
       
   414 	else if (command == KTOCSPCommandAllAuthorisationSchemes)
       
   415 		{
       
   416 		AllAuthorisationSchemesCommandL();
       
   417 		}
       
   418 	else if (command == KTOCSPCommandSetMaxStatusAge)
       
   419 		{
       
   420 		SetMaxStatusAgeCommandL();
       
   421 		}
       
   422 	else if (command == KTOCSPCommandSetFilterParams)
       
   423 		{
       
   424 		SetFilterParamsCommandL();
       
   425 		}
       
   426 	else if (command == KTOCSPCommandCancel)
       
   427 		{
       
   428 		CancelCommandL();
       
   429 		}
       
   430 	else if (command == KTOCSPCommandCheck)
       
   431 		{
       
   432 		CheckCommand();
       
   433 		}
       
   434 	else if (command == KTOCSPCommandTestCancel)
       
   435 		{
       
   436 		TestCancelCommand();
       
   437 		}
       
   438 	else if (command == KTOCSPCommandTestSummary)
       
   439 		{
       
   440 		TestSummaryCommandL();
       
   441 		}
       
   442 	else if (command == KTOCSPCommandTestOutcome)
       
   443 		{
       
   444 		TestOutcomeCommandL();
       
   445 		}
       
   446 	else if (command == KTOCSPCommandTestTransport)
       
   447 		{
       
   448 		TestTransportCommandL();
       
   449 		}
       
   450 	else if (command == KTOCSPCommandTestTransportRetry)
       
   451 		{
       
   452 		TestTransportRetryCommandL();
       
   453 		}
       
   454 	else if (command == KTOCSPCommandNonce)
       
   455 		{
       
   456 		SetNonceCommandL();
       
   457 		}
       
   458 	else if (command == KTOCSPCommandLogResponse)
       
   459 		{
       
   460 		LogResponseCommandL();
       
   461 		}
       
   462 	else if (command == KTOCSPCommandLogRequest)
       
   463 		{
       
   464 		LogRequestCommandL();
       
   465 		}
       
   466 	else if (command == KTOCSPCheckResponderCert)
       
   467 		{
       
   468 		SetResponderCertCheck();
       
   469 		}
       
   470 	else if(command == KTOCSPAddCertToStore)
       
   471 		{
       
   472 		AddCertToStoreL();
       
   473 		}
       
   474 	else if(command ==  KTOCSPCheckCertsWithAiaOnly )
       
   475 		{
       
   476 		SetCheckCertsWithAiaOnly();
       
   477 		}
       
   478 	else if(command  == KTOCSPUseAIA)
       
   479 		{
       
   480 		SetUseAIAL();
       
   481 		}
       
   482 	else if(command == KTOCSPExpectedError)
       
   483 		{
       
   484 		LogErrorL();
       
   485 		}
       
   486 	else
       
   487 		{
       
   488 		UnknownCommandL(command);
       
   489 		}
       
   490 
       
   491 	return ETrue;
       
   492 	}
       
   493 
       
   494 void CTOCSPCommand::LogErrorL()
       
   495 	{
       
   496 	if (iTokens.Count() != 1)
       
   497 		{
       
   498 		WrongNumberOfArgumentsL();
       
   499 		}
       
   500 
       
   501 	TLex expectedErrorLex(iTokens[0]);
       
   502 	TInt expectedError = 0;
       
   503 	User::LeaveIfError(expectedErrorLex.Val(expectedError));
       
   504 
       
   505 	iTestResult = (expectedError == iError)?ETrue:EFalse;
       
   506 
       
   507 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   508 
       
   509 	}
       
   510 
       
   511 void CTOCSPCommand::RunL()
       
   512 	{
       
   513 	TInt err = iStatus.Int();
       
   514 
       
   515 	// The engine does not get a chance to process the cancel notification so we handle it here
       
   516 	if (err == KErrCancel)
       
   517 		{
       
   518 		// Cancel expected
       
   519 		iCheckCancelled = ETrue;
       
   520 		}
       
   521 	else
       
   522 		{
       
   523 		User::LeaveIfError(err);
       
   524 		}
       
   525 
       
   526 	switch (iState)
       
   527 		{
       
   528 		case EEngineStart:
       
   529 		case EEngineEnd:
       
   530 		case EDirectAuthorisationCommand:
       
   531 		case ECheckCommand:			
       
   532 			User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   533 			break;
       
   534 
       
   535 		default:
       
   536             User::Panic(_L("TOCSP"), 1);
       
   537 			break;
       
   538 		}
       
   539 	}
       
   540 
       
   541 TInt CTOCSPCommand::RunError(TInt aError)
       
   542     {
       
   543     iError = aError;
       
   544     User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   545     return KErrNone;
       
   546     }
       
   547 
       
   548 void CTOCSPCommand::DoCancel()
       
   549 	{
       
   550 	switch (iState)
       
   551 		{
       
   552 		case EEngineStart:
       
   553 		case EEngineEnd:
       
   554 		case EDirectAuthorisationCommand:
       
   555 		case ECheckCommand:
       
   556 			iEngine->Cancel();
       
   557 			break;
       
   558 			
       
   559 		default:
       
   560             User::Panic(_L("TOCSP"), 1);
       
   561 			break;
       
   562 		}
       
   563 	}
       
   564 
       
   565 void CTOCSPCommand::LogCommandL(const TDesC& aLine)
       
   566 	{
       
   567 	if (iVerbose)
       
   568 		{
       
   569 		// To file only
       
   570 		if (iSkipping)
       
   571 			{
       
   572 			iLog.LogL(_L("Skipped: "), EFalse);
       
   573 			}
       
   574 		else
       
   575 			{
       
   576 			iLog.LogL(_L("Input: "), EFalse);
       
   577 			}
       
   578 
       
   579 		iLog.LogL(aLine, EFalse);		
       
   580 		
       
   581 		TInt match;
       
   582 		_LIT(KMatch,"*START*");
       
   583 		match = aLine.Match(KMatch);
       
   584 		if (match==0)
       
   585 			{
       
   586 		iTmsId.Copy(TEFparser::ParseNthElement(aLine,2));
       
   587 		
       
   588 		TBuf<64> timeBuf;
       
   589 		TTime time;
       
   590 		time.UniversalTime();
       
   591 		TDateTime dateTime = time.DateTime();
       
   592 		_LIT(KDateFormat,"%02d:%02d:%02d:%03d "); 
       
   593 		timeBuf.AppendFormat(KDateFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),(dateTime.MicroSecond()/1000));
       
   594 		
       
   595 		iLog.LogL(_L("\r\n"));
       
   596 		iLog.LogL(timeBuf);	
       
   597 		iLog.LogL(_L("Command = START_TESTCASE "));
       
   598 		iLog.LogL(iTmsId);
       
   599 			}	        
       
   600 		iLog.LogL(_L("\n"));
       
   601 		}
       
   602 	}
       
   603 
       
   604 
       
   605 void CTOCSPCommand::UnknownCommandL(const TDesC& aCommand)
       
   606 	{
       
   607 	// Log to screen and file
       
   608 	iLog.LogL(_L("Unrecognised command \""), ETrue);
       
   609 	iLog.LogL(aCommand);
       
   610 	iLog.LogL(_L("\" - aborting\n"));
       
   611 	
       
   612 	User::RequestComplete(iOriginalRequestStatus, KErrCorrupt);
       
   613 	}
       
   614 
       
   615 
       
   616 void CTOCSPCommand::PrintCommandL(const TDesC& aMess)
       
   617 	{
       
   618 	if (iVerbose)
       
   619 		{
       
   620 		// To screen and file
       
   621 		iLog.LogL(aMess, ETrue);
       
   622 		iLog.LogL(_L("\n"), ETrue);
       
   623 		}
       
   624 
       
   625 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   626 	}
       
   627 
       
   628 
       
   629 void CTOCSPCommand::StartCommandL()
       
   630 	{
       
   631 	if (iInsideTest)
       
   632 		{
       
   633 		if (iVerbose)
       
   634 			{
       
   635 			iLog.LogL(_L("Misplaced START command: not inside test\n"));
       
   636 			}
       
   637 		User::Leave(KErrCorrupt);
       
   638 		}
       
   639 
       
   640 	if (iTokens.Count() != 1)
       
   641 		{
       
   642 		WrongNumberOfArgumentsL();
       
   643 		}
       
   644 
       
   645 	iInsideTest = ETrue;
       
   646 	iTestResult = ETrue;
       
   647 	iTransportSet = EFalse;
       
   648 
       
   649 	iResult.NewTestL(iTokens[0]);
       
   650 
       
   651 	if (iVerbose)
       
   652 		{
       
   653 		iLog.LogL(_L("Test: "));
       
   654 		iLog.LogL(iTokens[0]);
       
   655 		iLog.NewLineL();
       
   656 		}
       
   657 
       
   658 	iEngine->StartL(iStatus);
       
   659 	iState = EEngineStart;
       
   660 	SetActive();
       
   661 	}
       
   662 
       
   663 
       
   664 void CTOCSPCommand::EndCommandL()
       
   665 	{
       
   666 	if (!iInsideTest)
       
   667 		{
       
   668 		if (iVerbose)
       
   669 			{
       
   670 			iLog.LogL(_L("Misplaced END command: not inside test\n"));
       
   671 			}
       
   672 		User::Leave(KErrCorrupt);
       
   673 		}
       
   674 
       
   675 	iInsideTest = EFalse;
       
   676 	iCheckCancelled = EFalse;
       
   677 	FinishedTestL();
       
   678 
       
   679 	if (iVerbose)
       
   680 		{
       
   681 		iLog.NewLineL();
       
   682 		}
       
   683 
       
   684 	iEngine->EndL(iStatus);
       
   685 	iState = EEngineEnd;
       
   686 	SetActive();
       
   687 	}
       
   688 
       
   689 
       
   690 void CTOCSPCommand::SetURICommandL()
       
   691 	{
       
   692 	TInt tokenCount = iTokens.Count();
       
   693 	
       
   694 	if (tokenCount < 1 || tokenCount > 3) 
       
   695 		{
       
   696 		WrongNumberOfArgumentsL();
       
   697 		}
       
   698 	
       
   699 	// Need to convert from unicode (as in file) to 8-bit (as used by OCSP)
       
   700 	TBuf8<256> uri8;
       
   701 	uri8.Copy(iTokens[0]);
       
   702 	_LIT8(KNull,"NULL");
       
   703 	if(uri8.Compare(KNull) == 0)
       
   704 		{
       
   705 		uri8.FillZ();
       
   706 		}
       
   707 	if(tokenCount == 3 )
       
   708 		{
       
   709 		if(iTokens[1].Compare(KTOCSPUseAIA) != 0 )
       
   710 			{
       
   711 			InvalidArgumentL(KTOCSPUseAIA);
       
   712 			}
       
   713 		if(iTokens[2].Compare(KTOCSPEnable) == 0)
       
   714 			{
       
   715 			iEngine->SetURIL(uri8, ETrue);
       
   716 			}
       
   717 		else if(iTokens[2].Compare(KTOCSPDisable) == 0)
       
   718 			{
       
   719 			iEngine->SetURIL(uri8, EFalse);
       
   720 			}
       
   721 		else
       
   722 			{
       
   723 			InvalidArgumentL(KTOCSPUseAIA,KTOCSPEnableDisable);
       
   724 			}
       
   725 		}
       
   726 	else
       
   727 		{
       
   728 		// default value
       
   729 		iEngine->SetURIL(uri8, ETrue);
       
   730 		}
       
   731 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   732 	}
       
   733 
       
   734 void CTOCSPCommand::SetTransportCommandL()
       
   735 	{
       
   736 	if (iTokens.Count() == 0)
       
   737 		{
       
   738 		WrongNumberOfArgumentsL();
       
   739 		}
       
   740 
       
   741 	TPtrC parameter = iTokens[0];
       
   742 	if (parameter == KTOCSPDefaultTransport)
       
   743 		{
       
   744 		if (iTokens.Count() != 1)
       
   745 			{
       
   746 			WrongNumberOfArgumentsL();
       
   747 			}
       
   748 		iEngine->SetDefaultTransportL();
       
   749 		}
       
   750 	else if (parameter == KTOCSPTestTransport)
       
   751 		{
       
   752 		if (iTokens.Count() < 2 || iTokens.Count() > 3)
       
   753 			{
       
   754 			WrongNumberOfArgumentsL();
       
   755 			}
       
   756 
       
   757 		iEngine->SetTestTransportL(iTokens[1], iTokens.Count() == 3 ? &iTokens[2] : NULL);
       
   758 		}
       
   759 	else if (parameter == KTOCSPOcspSupportTransport)
       
   760 		{
       
   761 		if (iTokens.Count() != 1)
       
   762 			{
       
   763 			WrongNumberOfArgumentsL();
       
   764 			}
       
   765 
       
   766 		iEngine->SetOcspSupportTransportL();
       
   767 		}
       
   768 	iTransportSet = ETrue;
       
   769 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   770 	}
       
   771 
       
   772 void CTOCSPCommand::SetTransportRetryCommandL()
       
   773 	{
       
   774 	if (!iTransportSet)
       
   775 		{
       
   776 		if (iVerbose)
       
   777 			{
       
   778 			iLog.LogL(_L("Command sequence error: TRANSPORTRETRY must appear after TRANSPORT command\n"));
       
   779 			}
       
   780 		User::Leave(KErrCorrupt);
       
   781 		}
       
   782 
       
   783 	if (iTokens.Count() != 1)
       
   784 		{
       
   785 		WrongNumberOfArgumentsL();
       
   786 		}
       
   787 
       
   788 	TInt retryCount = 0;
       
   789 	TLex lex(iTokens[0]);
       
   790 	if ((lex.Val(retryCount) != KErrNone) || (retryCount < 0))
       
   791 		{
       
   792 		if (iVerbose)
       
   793 			{
       
   794 			iLog.LogL(_L("Invalid retry count in TRANSPORTRETRY command\n"));
       
   795 			}
       
   796 		User::Leave(KErrArgument);
       
   797 		}
       
   798 
       
   799 	iEngine->SetTransportRetryCount(static_cast<TUint>(retryCount));
       
   800 
       
   801 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   802 	}
       
   803 
       
   804 void CTOCSPCommand::SetTransportTimeoutCommandL()
       
   805 	{
       
   806 	if (!iTransportSet)
       
   807 		{
       
   808 		if (iVerbose)
       
   809 			{
       
   810 			iLog.LogL(_L("Command sequence error: TRANSPORTTIMEOUT must appear after TRANSPORT command\n"));
       
   811 			}
       
   812 		User::Leave(KErrCorrupt);
       
   813 		}
       
   814 
       
   815 	if (iTokens.Count() != 1)
       
   816 		{
       
   817 		WrongNumberOfArgumentsL();
       
   818 		}
       
   819 
       
   820 	TInt timeout = 0;
       
   821 	TLex lex(iTokens[0]);
       
   822 	if ((lex.Val(timeout) != KErrNone) || (timeout < -1))
       
   823 		{
       
   824 		if (iVerbose)
       
   825 			{
       
   826 			iLog.LogL(_L("Invalid timeout in TRANSPORTTIMEOUT command\n"));
       
   827 			}
       
   828 		User::Leave(KErrArgument);
       
   829 		}
       
   830 
       
   831 	iEngine->SetTransportTimeout(timeout);
       
   832 
       
   833 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   834 	}
       
   835 
       
   836 void CTOCSPCommand::SetNonceCommandL()
       
   837 	{
       
   838 	if (iTokens.Count() != 1)
       
   839 		{
       
   840 		WrongNumberOfArgumentsL();
       
   841 		}
       
   842 
       
   843 	TPtrC param = iTokens[0];
       
   844 	if (param == KTOCSPOn)
       
   845 		{
       
   846 		iEngine->SetNonce(ETrue);
       
   847 		}
       
   848 	else if (param == KTOCSPOff)
       
   849 		{
       
   850 		iEngine->SetNonce(EFalse);
       
   851 		}
       
   852 	else
       
   853 		{
       
   854 		User::Leave(KErrArgument);
       
   855 		}
       
   856 
       
   857 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   858 	}
       
   859 
       
   860 
       
   861 void CTOCSPCommand::CertCommandL()
       
   862 	{
       
   863 	if (iTokens.Count() != 2)
       
   864 		{
       
   865 		WrongNumberOfArgumentsL();
       
   866 		}
       
   867 
       
   868 	TPtrC subjectCert = iTokens[0];
       
   869 	TPtrC issuerCert = iTokens[1];
       
   870 
       
   871 	// Open file server session
       
   872 	RFs session;
       
   873 	User::LeaveIfError(session.Connect());
       
   874 	CleanupClosePushL(session);
       
   875 
       
   876 	HBufC8* subjectData = 0;
       
   877 	TRAPD(err, subjectData = Input::ReadFileL(subjectCert, session));
       
   878 	CleanupStack::PushL(subjectData);
       
   879 	if (err != KErrNone)
       
   880 		{
       
   881 		if (err != KErrNoMemory && iVerbose)
       
   882 			{
       
   883 			iLog.LogL(_L("Error opening "));
       
   884 			iLog.LogL(subjectCert);
       
   885 			}
       
   886 		User::Leave(err);
       
   887 		}
       
   888 
       
   889 	HBufC8* issuerData = 0;
       
   890 	TRAP(err, issuerData = Input::ReadFileL(issuerCert, session));
       
   891 	CleanupStack::PushL(issuerData);
       
   892 	if (err != KErrNone)
       
   893 		{
       
   894 		if (err != KErrNoMemory && iVerbose)
       
   895 			{
       
   896 			iLog.LogL(_L("Error opening "));
       
   897 			iLog.LogL(issuerCert);
       
   898 			}
       
   899 		User::Leave(err);
       
   900 		}
       
   901 
       
   902 	// Engine will actually read + own the cert
       
   903 	iEngine->AddCertL(*subjectData, *issuerData);
       
   904 
       
   905 	CleanupStack::PopAndDestroy(3); // issuerData, subjectData, close session
       
   906 
       
   907 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   908 	}
       
   909 
       
   910 
       
   911 void CTOCSPCommand::ValidationDateCommandL()
       
   912 	{
       
   913 	if (iTokens.Count() != 5)
       
   914 		{
       
   915 		WrongNumberOfArgumentsL();
       
   916 		}
       
   917 
       
   918 	iEngine->SetValidationTimeL(ParseTimeL(0));
       
   919 
       
   920 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   921 	}
       
   922 
       
   923 /**
       
   924  * Parse a series of input tokens representing a time - format is:
       
   925  * YEAR MONTH DAY HOUR MINUTE
       
   926  */
       
   927 
       
   928 TTime CTOCSPCommand::ParseTimeL(TInt aStartToken)
       
   929 	{
       
   930 	TLex lexer;
       
   931 	TInt year, month, day, hour, minute;
       
   932 
       
   933 	lexer.Assign(iTokens[aStartToken++]);
       
   934 	User::LeaveIfError(lexer.Val(year));
       
   935 
       
   936 	lexer.Assign(iTokens[aStartToken++]);
       
   937 	User::LeaveIfError(lexer.Val(month));
       
   938 
       
   939 	lexer.Assign(iTokens[aStartToken++]);
       
   940 	User::LeaveIfError(lexer.Val(day));
       
   941 
       
   942 	lexer.Assign(iTokens[aStartToken++]);
       
   943 	User::LeaveIfError(lexer.Val(hour));
       
   944 
       
   945 	lexer.Assign(iTokens[aStartToken]);
       
   946 	User::LeaveIfError(lexer.Val(minute));
       
   947 
       
   948 	// Internal month and day are 0-based
       
   949 	TDateTime dateTime(year, TMonth(--month), --day, hour, minute, 0, 0);
       
   950 
       
   951 	return dateTime;
       
   952 	}
       
   953 
       
   954 
       
   955 void CTOCSPCommand::SetMaxStatusAgeCommandL()
       
   956 	{
       
   957 	if (iTokens.Count() != 1)
       
   958 		{
       
   959 		WrongNumberOfArgumentsL();
       
   960 		}
       
   961 
       
   962 	if (iTokens[0] == KTOCSPOff)
       
   963 		{
       
   964 		iEngine->SetMaxStatusAgeL(0);
       
   965 		}
       
   966 	else
       
   967 		{
       
   968 		TLex lexer;
       
   969 		lexer.Assign(iTokens[0]);
       
   970 		TUint seconds;
       
   971 		User::LeaveIfError(lexer.Val(seconds));
       
   972 		iEngine->SetMaxStatusAgeL(seconds);
       
   973 		}
       
   974 
       
   975 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
   976 	}
       
   977 
       
   978 void CTOCSPCommand::SetFilterParamsCommandL()
       
   979 	{
       
   980 	if (iTokens.Count() != 9)
       
   981 		{
       
   982 		WrongNumberOfArgumentsL();
       
   983 		}
       
   984 	TInt numDelayResp = 0, countDropResp = 0;
       
   985 	TInt countCorruptHTTPDataHeader = 0, countCorruptHTTPDataBodySizeLarge = 0, countCorruptHTTPDataBodySizeSmall = 0;
       
   986 	TInt countCorruptOCSPData = 0;
       
   987 	TInt countInternalErrorResp = 0, countTryLaterResp = 0;
       
   988 	TInt countSigValidateFailure = 0;
       
   989 
       
   990 	TLex lex(iTokens[0]);
       
   991 	if ((lex.Val(numDelayResp) != KErrNone) || (numDelayResp < -1))
       
   992 		{
       
   993 		if (iVerbose)
       
   994 			{
       
   995 			iLog.LogL(_L("Invalid numDelayResp in FILTERPARAMS command\n"));
       
   996 			}
       
   997 		User::Leave(KErrArgument);
       
   998 		}
       
   999 
       
  1000 	lex = iTokens[1];
       
  1001 	if ((lex.Val(countDropResp) != KErrNone) || (countDropResp < -1))
       
  1002 		{
       
  1003 		if (iVerbose)
       
  1004 			{
       
  1005 			iLog.LogL(_L("Invalid countDropResp in FILTERPARAMS command\n"));
       
  1006 			}
       
  1007 		User::Leave(KErrArgument);
       
  1008 		}
       
  1009 
       
  1010 	lex = iTokens[2];
       
  1011 	if ((lex.Val(countCorruptHTTPDataHeader) != KErrNone) || (countCorruptHTTPDataHeader < -1))
       
  1012 		{
       
  1013 		if (iVerbose)
       
  1014 			{
       
  1015 			iLog.LogL(_L("Invalid countCorruptHTTPDataHeader in FILTERPARAMS command\n"));
       
  1016 			}
       
  1017 		User::Leave(KErrArgument);
       
  1018 		}
       
  1019 
       
  1020 	lex = iTokens[3];
       
  1021 	if ((lex.Val(countCorruptHTTPDataBodySizeLarge) != KErrNone) || (countCorruptHTTPDataBodySizeLarge < -1))
       
  1022 		{
       
  1023 		if (iVerbose)
       
  1024 			{
       
  1025 			iLog.LogL(_L("Invalid countCorruptHTTPDataBodySizeLarge in FILTERPARAMS command\n"));
       
  1026 			}
       
  1027 		User::Leave(KErrArgument);
       
  1028 		}
       
  1029 
       
  1030 	lex = iTokens[4];
       
  1031 	if ((lex.Val(countCorruptHTTPDataBodySizeSmall) != KErrNone) || (countCorruptHTTPDataBodySizeSmall < -1))
       
  1032 		{
       
  1033 		if (iVerbose)
       
  1034 			{
       
  1035 			iLog.LogL(_L("Invalid countCorruptHTTPDataBodySizeSmall in FILTERPARAMS command\n"));
       
  1036 			}
       
  1037 		User::Leave(KErrArgument);
       
  1038 		}
       
  1039 
       
  1040 	lex = iTokens[5];
       
  1041 	if ((lex.Val(countCorruptOCSPData) != KErrNone) || (countCorruptOCSPData < -1))
       
  1042 		{
       
  1043 		if (iVerbose)
       
  1044 			{
       
  1045 			iLog.LogL(_L("Invalid countCorruptOCSPData in FILTERPARAMS command\n"));
       
  1046 			}
       
  1047 		User::Leave(KErrArgument);
       
  1048 		}
       
  1049 
       
  1050 	lex = iTokens[6];
       
  1051 	if ((lex.Val(countInternalErrorResp) != KErrNone) || (countInternalErrorResp < -1))
       
  1052 		{
       
  1053 		if (iVerbose)
       
  1054 			{
       
  1055 			iLog.LogL(_L("Invalid countInternalErrorResp in FILTERPARAMS command\n"));
       
  1056 			}
       
  1057 		User::Leave(KErrArgument);
       
  1058 		}
       
  1059 
       
  1060 	lex = iTokens[7];
       
  1061 	if ((lex.Val(countTryLaterResp) != KErrNone) || (countTryLaterResp < -1))
       
  1062 		{
       
  1063 		if (iVerbose)
       
  1064 			{
       
  1065 			iLog.LogL(_L("Invalid countTryLaterResp in FILTERPARAMS command\n"));
       
  1066 			}
       
  1067 		User::Leave(KErrArgument);
       
  1068 		}
       
  1069 
       
  1070 	lex = iTokens[8];
       
  1071 	if ((lex.Val(countSigValidateFailure) != KErrNone) || (countSigValidateFailure < -1))
       
  1072 		{
       
  1073 		if (iVerbose)
       
  1074 			{
       
  1075 			iLog.LogL(_L("Invalid countSigValidateFailure in FILTERPARAMS command\n"));
       
  1076 			}
       
  1077 		User::Leave(KErrArgument);
       
  1078 		}
       
  1079 
       
  1080 	iEngine->SetFilterParameters(numDelayResp, countDropResp,
       
  1081 			countCorruptHTTPDataHeader, countCorruptHTTPDataBodySizeLarge, countCorruptHTTPDataBodySizeSmall,
       
  1082 			countCorruptOCSPData, 
       
  1083 			countInternalErrorResp, countTryLaterResp, countSigValidateFailure);
       
  1084 
       
  1085 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1086 	}
       
  1087 
       
  1088 // Pass a certificate (file) to be used as a root cert for validation of the response
       
  1089 void CTOCSPCommand::DirectAuthorisationCommandL()
       
  1090 	{
       
  1091 	iState = EDirectAuthorisationCommand;
       
  1092 	
       
  1093 	switch (iTokens.Count())
       
  1094 		{
       
  1095 	case 1:
       
  1096 		// since CA Delegate support was added, the script
       
  1097 		// cannot assume that direct authorisation is always
       
  1098 		// used.  Therefore, the special case of
       
  1099 		// "AUTHORISATIONCERT AUTHCERTNONE" is used to indicate that
       
  1100 		// direct authorisation should be used, even if no
       
  1101 		// certs are supplied.
       
  1102 		if (iTokens[0] != KAuthCertNone)
       
  1103 			User::Leave(KErrArgument);
       
  1104 		
       
  1105 		iEngine->UseDirectAuthorisation();
       
  1106 		User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1107 		return;
       
  1108 		
       
  1109 	case 2:
       
  1110 		iCert.Set(iTokens[0]);
       
  1111 		iLabel.Set(iTokens[1]);
       
  1112 		break;
       
  1113 		
       
  1114 	default:
       
  1115 		WrongNumberOfArgumentsL();
       
  1116 		}
       
  1117 
       
  1118 	iEngine->AddDirectAuthorisationCert(iCert, iLabel, iStatus);
       
  1119 	SetActive();
       
  1120 	}
       
  1121 
       
  1122 void CTOCSPCommand::CADelegateAuthorisationCommandL()
       
  1123 /**
       
  1124 	Instruct engine to use CA delegate authorisation.
       
  1125  */
       
  1126 	{
       
  1127 	if (iTokens.Count() != 0)
       
  1128 		{
       
  1129 		WrongNumberOfArgumentsL();
       
  1130 		}
       
  1131 
       
  1132 	iEngine->UseCADelegateAuthorisation();
       
  1133 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1134 	}
       
  1135 
       
  1136 void CTOCSPCommand::CADirectAuthorisationCommandL()
       
  1137 /**
       
  1138 	Instruct engine to expect the response is signed
       
  1139 	directly by the CA.
       
  1140  */
       
  1141 	{
       
  1142 	if (iTokens.Count() != 0)
       
  1143 		{
       
  1144 		WrongNumberOfArgumentsL();
       
  1145 		}
       
  1146 
       
  1147 	iEngine->UseCADirectAuthorisation();
       
  1148 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1149 	}
       
  1150 
       
  1151 void CTOCSPCommand::AllAuthorisationSchemesCommandL()
       
  1152 /**
       
  1153 	Instruct engine to expect allocate all supported
       
  1154 	authorisation schemes.
       
  1155 
       
  1156 	The script will have to specify which authorisation certs
       
  1157 	are supported for direct authorisation with AUTHORISATIONCERT,
       
  1158 	later in the script.
       
  1159  */
       
  1160 	{
       
  1161 	if (iTokens.Count() != 0)
       
  1162 		{
       
  1163 		WrongNumberOfArgumentsL();
       
  1164 		}
       
  1165 
       
  1166 	iEngine->UseAllAuthorisationSchemes();
       
  1167 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1168 	}
       
  1169 
       
  1170 void CTOCSPCommand::CancelCommandL()
       
  1171 	{
       
  1172 	if (iTokens.Count() != 1)
       
  1173 		{
       
  1174 		WrongNumberOfArgumentsL();
       
  1175 		}
       
  1176 
       
  1177 	TLex timeLex(iTokens[0]);
       
  1178 	TInt time = 0;
       
  1179 	User::LeaveIfError(timeLex.Val(time));
       
  1180 
       
  1181 	iEngine->SetCancelTime(time);
       
  1182 
       
  1183 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1184 	}
       
  1185 
       
  1186 void CTOCSPCommand::CheckCommand()
       
  1187 	{
       
  1188 	iState = ECheckCommand;
       
  1189 	iEngine->Check(iStatus);
       
  1190 	SetActive();
       
  1191 	}
       
  1192 
       
  1193 void CTOCSPCommand::TestCancelCommand()
       
  1194 	{
       
  1195 	iTestResult = iTestResult && iCheckCancelled;
       
  1196 
       
  1197 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1198 	}
       
  1199 
       
  1200 void CTOCSPCommand::TestSummaryCommandL()
       
  1201 	{
       
  1202 	if (iTokens.Count() != 1)
       
  1203 		{
       
  1204 		WrongNumberOfArgumentsL();
       
  1205 		}
       
  1206 
       
  1207 	TLex expectedResultLex(iTokens[0]);
       
  1208 	TInt expectedResult = 0;
       
  1209 	User::LeaveIfError(expectedResultLex.Val(expectedResult));
       
  1210 
       
  1211 	iTestResult = iTestResult && iEngine->TestSummaryL(STATIC_CAST(OCSP::TResult, expectedResult));
       
  1212 
       
  1213 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1214 	}
       
  1215 
       
  1216 
       
  1217 void CTOCSPCommand::TestOutcomeCommandL()
       
  1218 	{
       
  1219 	if (iTokens.Count() != 3)
       
  1220 		{
       
  1221 		WrongNumberOfArgumentsL();
       
  1222 		}
       
  1223 
       
  1224 	TLex certIndexLex(iTokens[0]);
       
  1225 	TInt certIndex = 0;
       
  1226 	User::LeaveIfError(certIndexLex.Val(certIndex));
       
  1227 
       
  1228 	TLex expectedStatusLex(iTokens[1]);
       
  1229 	TInt expectedStatus = 0;
       
  1230 	User::LeaveIfError(expectedStatusLex.Val(expectedStatus));
       
  1231 
       
  1232 	TLex expectedResultLex(iTokens[2]);
       
  1233 	TInt expectedResult = 0;
       
  1234 	User::LeaveIfError(expectedResultLex.Val(expectedResult));
       
  1235 
       
  1236 	TOCSPOutcome expectedOutcome(STATIC_CAST(OCSP::TStatus, expectedStatus), STATIC_CAST(OCSP::TResult, expectedResult));
       
  1237 
       
  1238 	iTestResult = iTestResult && iEngine->TestOutcomeL(certIndex, expectedOutcome);
       
  1239 
       
  1240 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1241 	}
       
  1242 
       
  1243 void CTOCSPCommand::TestTransportCommandL()
       
  1244 	{
       
  1245 	if (iTokens.Count() != 4)
       
  1246 		{
       
  1247 		WrongNumberOfArgumentsL();
       
  1248 		}
       
  1249 
       
  1250 	TLex lex(iTokens[0]);
       
  1251 	TInt retryCountNum = 0;
       
  1252 	if ((lex.Val(retryCountNum) != KErrNone) || (retryCountNum < 0))
       
  1253 		{
       
  1254 		if (iVerbose)
       
  1255 			{
       
  1256 			iLog.LogL(_L("Invalid request number in TESTTRANSPORT command"), ETrue);
       
  1257 			}
       
  1258 		User::Leave(KErrArgument);
       
  1259 		}
       
  1260 
       
  1261 	// Check the method name supplied (do a case insensitive compare)
       
  1262 	TPtrC ptrHttpMethod = iTokens[1];
       
  1263 	if (ptrHttpMethod.CompareC(_L("GET"), 2, NULL) && 
       
  1264 			ptrHttpMethod.CompareC(_L("POST"), 2, NULL))
       
  1265 		{
       
  1266 		if (iVerbose)
       
  1267 			{
       
  1268 			iLog.LogL(_L("Invalid HTTP method name in TESTTRANSPORT command"), ETrue);
       
  1269 			}
       
  1270 		User::Leave(KErrArgument);
       
  1271 		}
       
  1272 
       
  1273 	// Get the response time range
       
  1274 	TInt expRespTimeRangeMin = 0;
       
  1275 	TInt expRespTimeRangeMax = 0;
       
  1276 	lex = iTokens[2];
       
  1277 	if (lex.Val(expRespTimeRangeMin) != KErrNone)
       
  1278 		{
       
  1279 		if (iVerbose)
       
  1280 			{
       
  1281 			iLog.LogL(_L("Invalid range (min) for response time in TESTTRANSPORT command"), ETrue);
       
  1282 			}
       
  1283 		User::Leave(KErrArgument);
       
  1284 		}
       
  1285 
       
  1286 	lex = iTokens[3];
       
  1287 	if ((lex.Val(expRespTimeRangeMax) != KErrNone) || expRespTimeRangeMax < expRespTimeRangeMin)
       
  1288 		{
       
  1289 		if (iVerbose)
       
  1290 			{
       
  1291 			iLog.LogL(_L("Invalid range (max) for response time in TESTTRANSPORT command"), ETrue);
       
  1292 			}
       
  1293 		User::Leave(KErrArgument);
       
  1294 		}
       
  1295 
       
  1296 	iTestResult = iTestResult && iEngine->TestTransportL(retryCountNum, ptrHttpMethod,  
       
  1297 															expRespTimeRangeMin, expRespTimeRangeMax);
       
  1298 
       
  1299 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1300 	}
       
  1301 
       
  1302 void CTOCSPCommand::TestTransportRetryCommandL()
       
  1303 	{
       
  1304 	if (iTokens.Count() != 1)
       
  1305 		{
       
  1306 		WrongNumberOfArgumentsL();
       
  1307 		}
       
  1308 
       
  1309 	TLex lex(iTokens[0]);
       
  1310 	TInt retryCount = 0;
       
  1311 	if ((lex.Val(retryCount) != KErrNone) || (retryCount < 0))
       
  1312 		{
       
  1313 		if (iVerbose)
       
  1314 			{
       
  1315 			iLog.LogL(_L("Invalid request count in TESTTRANSPORTRETRY command"), ETrue);
       
  1316 			}
       
  1317 		User::Leave(KErrArgument);
       
  1318 		}
       
  1319 
       
  1320 	iTestResult = iTestResult && iEngine->TestTransportRetryL(retryCount);
       
  1321 
       
  1322 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1323 	}
       
  1324 
       
  1325 void CTOCSPCommand::LogResponseCommandL()
       
  1326 	{
       
  1327 	if (iTokens.Count() != 1)
       
  1328 		{
       
  1329 		WrongNumberOfArgumentsL();
       
  1330 		}
       
  1331 
       
  1332     iEngine->LogResponseL(iTokens[0]);
       
  1333 
       
  1334 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1335 	}
       
  1336 
       
  1337 
       
  1338 void CTOCSPCommand::LogRequestCommandL()
       
  1339 	{
       
  1340 	if (iTokens.Count() != 1)
       
  1341 		{
       
  1342 		WrongNumberOfArgumentsL();
       
  1343 		}
       
  1344 
       
  1345     iEngine->LogRequestL(iTokens[0]);
       
  1346 
       
  1347 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1348 	}
       
  1349 
       
  1350 
       
  1351 void CTOCSPCommand::SetVerbose(TBool aVerbose)
       
  1352 	{
       
  1353 	iVerbose = aVerbose;
       
  1354 	iEngine->SetVerbose(aVerbose);
       
  1355 	}
       
  1356 
       
  1357 
       
  1358 void CTOCSPCommand::FinishedTestL()
       
  1359 	{	
       
  1360 	TBuf<64> timeBuf;
       
  1361 	TTime time;
       
  1362 	time.UniversalTime();
       
  1363 	TDateTime dateTime = time.DateTime();
       
  1364 	_LIT(KDateFormat,"%02d:%02d:%02d:%03d "); 
       
  1365 	timeBuf.AppendFormat(KDateFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),(dateTime.MicroSecond()/1000));	
       
  1366 		
       
  1367 	iLog.LogL(_L("\r\n"));
       
  1368 	iLog.LogL(timeBuf);	
       
  1369 	iLog.LogL(_L("Command = END_TESTCASE "), EFalse);
       
  1370 	iLog.LogL(iTmsId, ETrue);
       
  1371 	iLog.LogL(_L(" ***TestCaseResult = "), ETrue);
       
  1372 	
       
  1373 	iResult.ResultL(iTestResult);
       
  1374 	if (iVerbose)
       
  1375 		{
       
  1376 		if (iTestResult)
       
  1377 			{
       
  1378 			iLog.LogL(_L("PASS\n"), ETrue);
       
  1379 			}
       
  1380 		else
       
  1381 			{
       
  1382 			iLog.LogL(_L("FAIL\n"), ETrue);
       
  1383 			}
       
  1384 		}
       
  1385 	}
       
  1386 
       
  1387 
       
  1388 void CTOCSPCommand::WrongNumberOfArgumentsL()
       
  1389 	{
       
  1390 	iLog.LogL(_L("Wrong number of arguments for command"), ETrue);
       
  1391 	User::Leave(KErrArgument);
       
  1392 	}
       
  1393 
       
  1394 void CTOCSPCommand::InvalidArgumentL(const TDesC& aCommand, const TDesC& aCommandOptions )
       
  1395 	{
       
  1396 	iLog.LogL(_L("Invalid input for:"), ETrue);
       
  1397 	iLog.LogL(aCommand, ETrue);
       
  1398 	iLog.LogL(_L(", Expected:"), ETrue);
       
  1399 	iLog.LogL(aCommandOptions, ETrue);
       
  1400 	User::Leave(KErrArgument);
       
  1401 	}
       
  1402 
       
  1403 void CTOCSPCommand::InvalidArgumentL(const TDesC& aCommand)
       
  1404 	{
       
  1405 	iLog.LogL(_L("Invalid input:"), ETrue);
       
  1406 	iLog.LogL(aCommand, ETrue);
       
  1407 	User::Leave(KErrArgument);
       
  1408 	}
       
  1409 
       
  1410 void CTOCSPCommand::SetResponderCertCheck()
       
  1411 	{
       
  1412 	iEngine->SetReponderCertCheck();
       
  1413 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1414 	}
       
  1415 
       
  1416 void CTOCSPCommand::AddCertToStoreL()
       
  1417 {
       
  1418 	if(iTokens.Count()!= 2)
       
  1419 		{
       
  1420 		WrongNumberOfArgumentsL();
       
  1421 		}
       
  1422 	
       
  1423 	TPtrC certFileName = iTokens[0];
       
  1424 	TPtrC certLabel = iTokens[1];
       
  1425 	
       
  1426 	iEngine->AddCertToStore(certFileName, certLabel, ECACertificate, iStatus);
       
  1427 	
       
  1428 	iState = EEngineEnd;
       
  1429 	SetActive();
       
  1430 }
       
  1431 
       
  1432 void CTOCSPCommand::SetCheckCertsWithAiaOnly()
       
  1433 	{
       
  1434 	iEngine->SetCheckCertsWithAiaOnly(ETrue);
       
  1435 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1436 	}
       
  1437 
       
  1438 void CTOCSPCommand::SetUseAIAL()
       
  1439 	{	
       
  1440 	if (iTokens.Count() != 1) 
       
  1441 		{
       
  1442 		WrongNumberOfArgumentsL();
       
  1443 		}
       
  1444 	
       
  1445 	if(iTokens[0].Compare(KTOCSPEnable) == 0)
       
  1446 		{
       
  1447 		iEngine->SetUseAIA(ETrue);
       
  1448 		}
       
  1449 	else if(iTokens[0].Compare(KTOCSPDisable) == 0)
       
  1450 		{
       
  1451 		iEngine->SetUseAIA(EFalse);
       
  1452 		}
       
  1453 	else
       
  1454 		{
       
  1455 		InvalidArgumentL(KTOCSPUseAIA,KTOCSPEnableDisable);
       
  1456 		}
       
  1457 	
       
  1458 	User::RequestComplete(iOriginalRequestStatus, KErrNone);
       
  1459 	}