networksecurity/tls/protocol/tlsconnection.cpp
branchRCL_3
changeset 75 c1029e558ef5
parent 67 bb2423252ea3
equal deleted inserted replaced
67:bb2423252ea3 75:c1029e558ef5
     1 // Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-2009 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".
    24 #include "recordprotocolevents.h"
    24 #include "recordprotocolevents.h"
    25 #include "tlshandshake.h"
    25 #include "tlshandshake.h"
    26 #include "applicationdata.h"
    26 #include "applicationdata.h"
    27 #include <es_sock.h>
    27 #include <es_sock.h>
    28 #include <in_sock.h>
    28 #include <in_sock.h>
    29 #include <featdiscovery.h>
       
    30 #include <featureuids.h>
       
    31 
    29 
    32 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    30 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    33 #include <ssl_internal.h>
    31 #include <ssl_internal.h>
    34 #endif
    32 #endif
    35 
    33 
    53   	LOG(Log::Printf(_L("RHeap::Size(), RHeap::Size() - RHeap::Available() %d, %d"), User::Heap().Size(), User::Heap().Size() - User::Heap().Available( nBlock ) );)
    51   	LOG(Log::Printf(_L("RHeap::Size(), RHeap::Size() - RHeap::Available() %d, %d"), User::Heap().Size(), User::Heap().Size() - User::Heap().Available( nBlock ) );)
    54 #endif
    52 #endif
    55 
    53 
    56 	CleanupStack::PushL(self);
    54 	CleanupStack::PushL(self);
    57 	self->ConstructL(aSocket, aProtocol);
    55 	self->ConstructL(aSocket, aProtocol);
    58 	CleanupStack::Pop(self);
    56 	CleanupStack::Pop();
    59 	return self;
    57 	return self;
    60 }
    58 }
    61 
    59 
    62 EXPORT_C MSecureSocket* CTlsConnection::NewL(MGenericSecureSocket& aSocket, const TDesC& aProtocol)
    60 EXPORT_C MSecureSocket* CTlsConnection::NewL(MGenericSecureSocket& aSocket, const TDesC& aProtocol)
    63 /**
    61 /**
    78   	LOG(Log::Printf(_L("RHeap::Size(), RHeap::Size() - RHeap::Available() %d, %d"), User::Heap().Size(), User::Heap().Size() - User::Heap().Available( nBlock ) );)
    76   	LOG(Log::Printf(_L("RHeap::Size(), RHeap::Size() - RHeap::Available() %d, %d"), User::Heap().Size(), User::Heap().Size() - User::Heap().Available( nBlock ) );)
    79 #endif
    77 #endif
    80 
    78 
    81 	CleanupStack::PushL(self);
    79 	CleanupStack::PushL(self);
    82 	self->ConstructL(aSocket, aProtocol);
    80 	self->ConstructL(aSocket, aProtocol);
    83 	CleanupStack::Pop(self);
    81 	CleanupStack::Pop();
    84 	return self;
    82 	return self;
    85 }
    83 }
    86 
    84 
    87 EXPORT_C void CTlsConnection::UnloadDll(TAny* /*aPtr*/)
    85 EXPORT_C void CTlsConnection::UnloadDll(TAny* /*aPtr*/)
    88 /**
    86 /**
   154 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   152 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   155 
   153 
   156 	User::LeaveIfError( SetProtocol(aProtocol) );
   154 	User::LeaveIfError( SetProtocol(aProtocol) );
   157 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   155 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   158 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   156 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   159 	TBool allowUntrustedCertificates = EFalse;
   157 	iTlsProvider->Attributes()->iDialogNonAttendedMode = EFalse;
   160 	allowUntrustedCertificates = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KFeatureIdFfHttpAllowUntrustedCertificates);
       
   161 	
       
   162 	if( allowUntrustedCertificates )
       
   163 	  {
       
   164       iTlsProvider->Attributes()->iDialogMode = ETTLSDialogModeAllowAutomatic;
       
   165 	  }
       
   166 	else
       
   167 	  {
       
   168 	  iTlsProvider->Attributes()->iDialogNonAttendedMode = EFalse;
       
   169 	  }
       
   170 	iDialogMode = EDialogModeAttended;
   158 	iDialogMode = EDialogModeAttended;
   171 
   159 
   172 	iGenericSocket = new(ELeave)CGenericSecureSocket<RSocket>(aSocket);
   160 	iGenericSocket = new(ELeave)CGenericSecureSocket<RSocket>(aSocket);
   173 
   161 
   174 	iRecordParser = new(ELeave)CRecordParser( *iGenericSocket, *iTlsProvider );
   162 	iRecordParser = new(ELeave)CRecordParser( *iGenericSocket, *iTlsProvider );
   216 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   204 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   217 
   205 
   218 	User::LeaveIfError( SetProtocol(aProtocol) );
   206 	User::LeaveIfError( SetProtocol(aProtocol) );
   219 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   207 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   220 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   208 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   221 	TBool allowUntrustedCertificates = EFalse;
   209 	iTlsProvider->Attributes()->iDialogNonAttendedMode = EFalse;
   222 	allowUntrustedCertificates = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KFeatureIdFfHttpAllowUntrustedCertificates);
       
   223 
       
   224 	if( allowUntrustedCertificates )
       
   225 	  {
       
   226 	  iTlsProvider->Attributes()->iDialogMode = ETTLSDialogModeAttended;
       
   227 	  }
       
   228 	else
       
   229 	  {
       
   230 	  iTlsProvider->Attributes()->iDialogNonAttendedMode = EFalse;
       
   231 	  }
       
   232 	iDialogMode = EDialogModeAttended;
   210 	iDialogMode = EDialogModeAttended;
   233 
   211 
   234 	iRecordParser = new(ELeave)CRecordParser( aSocket, *iTlsProvider );
   212 	iRecordParser = new(ELeave)CRecordParser( aSocket, *iTlsProvider );
   235   	LOG(Log::Printf(_L("iRecordParser %x - %x"), iRecordParser, (TUint)iRecordParser + sizeof( CRecordParser ));)
   213   	LOG(Log::Printf(_L("iRecordParser %x - %x"), iRecordParser, (TUint)iRecordParser + sizeof( CRecordParser ));)
   236 	iRecordComposer = new(ELeave)CRecordComposer( aSocket, *iTlsProvider );
   214 	iRecordComposer = new(ELeave)CRecordComposer( aSocket, *iTlsProvider );
   930 	
   908 	
   931 	// This method must ensure that the dialog mode passed in is part of the 
   909 	// This method must ensure that the dialog mode passed in is part of the 
   932 	// TDialogMode enum or has the value EDialogModeUnattended/EDialogModeAttended. 
   910 	// TDialogMode enum or has the value EDialogModeUnattended/EDialogModeAttended. 
   933 	// Otherwise, it must return KErrArgument
   911 	// Otherwise, it must return KErrArgument
   934 	TInt ret = KErrNone;
   912 	TInt ret = KErrNone;
   935 	TBool allowUntrustedCertificates = EFalse;
   913    
   936 	TRAP(ret, allowUntrustedCertificates = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KFeatureIdFfHttpAllowUntrustedCertificates));
   914     switch(aDialogMode)
   937 	
   915     {
   938 	if(KErrNone == ret)
   916         case EDialogModeUnattended:
   939 	{
   917         case EDialogModeAttended:
   940 		TTLSDialogMode tlsDialogMode( ETTLSDialogModeAttended );
   918             iDialogMode = aDialogMode;
   941 		switch(aDialogMode)
   919         break;
   942 		{
   920         
   943 			case EDialogModeUnattended:
   921         default:  //-- wrong mode
   944 				{
   922             LOG(Log::Printf(_L("SetDialogMode() - Unknown dialog mode, default setting (Attended mode) being used"));)
   945 				if( allowUntrustedCertificates )
   923         return KErrArgument;    
   946 					{
   924     };
   947 					tlsDialogMode = ETTLSDialogModeUnattended;
   925 
   948 					iDialogMode = aDialogMode;
   926     if ( iTlsProvider )
   949 					break;        
   927     {
   950 					}
   928    	    iTlsProvider->Attributes()->iDialogNonAttendedMode = (iDialogMode == EDialogModeUnattended);
   951 				}
   929     }	
   952 			case EDialogModeAttended:
       
   953 				{
       
   954 				if( allowUntrustedCertificates )
       
   955 					{
       
   956 					tlsDialogMode = ETTLSDialogModeAttended;
       
   957 					}
       
   958 				iDialogMode = aDialogMode;
       
   959 				break;
       
   960 				}
       
   961 			case EDialogModeAllowAutomatic:
       
   962 				{
       
   963 				tlsDialogMode = ETTLSDialogModeAllowAutomatic;
       
   964 				iDialogMode = aDialogMode;
       
   965 				break; 
       
   966 				}
       
   967 			
       
   968 			default:  //-- wrong mode
       
   969 				LOG(Log::Printf(_L("SetDialogMode() - Unknown dialog mode, default setting (Attended mode) being used"));)
       
   970 			return KErrArgument;    
       
   971 		};
       
   972 
       
   973 		if ( iTlsProvider )
       
   974 		{
       
   975 		if( allowUntrustedCertificates )
       
   976 			{
       
   977 			iTlsProvider->Attributes()->iDialogMode = tlsDialogMode;
       
   978 			}
       
   979 		else
       
   980 			{
       
   981 			iTlsProvider->Attributes()->iDialogNonAttendedMode = (iDialogMode == EDialogModeUnattended);
       
   982 			}
       
   983 		}
       
   984 	}
       
   985 
   930 
   986     return ret;
   931     return ret;
   987 }
   932 }
   988 
   933 
   989 TInt CTlsConnection::SetOpt(TUint aOptionName,TUint aOptionLevel, const TDesC8& aOption)
   934 TInt CTlsConnection::SetOpt(TUint aOptionName,TUint aOptionLevel, const TDesC8& aOption)
  1242 	   if ( iHandshake != aStateMachine )
  1187 	   if ( iHandshake != aStateMachine )
  1243 	      {
  1188 	      {
  1244 		   return EFalse;
  1189 		   return EFalse;
  1245 	      }
  1190 	      }
  1246       else
  1191       else
  1247          {
  1192          {//delete data path in case it's re-negotiation what's failed
  1248 		 //We came here since tls handshake failed for some reasons.
  1193          delete iSendAppData;
  1249          //Attempting to delete the application data state machines here,
  1194          iSendAppData = NULL;
  1250          //leads to sending incorrect status to the caller application.
  1195          delete iRecvAppData;
  1251          //Allow the cleanup of handshake statemachine to continue here.
  1196          iRecvAppData = NULL;
  1252          //Let the application data state machines be cleaned up by the 
  1197          ResetCryptoAttributes();
  1253          //tlsconnection desctructor function.
       
  1254          
       
  1255          //delete iSendAppData;
       
  1256          //iSendAppData = NULL;
       
  1257          //delete iRecvAppData;
       
  1258          //iRecvAppData = NULL;
       
  1259          //ResetCryptoAttributes();
       
  1260          }
  1198          }
  1261    }
  1199    }
  1262    else
  1200    else
  1263    {//from now on we propose the alrady negotiated protocol untill the connection is closed
  1201    {//from now on we propose the alrady negotiated protocol untill the connection is closed
  1264       iTlsProvider->Attributes()->iProposedProtocol = iTlsProvider->Attributes()->iNegotiatedProtocol;
  1202       iTlsProvider->Attributes()->iProposedProtocol = iTlsProvider->Attributes()->iNegotiatedProtocol;
  1368 		//and wait for re-negotiation to finish (see CTlsConnection::OnCompletion)
  1306 		//and wait for re-negotiation to finish (see CTlsConnection::OnCompletion)
  1369 	}
  1307 	}
  1370 	else
  1308 	else
  1371 	{	
  1309 	{	
  1372 		iRecordComposer->SetUserData( (TDesC8*)&aDesc );
  1310 		iRecordComposer->SetUserData( (TDesC8*)&aDesc );
  1373 		iRecordComposer->ResetCurrentPos();
  1311    	iRecordComposer->ResetCurrentPos();
  1374 		iSendAppData->Start( &aStatus, this );
  1312 		iSendAppData->Start( &aStatus, this );
  1375 	}
  1313 	}
  1376 	
  1314 	
  1377 	return ETrue;
  1315 	return ETrue;
  1378 }
  1316 }