eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/plugin/src/EapTlsPeapUiConnection.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 428 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 #include "EapTlsPeapUtils.h"
       
    28 #include <EapTlsPeapUiConnection.h>
       
    29 #include <EapTlsPeapUiDataConnection.h>
       
    30 #include <EapTlsPeapUiCipherSuites.h>
       
    31 #include <EapTlsPeapUiEapTypes.h>
       
    32 #include <EapTlsPeapUiCertificates.h>
       
    33 #include <AbsEapTlsPeapUiCertificates.h>
       
    34 #include "eap_am_trace_symbian.h"
       
    35 
       
    36 #ifdef USE_PAC_STORE
       
    37 #include "pac_store_db_symbian.h"
       
    38 #endif
       
    39 
       
    40 CEapTlsPeapUiConnection::CEapTlsPeapUiConnection(
       
    41     const TIndexType aIndexType,
       
    42     const TInt aIndex,
       
    43     const TInt aTunnelingType,
       
    44 	const TInt aEapType)
       
    45     : iIndexType(aIndexType)
       
    46     , iIndex(aIndex)
       
    47     , iTunnelingType(aTunnelingType)
       
    48     , iEapType(aEapType)
       
    49     , iIsConnected(EFalse)
       
    50     , iDataConn(NULL)
       
    51     , iCipherSuites(NULL)
       
    52     , iEapTypes(NULL)
       
    53     , iCertificates(NULL)
       
    54     , iPacStoreDb(NULL)
       
    55 {
       
    56 }
       
    57 
       
    58 
       
    59 CEapTlsPeapUiConnection::~CEapTlsPeapUiConnection()
       
    60 {
       
    61 #ifdef USE_PAC_STORE
       
    62 	delete iPacStoreDb;
       
    63 #endif
       
    64 }
       
    65 
       
    66 TInt CEapTlsPeapUiConnection::Connect()
       
    67 {
       
    68 	if(iIsConnected)
       
    69 	{
       
    70 		// Already connected.
       
    71 		return KErrNone;
       
    72 	}
       
    73 	
       
    74 	TRAPD(err, ConnectL());
       
    75 	if(err == KErrNone)
       
    76 	{
       
    77 		iIsConnected = ETrue;
       
    78 	}
       
    79 	
       
    80 	return err;
       
    81 }
       
    82 
       
    83 void CEapTlsPeapUiConnection::ConnectL()
       
    84 {
       
    85 #ifdef USE_EAP_EXPANDED_TYPES
       
    86 
       
    87 	eap_type_value_e tunnelingType(static_cast<eap_type_ietf_values_e>(iTunnelingType));
       
    88 	eap_type_value_e eapType(static_cast<eap_type_ietf_values_e>(iEapType));
       
    89 
       
    90 #else
       
    91 
       
    92 	eap_type_value_e tunnelingType = static_cast<eap_type_value_e>(iTunnelingType);
       
    93 	eap_type_value_e eapType = static_cast<eap_type_value_e>(iEapType);
       
    94 
       
    95 #endif //#ifdef USE_EAP_EXPANDED_TYPES
       
    96 
       
    97 #ifdef USE_PAC_STORE
       
    98 #ifdef USE_FAST_EAP_TYPE
       
    99 	
       
   100 	if(iEapType == eap_type_fast && iPacStoreDb == NULL)
       
   101 	{
       
   102 		iPacStoreDb = CPacStoreDatabase::NewL();
       
   103 		User::LeaveIfNull(iPacStoreDb);
       
   104 		
       
   105 		EAP_TRACE_DEBUG_SYMBIAN(
       
   106 			(_L("CEapTlsPeapUiConnection::Connect Created PAC store")));	
       
   107 		
       
   108 		iPacStoreDb->OpenPacStoreL();
       
   109 		iPacStoreDb->CreateDeviceSeed( NULL );
       
   110 		EAP_TRACE_DEBUG_SYMBIAN(
       
   111 			(_L("CEapTlsPeapUiConnection::Connect Opened PAC store")));	
       
   112 	}
       
   113 	
       
   114 #endif	// End: #ifdef USE_FAST_EAP_TYPE
       
   115 #endif // End: 	#ifdef USE_PAC_STORE
       
   116 
       
   117 	// Open or create the databse where all the settings are stored.
       
   118 	EapTlsPeapUtils::OpenDatabaseL(
       
   119 		iDbNamedDatabase, 
       
   120 		iDbs, 
       
   121 		iIndexType,
       
   122 		iIndex, 
       
   123 		tunnelingType, 
       
   124 		eapType);
       
   125 }
       
   126 
       
   127 
       
   128 TInt CEapTlsPeapUiConnection::Close()
       
   129 {
       
   130     if (iIsConnected)
       
   131     {    	
       
   132 
       
   133 #ifdef USE_PAC_STORE    	
       
   134 
       
   135 #ifdef USE_FAST_EAP_TYPE
       
   136 	
       
   137 		if(iEapType == eap_type_fast && iPacStoreDb != NULL)
       
   138 		{
       
   139 			iPacStoreDb->Close();
       
   140 		}
       
   141 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
       
   142 	
       
   143 #endif	// End: #ifdef USE_PAC_STORE
       
   144 	
       
   145         iDbNamedDatabase.Close();
       
   146         
       
   147         iDbs.Close(); // Both the Dbs are closed and server can be closed now.
       
   148     }
       
   149     
       
   150     iIsConnected = EFalse;
       
   151 
       
   152     return KErrNone;
       
   153 }
       
   154 
       
   155 
       
   156 CEapTlsPeapUiDataConnection * CEapTlsPeapUiConnection::GetDataConnection()
       
   157 {
       
   158     if (!iDataConn)
       
   159     {
       
   160         iDataConn = new CEapTlsPeapUiDataConnection(this);
       
   161     }
       
   162 
       
   163     return iDataConn;
       
   164 }
       
   165 
       
   166 
       
   167 CEapTlsPeapUiCipherSuites * CEapTlsPeapUiConnection::GetCipherSuiteConnection()
       
   168 {
       
   169     if (!iCipherSuites)
       
   170     {
       
   171         iCipherSuites = new CEapTlsPeapUiCipherSuites(this);
       
   172     }
       
   173 
       
   174     return iCipherSuites;
       
   175 }
       
   176 	
       
   177 	
       
   178 CEapTlsPeapUiCertificates * CEapTlsPeapUiConnection::GetCertificateConnection(MEapTlsPeapUiCertificates * const aParent)
       
   179 {
       
   180     if (!iCertificates)
       
   181     {
       
   182         iCertificates = new CEapTlsPeapUiCertificates(this, aParent);
       
   183     }
       
   184 
       
   185     return iCertificates;
       
   186 }
       
   187 	
       
   188 	
       
   189 CEapTlsPeapUiEapTypes * CEapTlsPeapUiConnection::GetEapTypeConnection()
       
   190 {
       
   191     if (!iEapTypes)
       
   192     {
       
   193         iEapTypes = new CEapTlsPeapUiEapTypes(this);
       
   194     }
       
   195 
       
   196     return iEapTypes;
       
   197 }
       
   198 	
       
   199 	
       
   200 TInt CEapTlsPeapUiConnection::GetDatabase(RDbNamedDatabase & aDatabase)
       
   201 {
       
   202     if (iIsConnected == EFalse)
       
   203     {
       
   204         return KErrSessionClosed;
       
   205     }
       
   206 
       
   207     aDatabase = iDbNamedDatabase;
       
   208     return KErrNone;
       
   209 }
       
   210 
       
   211 
       
   212 TIndexType CEapTlsPeapUiConnection::GetIndexType()
       
   213 {
       
   214     return iIndexType;
       
   215 }
       
   216 
       
   217 
       
   218 TInt CEapTlsPeapUiConnection::GetIndex()
       
   219 {
       
   220     return iIndex;
       
   221 }
       
   222 
       
   223 TInt CEapTlsPeapUiConnection::GetTunnelingType()
       
   224 {
       
   225     return iTunnelingType;
       
   226 }
       
   227 
       
   228 TInt CEapTlsPeapUiConnection::GetEapType()
       
   229 {
       
   230     return iEapType;
       
   231 }
       
   232 
       
   233 
       
   234 TBool CEapTlsPeapUiConnection::IsPacStoreMasterKeyPresentL()
       
   235 {
       
   236 	TBool status(EFalse);
       
   237 		
       
   238 #ifdef USE_FAST_EAP_TYPE	
       
   239 	
       
   240 	if(iEapType == eap_type_fast)
       
   241 	{
       
   242 	    if (iIsConnected == EFalse)
       
   243 	    {
       
   244 	        User::Leave(KErrSessionClosed);
       
   245 	    }
       
   246 	    
       
   247 	    status = iPacStoreDb->IsMasterKeyPresentL();
       
   248 		
       
   249 		if (status)
       
   250 		{
       
   251 			EAP_TRACE_DEBUG_SYMBIAN(
       
   252 				(_L("CEapTlsPeapUiConnection::IsPacStoreMasterKeyPresentL Master key present! \n")));				
       
   253 		}
       
   254 		
       
   255 		return status;
       
   256 	}
       
   257 	else
       
   258 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
       
   259 	{
       
   260 		User::Leave(KErrNotSupported);
       
   261 	}
       
   262 	
       
   263 	return status;
       
   264 }
       
   265 
       
   266 TInt CEapTlsPeapUiConnection::DestroyPacStore()
       
   267 {
       
   268 #ifdef USE_FAST_EAP_TYPE
       
   269 	
       
   270 	if(iEapType == eap_type_fast)
       
   271 	{
       
   272 	    if (iIsConnected == EFalse)
       
   273 	    {
       
   274 	        return KErrSessionClosed;
       
   275 	    }
       
   276 	    
       
   277 	    TInt error = iPacStoreDb->DestroyPacStore();	    
       
   278 
       
   279 	    return error;
       
   280 	}
       
   281 	else
       
   282 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
       
   283 	{
       
   284 		return KErrNotSupported;
       
   285 	}	
       
   286 }
       
   287 	
       
   288 TBool CEapTlsPeapUiConnection::VerifyPacStorePasswordL(
       
   289 	const TDesC& aPacStorePw)
       
   290 {
       
   291 	if(aPacStorePw.Size() <= 0)	
       
   292 	{
       
   293 		EAP_TRACE_DEBUG_SYMBIAN(
       
   294 			(_L("CEapTlsPeapUiConnection::VerifyPacStorePasswordL: PAC store PW can not be EMPTY!")));				
       
   295 		
       
   296 		User::Leave(KErrArgument);
       
   297 	}
       
   298 	
       
   299 	TBool status(EFalse);
       
   300 		
       
   301 #ifdef USE_FAST_EAP_TYPE	
       
   302 	
       
   303 	if(iEapType == eap_type_fast)
       
   304 	{
       
   305 	    if (iIsConnected == EFalse)
       
   306 	    {
       
   307 	        User::Leave(KErrSessionClosed);
       
   308 	    }
       
   309 	    
       
   310 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
       
   311 		("CEapTlsPeapUiConnection::VerifyPacStorePasswordL:PW from caller (16bits)",
       
   312 		aPacStorePw.Ptr(), 
       
   313 		aPacStorePw.Size()));
       
   314 		
       
   315 		HBufC8* pacStorePWBuf8 = HBufC8::NewLC(aPacStorePw.Size());
       
   316 		TPtr8 pacStorePWPtr8 = pacStorePWBuf8->Des();
       
   317 		pacStorePWPtr8.Copy(aPacStorePw);
       
   318 	    
       
   319 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
       
   320 		("CEapTlsPeapUiConnection::VerifyPacStorePasswordL:PW used for masterkey verification (8bits)",
       
   321 		pacStorePWPtr8.Ptr(), 
       
   322 		pacStorePWPtr8.Size()));	    
       
   323 	    
       
   324 	    status = iPacStoreDb->IsMasterKeyAndPasswordMatchingL(pacStorePWPtr8);
       
   325 	    
       
   326 	    CleanupStack::PopAndDestroy(pacStorePWBuf8);
       
   327 		
       
   328 		if (status)
       
   329 		{
       
   330 			// Password and master key are matching.
       
   331 			// Means, This is the password used to create the master key.
       
   332 			EAP_TRACE_DEBUG_SYMBIAN(
       
   333 				(_L("CEapTlsPeapUiConnection::VerifyPacStorePasswordL PAC store PW verified OK (true) \n")));				
       
   334 		}
       
   335 	}
       
   336 	else
       
   337 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
       
   338 	{
       
   339 		User::Leave(KErrNotSupported);
       
   340 	}
       
   341 	
       
   342 	return status;
       
   343 }
       
   344 
       
   345 TInt CEapTlsPeapUiConnection::CreatePacStoreMasterKey(
       
   346 	const TDesC& aPacStorePw)
       
   347 {
       
   348 	if(aPacStorePw.Size() <= 0)	
       
   349 	{
       
   350 		EAP_TRACE_DEBUG_SYMBIAN(
       
   351 			(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey PAC store PW can not be EMPTY!")));				
       
   352 		
       
   353 		return KErrArgument;
       
   354 	}
       
   355 		
       
   356 #ifdef USE_FAST_EAP_TYPE	
       
   357 	
       
   358 	if(iEapType == eap_type_fast)
       
   359 	{
       
   360 	    if (iIsConnected == EFalse)
       
   361 	    {
       
   362 	        return KErrSessionClosed;
       
   363 	    }
       
   364 	    
       
   365 	  TInt creationStatus(KErrNone);
       
   366 	  	  
       
   367 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
       
   368 		("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:PW from caller (16bits)",
       
   369 		aPacStorePw.Ptr(), 
       
   370 		aPacStorePw.Size()));
       
   371 		
       
   372 		HBufC8* pacStorePWBuf8 = NULL;
       
   373 		TRAPD(err, pacStorePWBuf8 = HBufC8::NewL(aPacStorePw.Size()));
       
   374 		if (err != KErrNone)
       
   375 		{
       
   376 			EAP_TRACE_DEBUG_SYMBIAN(
       
   377 				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:Allocation failed\n")));
       
   378 			return KErrNoMemory;
       
   379 		}
       
   380 		
       
   381 		TPtr8 pacStorePWPtr8 = pacStorePWBuf8->Des();
       
   382 		pacStorePWPtr8.Copy(aPacStorePw);
       
   383 	    
       
   384 		EAP_TRACE_DATA_DEBUG_SYMBIAN(
       
   385 		("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:PW used for masterkey creation (8bits)",
       
   386 		pacStorePWPtr8.Ptr(), 
       
   387 		pacStorePWPtr8.Size()));
       
   388 		
       
   389 		TRAPD(err1, creationStatus = iPacStoreDb->CreateAndSaveMasterKeyL(pacStorePWPtr8));
       
   390 	    
       
   391 		delete pacStorePWBuf8;
       
   392 		
       
   393 		if(err1 != KErrNone)
       
   394 		{
       
   395 			EAP_TRACE_DEBUG_SYMBIAN(
       
   396 				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey:Creation failed %d\n"), err1));
       
   397 		}
       
   398 				
       
   399 		if (creationStatus == KErrNone)
       
   400 		{
       
   401 			EAP_TRACE_DEBUG_SYMBIAN(
       
   402 				(_L("CEapTlsPeapUiConnection::CreatePacStoreMasterKey Master key created OK\n")));				
       
   403 		}
       
   404 		return creationStatus;
       
   405 	}
       
   406 	else
       
   407 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
       
   408 	{
       
   409 		return KErrNotSupported;
       
   410 	}
       
   411 }
       
   412 
       
   413 CPacStoreDatabase * CEapTlsPeapUiConnection::GetPacStoreDb()
       
   414 {
       
   415 #ifdef USE_FAST_EAP_TYPE
       
   416 	
       
   417 	if(iEapType == eap_type_fast)
       
   418 	{
       
   419 	    return iPacStoreDb;
       
   420 	}
       
   421 	else
       
   422 #endif	// End: #ifdef USE_FAST_EAP_TYPE		
       
   423 	{
       
   424 		return NULL;
       
   425 	}	
       
   426 }
       
   427 
       
   428 // End of file