networksecurity/tlsprovider/Test/tlstest2/delayedgetsessionstep.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2008-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 /**
       
    17  @file delayedgetsessionstep.cpp
       
    18  @internalTechnology
       
    19 */
       
    20 #include "delayedgetsessionstep.h"
       
    21 #include <tlsprovinterface.h>
       
    22 
       
    23 #define KServer2  _L8("192.168.10.11")
       
    24 #define KSessionId4 _L8("444444444455555555556666666666")
       
    25 #define KSessionId2 _L8("222222222233333333334444444444")
       
    26 
       
    27 CDelayedGetSessionStep::CDelayedGetSessionStep()
       
    28 	{
       
    29 	SetTestStepName(KDelayedGetSessionStep);
       
    30 	}
       
    31 	
       
    32 TVerdict CDelayedGetSessionStep::doTestStepL()
       
    33 	{
       
    34 	TInt sessionDelay;
       
    35 	sessionDelay = ReadGetSessionDelayL();
       
    36 	
       
    37 	// first we have to retrieve the available cipher suites
       
    38 	TInt err = GetCipherSuitesL();  
       
    39 	TInt sessionIdLength(0) ;
       
    40 	
       
    41 	CTlsCryptoAttributes* tlsCryptoAttributes = Provider()->Attributes();
       
    42 				
       
    43 	CX509Certificate* cert = NULL;
       
    44 	err = VerifyServerCertificateL(cert);
       
    45 	delete cert; // don't really need the cert
       
    46 	
       
    47 	err = CreateSessionL();
       
    48 		
       
    49 	// ensure we succeeded
       
    50 	if (err != KErrNone)
       
    51 		{
       
    52 		INFO_PRINTF2(_L("Failed! Create Session failed! (Error %d)"), err);
       
    53 		SetTestStepResult(EFail);
       
    54 		}
       
    55 	
       
    56 	HBufC8* keyExMessage = NULL;
       
    57 	err = ClientKeyExchange(keyExMessage);
       
    58 	
       
    59 	if (err != KErrNone)
       
    60 		{
       
    61 		INFO_PRINTF2(_L("Failed! Key exchange failed! (Error %d)"), err);
       
    62 		SetTestStepResult(EFail);
       
    63 		}
       
    64 	CleanupStack::PushL(keyExMessage);	
       
    65 	
       
    66 	// Call ServerFinished to do the chache
       
    67 	// derive the premaster secret from the key exchange method	
       
    68  	INFO_PRINTF1(_L("Deriving master secret."));
       
    69 	HBufC8* premaster = DerivePreMasterSecretL(*keyExMessage);
       
    70 	CleanupStack::PopAndDestroy(keyExMessage);  
       
    71 	 
       
    72 	// compute the master secret from the premaster.
       
    73 	CleanupStack::PushL(premaster);
       
    74 	HBufC8* master = ComputeMasterSecretL(*premaster);
       
    75 	CleanupStack::PopAndDestroy(premaster);
       
    76 	CleanupStack::PushL(master);  
       
    77 	
       
    78 	// do the caching 
       
    79 	ValidateServerFinishL(*master);
       
    80 	
       
    81 	CleanupStack::PopAndDestroy(master);
       
    82 	
       
    83 	err = VerifyGetSessionL(tlsCryptoAttributes->iSessionNameAndID.iServerName, sessionIdLength);
       
    84 	// case A			
       
    85 	if (err != KErrNone || sessionIdLength == 0)
       
    86 		{
       
    87 		INFO_PRINTF1(_L("Case A Failed! GetSession failed!"));
       
    88 		SetTestStepResult(EFail);
       
    89 		return TestStepResult();
       
    90 		}
       
    91 	
       
    92 	RTimer timer;
       
    93 	TRequestStatus timerStatus;
       
    94 	timer.CreateLocal();
       
    95 	TTimeIntervalMicroSeconds32 waitTime( 1000000*(sessionDelay));
       
    96 	timer.After( timerStatus, waitTime);
       
    97 	User::WaitForRequest(timerStatus);
       
    98 	timer.Close();  
       
    99 	
       
   100 	err = 0;
       
   101 	sessionIdLength = 0;
       
   102 	
       
   103 	err = VerifyGetSessionL(tlsCryptoAttributes->iSessionNameAndID.iServerName, sessionIdLength);
       
   104 	// case B, delay should have caused session to be cleared.
       
   105 	if ( sessionIdLength != 0)
       
   106 		{
       
   107 		INFO_PRINTF1(_L("Case B Failed! GetSession failed!"));
       
   108 		SetTestStepResult(EFail);
       
   109 		}
       
   110 						
       
   111 	return TestStepResult();
       
   112 	}
       
   113