networksecurity/tls/protocol/tlsconnection.cpp
branchRCL_3
changeset 22 8d540f55e491
parent 21 abbed5a4b42a
child 23 425d8f4f7fa5
equal deleted inserted replaced
21:abbed5a4b42a 22: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".
    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>
    29 
    31 
    30 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    32 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    31 #include <ssl_internal.h>
    33 #include <ssl_internal.h>
    32 #endif
    34 #endif
    33 
    35 
   152 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   154 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   153 
   155 
   154 	User::LeaveIfError( SetProtocol(aProtocol) );
   156 	User::LeaveIfError( SetProtocol(aProtocol) );
   155 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   157 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   156 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   158 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   157 	iTlsProvider->Attributes()->iDialogNonAttendedMode = EFalse;
   159 	TBool allowUntrustedCertificates = 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 	  }
   158 	iDialogMode = EDialogModeAttended;
   170 	iDialogMode = EDialogModeAttended;
   159 
   171 
   160 	iGenericSocket = new(ELeave)CGenericSecureSocket<RSocket>(aSocket);
   172 	iGenericSocket = new(ELeave)CGenericSecureSocket<RSocket>(aSocket);
   161 
   173 
   162 	iRecordParser = new(ELeave)CRecordParser( *iGenericSocket, *iTlsProvider );
   174 	iRecordParser = new(ELeave)CRecordParser( *iGenericSocket, *iTlsProvider );
   163   	LOG(Log::Printf(_L("iRecordParser %x - %x"), iRecordParser, (TUint)iRecordParser + sizeof( CRecordParser ));)
   175   	LOG(Log::Printf(_L("iRecordParser %x - %x"), iRecordParser, (TUint)iRecordParser + sizeof( CRecordParser ));)
   164 	iRecordComposer = new(ELeave)CRecordComposer( *iGenericSocket, *iTlsProvider );
   176 	iRecordComposer = new(ELeave)CRecordComposer( *iGenericSocket, *iTlsProvider );
   165 	TBuf<32> tempBuf;
   177 	TBuf<32> tempBuf;
   166    	tempBuf.Copy(aProtocol);
   178     tempBuf.Copy(aProtocol);
   167    	tempBuf.UpperCase();
   179     tempBuf.UpperCase();
   168    	TInt ret = tempBuf.Compare(KProtocolVerSSL30);
   180     TInt ret = tempBuf.Compare(KProtocolVerSSL30);
   169    	if (!ret)
   181     if (!ret)
   170    	    {
   182       {
   171 	    iRecordComposer->SetVersion(&KSSL3_0);
   183       iRecordComposer->SetVersion(&KSSL3_0);
   172    	    }
   184   	  }
   173    	else
   185     else
   174    	    {
   186       {
   175 	    iRecordComposer->SetVersion(&KTLS1_0);
   187       iRecordComposer->SetVersion(&KTLS1_0);
   176    	    }
   188       }
   177 
       
   178   	LOG(Log::Printf(_L("iRecordComposer %x - %x"), iRecordComposer, (TUint)iRecordComposer + sizeof( CRecordComposer ));)
   189   	LOG(Log::Printf(_L("iRecordComposer %x - %x"), iRecordComposer, (TUint)iRecordComposer + sizeof( CRecordComposer ));)
   179 
   190 
   180 #ifdef _DEBUG
   191 #ifdef _DEBUG
   181    TInt nBlock;
   192    TInt nBlock;
   182   	LOG(Log::Printf(_L("RHeap::Size(), RHeap::Size() - RHeap::Available() %d, %d"), User::Heap().Size(), User::Heap().Size() - User::Heap().Available( nBlock ) );)
   193   	LOG(Log::Printf(_L("RHeap::Size(), RHeap::Size() - RHeap::Available() %d, %d"), User::Heap().Size(), User::Heap().Size() - User::Heap().Available( nBlock ) );)
   205 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   216 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   206 
   217 
   207 	User::LeaveIfError( SetProtocol(aProtocol) );
   218 	User::LeaveIfError( SetProtocol(aProtocol) );
   208 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   219 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   209 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   220 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   210 	iTlsProvider->Attributes()->iDialogNonAttendedMode = EFalse;
   221 	TBool allowUntrustedCertificates = 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 	  }
   211 	iDialogMode = EDialogModeAttended;
   232 	iDialogMode = EDialogModeAttended;
   212 
   233 
   213 	iRecordParser = new(ELeave)CRecordParser( aSocket, *iTlsProvider );
   234 	iRecordParser = new(ELeave)CRecordParser( aSocket, *iTlsProvider );
   214   	LOG(Log::Printf(_L("iRecordParser %x - %x"), iRecordParser, (TUint)iRecordParser + sizeof( CRecordParser ));)
   235   	LOG(Log::Printf(_L("iRecordParser %x - %x"), iRecordParser, (TUint)iRecordParser + sizeof( CRecordParser ));)
   215 	iRecordComposer = new(ELeave)CRecordComposer( aSocket, *iTlsProvider );
   236 	iRecordComposer = new(ELeave)CRecordComposer( aSocket, *iTlsProvider );
   909 	
   930 	
   910 	// This method must ensure that the dialog mode passed in is part of the 
   931 	// This method must ensure that the dialog mode passed in is part of the 
   911 	// TDialogMode enum or has the value EDialogModeUnattended/EDialogModeAttended. 
   932 	// TDialogMode enum or has the value EDialogModeUnattended/EDialogModeAttended. 
   912 	// Otherwise, it must return KErrArgument
   933 	// Otherwise, it must return KErrArgument
   913 	TInt ret = KErrNone;
   934 	TInt ret = KErrNone;
   914    
   935 	TBool allowUntrustedCertificates = EFalse;
   915     switch(aDialogMode)
   936 	TRAP(ret, allowUntrustedCertificates = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KFeatureIdFfHttpAllowUntrustedCertificates));
   916     {
   937 	
   917         case EDialogModeUnattended:
   938 	if(KErrNone == ret)
   918         case EDialogModeAttended:
   939 	{
   919             iDialogMode = aDialogMode;
   940 		TTLSDialogMode tlsDialogMode( ETTLSDialogModeAttended );
   920         break;
   941 		switch(aDialogMode)
   921         
   942 		{
   922         default:  //-- wrong mode
   943 			case EDialogModeUnattended:
   923             LOG(Log::Printf(_L("SetDialogMode() - Unknown dialog mode, default setting (Attended mode) being used"));)
   944 				{
   924         return KErrArgument;    
   945 				if( allowUntrustedCertificates )
   925     };
   946 					{
   926 
   947 					tlsDialogMode = ETTLSDialogModeUnattended;
   927     if ( iTlsProvider )
   948 					iDialogMode = aDialogMode;
   928     {
   949 					break;        
   929    	    iTlsProvider->Attributes()->iDialogNonAttendedMode = (iDialogMode == EDialogModeUnattended);
   950 					}
   930     }	
   951 				}
       
   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 	}
   931 
   985 
   932     return ret;
   986     return ret;
   933 }
   987 }
   934 
   988 
   935 TInt CTlsConnection::SetOpt(TUint aOptionName,TUint aOptionLevel, const TDesC8& aOption)
   989 TInt CTlsConnection::SetOpt(TUint aOptionName,TUint aOptionLevel, const TDesC8& aOption)