networksecurity/tls/protocol/tlsconnection.cpp
branchRCL_3
changeset 53 7e41d162e158
parent 10 c64cefac6e99
child 57 abbed5a4b42a
equal deleted inserted replaced
52:3652a10b304a 53:7e41d162e158
     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 );
   204 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   216 	iTlsProvider = CTLSProvider::ConnectL();		// Set up Security/crypto interfaces
   205 
   217 
   206 	User::LeaveIfError( SetProtocol(aProtocol) );
   218 	User::LeaveIfError( SetProtocol(aProtocol) );
   207 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   219 	iTlsProvider->Attributes()->iCurrentCipherSuite.iLoByte = 0x00;
   208 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   220 	iTlsProvider->Attributes()->iCurrentCipherSuite.iHiByte = 0x00;
   209 	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 	  }
   210 	iDialogMode = EDialogModeAttended;
   232 	iDialogMode = EDialogModeAttended;
   211 
   233 
   212 	iRecordParser = new(ELeave)CRecordParser( aSocket, *iTlsProvider );
   234 	iRecordParser = new(ELeave)CRecordParser( aSocket, *iTlsProvider );
   213   	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 ));)
   214 	iRecordComposer = new(ELeave)CRecordComposer( aSocket, *iTlsProvider );
   236 	iRecordComposer = new(ELeave)CRecordComposer( aSocket, *iTlsProvider );
   908 	
   930 	
   909 	// 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 
   910 	// TDialogMode enum or has the value EDialogModeUnattended/EDialogModeAttended. 
   932 	// TDialogMode enum or has the value EDialogModeUnattended/EDialogModeAttended. 
   911 	// Otherwise, it must return KErrArgument
   933 	// Otherwise, it must return KErrArgument
   912 	TInt ret = KErrNone;
   934 	TInt ret = KErrNone;
   913    
   935 	TBool allowUntrustedCertificates = EFalse;
   914     switch(aDialogMode)
   936 	TRAP(ret, allowUntrustedCertificates = CFeatureDiscovery::IsFeatureSupportedL(NFeature::KFeatureIdFfHttpAllowUntrustedCertificates));
   915     {
   937 	
   916         case EDialogModeUnattended:
   938 	if(KErrNone == ret)
   917         case EDialogModeAttended:
   939 	{
   918             iDialogMode = aDialogMode;
   940 		TTLSDialogMode tlsDialogMode( ETTLSDialogModeAttended );
   919         break;
   941 		switch(aDialogMode)
   920         
   942 		{
   921         default:  //-- wrong mode
   943 			case EDialogModeUnattended:
   922             LOG(Log::Printf(_L("SetDialogMode() - Unknown dialog mode, default setting (Attended mode) being used"));)
   944 				{
   923         return KErrArgument;    
   945 				if( allowUntrustedCertificates )
   924     };
   946 					{
   925 
   947 					tlsDialogMode = ETTLSDialogModeUnattended;
   926     if ( iTlsProvider )
   948 					iDialogMode = aDialogMode;
   927     {
   949 					break;        
   928    	    iTlsProvider->Attributes()->iDialogNonAttendedMode = (iDialogMode == EDialogModeUnattended);
   950 					}
   929     }	
   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 	}
   930 
   985 
   931     return ret;
   986     return ret;
   932 }
   987 }
   933 
   988 
   934 TInt CTlsConnection::SetOpt(TUint aOptionName,TUint aOptionLevel, const TDesC8& aOption)
   989 TInt CTlsConnection::SetOpt(TUint aOptionName,TUint aOptionLevel, const TDesC8& aOption)