networksecurity/tls/ts_tls/T_TLS_test.cpp
branchRCL_3
changeset 58 8d540f55e491
parent 57 abbed5a4b42a
child 75 c1029e558ef5
equal deleted inserted replaced
57:abbed5a4b42a 58:8d540f55e491
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   286 		err = iTlsSocket->SetProtocol( prot );
   286 		err = iTlsSocket->SetProtocol( prot );
   287 		if ( err )
   287 		if ( err )
   288 			{
   288 			{
   289 			iTestStep->Log( _L("Failed to set Protocol for use: (%d)"),err );
   289 			iTestStep->Log( _L("Failed to set Protocol for use: (%d)"),err );
   290 			}
   290 			}
   291 
   291 #ifdef HTTP_ALLOW_UNTRUSTED_CERTIFICATES
       
   292 		if(iTLSDialogMode) 
       
   293 		    {
       
   294             iStatus = iTlsSocket->SetOpt(KSoDialogMode,KSolInetSSL,iTLSDialogModeValue);
       
   295             if ( iStatus != KErrNone )
       
   296                 {
       
   297                 if(iExpectedErrorCode == iStatus.Int())
       
   298                     {
       
   299                     iTestStep->Log( _L("iTlsSocket->SetOpt() failed with KErrArgument because of invalid DialogModeValue "));
       
   300                     iRunState = EConnectionClosed;
       
   301                     iTestPassed = ETrue;
       
   302                     }
       
   303                 else
       
   304                     {
       
   305                     iTestStep->Log( _L("iTlsSocket->SetOpt() failed with error: %d"), iStatus.Int());
       
   306                     }
       
   307                 iTlsSocket->Close();                 
       
   308                 iTimer.After( iStatus, 1000000 );
       
   309                 SetActive();
       
   310                 break;
       
   311                 }
       
   312 		    }
       
   313 #endif  // HTTP_ALLOW_UNTRUSTED_CERTIFICATES
   292 		// Set the domain name we're connecting to...
   314 		// Set the domain name we're connecting to...
   293 		iStatus = iTlsSocket->SetOpt(KSoSSLDomainName,KSolInetSSL, iDNSName);
   315 		iStatus = iTlsSocket->SetOpt(KSoSSLDomainName,KSolInetSSL, iDNSName);
   294 		if ( iStatus != KErrNone )
   316 		if ( iStatus != KErrNone )
   295 			{
   317 			{
   296 			iTestStep->Log( KStateErrReceivePage, iStatus.Int() );
   318 			iTestStep->Log( KStateErrReceivePage, iStatus.Int() );
   328 
   350 
   329 
   351 
   330 
   352 
   331 		if ( iStatus != KErrNone )
   353 		if ( iStatus != KErrNone )
   332 			{
   354 			{
   333 			TPtrC errorText = iTestStep->EpocErrorToText(iStatus.Int());
   355 #ifdef HTTP_ALLOW_UNTRUSTED_CERTIFICATES
   334 			iTestStep->Log( _L("ESecureConnected:%S %d"),&errorText, iStatus.Int() );
   356             if(iExpectedErrorCode == iStatus.Int())
   335 			iTestStep->Log( KStateErrReceivePage, iStatus.Int() );
   357                 {
   336 			iTestStep->Log( KStateErrReceivePage, iStatus.Int() );
   358                 iTestStep->Log( _L("Received Untrusted CA"));
   337 			iRunState = EConnectionClosed;
   359                 iRunState = EConnectionClosed;
   338 			iTestPassed = EFalse;
   360                 iTestPassed = ETrue;
   339 			iTlsSocket->Close();				 
   361                 }
   340 			iTimer.After( iStatus, 1000000 );
   362             else
   341 			SetActive();
   363                 {
   342 			break;
   364 #endif  // HTTP_ALLOW_UNTRUSTED_CERTIFICATES
   343 			}
   365                 TPtrC errorText = iTestStep->EpocErrorToText(iStatus.Int());
       
   366                 iTestStep->Log( _L("ESecureConnected:%S %d"),&errorText, iStatus.Int() );
       
   367                 iTestStep->Log( KStateErrReceivePage, iStatus.Int() );
       
   368                 iTestStep->Log( KStateErrReceivePage, iStatus.Int() );
       
   369                 iRunState = EConnectionClosed;
       
   370                 iTestPassed = EFalse;
       
   371 #ifdef HTTP_ALLOW_UNTRUSTED_CERTIFICATES
       
   372                 }
       
   373 #endif  // HTTP_ALLOW_UNTRUSTED_CERTIFICATES
       
   374                 iTlsSocket->Close();                 
       
   375                 iTimer.After( iStatus, 1000000 );
       
   376                 SetActive();
       
   377                 break;                
       
   378             }
   344 		else
   379 		else
   345 			{
   380 			{
   346 			iTestStep->Log( _L("ESecureConnected:KErrNone %d"),iStatus.Int() );
   381 			iTestStep->Log( _L("ESecureConnected:KErrNone %d"),iStatus.Int() );
   347 			}
   382 			}
   348 
   383 
   719 void CTLSTest::DoCancel()
   754 void CTLSTest::DoCancel()
   720 	{	
   755 	{	
   721 	// Cancel the connect
   756 	// Cancel the connect
   722 	iSocket.CancelConnect();
   757 	iSocket.CancelConnect();
   723 	}
   758 	}
   724 
   759 #ifdef HTTP_ALLOW_UNTRUSTED_CERTIFICATES
   725 void CTLSTest::ConnectL( const TDesC &aAddress, 
   760 void CTLSTest::ConnectL( const TDesC &aAddress, 
   726 				const TInt aPortNum, 
   761 				const TInt aPortNum, 
   727 				const TDesC &aPage, 
   762 				const TDesC &aPage, 
   728 				const TDesC8 &aCipherSuite, 
   763 				const TDesC8 &aCipherSuite, 
   729 				const TInt aCipher, 
   764 				const TInt aCipher, 
   730 				const TInt aSimpleGet, 
   765 				const TInt aSimpleGet, 
   731 				const TInt aTestEndDelay, 
   766 				const TInt aTestEndDelay, 
   732 				const TDesC8& aDNSName ,
   767 				const TDesC8& aDNSName ,
   733 				const TDesC& aProtocol, 
   768 				const TDesC& aProtocol, 
   734 				TBool aUseGenericSocket, 
   769 				TBool aUseGenericSocket, 
   735 				TBool aEAPKeyDerivation )
   770 				TBool aEAPKeyDerivation,
       
   771 				TBool aTLSDialogMode,
       
   772 				TInt aTLSDialogModeValue,
       
   773 				TInt aExpectedErrorCode )
       
   774 #else
       
   775 void CTLSTest::ConnectL( const TDesC &aAddress, 
       
   776                 const TInt aPortNum, 
       
   777                 const TDesC &aPage, 
       
   778                 const TDesC8 &aCipherSuite, 
       
   779                 const TInt aCipher, 
       
   780                 const TInt aSimpleGet, 
       
   781                 const TInt aTestEndDelay, 
       
   782                 const TDesC8& aDNSName ,
       
   783                 const TDesC& aProtocol, 
       
   784                 TBool aUseGenericSocket, 
       
   785                 TBool aEAPKeyDerivation )
       
   786 #endif  // HTTP_ALLOW_UNTRUSTED_CERTIFICATES
   736 	{
   787 	{
   737 #if 0
   788 #if 0
   738 	iRunState = EDummyConnection;
   789 	iRunState = EDummyConnection;
   739 	TRequestStatus* p=&iStatus;
   790 	TRequestStatus* p=&iStatus;
   740 	User::RequestComplete( p, KErrNone );
   791 	User::RequestComplete( p, KErrNone );
   771 	iPage.Copy( aPage );
   822 	iPage.Copy( aPage );
   772 	iSimpleGet = aSimpleGet;
   823 	iSimpleGet = aSimpleGet;
   773 	iTestEndDelay = aTestEndDelay;
   824 	iTestEndDelay = aTestEndDelay;
   774 	iUseGenericSocket = aUseGenericSocket;
   825 	iUseGenericSocket = aUseGenericSocket;
   775 	iEAPKeyDerivation = aEAPKeyDerivation;
   826 	iEAPKeyDerivation = aEAPKeyDerivation;
   776 
   827 #ifdef HTTP_ALLOW_UNTRUSTED_CERTIFICATES
       
   828 	iTLSDialogMode = aTLSDialogMode;
       
   829 	iTLSDialogModeValue = aTLSDialogModeValue;
       
   830 	iExpectedErrorCode = aExpectedErrorCode;
       
   831 #endif  // HTTP_ALLOW_UNTRUSTED_CERTIFICATES
   777 	// Print info to the log
   832 	// Print info to the log
   778 	iTestStep->Log( _L("*****Connecting to*****") );
   833 	iTestStep->Log( _L("*****Connecting to*****") );
   779 	iTestStep->Log( _L("%s:%d "), iAddress.PtrZ(), iPortNum ); 
   834 	iTestStep->Log( _L("%s:%d "), iAddress.PtrZ(), iPortNum ); 
   780 
   835 
   781 
   836