networksecurity/tlsprovider/Test/tlstest2/ciphersuitesstep.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2006-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 ciphersuitestep.cpp
       
    18  @internalTechnology
       
    19 */
       
    20 #include "ciphersuitesstep.h"
       
    21 
       
    22 #include <tlsprovinterface.h>
       
    23 
       
    24 CCipherSuitesStep::CCipherSuitesStep()
       
    25 	{
       
    26 	SetTestStepName(KCipherSuitesStep);
       
    27 	}
       
    28 
       
    29 TVerdict CCipherSuitesStep::doTestStepPreambleL()
       
    30 	{
       
    31 	// No tls setup required.
       
    32 	ConstructL();
       
    33 	
       
    34 	CTlsCryptoAttributes* atts = Provider()->Attributes();
       
    35 	// Reads if NULL ciphers suites are to be allowed from INI file.
       
    36 	ReadUseNullCipher();
       
    37 	if(UseNullCipher())
       
    38 		{
       
    39 		// Enables null cipher by setting appropiate parameter  
       
    40 		atts->iAllowNullCipherSuites = ETrue;
       
    41  		}		
       
    42 		
       
    43 		
       
    44 	
       
    45 	// Reads PSK values if included in INI file.
       
    46 	ReadPskToBeUsedL();
       
    47 	
       
    48 	// Reads if NULL ciphers suites are to be allowed from INI file.
       
    49 	ReadUseNullCipher();
       
    50 	
       
    51 	
       
    52 	// If cipher suite under test is uses PSK (Pre Shared Key)
       
    53 	if(UsePsk())
       
    54 		{
       
    55 		// Populates values for PSK 
       
    56 		atts->iPskConfigured = true;
       
    57 		}
       
    58 
       
    59 
       
    60 	if(UseNullCipher())
       
    61 		{
       
    62 		// Enables null cipher by setting appropiate parameter  
       
    63 		atts->iAllowNullCipherSuites = ETrue;
       
    64  		}		
       
    65 		
       
    66 		
       
    67 	// read the list of cipher suites (in order) that
       
    68 	// we think we ought to be supporting.
       
    69 	TInt numCiphers(0);
       
    70 	if (!GetIntFromConfig(ConfigSection(), KNumCipherSuites, numCiphers))
       
    71 		{
       
    72 		User::Leave(KErrNotFound);
       
    73 		}
       
    74 		
       
    75 	INFO_PRINTF1(_L("Reading expected cipher suited from ini."));
       
    76 		
       
    77 	for (TInt i = 1; i <= numCiphers; ++i)
       
    78 		{
       
    79 		TBuf<128> suiteTag;
       
    80 		suiteTag.Append(KCipherSuiteBase);
       
    81 		suiteTag.AppendNum(i);
       
    82 		
       
    83 		TInt cipherSuite(0);
       
    84 		if (!GetHexFromConfig(ConfigSection(), suiteTag, cipherSuite))
       
    85 			{
       
    86 			User::Leave(KErrNotFound);
       
    87 			}
       
    88 			
       
    89 		TTLSCipherSuite suite;
       
    90 		suite.iLoByte = cipherSuite & 0xFF;
       
    91 		suite.iHiByte = (((TUint)cipherSuite) >> 8) & 0xFF;
       
    92 		
       
    93 		iSuites.AppendL(suite);
       
    94 		}
       
    95 	return EPass;
       
    96 	}
       
    97 
       
    98 TVerdict CCipherSuitesStep::doTestStepL()
       
    99 	{
       
   100 	SetTestStepResult(EFail);
       
   101 	INFO_PRINTF1(_L("Fetching TLS Provider supported cipher suites."));
       
   102 	TInt err = GetCipherSuitesL();
       
   103 	if (err != KErrNone)
       
   104 		{
       
   105 		INFO_PRINTF1(_L("Failed! Could not get supported cipher suites from TLS Provider!"));
       
   106 		}
       
   107 	else if (CipherSuites().Count() != iSuites.Count())
       
   108 		{
       
   109 		INFO_PRINTF3(_L("Failed! TLS Provider supports %d suites, expecting %d."),
       
   110 			CipherSuites().Count(), iSuites.Count());
       
   111 		}
       
   112 	else
       
   113 		{
       
   114 		for (TInt i = 0; i < iSuites.Count(); ++i)
       
   115 			{
       
   116 	 	
       
   117 			if (!(iSuites[i] == CipherSuites()[i]))
       
   118 				{
       
   119 				INFO_PRINTF1(_L("Failed! Cipher suites or order different from expected!"));
       
   120  				return TestStepResult();
       
   121 				}
       
   122 			}
       
   123 		}
       
   124 	
       
   125 	// does nothing significant but increases code coverage.
       
   126 	Provider()->ReConnectL();
       
   127 	Provider()->ReConnectL();
       
   128 	err = GetCipherSuitesL();
       
   129 	Provider()->ConnectL();
       
   130 	Provider()->ReConnectL();
       
   131 		
       
   132 	if (err != KErrNone)
       
   133 		{
       
   134 		INFO_PRINTF1(_L("Failed! Could not get supported cipher suites from TLS Provider!"));
       
   135 		}
       
   136 	else if (CipherSuites().Count() != iSuites.Count())
       
   137 		{
       
   138 		INFO_PRINTF3(_L("Failed! TLS Provider supports %d suites, expecting %d."),
       
   139 			CipherSuites().Count(), iSuites.Count());
       
   140 		}
       
   141 	else
       
   142 		{
       
   143 		SetTestStepResult(EPass);
       
   144 		for (TInt i = 0; i < iSuites.Count(); ++i)
       
   145 			{
       
   146 			if (!(iSuites[i] == CipherSuites()[i]))
       
   147 				{
       
   148 				INFO_PRINTF1(_L("Failed! Cipher suites or order different from expected!"));
       
   149 			
       
   150 				SetTestStepResult(EFail);
       
   151 				break;
       
   152 				}
       
   153 			}
       
   154 		}
       
   155 	return TestStepResult();
       
   156 	}
       
   157 	
       
   158 CCipherSuitesStep::~CCipherSuitesStep()
       
   159 	{
       
   160 	iSuites.Close();
       
   161 	}