networksecurity/tlsprovider/Test/ttlsoom/tlsoomstepbase.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2005-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
       
    18 */
       
    19 
       
    20 #include "tlsoomstepbase.h"
       
    21 
       
    22 #include <TestExecuteLog.h>
       
    23 
       
    24 TVerdict CTlsOOMStepBase::Start()
       
    25 	{
       
    26 	
       
    27 	for (TInt i = 1; i < KMaxOOMSteps; i++)
       
    28 		{
       
    29 		
       
    30 		__UHEAP_MARK;
       
    31 		__UHEAP_FAILNEXT(i);
       
    32 		
       
    33 		TRAPD(err, DoTestStepL());
       
    34 		
       
    35 		__UHEAP_MARKEND;
       
    36 		__UHEAP_RESET;
       
    37 		
       
    38 		if (err == KErrNone && iStatus == KErrNone)
       
    39 			{
       
    40 		
       
    41 			return EPass;
       
    42 			
       
    43 			}
       
    44 		
       
    45 		
       
    46 		}
       
    47 		
       
    48 	return EFail;
       
    49 	
       
    50 	}
       
    51 	
       
    52 void CTlsOOMStepBase::RunL()
       
    53 	{
       
    54 	CActiveScheduler::Stop();
       
    55 	}
       
    56 	
       
    57 CTlsOOMStepBase::CTlsOOMStepBase(CTestExecuteLogger& aLogger, const TDesC& aConfigPath)
       
    58 	: CActive(EPriorityStandard),
       
    59 	  iLogger(aLogger),
       
    60 	  iConfigPath(aConfigPath)
       
    61 	{
       
    62 	CActiveScheduler::Add(this);
       
    63 	}
       
    64 
       
    65 void CTlsOOMStepBase::DoCancel()
       
    66 	{
       
    67 	}
       
    68 	
       
    69 // Leaves the tlsprovider and certificate on the stack
       
    70 // the attributes become owned by the provider.
       
    71 
       
    72 void CTlsOOMStepBase::InitTlsProviderLC(CTLSProvider*& aTlsProvider, CTlsCryptoAttributes*& aCryptoAttributes,
       
    73 	HBufC8*& aServerCert)
       
    74 	{
       
    75 	
       
    76 	aTlsProvider = CTLSProvider::ConnectL();
       
    77 	CleanupStack::PushL(aTlsProvider);
       
    78 	
       
    79 	RArray<TTLSCipherSuite> userCipherSuites;
       
    80 	CleanupClosePushL(userCipherSuites);
       
    81 	iStatus = KRequestPending;
       
    82 	aTlsProvider->CipherSuitesL(userCipherSuites, iStatus);
       
    83 	SetActive();
       
    84 	CActiveScheduler::Start();
       
    85 	TInt err = (0 == userCipherSuites.Count()) ? KErrNotSupported : KErrNone; 
       
    86 	User::LeaveIfError(err);
       
    87 	CleanupStack::PopAndDestroy(&userCipherSuites);
       
    88 
       
    89 	aCryptoAttributes = aTlsProvider->Attributes();
       
    90 	
       
    91 	RFs fs;
       
    92 	User::LeaveIfError(fs.Connect());
       
    93 	CleanupClosePushL(fs);
       
    94 	
       
    95 	// Read server random
       
    96 	
       
    97 	static const TInt KRandomDataLen = 32;
       
    98 	
       
    99 	TBuf8<KRandomDataLen> input;
       
   100 	_LIT(KServerRandomFileName, "server.rnd");
       
   101 	ReadFileDataL(input, KServerRandomFileName, fs);
       
   102 	aCryptoAttributes->iMasterSecretInput.iServerRandom.Copy(input.Ptr(), KRandomDataLen);
       
   103 	
       
   104 	// Read Client Random
       
   105 	input.Zero();
       
   106 	_LIT(KClientRandomFileName, "client.rnd");
       
   107 	ReadFileDataL(input, KClientRandomFileName, fs);
       
   108 	aCryptoAttributes->iMasterSecretInput.iClientRandom.Copy(input.Ptr(), KRandomDataLen);
       
   109 	
       
   110 	// Read server key parameters
       
   111 	
       
   112 	TBuf8<1000> paramInput;
       
   113 	_LIT(KParamFileFormat, "keyparam%d.prm");
       
   114 	
       
   115 	TBuf<14> paramFile;
       
   116 	
       
   117 	for (TInt i = 1; i <= 3; i++)
       
   118 		{
       
   119 		
       
   120 		paramFile.Format(KParamFileFormat, i);
       
   121 		ReadFileDataL(paramInput, paramFile, fs);
       
   122 		
       
   123 		switch (i)
       
   124 			{
       
   125 			case 1:
       
   126 				 aCryptoAttributes->iPublicKeyParams->iValue1 = paramInput.AllocL();
       
   127 				 break;
       
   128 			case 2:
       
   129 				 aCryptoAttributes->iPublicKeyParams->iValue2 = paramInput.AllocL();
       
   130 				 break; 
       
   131 			case 3:
       
   132 				 aCryptoAttributes->iPublicKeyParams->iValue3 = paramInput.AllocL();
       
   133 				 break; 
       
   134 			}
       
   135 			
       
   136 		paramInput.Zero();
       
   137 		
       
   138 		}
       
   139 		
       
   140 	aCryptoAttributes->iPublicKeyParams->iKeyType = ERsa;
       
   141 	
       
   142 	// Read server certificate
       
   143 	
       
   144 	TBuf8<1000> certInput;
       
   145 	_LIT(KCertFileName, "server.cer");
       
   146 	ReadFileDataL(certInput, KCertFileName, fs);
       
   147 	
       
   148 	aServerCert = certInput.AllocL();
       
   149 	
       
   150 	CleanupStack::PopAndDestroy(&fs);
       
   151 	CleanupStack::PushL(aServerCert);
       
   152 	
       
   153 	}
       
   154 	
       
   155 void CTlsOOMStepBase::ReadFileDataL(TDes8& aDest, const TDesC& aFileName, RFs& aFileServer)
       
   156 	{
       
   157 	
       
   158 	TPath fileName;	
       
   159 	RFile file;
       
   160 	_LIT(KFileNameFormat, "%S\\%S");
       
   161 	
       
   162 	fileName.Format(KFileNameFormat, &iConfigPath, &aFileName);
       
   163 	
       
   164 	User::LeaveIfError(file.Open(aFileServer, fileName, EFileRead));
       
   165 	CleanupClosePushL(file);
       
   166 	
       
   167 	User::LeaveIfError(file.Read(aDest));
       
   168 	
       
   169 	CleanupStack::PopAndDestroy(&file);
       
   170 	
       
   171 	}