networksecurity/tlsprovider/Test/tlstest2/multicancelstep.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 multicancelstep.cpp
       
    18  @internalTechnology
       
    19 */
       
    20 #include "multicancelstep.h"
       
    21 #include <tlsprovinterface.h>
       
    22 
       
    23 
       
    24 CMultiCancelStep::CMultiCancelStep()
       
    25 	{
       
    26 	SetTestStepName(KMultiCancelStep);
       
    27 	}
       
    28 	
       
    29 TVerdict CMultiCancelStep::doTestStepL()
       
    30 	{
       
    31 	INFO_PRINTF1(_L("Calling TLS Provider to fetch cipher suites."));
       
    32 	
       
    33 	// Gets cipher suite with cancellation to increase test code coverage.
       
    34 	TInt err = GetCipherSuitesWithCancelL();
       
    35 	if (err != KErrNone && err != KErrCancel)
       
    36 		{
       
    37 		INFO_PRINTF2(_L("Unnexpected error when retrieving supported cipher suites! (with cancellation) (Error %d)"),			err);
       
    38 		SetTestStepResult(EFail);
       
    39 		return TestStepResult();
       
    40 		}
       
    41 	
       
    42 	// first we have to retrieve the available cipher suites
       
    43 	err = 0;
       
    44 	err = GetCipherSuitesL();
       
    45 	
       
    46 	if (err != KErrNone)
       
    47 		{
       
    48 		INFO_PRINTF2(_L("Failed! Cannot retrieve supported cipher suites! (Error %d)"),
       
    49 			err);
       
    50 		SetTestStepResult(EFail);
       
    51 		return TestStepResult();
       
    52 		}
       
    53 		
       
    54 	// verifies certificate if is not a PSK cipher suite
       
    55   	if( !UsePsk() )
       
    56 		{
       
    57 			// we have to verify the server certificate, to supply the certificate
       
    58 		// and its parameters to the TLS provider.
       
    59 
       
    60 		INFO_PRINTF1(_L("Calling TLS Provider to verify server certificate, followed of cancellation of request."));
       
    61 
       
    62 		CX509Certificate* cert = NULL;
       
    63 		
       
    64 		// Important part of the test: cancellation
       
    65  		err = VerifyServerCertificateWithCancelL(cert);
       
    66 		delete cert;
       
    67 		
       
    68 			// make sure it returned was cancelled.
       
    69 		if (err != KErrCancel)
       
    70 			{
       
    71 			INFO_PRINTF2(_L("Failed! Server Certificate cancelled returned incorrect Error: %d"),
       
    72 				err);
       
    73 			SetTestStepResult(EFail);
       
    74 			return TestStepResult();
       
    75 			}
       
    76 				
       
    77 		// Reissue same request but this time it does not cancel request.
       
    78 		err = VerifyServerCertificateL(cert);
       
    79 		delete cert;
       
    80 				
       
    81 		// make sure it completed sucessfully.
       
    82 		if (err != KErrNone)
       
    83 			{
       
    84 			INFO_PRINTF2(_L("Failed! Server Certificate did not verify correctly! (Error %d)"),
       
    85 					err);
       
    86 			SetTestStepResult(EFail);
       
    87 			return TestStepResult();
       
    88 			}
       
    89 		}   
       
    90 	
       
    91   	INFO_PRINTF1(_L("Creating TLS Session."));	
       
    92   	// now, create a session with followed of a cancel of request
       
    93   	err = CreateSessionWithCancelL();
       
    94   	if (err != KErrCancel)
       
    95 		{
       
    96 		INFO_PRINTF2(_L("Failed! CreateSession cancelled returned incorrect Error: %d"),
       
    97 			err);
       
    98 		SetTestStepResult(EFail);
       
    99 		return TestStepResult();
       
   100 		}
       
   101   	
       
   102 	// now, create a session with the parameters set in the preamble
       
   103 	err = CreateSessionL();
       
   104 	
       
   105 	// Ensure we succeeded
       
   106 	if (err != KErrNone)
       
   107 		{
       
   108 		INFO_PRINTF2(_L("Failed! Create Session failed! (Error %d)"), err);
       
   109 		SetTestStepResult(EFail);
       
   110 		return TestStepResult();
       
   111 		}
       
   112 	
       
   113 	INFO_PRINTF1(_L("Calling TLS session key exchange with cancellation."));
       
   114 	HBufC8* keyExMessage = NULL;
       
   115 	
       
   116 	// Important part of the test: cancellation
       
   117 	err = ClientKeyExchangeWithCancel(keyExMessage);
       
   118 	
       
   119 	if (err != KErrCancel)
       
   120 		{
       
   121 		INFO_PRINTF2(_L("Client Key Exchange cancellation returned incorrect Error %d)"), err);
       
   122 		delete keyExMessage;
       
   123 		SetTestStepResult(EFail);
       
   124 		return TestStepResult();
       
   125 		}
       
   126 	
       
   127 	// Makes same request but this time does not cancel it
       
   128 	err = ClientKeyExchange(keyExMessage);
       
   129 		
       
   130 	if (err != KErrNone)
       
   131 		{
       
   132 		INFO_PRINTF2(_L("Failed! Key exchange failed! (Error %d)"), err);
       
   133 		delete keyExMessage;
       
   134 		SetTestStepResult(EFail);
       
   135 		return TestStepResult();
       
   136 		}
       
   137 	
       
   138 	INFO_PRINTF1(_L("Deriving premaster secret."));
       
   139 			
       
   140 	// derive the premaster secret from the key exchange method	
       
   141 	CleanupStack::PushL(keyExMessage);
       
   142 	HBufC8* premaster = DerivePreMasterSecretL(*keyExMessage);
       
   143 	CleanupStack::PopAndDestroy(keyExMessage);
       
   144 	
       
   145 	INFO_PRINTF1(_L("Deriving master secret."));
       
   146 	
       
   147 	// compute the master secret from the premaster.
       
   148 	CleanupStack::PushL(premaster);
       
   149 	HBufC8* master = ComputeMasterSecretL(*premaster);
       
   150 	CleanupStack::PopAndDestroy(premaster);
       
   151 	CleanupStack::PushL(master);
       
   152 	
       
   153 	ValidateServerFinishedL(*master);
       
   154 		
       
   155 	CleanupStack::PopAndDestroy(master);
       
   156 			
       
   157 	return TestStepResult();
       
   158 		
       
   159 	}
       
   160