networksecurity/tlsprovider/Test/src/TlsProvTestSteps4.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2003-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 "TlsProvTestStep.h"
       
    17 #include <test/testexecutelog.h>
       
    18 #include <hash.h>
       
    19 
       
    20 
       
    21 
       
    22 #define KTLSCachingTimeout  200 
       
    23 
       
    24 TVerdict CTlsProvTestActive::doTest4_0L( CTlsProvStep* aStep )
       
    25 	{
       
    26 	
       
    27 	CTlsTestRandom rnd;
       
    28 	
       
    29 	SetThreadRandomL( &rnd );
       
    30 		
       
    31 	CTLSProvider* tlsProvider = CTLSProvider::ConnectL();
       
    32 	
       
    33 	RArray<TTLSCipherSuite> userCipherSuiteList;
       
    34 	iStatus = KRequestPending;
       
    35 	tlsProvider->CipherSuitesL( userCipherSuiteList ,iStatus);	
       
    36 	
       
    37 	SetActive();
       
    38 	CActiveScheduler::Start();
       
    39 	
       
    40 	CTLSSession* sessionObj = NULL;
       
    41 	
       
    42 	CTlsCryptoAttributes* tlsCryptoAttributes = tlsProvider->Attributes();
       
    43 			
       
    44 	HBufC8* encServerCert = NULL;
       
    45 	
       
    46 	TInt res = StandardTestInitL(aStep, tlsCryptoAttributes, encServerCert);
       
    47 	if( res  < 0 )
       
    48 		{
       
    49 		iLogInfo.Copy( _L("	4.0:  problems with test data files") );
       
    50 		return EFail;
       
    51 		}
       
    52 	
       
    53 				
       
    54 	CX509Certificate* serverCert = NULL;
       
    55 	iStatus = KRequestPending;
       
    56 	tlsProvider->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
    57 	SetActive();
       
    58 	CActiveScheduler::Start();
       
    59 	
       
    60 	serverCert = CX509Certificate::NewL(encServerCert->Des()); //- remove when VerifyServerCertificate ready
       
    61 		
       
    62 	
       
    63 	
       
    64 	HBufC8* clientKeyExch = NULL;
       
    65 	
       
    66 	iStatus = KRequestPending;
       
    67 	tlsProvider->CreateL( sessionObj,
       
    68 						iStatus);	
       
    69 	SetActive();
       
    70 	CActiveScheduler::Start();	
       
    71 	
       
    72 		
       
    73 	// check that ClientKeyExch is not NULL
       
    74 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj) )
       
    75 		{
       
    76 		iLogInfo.Copy( _L("	4.0:  CTLSProvider::Create failed") );
       
    77 		return EInconclusive;
       
    78 		}
       
    79 	
       
    80 	iStatus = KRequestPending;
       
    81 	sessionObj->ClientKeyExchange(clientKeyExch, iStatus);
       
    82 	SetActive();
       
    83 	CActiveScheduler::Start();
       
    84 	
       
    85 	// check that ClientKeyExch is not NULL
       
    86 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
    87 		{
       
    88 		iLogInfo.Copy( _L("	4.0:  CTLSSession::ClientKeyExchange failed") );
       
    89 		return EInconclusive;
       
    90 		}
       
    91 		
       
    92 	if( EFalse == CacheSessionL( aStep, sessionObj) )
       
    93 		return EInconclusive;
       
    94 			
       
    95 	iStatus = KRequestPending;
       
    96 	CX509Certificate* cert;
       
    97 	sessionObj->ServerCertificate( cert, iStatus );
       
    98 		
       
    99 	SetActive();
       
   100 	CActiveScheduler::Start();
       
   101 	
       
   102 	
       
   103 	
       
   104 	if ( KErrNone != iStatus.Int() )
       
   105 		{
       
   106 		iLogInfo.Copy( _L("	4.0:  CTLSSession::ServerCertificte - returned with error") );
       
   107 		return EFail;
       
   108 		}
       
   109 	
       
   110 	//compare retrieved cert with original one:
       
   111 	if ( cert->IsEqualL( *serverCert ) == EFalse  ) 
       
   112 		{
       
   113 		iLogInfo.Copy( _L("	4.0:  retrieved certificate doesn't match") );
       
   114 		return EFail;
       
   115 		}
       
   116 	
       
   117 	iLogInfo.Copy( _L("	4.0:  OK") );
       
   118 	
       
   119 	delete tlsProvider;	
       
   120 	delete sessionObj;
       
   121 	
       
   122 	return EPass;
       
   123 	
       
   124 	} 	
       
   125 
       
   126 
       
   127 
       
   128 TVerdict CTlsProvTestActive::doTest4_1L( CTlsProvStep* aStep )
       
   129 	{
       
   130 	
       
   131 	CTlsTestRandom rnd;
       
   132 	
       
   133 	SetThreadRandomL( &rnd );
       
   134 	
       
   135 	RArray<TTLSCipherSuite> userCipherSuiteList;
       
   136 	CTLSProvider* tlsProvider = CTLSProvider::ConnectL();
       
   137 	
       
   138 	iStatus = KRequestPending;
       
   139 	tlsProvider->CipherSuitesL( userCipherSuiteList ,iStatus);	
       
   140 	SetActive();
       
   141 	CActiveScheduler::Start();
       
   142 	
       
   143 			
       
   144 	CTLSSession* sessionObj;
       
   145 	
       
   146 	CTlsCryptoAttributes* tlsCryptoAttributes = tlsProvider->Attributes();
       
   147 		
       
   148 	HBufC8* encServerCert = NULL;
       
   149 	
       
   150 	TInt res = StandardTestInitL(aStep, tlsCryptoAttributes, encServerCert);
       
   151 		
       
   152 	if( res  < 0 )
       
   153 		{
       
   154 		iLogInfo.Copy( _L("	4.1:  problems with test data files") );
       
   155 		return EFail;
       
   156 		}
       
   157 	tlsCryptoAttributes->iSessionNameAndID.iServerName.iAddress.Copy( KServer2 );
       
   158 	tlsCryptoAttributes->iNegotiatedProtocol.iMajor = 3;
       
   159 	tlsCryptoAttributes->iNegotiatedProtocol.iMinor = 0; 
       
   160 	
       
   161 	tlsCryptoAttributes->iProposedProtocol.iMajor = 3;
       
   162 	tlsCryptoAttributes->iProposedProtocol.iMinor = 0; 
       
   163 		
       
   164 		
       
   165 	CX509Certificate* serverCert = NULL;
       
   166 	iStatus = KRequestPending;
       
   167 	tlsProvider->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   168 	SetActive();
       
   169 	CActiveScheduler::Start();
       
   170 	
       
   171 		
       
   172 	tlsCryptoAttributes->iClientAuthenticate = EFalse; 
       
   173 	tlsCryptoAttributes->iDialogNonAttendedMode = ETrue;
       
   174 	
       
   175 	
       
   176 	HBufC8* clientKeyExch = NULL;
       
   177 	
       
   178 	iStatus = KRequestPending;
       
   179 	tlsProvider->CreateL( sessionObj,
       
   180 						iStatus);	
       
   181 	SetActive();
       
   182 	CActiveScheduler::Start();	
       
   183 	
       
   184 	// check that ClientKeyExch is not NULL
       
   185 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj) )
       
   186 		{
       
   187 		iLogInfo.Copy( _L("	4.1:  CTLSProvider::Create failed") );
       
   188 		return EInconclusive;
       
   189 		}
       
   190 		
       
   191 		
       
   192 	iStatus = KRequestPending;
       
   193 	sessionObj->ClientKeyExchange(clientKeyExch, iStatus);
       
   194 	SetActive();
       
   195 	CActiveScheduler::Start();
       
   196 	
       
   197 	// check that ClientKeyExch is not NULL
       
   198 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   199 		{
       
   200 		iLogInfo.Copy( _L("	4.1:  CTLSSession::ClientKeyExchange failed") );
       
   201 		return EInconclusive;
       
   202 		}
       
   203 		
       
   204 	if( EFalse == CacheSessionL( aStep, sessionObj) )
       
   205 		return EInconclusive;
       
   206 			
       
   207 	TTLSSessionId sessionId;
       
   208 	
       
   209 	iStatus = KRequestPending;
       
   210 	tlsProvider->GetSessionL(
       
   211 		tlsCryptoAttributes->iSessionNameAndID.iServerName,
       
   212 		sessionId,
       
   213 		iStatus );
       
   214 		
       
   215 		
       
   216 	SetActive();
       
   217 	CActiveScheduler::Start();
       
   218 	
       
   219 	
       
   220 	
       
   221 	if ( KErrNone != iStatus.Int() )
       
   222 		{
       
   223 		iLogInfo.Copy( _L("	4.1:  CTLSProvider::GetSession - returned with error") );
       
   224 		return EFail;
       
   225 		}
       
   226 	
       
   227 	if (  0 != sessionId.Compare( 
       
   228 								tlsCryptoAttributes->iSessionNameAndID.iSessionId ) ) 
       
   229 		{
       
   230 		iLogInfo.Copy( _L("	4.1:  CTLSProvider::GetSession - BAD session id") );
       
   231 		return EFail;
       
   232 		}
       
   233 		
       
   234 		
       
   235 	iLogInfo.Copy( _L("	4.1:  OK") );
       
   236 	
       
   237 			
       
   238 	return EPass;
       
   239 	
       
   240 	} 
       
   241 
       
   242 	
       
   243 
       
   244 TVerdict CTlsProvTestActive::doTest4_2L( CTlsProvStep* aStep )
       
   245 	{
       
   246 	
       
   247 	CTlsTestRandom rnd;
       
   248 	
       
   249 	SetThreadRandomL( &rnd );
       
   250 	
       
   251 	RArray<TTLSCipherSuite> userCipherSuiteList;
       
   252 	CTLSProvider* tlsProvider = CTLSProvider::ConnectL();
       
   253 	CTLSProvider* tlsProvider2 = CTLSProvider::ConnectL();
       
   254 			
       
   255 	iStatus = KRequestPending;
       
   256 	tlsProvider->CipherSuitesL( userCipherSuiteList ,iStatus);	
       
   257 	SetActive();
       
   258 	CActiveScheduler::Start();
       
   259 	
       
   260 			
       
   261 	CTLSSession* sessionObj;
       
   262 	CTLSSession* sessionObj2;
       
   263 			
       
   264 	CTlsCryptoAttributes* tlsCryptoAttributes = tlsProvider->Attributes();
       
   265 	
       
   266 	HBufC8* encServerCert = NULL;
       
   267 	
       
   268 	TInt res = StandardTestInitL(aStep, tlsCryptoAttributes, encServerCert);
       
   269 	if( res  < 0 )
       
   270 		{
       
   271 		iLogInfo.Copy( _L("	4.2:  problems with test data files (1)") );
       
   272 		return EFail;
       
   273 		}
       
   274 			
       
   275 	CX509Certificate* serverCert = NULL;
       
   276 	iStatus = KRequestPending;
       
   277 	tlsProvider->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   278 	SetActive();
       
   279 	CActiveScheduler::Start();
       
   280 			
       
   281 		
       
   282 	HBufC8* clientKeyExch = NULL;
       
   283 	
       
   284 	iStatus = KRequestPending;
       
   285 	tlsProvider->CreateL( sessionObj,
       
   286 						iStatus);	
       
   287 	SetActive();
       
   288 	CActiveScheduler::Start();	
       
   289 	
       
   290 	// check that ClientKeyExch is not NULL
       
   291 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj) )
       
   292 		{
       
   293 		iLogInfo.Copy( _L("	4.2:  CTLSProvider::Create failed") );
       
   294 		return EInconclusive;
       
   295 		}
       
   296 		
       
   297 	iStatus = KRequestPending;
       
   298 	sessionObj->ClientKeyExchange(clientKeyExch, iStatus);
       
   299 	SetActive();
       
   300 	CActiveScheduler::Start();
       
   301 	
       
   302 	// check that ClientKeyExch is not NULL
       
   303 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   304 		{
       
   305 		iLogInfo.Copy( _L("	4.2:  CTLSSession::ClientKeyExchange failed") );
       
   306 		return EInconclusive;
       
   307 		}
       
   308 		
       
   309 	if( EFalse == CacheSessionL( aStep, sessionObj) )
       
   310 		return EInconclusive;
       
   311 			
       
   312 		
       
   313 	//
       
   314 	// entry 2
       
   315 	
       
   316 	delete clientKeyExch;	
       
   317 	clientKeyExch = NULL;
       
   318 	
       
   319 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLServerRnd"),aStep->iServerRnd);
       
   320 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLClientRnd"),aStep->iClientRnd);
       
   321 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLKeyParams1"),aStep->iKeyParam1);
       
   322 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLKeyParams2"),aStep->iKeyParam2);
       
   323 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLKeyParams3"),aStep->iKeyParam3);
       
   324 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLServerCert"),aStep->iServerCertChain);
       
   325 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLHandshakeMsgsServer"),aStep->iHandshakeMsgsServer);
       
   326 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLSrvFinishedCheckOutput"),aStep->iSrvFinishedCheckOutput);
       
   327 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLPremaster"),aStep->iPremaster);
       
   328 	
       
   329 	RFs fs;
       
   330 	if ( KErrNone != fs.Connect() )
       
   331 		{
       
   332 		iLogInfo.Copy( _L("	4.2:  problems with file system (2)") );
       
   333 		return EFail;
       
   334 		}
       
   335 		
       
   336 	CFileMan* fMan = CFileMan::NewL( fs );
       
   337 	
       
   338 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   339 	TBuf<128> fileName (sysDrive.Name());
       
   340 	fileName.Append(_L("\\Premaster.bin"));
       
   341 	
       
   342 	fMan->Delete(fileName);
       
   343 	fMan->Copy( aStep->iPremaster,	fileName, CFileMan::EOverWrite );
       
   344 	fs.Close();	
       
   345 			
       
   346 	
       
   347 	RArray<TTLSCipherSuite> userCipherSuiteList2;
       
   348 	iStatus = KRequestPending;
       
   349 	tlsProvider2->CipherSuitesL( userCipherSuiteList2 ,iStatus);	
       
   350 	SetActive();
       
   351 	CActiveScheduler::Start();
       
   352 	
       
   353 	CTlsCryptoAttributes* tlsCryptoAttributes2 = tlsProvider2->Attributes();
       
   354 		
       
   355 	tlsCryptoAttributes2->iSessionNameAndID.iServerName.iAddress.Copy( KServer1 );
       
   356 	tlsCryptoAttributes2->iSessionNameAndID.iServerName.iPort = 10;
       
   357 	tlsCryptoAttributes2->iSessionNameAndID.iSessionId.Copy( KSessionId2 );
       
   358 	 
       
   359 	
       
   360 	tlsCryptoAttributes2->iCompressionMethod = ENullCompression;
       
   361 	tlsCryptoAttributes2->iCurrentCipherSuite.iHiByte = 0;
       
   362 	tlsCryptoAttributes2->iCurrentCipherSuite.iLoByte = 3;
       
   363 	
       
   364 		
       
   365 	tlsCryptoAttributes2->iNegotiatedProtocol.iMajor = 3;
       
   366 	tlsCryptoAttributes2->iNegotiatedProtocol.iMinor = 0; 
       
   367 	
       
   368 	tlsCryptoAttributes2->iProposedProtocol.iMajor = 3;
       
   369 	tlsCryptoAttributes2->iProposedProtocol.iMinor = 0; 
       
   370 	
       
   371 		
       
   372 	tlsCryptoAttributes2->iPublicKeyParams->iKeyType = ERsa;
       
   373 	
       
   374 	tlsCryptoAttributes2->iClientAuthenticate = EFalse; 
       
   375 	tlsCryptoAttributes2->iDialogNonAttendedMode = ETrue;
       
   376 	
       
   377 		
       
   378 	delete encServerCert;
       
   379 	encServerCert = NULL;
       
   380 	
       
   381 	res = aStep->ReadDataForCreateL(tlsCryptoAttributes2, encServerCert);
       
   382 	if( res  < 0 )
       
   383 		{
       
   384 		iLogInfo.Copy( _L("	4.2:  problems with test data files (2)") );
       
   385 		return EFail;
       
   386 		}
       
   387 	
       
   388 		
       
   389 	delete serverCert;
       
   390 	serverCert = NULL;
       
   391 	iStatus = KRequestPending;
       
   392 	tlsProvider2->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   393 	SetActive();
       
   394 	CActiveScheduler::Start();
       
   395 	
       
   396 	
       
   397 	iStatus = KRequestPending;
       
   398 	tlsProvider2->CreateL( sessionObj2,
       
   399 						iStatus);	
       
   400 	SetActive();
       
   401 	CActiveScheduler::Start();	
       
   402 	
       
   403 	// check that ClientKeyExch is not NULL
       
   404 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj2) ) 
       
   405 		{
       
   406 		iLogInfo.Copy( _L("	4.2:  CTLSProvider::Create failed") );
       
   407 		return EInconclusive;
       
   408 		}
       
   409 		
       
   410 	iStatus = KRequestPending;
       
   411 	sessionObj2->ClientKeyExchange(clientKeyExch, iStatus);
       
   412 	SetActive();
       
   413 	CActiveScheduler::Start();
       
   414 	
       
   415 	// check that ClientKeyExch is not NULL
       
   416 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   417 		{
       
   418 		iLogInfo.Copy( _L("	4.2:  CTLSSession::ClientKeyExchange failed (4)") );
       
   419 		return EInconclusive;
       
   420 		}
       
   421 		
       
   422 	delete clientKeyExch;	
       
   423 	clientKeyExch = NULL;
       
   424 	
       
   425 	if( EFalse == CacheSessionL( aStep, sessionObj2) )
       
   426 		return EInconclusive;
       
   427 	
       
   428 	
       
   429 	// entry 2 inserted
       
   430 	//
       
   431 	
       
   432 	//
       
   433 			
       
   434 		
       
   435 	TTLSSessionId sessionId;
       
   436 	
       
   437 	CTLSProvider* tlsProvider3 = CTLSProvider::ConnectL();
       
   438 	
       
   439 	RArray<TTLSCipherSuite> userCipherSuiteList3;
       
   440 	iStatus = KRequestPending;
       
   441 	tlsProvider3->CipherSuitesL( userCipherSuiteList3 ,iStatus);	
       
   442 	SetActive();
       
   443 	CActiveScheduler::Start();
       
   444 	
       
   445 	CTlsCryptoAttributes* tlsCryptoAttributes3 = tlsProvider3->Attributes();
       
   446 		
       
   447 	tlsCryptoAttributes3->iCurrentCipherSuite.iHiByte = 0;
       
   448 	tlsCryptoAttributes3->iCurrentCipherSuite.iLoByte = 3;
       
   449 	
       
   450 		
       
   451 	tlsCryptoAttributes3->iNegotiatedProtocol.iMajor = 3;
       
   452 	tlsCryptoAttributes3->iNegotiatedProtocol.iMinor = 0; 
       
   453 	
       
   454 	tlsCryptoAttributes3->iProposedProtocol.iMajor = 3;
       
   455 	tlsCryptoAttributes3->iProposedProtocol.iMinor = 0; 
       
   456 	TTLSSessionNameAndID sessionNameAndID;
       
   457 	sessionNameAndID.iServerName.iAddress.Copy( KServer1 );
       
   458 	sessionNameAndID.iServerName.iPort = 10;
       
   459 			
       
   460 		
       
   461 	iStatus = KRequestPending;
       
   462 	tlsProvider3->GetSessionL(
       
   463 		sessionNameAndID.iServerName,
       
   464 		sessionId,
       
   465 		iStatus );
       
   466 		
       
   467 	SetActive();
       
   468 	CActiveScheduler::Start();
       
   469 	
       
   470 		
       
   471 	if ( KErrNone != iStatus.Int() )
       
   472 		{
       
   473 		iLogInfo.Copy( _L("	4.2:  CTLSProvider::GetSession - returned with error") );
       
   474 		return EFail;
       
   475 		}
       
   476 	
       
   477 	
       
   478 	if (  0 != sessionId.Compare( tlsCryptoAttributes2->iSessionNameAndID.iSessionId ) ) 
       
   479 		{
       
   480 		iLogInfo.Copy( _L("	4.2:  CTLSProvider::GetSession - BAD session id") );
       
   481 		return EFail;
       
   482 		}
       
   483 		
       
   484 		
       
   485 	return EPass;
       
   486 	
       
   487 	} 	
       
   488 
       
   489 TVerdict CTlsProvTestActive::doTest4_3L( CTlsProvStep* aStep )
       
   490 	{
       
   491 	
       
   492 	CTlsTestRandom rnd;
       
   493 	
       
   494 	SetThreadRandomL( &rnd );
       
   495 	
       
   496 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("ServerRnd"),aStep->iServerRnd);
       
   497 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("ClientRnd"),aStep->iClientRnd);
       
   498 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("KeyParams1"),aStep->iKeyParam1);
       
   499 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("KeyParams2"),aStep->iKeyParam2);
       
   500 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("KeyParams3"),aStep->iKeyParam3);
       
   501 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("ServerCert"),aStep->iServerCertChain);
       
   502 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("HandshakeMsgsServer"),aStep->iHandshakeMsgsServer);
       
   503 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SrvFinishedCheckOutput"),aStep->iSrvFinishedCheckOutput);
       
   504 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("Premaster"),aStep->iPremaster);
       
   505 	
       
   506 	RArray<TTLSCipherSuite> userCipherSuiteList;
       
   507 	CTLSProvider* tlsProvider = CTLSProvider::ConnectL();
       
   508 	
       
   509 	iStatus = KRequestPending;
       
   510 	tlsProvider->CipherSuitesL( userCipherSuiteList ,iStatus);	
       
   511 	SetActive();
       
   512 	CActiveScheduler::Start();
       
   513 		
       
   514 	TTLSSessionNameAndID sessionNameAndID;
       
   515 	sessionNameAndID.iServerName.iAddress.Copy( KServer3 );
       
   516 	sessionNameAndID.iServerName.iPort = 20;
       
   517 			
       
   518 	TTLSSessionId sessionId;
       
   519 	
       
   520 	iStatus = KRequestPending;
       
   521 	tlsProvider->GetSessionL(
       
   522 		sessionNameAndID.iServerName,
       
   523 		sessionId,
       
   524 		iStatus );
       
   525 		
       
   526 	SetActive();
       
   527 	CActiveScheduler::Start();
       
   528 	
       
   529 	if ( 0 != sessionId.Length()  )
       
   530 		{
       
   531 		iLogInfo.Copy( _L("	4.3:  CTLSProvider::GetSession - wrong error code returned") );
       
   532 		return EFail;
       
   533 		}
       
   534 		
       
   535 	// now lets insert some entries and try again
       
   536 	
       
   537 	CTlsCryptoAttributes* tlsCryptoAttributes = tlsProvider->Attributes();
       
   538 		
       
   539 	tlsCryptoAttributes->iSessionNameAndID.iServerName.iPort = 10;
       
   540 		 
       
   541 	tlsCryptoAttributes->iDialogNonAttendedMode = ETrue;
       
   542 	tlsCryptoAttributes->iCompressionMethod = ENullCompression;
       
   543 	tlsCryptoAttributes->iCurrentCipherSuite.iHiByte = 0;
       
   544 	tlsCryptoAttributes->iCurrentCipherSuite.iLoByte = 5; 
       
   545 	
       
   546 		
       
   547 	tlsCryptoAttributes->iNegotiatedProtocol.iMajor = 3;
       
   548 	tlsCryptoAttributes->iNegotiatedProtocol.iMinor = 1; 
       
   549 	
       
   550 	tlsCryptoAttributes->iProposedProtocol.iMajor = 3;
       
   551 	tlsCryptoAttributes->iProposedProtocol.iMinor = 1; 
       
   552 	
       
   553 	
       
   554 	tlsCryptoAttributes->iPublicKeyParams = NULL;
       
   555 	
       
   556 			
       
   557 	HBufC8* encServerCert = NULL;
       
   558 	
       
   559 		
       
   560 	TInt res = aStep->ReadDataForCreateL(tlsCryptoAttributes, encServerCert);
       
   561 	if( res  < 0 )
       
   562 		{
       
   563 		iLogInfo.Copy( _L("	4.3:  problems with test data files") );
       
   564 		return EFail;
       
   565 		}
       
   566 		
       
   567 	CX509Certificate* serverCert = NULL;
       
   568 	iStatus = KRequestPending;
       
   569 	tlsProvider->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   570 	SetActive();
       
   571 	CActiveScheduler::Start();
       
   572 			
       
   573 	tlsCryptoAttributes->iClientAuthenticate = EFalse; 
       
   574 	tlsCryptoAttributes->iDialogNonAttendedMode = ETrue;
       
   575 	
       
   576 	
       
   577 	tlsCryptoAttributes->iSessionNameAndID.iServerName.iAddress.Copy( KServer1 );
       
   578 	tlsCryptoAttributes->iSessionNameAndID.iSessionId.Append( KSessionId1 );
       
   579 	
       
   580 	CTLSSession* sessionObj = NULL;
       
   581 	HBufC8* clientKeyExch = NULL;
       
   582 	
       
   583 	iStatus = KRequestPending;
       
   584 	tlsProvider->CreateL( sessionObj,
       
   585 						iStatus);	
       
   586 	SetActive();
       
   587 	CActiveScheduler::Start();
       
   588 	
       
   589 	delete serverCert;
       
   590 	serverCert = NULL;
       
   591 	
       
   592 	// check that ClientKeyExch is not NULL
       
   593 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj) )
       
   594 		{
       
   595 		iLogInfo.Copy( _L("	4.3:  CTLSProvider::Create failed") );
       
   596 		return EInconclusive;
       
   597 		}
       
   598 		
       
   599 	iStatus = KRequestPending;
       
   600 	sessionObj->ClientKeyExchange(clientKeyExch, iStatus);
       
   601 	SetActive();
       
   602 	CActiveScheduler::Start();
       
   603 	
       
   604 	// check that ClientKeyExch is not NULL
       
   605 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   606 		{
       
   607 		iLogInfo.Copy( _L("	4.3:  CTLSSession::ClientKeyExchange failed") );
       
   608 		return EInconclusive;
       
   609 		}
       
   610 		
       
   611 	if( EFalse == CacheSessionL( aStep, sessionObj) )
       
   612 		return EInconclusive;
       
   613 		
       
   614 	// now lets try to retrieve invalid session
       
   615 	iStatus = KRequestPending;
       
   616 	tlsProvider->GetSessionL(
       
   617 		sessionNameAndID.iServerName,
       
   618 		sessionId,
       
   619 		iStatus );
       
   620 		
       
   621 	SetActive();
       
   622 	CActiveScheduler::Start();
       
   623 	
       
   624 	if ( ( 0 != sessionId.Length() ) )
       
   625 		{
       
   626 		iLogInfo.Copy( _L("	4.3:  CTLSProvider::GetSession - wrong error code returned") );
       
   627 		return EFail;
       
   628 		}
       
   629 	
       
   630 	iLogInfo.Copy( _L("	4.3:  OK") );
       
   631 	
       
   632 	return EPass;
       
   633 	
       
   634 	} 	
       
   635 	
       
   636 
       
   637 TVerdict CTlsProvTestActive::doTest4_4L( CTlsProvStep* aStep )
       
   638 	{
       
   639 	CTlsTestRandom rnd;
       
   640 	
       
   641 	SetThreadRandomL( &rnd );
       
   642 				
       
   643 	RArray<TTLSCipherSuite> userCipherSuiteList;
       
   644 	CTLSProvider* tlsProvider = CTLSProvider::ConnectL();
       
   645 	CTLSProvider* tlsProvider2 = CTLSProvider::ConnectL();
       
   646 	CTLSProvider* tlsProvider3 = CTLSProvider::ConnectL();
       
   647 	CTLSProvider* tlsProvider4 = CTLSProvider::ConnectL();
       
   648 		
       
   649 	iStatus = KRequestPending;
       
   650 	tlsProvider->CipherSuitesL( userCipherSuiteList ,iStatus);	
       
   651 	SetActive();
       
   652 	CActiveScheduler::Start();
       
   653 	
       
   654 			
       
   655 	CTLSSession* sessionObj;
       
   656 	CTLSSession* sessionObj2;
       
   657 	CTLSSession* sessionObj3;
       
   658 	CTLSSession* sessionObj4;
       
   659 		
       
   660 	CTlsCryptoAttributes* tlsCryptoAttributes = tlsProvider->Attributes();
       
   661 	
       
   662 	HBufC8* encServerCert = NULL;
       
   663 	
       
   664 	TInt res = StandardTestInitL(aStep, tlsCryptoAttributes, encServerCert);
       
   665 	if( res  < 0 )
       
   666 		{
       
   667 		iLogInfo.Copy( _L("	4.4:  problems with test data files (1)") );
       
   668 		return EFail;
       
   669 		}
       
   670 			
       
   671 	CX509Certificate* serverCert = NULL;
       
   672 	iStatus = KRequestPending;
       
   673 	tlsProvider->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   674 	SetActive();
       
   675 	CActiveScheduler::Start();
       
   676 	
       
   677 		
       
   678 		
       
   679 	HBufC8* clientKeyExch = NULL;
       
   680 	
       
   681 	iStatus = KRequestPending;
       
   682 	tlsProvider->CreateL( sessionObj,
       
   683 						iStatus);	
       
   684 	SetActive();
       
   685 	CActiveScheduler::Start();	
       
   686 	
       
   687 	// check that ClientKeyExch is not NULL
       
   688 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj) )
       
   689 		{
       
   690 		iLogInfo.Copy( _L("	4.4:  CTLSProvider::Create failed") );
       
   691 		return EInconclusive;
       
   692 		}
       
   693 		
       
   694 	iStatus = KRequestPending;
       
   695 	sessionObj->ClientKeyExchange(clientKeyExch, iStatus);
       
   696 	SetActive();
       
   697 	CActiveScheduler::Start();
       
   698 	
       
   699 	// check that ClientKeyExch is not NULL
       
   700 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   701 		{
       
   702 		iLogInfo.Copy( _L("	4.4:  CTLSSession::ClientKeyExchange failed") );
       
   703 		return EInconclusive;
       
   704 		}
       
   705 		
       
   706 	if( EFalse == CacheSessionL( aStep, sessionObj) )
       
   707 		return EInconclusive;
       
   708 			
       
   709 	//
       
   710 	// entry 2 - diferent sever but same session id
       
   711 	
       
   712 	delete clientKeyExch;	
       
   713 	clientKeyExch = NULL;
       
   714 	
       
   715 	RArray<TTLSCipherSuite> userCipherSuiteList2;
       
   716 	iStatus = KRequestPending;
       
   717 	tlsProvider2->CipherSuitesL( userCipherSuiteList2 ,iStatus);	
       
   718 	SetActive();
       
   719 	CActiveScheduler::Start();
       
   720 	
       
   721 	CTlsCryptoAttributes* tlsCryptoAttributes2 = tlsProvider2->Attributes();
       
   722 		
       
   723 	delete encServerCert;
       
   724 	encServerCert = NULL;
       
   725 	res = StandardTestInitL(aStep, tlsCryptoAttributes2, encServerCert);
       
   726 	if( res  < 0 )
       
   727 		{
       
   728 		iLogInfo.Copy( _L("	4.4:  problems with test data files (2)") );
       
   729 		return EFail;
       
   730 		}
       
   731 	tlsCryptoAttributes2->iSessionNameAndID.iServerName.iAddress.Copy( KServer2 );
       
   732 	
       
   733 	delete serverCert;
       
   734 	serverCert = NULL;
       
   735 	iStatus = KRequestPending;
       
   736 	tlsProvider2->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   737 	SetActive();
       
   738 	CActiveScheduler::Start();
       
   739 	
       
   740 	
       
   741 	iStatus = KRequestPending;
       
   742 	tlsProvider2->CreateL( sessionObj2,
       
   743 						iStatus);	
       
   744 	SetActive();
       
   745 	CActiveScheduler::Start();	
       
   746 	
       
   747 	// check that ClientKeyExch is not NULL
       
   748 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj2) )
       
   749 		{
       
   750 		iLogInfo.Copy( _L("	4.4:  CTLSProvider::Create failed") );
       
   751 		return EInconclusive;
       
   752 		}
       
   753 		
       
   754 	iStatus = KRequestPending;
       
   755 	sessionObj2->ClientKeyExchange(clientKeyExch, iStatus);
       
   756 	SetActive();
       
   757 	CActiveScheduler::Start();
       
   758 	
       
   759 	// check that ClientKeyExch is not NULL
       
   760 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   761 		{
       
   762 		iLogInfo.Copy( _L("	4.4:  CTLSSession::ClientKeyExchange failed") );
       
   763 		return EInconclusive;
       
   764 		}
       
   765 			
       
   766 	if( EFalse == CacheSessionL( aStep, sessionObj2) )
       
   767 		return EInconclusive;
       
   768 	
       
   769 	// entry 2 
       
   770 	//
       
   771 	
       
   772 	//
       
   773 	// entry 3
       
   774 	
       
   775 	delete clientKeyExch;	
       
   776 	clientKeyExch = NULL;
       
   777 	
       
   778 	RArray<TTLSCipherSuite> userCipherSuiteList3;
       
   779 	iStatus = KRequestPending;
       
   780 	tlsProvider3->CipherSuitesL( userCipherSuiteList3 ,iStatus);	
       
   781 	SetActive();
       
   782 	CActiveScheduler::Start();
       
   783 		
       
   784 	CTlsCryptoAttributes* tlsCryptoAttributes3 = tlsProvider3->Attributes();
       
   785 	
       
   786 	delete encServerCert;
       
   787 	encServerCert = NULL;
       
   788 		
       
   789 	res = StandardTestInitL(aStep, tlsCryptoAttributes3, encServerCert);
       
   790 	if( res  < 0 )
       
   791 		{
       
   792 		iLogInfo.Copy( _L("	4.4:  problems with test data files (3)") );
       
   793 		return EFail;
       
   794 		}
       
   795 	tlsCryptoAttributes3->iSessionNameAndID.iServerName.iAddress.Copy( KServer2 );
       
   796 	tlsCryptoAttributes3->iSessionNameAndID.iSessionId.Copy( KSessionId3 );	
       
   797 	
       
   798 	delete serverCert;
       
   799 	serverCert = NULL;
       
   800 	iStatus = KRequestPending;
       
   801 	tlsProvider3->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   802 	SetActive();
       
   803 	CActiveScheduler::Start();
       
   804 	
       
   805 	
       
   806 	iStatus = KRequestPending;
       
   807 	tlsProvider3->CreateL( sessionObj3,
       
   808 						iStatus);	
       
   809 	SetActive();
       
   810 	CActiveScheduler::Start();	
       
   811 	
       
   812 	// check that ClientKeyExch is not NULL
       
   813 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj3) ) 
       
   814 		{
       
   815 		iLogInfo.Copy( _L("	4.4:  CTLSProvider::Create failed") );
       
   816 		return EInconclusive;
       
   817 		}
       
   818 		
       
   819 		
       
   820 	iStatus = KRequestPending;
       
   821 	sessionObj3->ClientKeyExchange(clientKeyExch, iStatus);
       
   822 	SetActive();
       
   823 	CActiveScheduler::Start();
       
   824 	
       
   825 	// check that ClientKeyExch is not NULL
       
   826 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   827 		{
       
   828 		iLogInfo.Copy( _L("	4.4:  CTLSSession::ClientKeyExchange failed") );
       
   829 		return EInconclusive;
       
   830 		}
       
   831 		
       
   832 	if( EFalse == CacheSessionL( aStep, sessionObj3) )
       
   833 		return EInconclusive;
       
   834 	
       
   835 	// entry 3 inserted
       
   836 	//
       
   837 	
       
   838 	//
       
   839 	// entry 4
       
   840 	
       
   841 	delete clientKeyExch;	
       
   842 	clientKeyExch = NULL;
       
   843 	
       
   844 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLServerRnd"),aStep->iServerRnd);
       
   845 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLClientRnd"),aStep->iClientRnd);
       
   846 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLKeyParams1"),aStep->iKeyParam1);
       
   847 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLKeyParams2"),aStep->iKeyParam2);
       
   848 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLKeyParams3"),aStep->iKeyParam3);
       
   849 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLServerCert"),aStep->iServerCertChain);
       
   850 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLHandshakeMsgsServer"),aStep->iHandshakeMsgsServer);
       
   851 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLSrvFinishedCheckOutput"),aStep->iSrvFinishedCheckOutput);
       
   852 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("SSLPremaster"),aStep->iPremaster);
       
   853 	
       
   854 	RFs fs;
       
   855 	if ( KErrNone != fs.Connect() )
       
   856 		{
       
   857 		iLogInfo.Copy( _L("	4.4:  problems with file system (4)") );
       
   858 		return EFail;
       
   859 		}
       
   860 		
       
   861 	CFileMan* fMan = CFileMan::NewL( fs );
       
   862 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
   863 	TBuf<128> fileName (sysDrive.Name());
       
   864 	fileName.Append(_L("\\Premaster.bin"));
       
   865 	
       
   866 	fMan->Delete(fileName);
       
   867 	fMan->Copy( aStep->iPremaster,	fileName, CFileMan::EOverWrite );
       
   868 	fs.Close();	
       
   869 			
       
   870 	
       
   871 	RArray<TTLSCipherSuite> userCipherSuiteList4;
       
   872 	iStatus = KRequestPending;
       
   873 	tlsProvider4->CipherSuitesL( userCipherSuiteList4 ,iStatus);	
       
   874 	SetActive();
       
   875 	CActiveScheduler::Start();
       
   876 	
       
   877 	CTlsCryptoAttributes* tlsCryptoAttributes4 = tlsProvider4->Attributes();
       
   878 		
       
   879 	tlsCryptoAttributes4->iSessionNameAndID.iServerName.iAddress.Copy( KServer2 );
       
   880 	tlsCryptoAttributes4->iSessionNameAndID.iServerName.iPort = 10;
       
   881 	tlsCryptoAttributes4->iSessionNameAndID.iSessionId.Append( KSessionId4 );
       
   882 	 
       
   883 	
       
   884 	tlsCryptoAttributes4->iCompressionMethod = ENullCompression;
       
   885 	tlsCryptoAttributes4->iCurrentCipherSuite.iHiByte = 0;
       
   886 	tlsCryptoAttributes4->iCurrentCipherSuite.iLoByte = 3;
       
   887 	
       
   888 		
       
   889 	tlsCryptoAttributes4->iNegotiatedProtocol.iMajor = 3;
       
   890 	tlsCryptoAttributes4->iNegotiatedProtocol.iMinor = 0; 
       
   891 	
       
   892 	tlsCryptoAttributes4->iProposedProtocol.iMajor = 3;
       
   893 	tlsCryptoAttributes4->iProposedProtocol.iMinor = 0; 
       
   894 	
       
   895 		
       
   896 	tlsCryptoAttributes4->iPublicKeyParams->iKeyType = ERsa;
       
   897 	
       
   898 	tlsCryptoAttributes4->iClientAuthenticate = EFalse; 
       
   899 	tlsCryptoAttributes4->iDialogNonAttendedMode = ETrue;
       
   900 	
       
   901 	
       
   902 	delete encServerCert;
       
   903 	encServerCert = NULL;
       
   904 	
       
   905 	res = aStep->ReadDataForCreateL(tlsCryptoAttributes4, encServerCert);
       
   906 	if( res  < 0 )
       
   907 		{
       
   908 		iLogInfo.Copy( _L("	4.4:  problems with test data files (4)") );
       
   909 		return EFail;
       
   910 		}
       
   911 	
       
   912 		
       
   913 	delete serverCert;
       
   914 	serverCert = NULL;
       
   915 	iStatus = KRequestPending;
       
   916 	tlsProvider4->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
   917 	SetActive();
       
   918 	CActiveScheduler::Start();
       
   919 	
       
   920 	
       
   921 	iStatus = KRequestPending;
       
   922 	tlsProvider4->CreateL( sessionObj4,
       
   923 						iStatus);	
       
   924 	SetActive();
       
   925 	CActiveScheduler::Start();	
       
   926 	
       
   927 	// check that ClientKeyExch is not NULL
       
   928 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj4) ) 
       
   929 		{
       
   930 		iLogInfo.Copy( _L("	4.4:  CTLSProvider::Create failed") );
       
   931 		return EInconclusive;
       
   932 		}
       
   933 		
       
   934 	iStatus = KRequestPending;
       
   935 	sessionObj4->ClientKeyExchange(clientKeyExch, iStatus);
       
   936 	SetActive();
       
   937 	CActiveScheduler::Start();
       
   938 	
       
   939 	// check that ClientKeyExch is not NULL
       
   940 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
   941 		{
       
   942 		iLogInfo.Copy( _L("	4.4:  CTLSSession::ClientKeyExchange failed (4)") );
       
   943 		return EInconclusive;
       
   944 		}
       
   945 		
       
   946 	delete clientKeyExch;	
       
   947 	clientKeyExch = NULL;
       
   948 	
       
   949 	if( EFalse == CacheSessionL( aStep, sessionObj4) )
       
   950 		return EInconclusive;
       
   951 	
       
   952 	
       
   953 	// entry 4 inserted
       
   954 	//
       
   955 	
       
   956 		
       
   957 	TTLSSessionId sessionId;		
       
   958 	//case A:
       
   959 	
       
   960 	
       
   961 	iStatus = KRequestPending;
       
   962 	tlsProvider4->GetSessionL(
       
   963 		tlsCryptoAttributes->iSessionNameAndID.iServerName,
       
   964 		sessionId, 
       
   965 		iStatus );
       
   966 		
       
   967 		
       
   968 	SetActive();
       
   969 	CActiveScheduler::Start();
       
   970 	
       
   971 	if ( ( 0 != sessionId.Length() ) )
       
   972 		{
       
   973 		iLogInfo.Copy( _L("	4.4:  A: CTLSProvider::GetSession - found session: BAD") );
       
   974 		return EFail;
       
   975 		}
       
   976 		
       
   977 	//case B:
       
   978 		
       
   979 	CTLSProvider* tlsProvider5 = CTLSProvider::ConnectL();
       
   980 	
       
   981 	
       
   982 	CTlsCryptoAttributes* tlsCryptoAttributes5 = tlsProvider5->Attributes();
       
   983 		
       
   984 	
       
   985 	tlsCryptoAttributes5->iNegotiatedProtocol.iMajor = 3;
       
   986 	tlsCryptoAttributes5->iNegotiatedProtocol.iMinor = 1; 
       
   987 	
       
   988 	tlsCryptoAttributes5->iProposedProtocol.iMajor = 2;
       
   989 	tlsCryptoAttributes5->iProposedProtocol.iMinor = 0; 
       
   990 	
       
   991 	TTLSSessionNameAndID sessionNameAndID;
       
   992 	sessionNameAndID.iServerName.iAddress.Copy( KServer2 );
       
   993 	sessionNameAndID.iServerName.iPort = 10;
       
   994 			
       
   995 	iStatus = KRequestPending;
       
   996 	tlsProvider5->GetSessionL(
       
   997 		sessionNameAndID.iServerName,
       
   998 		sessionId,
       
   999 		iStatus );
       
  1000 		
       
  1001 	SetActive();
       
  1002 	CActiveScheduler::Start();
       
  1003 	
       
  1004 	if ( 0 != sessionId.Length()  )
       
  1005 		{
       
  1006 		iLogInfo.Copy( _L("	4.4: B: CTLSProvider::GetSession - found session: BAD") );
       
  1007 		return EFail;
       
  1008 		}
       
  1009 		
       
  1010 	
       
  1011 	//case C (positive):
       
  1012 		
       
  1013 	tlsCryptoAttributes5->iCurrentCipherSuite.iHiByte = 0;
       
  1014 	tlsCryptoAttributes5->iCurrentCipherSuite.iLoByte = 3;
       
  1015 	
       
  1016 		
       
  1017 	tlsCryptoAttributes5->iNegotiatedProtocol.iMajor = 3;
       
  1018 	tlsCryptoAttributes5->iNegotiatedProtocol.iMinor = 0; 
       
  1019 	
       
  1020 	tlsCryptoAttributes5->iProposedProtocol.iMajor = 3;
       
  1021 	tlsCryptoAttributes5->iProposedProtocol.iMinor = 0; 
       
  1022 	
       
  1023 	iStatus = KRequestPending;
       
  1024 	tlsProvider5->GetSessionL(
       
  1025 		sessionNameAndID.iServerName,
       
  1026 		sessionId,
       
  1027 		iStatus );
       
  1028 		
       
  1029 	SetActive();
       
  1030 	CActiveScheduler::Start();
       
  1031 	
       
  1032 	if ( ( 0 == sessionId.Length() ) )
       
  1033 		{
       
  1034 		iLogInfo.Copy( _L("	4.4:  C: CTLSProvider::GetSession - failed") );
       
  1035 		return EFail;
       
  1036 		}
       
  1037 	
       
  1038 	tlsCryptoAttributes5->iCurrentCipherSuite.iHiByte = 0;
       
  1039 	tlsCryptoAttributes5->iCurrentCipherSuite.iLoByte = 3;
       
  1040 	
       
  1041 		
       
  1042 	tlsCryptoAttributes5->iNegotiatedProtocol.iMajor = 3;
       
  1043 	tlsCryptoAttributes5->iNegotiatedProtocol.iMinor = 1; 
       
  1044 	
       
  1045 	tlsCryptoAttributes5->iProposedProtocol.iMajor = 3;
       
  1046 	tlsCryptoAttributes5->iProposedProtocol.iMinor = 1; 
       
  1047 	
       
  1048 	iStatus = KRequestPending;
       
  1049 	tlsProvider5->GetSessionL(
       
  1050 		sessionNameAndID.iServerName,
       
  1051 		sessionId,
       
  1052 		iStatus );
       
  1053 		
       
  1054 	SetActive();
       
  1055 	CActiveScheduler::Start();
       
  1056 	
       
  1057 	if ( ( 0 == sessionId.Length() ) )
       
  1058 		{
       
  1059 		iLogInfo.Copy( _L("	4.4:  D: CTLSProvider::GetSession - failed") );
       
  1060 		return EFail;
       
  1061 		}
       
  1062 	
       
  1063 	
       
  1064 	iLogInfo.Copy( _L("	4.4:  OK") );	
       
  1065 	
       
  1066 	delete tlsProvider;	
       
  1067 	delete tlsProvider2;
       
  1068 	delete tlsProvider3;
       
  1069 	delete tlsProvider4;
       
  1070 	delete tlsProvider5;
       
  1071 	delete sessionObj;
       
  1072 	delete sessionObj2;	
       
  1073 	delete sessionObj3;	
       
  1074 	delete sessionObj4;	
       
  1075 		
       
  1076 	return EPass;
       
  1077 	
       
  1078 	} 	
       
  1079 	
       
  1080 
       
  1081 
       
  1082 TVerdict CTlsProvTestActive::doTest4_5L( CTlsProvStep* aStep )
       
  1083 	{
       
  1084 	CTlsTestRandom rnd;
       
  1085 	
       
  1086 	SetThreadRandomL( &rnd );
       
  1087 	
       
  1088 	RArray<TTLSCipherSuite> userCipherSuiteList;
       
  1089 	CTLSProvider* tlsProvider = CTLSProvider::ConnectL();
       
  1090 	
       
  1091 	iStatus = KRequestPending;
       
  1092 	tlsProvider->CipherSuitesL( userCipherSuiteList ,iStatus);	
       
  1093 	SetActive();
       
  1094 	CActiveScheduler::Start();
       
  1095 	
       
  1096 			
       
  1097 	CTLSSession* sessionObj;
       
  1098 	
       
  1099 	CTlsCryptoAttributes* tlsCryptoAttributes = tlsProvider->Attributes();
       
  1100 	HBufC8* encServerCert = NULL;	
       
  1101 		
       
  1102 	TInt res =  StandardTestInitL(aStep, tlsCryptoAttributes, encServerCert);
       
  1103 	if( res  < 0 )
       
  1104 		{
       
  1105 		iLogInfo.Copy( _L("	4.5:  problems with test data files") );
       
  1106 		return EFail;
       
  1107 		}
       
  1108 	tlsCryptoAttributes->iSessionNameAndID.iSessionId.Copy( KSessionId2 );
       
  1109 		
       
  1110 	CX509Certificate* serverCert = NULL;
       
  1111 	iStatus = KRequestPending;
       
  1112 	tlsProvider->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
  1113 	SetActive();
       
  1114 	CActiveScheduler::Start();
       
  1115 	
       
  1116 	HBufC8* clientKeyExch = NULL;
       
  1117 	
       
  1118 	iStatus = KRequestPending;
       
  1119 	tlsProvider->CreateL( sessionObj,
       
  1120 						iStatus);	
       
  1121 	SetActive();
       
  1122 	CActiveScheduler::Start();	
       
  1123 	
       
  1124 	// check that ClientKeyExch is not NULL
       
  1125 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj) )
       
  1126 		{
       
  1127 		iLogInfo.Copy( _L("	4.5:  CTLSProvider::Create failed") );
       
  1128 		return EInconclusive;
       
  1129 		}
       
  1130 		
       
  1131 	iStatus = KRequestPending;
       
  1132 	sessionObj->ClientKeyExchange(clientKeyExch, iStatus);
       
  1133 	SetActive();
       
  1134 	CActiveScheduler::Start();
       
  1135 	
       
  1136 	// check that ClientKeyExch is not NULL
       
  1137 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
  1138 		{
       
  1139 		iLogInfo.Copy( _L("	4.5:  CTLSSession::ClientKeyExchange failed") );
       
  1140 		return EInconclusive;
       
  1141 		}
       
  1142 		
       
  1143 	if( EFalse == CacheSessionL( aStep, sessionObj) )
       
  1144 		return EInconclusive;
       
  1145 	
       
  1146 		
       
  1147 	TTLSSessionNameAndID sessionNameAndId;
       
  1148 	
       
  1149 	sessionNameAndId.iServerName.iAddress.Copy( KServer1 );
       
  1150 	sessionNameAndId.iServerName.iPort = 10;
       
  1151 	sessionNameAndId.iSessionId.Append( KSessionId2 );
       
  1152 	 
       
  1153 	
       
  1154 	iStatus = KRequestPending;
       
  1155 	tlsProvider->ClearSessionCacheL( 
       
  1156 			sessionNameAndId, 
       
  1157 			iStatus);
       
  1158 	SetActive();
       
  1159 	CActiveScheduler::Start();
       
  1160 	
       
  1161 	if ( (KErrNone != iStatus.Int()) )
       
  1162 		{
       
  1163 		iLogInfo.Copy( _L("	4.5:  CTLSProvider::ClearSessionCache - failed") );
       
  1164 		return EFail;
       
  1165 		}
       
  1166 	
       
  1167 	
       
  1168 	TTLSSessionId sessionId;
       
  1169 	
       
  1170 	iStatus = KRequestPending;
       
  1171 	tlsProvider->GetSessionL(
       
  1172 		sessionNameAndId.iServerName,
       
  1173 		sessionId,
       
  1174 		iStatus );
       
  1175 		
       
  1176 		
       
  1177 	SetActive();
       
  1178 	CActiveScheduler::Start();
       
  1179 		
       
  1180 	if ( ( 0 != sessionId.Length() ) )
       
  1181 		{
       
  1182 		iLogInfo.Copy( _L("	4.5:  session cleared but STILL in cache") );
       
  1183 		return EFail;
       
  1184 		}
       
  1185 	
       
  1186 	
       
  1187 	iLogInfo.Copy( _L("	4.5:  OK") );
       
  1188 	
       
  1189 	
       
  1190 	return EPass;
       
  1191 	
       
  1192 	} 	
       
  1193 
       
  1194 
       
  1195 TVerdict CTlsProvTestActive::doTest4_6L( CTlsProvStep* aStep )
       
  1196 	{
       
  1197 	CTlsTestRandom rnd;
       
  1198 	
       
  1199 	SetThreadRandomL( &rnd ); 
       
  1200 	
       
  1201 	RArray<TTLSCipherSuite> userCipherSuiteList;
       
  1202 	CTLSProvider* tlsProvider = CTLSProvider::ConnectL();
       
  1203 	CTLSProvider* tlsProvider2 = CTLSProvider::ConnectL();
       
  1204 	CTLSProvider* tlsProvider3 = CTLSProvider::ConnectL();
       
  1205 	
       
  1206 	CTLSSession* sessionObj;
       
  1207 	CTLSSession* sessionObj2;
       
  1208 	CTLSSession* sessionObj3;
       
  1209 	
       
  1210 		
       
  1211 	iStatus = KRequestPending;
       
  1212 	tlsProvider->CipherSuitesL( userCipherSuiteList ,iStatus);	
       
  1213 	SetActive();
       
  1214 	CActiveScheduler::Start();
       
  1215 				
       
  1216 	
       
  1217 	CTlsCryptoAttributes* tlsCryptoAttributes = tlsProvider->Attributes();
       
  1218 		
       
  1219 	HBufC8* encServerCert = NULL;
       
  1220 		
       
  1221 	TInt res =  StandardTestInitL(aStep, tlsCryptoAttributes, encServerCert);
       
  1222 	if( res  < 0 )
       
  1223 		{
       
  1224 		iLogInfo.Copy( _L("	4.6:  problems with test data files") );
       
  1225 		return EFail;
       
  1226 		}
       
  1227 		
       
  1228 	CX509Certificate* serverCert = NULL;
       
  1229 	iStatus = KRequestPending;
       
  1230 	tlsProvider->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
  1231 	SetActive();
       
  1232 	CActiveScheduler::Start();
       
  1233 	
       
  1234 		
       
  1235 	HBufC8* clientKeyExch = NULL;
       
  1236 	
       
  1237 	iStatus = KRequestPending;
       
  1238 	tlsProvider->CreateL( sessionObj,
       
  1239 						iStatus);	
       
  1240 	SetActive();
       
  1241 	CActiveScheduler::Start();	
       
  1242 	
       
  1243 	// check that ClientKeyExch is not NULL
       
  1244 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj) ) 
       
  1245 		{
       
  1246 		iLogInfo.Copy( _L("	4.6:  CTLSProvider::Create failed") );
       
  1247 		return EInconclusive;
       
  1248 		}
       
  1249 		
       
  1250 	iStatus = KRequestPending;
       
  1251 	sessionObj->ClientKeyExchange(clientKeyExch, iStatus);
       
  1252 	SetActive();
       
  1253 	CActiveScheduler::Start();
       
  1254 	
       
  1255 	// check that ClientKeyExch is not NULL
       
  1256 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
  1257 		{
       
  1258 		iLogInfo.Copy( _L("	4.6:  CTLSSession::ClientKeyExchange failed") );
       
  1259 		return EInconclusive;
       
  1260 		}
       
  1261 	
       
  1262 	
       
  1263 	if( EFalse == CacheSessionL( aStep, sessionObj) )
       
  1264 		return EInconclusive;
       
  1265 		
       
  1266 		
       
  1267 				
       
  1268 	//
       
  1269 	// entry 2 
       
  1270 	
       
  1271 	delete clientKeyExch;	
       
  1272 	clientKeyExch = NULL;
       
  1273 		
       
  1274 	
       
  1275 	CTlsCryptoAttributes* tlsCryptoAttributes2 = tlsProvider2->Attributes();
       
  1276 	
       
  1277 	delete encServerCert;
       
  1278 	encServerCert = NULL;	
       
  1279 		
       
  1280 	res = StandardTestInitL(aStep, tlsCryptoAttributes2, encServerCert);
       
  1281 	if( res  < 0 )
       
  1282 		{
       
  1283 		iLogInfo.Copy( _L("	4.6:  problems with test data files") );
       
  1284 		return EFail;
       
  1285 		}
       
  1286 	tlsCryptoAttributes2->iSessionNameAndID.iSessionId.Copy( KSessionId2 );
       
  1287 	
       
  1288 	RArray<TTLSCipherSuite> userCipherSuiteList2;
       
  1289 	iStatus = KRequestPending;
       
  1290 	tlsProvider2->CipherSuitesL( userCipherSuiteList2 ,iStatus);	
       
  1291 	SetActive();
       
  1292 	CActiveScheduler::Start();
       
  1293 	
       
  1294 	delete serverCert;
       
  1295 	serverCert = NULL;
       
  1296 	iStatus = KRequestPending;
       
  1297 	tlsProvider2->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
  1298 	SetActive();
       
  1299 	CActiveScheduler::Start();
       
  1300 		
       
  1301 	iStatus = KRequestPending;
       
  1302 	tlsProvider2->CreateL( sessionObj2,
       
  1303 						iStatus);	
       
  1304 	SetActive();
       
  1305 	CActiveScheduler::Start();	
       
  1306 	
       
  1307 	// check that ClientKeyExch is not NULL
       
  1308 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj2) ) 
       
  1309 		{
       
  1310 		iLogInfo.Copy( _L("	4.6:  CTLSProvider::Create failed") );
       
  1311 		return EInconclusive;
       
  1312 		}
       
  1313 		
       
  1314 	iStatus = KRequestPending;
       
  1315 	sessionObj2->ClientKeyExchange(clientKeyExch, iStatus);
       
  1316 	SetActive();
       
  1317 	CActiveScheduler::Start();
       
  1318 	
       
  1319 	// check that ClientKeyExch is not NULL
       
  1320 	if ( (NULL == clientKeyExch) || ( 0 == clientKeyExch->Length()) ) 
       
  1321 		{
       
  1322 		iLogInfo.Copy( _L("	4.6:  CTLSSession::ClientKeyExchange failed") );
       
  1323 		return EInconclusive;
       
  1324 		}
       
  1325 		
       
  1326 	delete clientKeyExch;	
       
  1327 	clientKeyExch = NULL;
       
  1328 	
       
  1329 	
       
  1330 	if( EFalse == CacheSessionL( aStep, sessionObj2) )
       
  1331 		return EInconclusive;
       
  1332 	
       
  1333 	// entry 2 
       
  1334 	//
       
  1335 	
       
  1336 	
       
  1337 	//
       
  1338 	// entry 3
       
  1339 	
       
  1340 	delete clientKeyExch;	
       
  1341 	clientKeyExch = NULL;
       
  1342 	
       
  1343 	RArray<TTLSCipherSuite> userCipherSuiteList3;
       
  1344 		
       
  1345 	iStatus = KRequestPending;
       
  1346 	tlsProvider3->CipherSuitesL( userCipherSuiteList3 ,iStatus);	
       
  1347 	SetActive();
       
  1348 	CActiveScheduler::Start();
       
  1349 	
       
  1350 		
       
  1351 	
       
  1352 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("ServerRnd2"),aStep->iServerRnd);
       
  1353 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("ClientRnd2"),aStep->iClientRnd);
       
  1354 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("KeyParams1_2"),aStep->iKeyParam1);
       
  1355 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("KeyParams2_2"),aStep->iKeyParam2);
       
  1356 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("KeyParams3_2"),aStep->iKeyParam3);
       
  1357 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("ServerCert2"),aStep->iServerCertChain);
       
  1358 	aStep->GetStringFromConfig(aStep->ConfigSection(),_L("ClientKeyExch2"),aStep->iClientKeyExch);
       
  1359 		
       
  1360 	CTlsCryptoAttributes* tlsCryptoAttributes3 = tlsProvider3->Attributes();
       
  1361 	
       
  1362 	tlsCryptoAttributes3->iClientAuthenticate = EFalse;
       
  1363 	tlsCryptoAttributes3->iDialogNonAttendedMode = ETrue;
       
  1364 	
       
  1365 	tlsCryptoAttributes3->iSessionNameAndID.iServerName.iAddress.Copy( KServer1 );
       
  1366 	tlsCryptoAttributes3->iSessionNameAndID.iServerName.iPort = 10;
       
  1367 	tlsCryptoAttributes3->iSessionNameAndID.iSessionId.Append( KSessionId3 );
       
  1368 	 
       
  1369 	
       
  1370 	tlsCryptoAttributes3->iCompressionMethod = ENullCompression;
       
  1371 	tlsCryptoAttributes3->iCurrentCipherSuite.iHiByte = 0;
       
  1372 	tlsCryptoAttributes3->iCurrentCipherSuite.iLoByte = 0x16;
       
  1373 	
       
  1374 		
       
  1375 	tlsCryptoAttributes3->iNegotiatedProtocol.iMajor = 3;
       
  1376 	tlsCryptoAttributes3->iNegotiatedProtocol.iMinor = 1; 
       
  1377 	
       
  1378 	tlsCryptoAttributes3->iProposedProtocol.iMajor = 3;
       
  1379 	tlsCryptoAttributes3->iProposedProtocol.iMinor = 1; 
       
  1380 		
       
  1381 		
       
  1382 	tlsCryptoAttributes3->iPublicKeyParams->iKeyType = EDHE;
       
  1383 		
       
  1384 	
       
  1385 	tlsCryptoAttributes3->iClientAuthenticate = EFalse; 
       
  1386 	tlsCryptoAttributes3->iDialogNonAttendedMode = ETrue;
       
  1387 	
       
  1388 	delete encServerCert;
       
  1389 	encServerCert = NULL;	
       
  1390 	
       
  1391 	res = aStep->ReadDataForCreateL(tlsCryptoAttributes3, encServerCert);
       
  1392 			
       
  1393 	if( res  < 0 )
       
  1394 		{
       
  1395 		iLogInfo.Copy( _L("	4.6:  problems with test data files") );
       
  1396 		return EFail;
       
  1397 		}
       
  1398 	
       
  1399 	delete serverCert;
       
  1400 	serverCert = NULL;
       
  1401 	iStatus = KRequestPending;
       
  1402 	tlsProvider3->VerifyServerCertificate( encServerCert->Des(), serverCert, iStatus);
       
  1403 	SetActive();
       
  1404 	CActiveScheduler::Start();
       
  1405 	
       
  1406 	iStatus = KRequestPending;
       
  1407 	tlsProvider3->CreateL( sessionObj3,
       
  1408 						iStatus);	
       
  1409 	SetActive();
       
  1410 	CActiveScheduler::Start();	
       
  1411 	
       
  1412 	HBufC8* clientKeyExchFromFile = NULL;
       
  1413 	res = aStep->ReadClientKeyExchL( clientKeyExchFromFile );
       
  1414 	if( res  < 0 )
       
  1415 		{
       
  1416 		iLogInfo.Copy( _L("	4.6:  problems with test data files (client key exchange)") );
       
  1417 		return EFail;
       
  1418 		}
       
  1419 			
       
  1420 	// check that ClientKeyExch is not NULL
       
  1421 	if ( (iStatus.Int() != KErrNone ) || (NULL == sessionObj3) )
       
  1422 		{
       
  1423 		iLogInfo.Copy( _L("	4.6:  CTLSProvider::Create failed") );
       
  1424 		return EInconclusive;
       
  1425 		}
       
  1426 		
       
  1427 		
       
  1428 	iStatus = KRequestPending;
       
  1429 	sessionObj3->ClientKeyExchange(clientKeyExch, iStatus);
       
  1430 	SetActive();
       
  1431 	CActiveScheduler::Start();
       
  1432 		
       
  1433 		
       
  1434 	// check that ClientKeyExch is not NULL
       
  1435 	if (  0 != clientKeyExchFromFile->Compare( clientKeyExch->Des() )  )
       
  1436 		{
       
  1437 		iLogInfo.Copy( _L("	4.6:  Client key exchange BAD (3, DHE)") );
       
  1438 		return EInconclusive;
       
  1439 		}
       
  1440 	
       
  1441 	// session should have been cached up to now but not set to resumable yet -
       
  1442 	// and it's left unresumable to check whether will be cleared after cache 
       
  1443 	// entries lifetime timeout
       
  1444 	
       
  1445 	//  entry 3
       
  1446 	//
       
  1447 				
       
  1448 	// before timeout:
       
  1449 	
       
  1450 	TTLSSessionId sessionId;
       
  1451 	
       
  1452 	iStatus = KRequestPending;
       
  1453 	tlsProvider2->GetSessionL(
       
  1454 		tlsCryptoAttributes->iSessionNameAndID.iServerName,
       
  1455 		sessionId,
       
  1456 		iStatus );
       
  1457 		
       
  1458 		
       
  1459 	SetActive();
       
  1460 	CActiveScheduler::Start();
       
  1461 	
       
  1462 	if ( ( 0 == sessionId.Length() ) )
       
  1463 		{
       
  1464 		iLogInfo.Copy( _L("	4.6:  Before timeout: CTLSProvider::GetSession - returned nothing") );
       
  1465 		return EFail;
       
  1466 		}
       
  1467 		
       
  1468 		
       
  1469 	// wait for timeout:
       
  1470 	RTimer timer;
       
  1471 	timer.CreateLocal();
       
  1472 	TTimeIntervalMicroSeconds32 waitTime( 1000000*(KTLSCachingTimeout + 5));
       
  1473 	timer.After( iStatus, waitTime);
       
  1474 	SetActive();
       
  1475 	CActiveScheduler::Start();	
       
  1476 	
       
  1477 	// after timeout
       
  1478 	sessionId.Zero();	
       
  1479 	
       
  1480 	iStatus = KRequestPending;
       
  1481 	tlsProvider2->GetSessionL(
       
  1482 		tlsCryptoAttributes->iSessionNameAndID.iServerName,
       
  1483 		sessionId, 
       
  1484 		iStatus );
       
  1485 		
       
  1486 		
       
  1487 	SetActive();
       
  1488 	CActiveScheduler::Start();
       
  1489 	
       
  1490 	if ( ( 0 != sessionId.Length() ) )
       
  1491 		{
       
  1492 		iLogInfo.Copy( _L("	4.6:  After timeout: CTLSProvider::GetSession - cache NOT empty") );
       
  1493 		return EFail;
       
  1494 		}
       
  1495 	
       
  1496 		
       
  1497 	iLogInfo.Copy( _L("	4.6:  OK") );	
       
  1498 	
       
  1499 	delete tlsProvider;	
       
  1500 	delete tlsProvider2;
       
  1501 	delete tlsProvider3;
       
  1502 	
       
  1503 	delete sessionObj;
       
  1504 	delete sessionObj2;		
       
  1505 	delete sessionObj3;		
       
  1506 	
       
  1507 	return EPass;
       
  1508 			
       
  1509 	} 
       
  1510 	
       
  1511