networksecurity/tlsprovider/Test/tlstest2/servcertwithdialogstep.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 servcertwithdialogstep.cpp
       
    18  @internalTechnology
       
    19 */
       
    20 #include "servcertwithdialogstep.h"
       
    21 #include <tlsprovinterface.h>
       
    22 
       
    23 CServCertWithDialogStep::CServCertWithDialogStep()
       
    24 	{
       
    25 	SetTestStepName(KServCertWithDialogStep);
       
    26 	}
       
    27 
       
    28 TVerdict CServCertWithDialogStep::doTestStepPreambleL()
       
    29 	{
       
    30 	ConstructL();
       
    31 	// reads value for secure dialog (Yes or Not)
       
    32 	if (EFalse == GetStringFromConfig(ConfigSection(),KDialogOption,iDialogOption))
       
    33 		{	
       
    34 		INFO_PRINTF1(_L("Expected DialogOption tag is required to continue the test"));
       
    35 		User::Leave(KErrNotFound);
       
    36 		}	
       
    37 	return EPass;
       
    38 	}
       
    39 	
       
    40 TVerdict CServCertWithDialogStep::doTestStepL()
       
    41 	{
       
    42 	// Deletes input and output files for dialog file.
       
    43 	DeleteSecureDialogFilesL();
       
    44 	
       
    45 	// Sets secure dialog used by this test framework to act with a "Yes" when necessary. 
       
    46  	RFs fs;
       
    47 	User::LeaveIfError(fs.Connect());
       
    48 	CleanupClosePushL(fs);
       
    49 	
       
    50 	RFileWriteStream stream;
       
    51 	TDriveUnit sysDrive (RFs::GetSystemDrive());
       
    52 	TBuf<128> inputFile (sysDrive.Name());
       
    53 	inputFile.Append(KInputFile);
       
    54 	
       
    55 	TInt err = stream.Open(fs, inputFile, EFileWrite | EFileShareExclusive);
       
    56 	if (err == KErrNotFound)
       
    57 		{
       
    58 		err = stream.Create(fs, inputFile, EFileWrite | EFileShareExclusive);
       
    59 		}
       
    60 	User::LeaveIfError(err);
       
    61 	stream.PushL();
       
    62 		
       
    63  	SetDialogRecordL(stream, EServerAuthenticationFailure, _L("Passphrase of the imported key file"), iDialogOption, KNullDesC);
       
    64 	stream.CommitL();
       
    65 	CleanupStack::PopAndDestroy(2, &fs); // and stream      
       
    66 		
       
    67 	CTlsCryptoAttributes* atts = Provider()->Attributes();
       
    68 	atts->iDialogNonAttendedMode = EFalse;  
       
    69 	
       
    70 	INFO_PRINTF1(_L("Calling TLS Provider Verify Certificate."));
       
    71 	
       
    72 	CX509Certificate* cert = NULL;
       
    73 	err = VerifyServerCertificateL(cert);
       
    74 	delete cert; // don't really need the cert
       
    75 	
       
    76 	TInt expectedResult;
       
    77 	
       
    78 	if (!GetIntFromConfig(ConfigSection(), KExpectedResult, expectedResult))
       
    79 		{
       
    80 		// failed to get expected result from config file... using KErrNone.
       
    81 		expectedResult = KErrNone;
       
    82 		}
       
    83 	
       
    84 	if (err != expectedResult)
       
    85 		{
       
    86 		INFO_PRINTF3(_L("Failed! TLS Provider returned error code %d, expecting %d."),
       
    87 			err, expectedResult);
       
    88 		SetTestStepResult(EFail);
       
    89 		return EFail;
       
    90 		}
       
    91 	else
       
    92 		{
       
    93 		INFO_PRINTF1(_L("Test passed."));
       
    94 		SetTestStepResult(EPass);
       
    95 		}
       
    96 	return TestStepResult();
       
    97 	}