networksecurity/tlsprovider/Test/tlstest2/cachedservcertstep.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 encodedcertstep.cpp
       
    18  @internalTechnology
       
    19 */
       
    20 #include "cachedservcertstep.h"
       
    21 
       
    22 #include <tlsprovinterface.h>
       
    23 
       
    24 CCachedServCertStep::CCachedServCertStep()
       
    25 	{
       
    26 	SetTestStepName(KCachedServCertStep);
       
    27 	}
       
    28 
       
    29 // Note this test step is not suitable to use with PSK cipher suites.	
       
    30 
       
    31 TVerdict CCachedServCertStep::doTestStepL()
       
    32 	{
       
    33 	
       
    34 	TRequestStatus status;
       
    35 	
       
    36   	INFO_PRINTF1(_L("Calling TLS Provider to fetch cipher suites."));
       
    37 	
       
    38 	// first we have to retrieve the available cipher suites
       
    39 	TInt err = GetCipherSuitesL();
       
    40 	
       
    41  	if (err != KErrNone)
       
    42 		{
       
    43 		INFO_PRINTF2(_L("Failed! Cannot retrieve supported cipher suites! (Error %d)"), err);
       
    44 		SetTestStepResult(EFail);
       
    45 		return TestStepResult();
       
    46 		}
       
    47 	
       
    48 		// we have to verify the server certificate, to supply the certificate
       
    49 		// and its parameters to the TLS provider.
       
    50 
       
    51 	INFO_PRINTF1(_L("Calling TLS Provider to verify server certificate."));
       
    52 
       
    53 	CX509Certificate* cert = NULL;
       
    54 
       
    55 	err = VerifyServerCertificateL(cert);
       
    56 	
       
    57 	CleanupStack::PushL(cert);
       
    58 		
       
    59 	// make sure it completed sucessfully.
       
    60 	if (err != KErrNone)
       
    61 		{
       
    62 		INFO_PRINTF2(_L("Failed! Server Certificate did not verify correctly! (Error %d)"),
       
    63 			err);
       
    64 		SetTestStepResult(EFail);
       
    65 		return TestStepResult();
       
    66 		}		
       
    67 			
       
    68   	INFO_PRINTF1(_L("Creating TLS Session."));	
       
    69 	
       
    70 	// now, create a session with the parameters set in the preamble
       
    71  	err = CreateSessionL();
       
    72 	
       
    73 	// ensure we succeeded
       
    74 	if (err != KErrNone)
       
    75 		{
       
    76 		INFO_PRINTF2(_L("Failed! Create Session failed! (Error %d)"), err);
       
    77 		SetTestStepResult(EFail);
       
    78 		CleanupStack::PopAndDestroy(cert);
       
    79 		return TestStepResult();
       
    80 		}
       
    81 	
       
    82  	INFO_PRINTF1(_L("Calling TLS session key exchange."));    
       
    83 	
       
    84  	HBufC8* keyExMessage = NULL;
       
    85   	err = ClientKeyExchange(keyExMessage);
       
    86 	
       
    87 	if (err != KErrNone)
       
    88 		{
       
    89 		INFO_PRINTF2(_L("Failed! Key exchange failed! (Error %d)"), err);
       
    90 		delete keyExMessage;
       
    91 		SetTestStepResult(EFail);
       
    92 		CleanupStack::PopAndDestroy(cert);
       
    93 		return TestStepResult();
       
    94 		}     
       
    95 		
       
    96   	CleanupStack::PushL(keyExMessage);
       
    97 	
       
    98 	// examine the key exchange message, checking it is as expected.
       
    99  	ExamineKeyExchangeMessageL(*keyExMessage, CipherSuites()); 
       
   100  	
       
   101  	CX509Certificate* cachedCert = NULL;
       
   102  	
       
   103  	// Increases test code coverage. (Cancellation).
       
   104  	// Actually, this behaves as a syncronous method, so cancellation will have no effect
       
   105  	SessionServerCertificateWithCancel(cachedCert);
       
   106  	 	
       
   107 	CleanupStack::PushL(cachedCert);
       
   108 	//compare retrieved cert with original one:
       
   109 	if ( cachedCert->IsEqualL( *cert ) == EFalse  ) 
       
   110 		{
       
   111 		INFO_PRINTF1(_L("Failed! Original server cert differs from cached one"));
       
   112 		SetTestStepResult(EFail);   
       
   113 		}
       
   114 	else
       
   115 		{
       
   116 		INFO_PRINTF1(_L("Original server cert is equal to cached one"));
       
   117 		}
       
   118 	
       
   119 	CleanupStack::PopAndDestroy(cachedCert);     
       
   120 	CleanupStack::PopAndDestroy(keyExMessage);     
       
   121     CleanupStack::PopAndDestroy(cert);
       
   122 	
       
   123 	return TestStepResult();
       
   124 	}
       
   125 
       
   126