eapol/eapol_framework/eapol_symbian/eap_server/src/eap_am_pac_store_symbian.cpp
changeset 49 43351a4f2da3
parent 47 712b4ffd76bb
equal deleted inserted replaced
47:712b4ffd76bb 49:43351a4f2da3
     1 /*
       
     2 * Copyright (c) 2009-2010 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:  interface to PAC-store.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 14 %
       
    20 */
       
    21 
       
    22 #include "eap_tools.h"
       
    23 #include "eap_status.h"
       
    24 #include "eap_am_export.h"
       
    25 #include "eap_am_pac_store_symbian.h"
       
    26 #include "abs_eap_am_pac_store.h"
       
    27 #include "eap_automatic_variable.h"
       
    28 #include "EapTraceSymbian.h"
       
    29 #include "EapConversion.h"
       
    30 #include "eap_type_tls_peap_types.h"
       
    31 #include "pac_store_db_parameters.h"
       
    32 #include "pac_store_db_symbian.h"
       
    33 #include <f32file.h>
       
    34 #include "EapPluginDbDefaults.h"
       
    35 
       
    36 /** @file */
       
    37 
       
    38 // ----------------------------------------------------------------------
       
    39 const TUint KMaxDBFieldNameLength = 255;
       
    40 
       
    41 // ----------------------------------------------------------------------
       
    42 
       
    43 eap_am_pac_store_symbian_c::eap_am_pac_store_symbian_c(
       
    44 	abs_eap_am_tools_c * const tools,
       
    45 	abs_eap_am_pac_store_c * const partner)
       
    46 	: m_am_tools(tools)
       
    47 	, m_partner(partner)
       
    48 	, m_is_valid(false)
       
    49 	, m_shutdown_was_called(false)
       
    50 	, iClientCreated(false)
       
    51 	, iPacStoreSessionOpened(false)
       
    52 	, iClient(NULL)
       
    53 	, m_PAC_store_password(tools)
       
    54 
       
    55 {
       
    56 
       
    57 	if (m_am_tools == 0
       
    58 		|| m_am_tools->get_is_valid() == false
       
    59 		|| m_partner == 0)
       
    60 	{
       
    61 		return;
       
    62 	}
       
    63 
       
    64 	m_is_valid = true;
       
    65 
       
    66 	EAP_TRACE_DEBUG(
       
    67 		m_am_tools,
       
    68 		TRACE_FLAGS_DEFAULT,
       
    69 		(EAPL("eap_am_pac_store_symbian_c::eap_am_pac_store_symbian_c(): this=0x%08x.\n"),
       
    70 		this));
       
    71 		
       
    72 	return;
       
    73 }
       
    74 
       
    75 // ----------------------------------------------------------------------
       
    76 
       
    77 eap_am_pac_store_symbian_c::~eap_am_pac_store_symbian_c()
       
    78 {
       
    79 	EAP_TRACE_DEBUG(
       
    80 		m_am_tools,
       
    81 		TRACE_FLAGS_DEFAULT,
       
    82 		(EAPL("eap_am_pac_store_symbian_c::~eap_am_pac_store_symbian_c(): this=0x%08x.\n"),
       
    83 		this));
       
    84 
       
    85 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::~eap_am_pac_store_symbian_c()");
       
    86 
       
    87 	delete iClient;
       
    88 	iClient = NULL;
       
    89 	
       
    90 	EAP_ASSERT(m_shutdown_was_called == true);
       
    91 }
       
    92 
       
    93 // ----------------------------------------------------------------------
       
    94 
       
    95 EAP_FUNC_EXPORT bool eap_am_pac_store_symbian_c::get_is_valid()
       
    96 {
       
    97 	EAP_TRACE_DEBUG(
       
    98 		m_am_tools,
       
    99 		TRACE_FLAGS_DEFAULT,
       
   100 		(EAPL("eap_am_pac_store_symbian_c::get_is_valid(): this=0x%08x. valid=%d\n"),
       
   101 		this, m_is_valid));
       
   102 
       
   103 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::get_is_valid()");
       
   104 
       
   105 	return m_is_valid;
       
   106 }
       
   107 
       
   108 // ----------------------------------------------------------------------
       
   109 
       
   110 // This is documented in abs_eap_stack_interface_c::configure().
       
   111 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::configure()
       
   112 {
       
   113 	EAP_TRACE_DEBUG(
       
   114 		m_am_tools,
       
   115 		TRACE_FLAGS_DEFAULT,
       
   116 		(EAPL("eap_am_pac_store_symbian_c::configure(): this=0x%08x.\n"),
       
   117 		this));
       
   118 
       
   119 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::configure()");
       
   120 
       
   121 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   122 }
       
   123 
       
   124 // ----------------------------------------------------------------------
       
   125 
       
   126 // This is documented in abs_eap_stack_interface_c::shutdown().
       
   127 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::shutdown()
       
   128 {
       
   129 	EAP_TRACE_DEBUG(
       
   130 		m_am_tools,
       
   131 		TRACE_FLAGS_DEFAULT,
       
   132 		(EAPL("eap_am_pac_store_symbian_c::shutdown(): this=0x%08x.\n"),
       
   133 		this));
       
   134 
       
   135 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::shutdown()");
       
   136 
       
   137 	m_shutdown_was_called = true;
       
   138 
       
   139 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   140 }
       
   141 
       
   142 // ----------------------------------------------------------------------
       
   143 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::open_pac_store()
       
   144 	{
       
   145 	EAP_TRACE_DEBUG(
       
   146 		m_am_tools,
       
   147 		TRACE_FLAGS_DEFAULT,
       
   148 		(EAPL("eap_am_pac_store_symbian_c::open_pac_store(): this=0x%08x.\n"),
       
   149 		this));
       
   150 
       
   151 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::open_pac_store()");
       
   152 
       
   153 	TRAPD(err, iClient = CPacStoreDatabase::NewL());
       
   154 	if (err || iClient == NULL)
       
   155 			{
       
   156 			m_partner->complete_open_pac_store(eap_status_process_general_error);
       
   157 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   158 			}
       
   159 	EAP_TRACE_DEBUG_SYMBIAN(
       
   160 			(_L("eap_am_pac_store_symbian_c::open_pac_store Created PAC store")));	
       
   161 		
       
   162 	TRAP(err, iClient->OpenPacStoreL());
       
   163 	if (err || iClient == NULL)
       
   164 		{
       
   165 		m_partner->complete_open_pac_store(eap_status_process_general_error);
       
   166 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   167 		}
       
   168 	EAP_TRACE_DEBUG_SYMBIAN(
       
   169 			(_L("eap_am_pac_store_symbian_c::open_pac_store Opened PAC store")));	
       
   170 
       
   171 	iClientCreated = ETrue;
       
   172 
       
   173 	m_partner->complete_open_pac_store(eap_status_ok);
       
   174 	
       
   175 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   176 	}
       
   177 
       
   178 // ----------------------------------------------------------------------
       
   179 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::create_device_seed()
       
   180 	{
       
   181 	EAP_TRACE_DEBUG(
       
   182 		m_am_tools,
       
   183 		TRACE_FLAGS_DEFAULT,
       
   184 		(EAPL("eap_am_pac_store_symbian_c::create_device_seed(): this=0x%08x.\n"),
       
   185 		this));
       
   186 
       
   187 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::create_device_seed()");
       
   188 
       
   189 	if(iClientCreated == EFalse)
       
   190 		{
       
   191 		m_partner->complete_create_device_seed(eap_status_process_general_error);
       
   192 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   193 		}
       
   194 
       
   195 	eap_variable_data_c aDeviceSeed(m_am_tools);
       
   196 	
       
   197 	eap_status_e status = iClient->CreateDeviceSeed(&aDeviceSeed);
       
   198 
       
   199 	m_partner->complete_create_device_seed(status);
       
   200 
       
   201 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   202 	}
       
   203 
       
   204 
       
   205 // ----------------------------------------------------------------------
       
   206 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::is_master_key_present()
       
   207 	{
       
   208 	EAP_TRACE_DEBUG(
       
   209 		m_am_tools,
       
   210 		TRACE_FLAGS_DEFAULT,
       
   211 		(EAPL("eap_am_pac_store_symbian_c::is_master_key_present(): this=0x%08x.\n"),
       
   212 		this));
       
   213 
       
   214 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::is_master_key_present()");
       
   215 
       
   216 	TBool present = EFalse;
       
   217 	if(iClientCreated == EFalse)
       
   218 		{
       
   219 		m_partner->complete_is_master_key_present(EFalse);
       
   220 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   221 		}
       
   222 
       
   223 	eap_status_e status(eap_status_ok);
       
   224 
       
   225 	TRAPD(err, present = iClient->IsMasterKeyPresentL());
       
   226 	if (err)
       
   227 		{
       
   228 		present = EFalse;
       
   229 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   230 		}
       
   231 
       
   232 	m_partner->complete_is_master_key_present(present);
       
   233 
       
   234 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   235 	}
       
   236 
       
   237 
       
   238 // ----------------------------------------------------------------------
       
   239 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::is_master_key_and_password_matching(
       
   240 		const eap_variable_data_c * const pac_store_password)
       
   241 	{
       
   242 	EAP_TRACE_DEBUG(
       
   243 		m_am_tools,
       
   244 		TRACE_FLAGS_DEFAULT,
       
   245 		(EAPL("eap_am_pac_store_symbian_c::is_master_key_and_password_matching(): this=0x%08x.\n"),
       
   246 		this));
       
   247 
       
   248 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::is_master_key_and_password_matching()");
       
   249 
       
   250 	TBool matching = EFalse;
       
   251 	
       
   252 	if(iClientCreated == EFalse)
       
   253 		{
       
   254 		m_partner->complete_is_master_key_and_password_matching(EFalse);
       
   255 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   256 		}
       
   257 
       
   258 	HBufC8* pacStorePW8(NULL);
       
   259 	
       
   260 	TRAPD(err, pacStorePW8 = HBufC8::NewL(pac_store_password->get_data_length()));
       
   261 	if (err)
       
   262 		{
       
   263 		m_partner->complete_is_master_key_and_password_matching(EFalse);
       
   264 		return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   265 		}
       
   266 	
       
   267 	TPtr8 pacStorePW8Ptr = 	pacStorePW8->Des();
       
   268 	
       
   269 	pacStorePW8Ptr.Copy(pac_store_password->get_data(), pac_store_password->get_data_length());
       
   270 		
       
   271 	eap_status_e status(eap_status_ok);
       
   272 
       
   273 	TRAP(err, matching = iClient->IsMasterKeyAndPasswordMatchingL(pacStorePW8Ptr));
       
   274 	if (err)
       
   275 		{
       
   276 		matching = EFalse;
       
   277 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   278 		}
       
   279 
       
   280 	delete pacStorePW8;	
       
   281 
       
   282 	m_partner->complete_is_master_key_and_password_matching(matching);
       
   283 
       
   284 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   285 	
       
   286 	}
       
   287 
       
   288 // ----------------------------------------------------------------------
       
   289 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::create_and_save_master_key(
       
   290 		const eap_variable_data_c * const pac_store_password)
       
   291 	{
       
   292 	EAP_TRACE_DEBUG(
       
   293 		m_am_tools,
       
   294 		TRACE_FLAGS_DEFAULT,
       
   295 		(EAPL("eap_am_pac_store_symbian_c::create_and_save_master_key(): this=0x%08x.\n"),
       
   296 		this));
       
   297 
       
   298 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::create_and_save_master_key()");
       
   299 
       
   300 	if(iClientCreated == EFalse)
       
   301 		{
       
   302 		m_partner->complete_create_and_save_master_key(eap_status_process_general_error);
       
   303 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   304 		}
       
   305 
       
   306 	HBufC8* pacStorePW8(NULL);
       
   307 	
       
   308 	eap_status_e status(eap_status_ok);
       
   309 
       
   310 	TRAPD(err, pacStorePW8 = HBufC8::NewL(pac_store_password->get_data_length()));
       
   311 	if (err)
       
   312 		{
       
   313 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   314 		m_partner->complete_create_and_save_master_key(status);
       
   315 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   316 		}
       
   317 	
       
   318 	TPtr8 pacStorePW8Ptr = 	pacStorePW8->Des();
       
   319 	
       
   320 	pacStorePW8Ptr.Copy(pac_store_password->get_data(), pac_store_password->get_data_length());
       
   321 
       
   322 	TRAP(err, iClient->CreateAndSaveMasterKeyL(pacStorePW8Ptr));
       
   323 	if (err)
       
   324 		{
       
   325 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   326 		}
       
   327 
       
   328 	delete pacStorePW8;	
       
   329 
       
   330 	m_partner->complete_create_and_save_master_key(status);
       
   331 
       
   332 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   333 	}
       
   334 
       
   335 
       
   336 // ----------------------------------------------------------------------
       
   337 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::is_pacstore_password_present()
       
   338 	{
       
   339 	EAP_TRACE_DEBUG(
       
   340 		m_am_tools,
       
   341 		TRACE_FLAGS_DEFAULT,
       
   342 		(EAPL("eap_am_pac_store_symbian_c::is_pacstore_password_present(): this=0x%08x.\n"),
       
   343 		this));
       
   344 
       
   345 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::is_pacstore_password_present()");
       
   346 
       
   347 	TBool present = EFalse;
       
   348 	if(iClientCreated == EFalse)
       
   349 		{
       
   350 		m_partner->complete_is_pacstore_password_present(EFalse);
       
   351 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   352 		}
       
   353 
       
   354 	eap_status_e status(eap_status_ok);
       
   355 
       
   356 	TRAPD(err, present = iClient->IsPacPasswordPresentL());
       
   357 	if (err)
       
   358 		{
       
   359 		present = EFalse;
       
   360 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   361 		}
       
   362 
       
   363 	m_partner->complete_is_pacstore_password_present(present);
       
   364 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   365 	}
       
   366 
       
   367 
       
   368 // ----------------------------------------------------------------------
       
   369 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::compare_pac_store_password(
       
   370 		eap_variable_data_c * const pac_store_password)
       
   371 	{
       
   372 	EAP_TRACE_DEBUG(
       
   373 		m_am_tools,
       
   374 		TRACE_FLAGS_DEFAULT,
       
   375 		(EAPL("eap_am_pac_store_symbian_c::compare_pac_store_password(): this=0x%08x.\n"),
       
   376 		this));
       
   377 
       
   378 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::compare_pac_store_password()");
       
   379 
       
   380 	TBool matching = EFalse;
       
   381 	
       
   382 	if(iClientCreated == EFalse)
       
   383 		{
       
   384 		m_partner->complete_compare_pac_store_password(EFalse);
       
   385 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   386 		}
       
   387 
       
   388 	HBufC8* pacStorePW8(NULL);
       
   389 	
       
   390 	TRAPD(err, pacStorePW8 = HBufC8::NewL(pac_store_password->get_data_length()));
       
   391 	if (err)
       
   392 		{
       
   393 		m_partner->complete_compare_pac_store_password(EFalse);
       
   394 		return EAP_STATUS_RETURN(m_am_tools, EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err)));
       
   395 		}
       
   396 	
       
   397 	TPtr8 pacStorePW8Ptr = 	pacStorePW8->Des();
       
   398 	
       
   399 	pacStorePW8Ptr.Copy(pac_store_password->get_data(), pac_store_password->get_data_length());
       
   400 		
       
   401 
       
   402 	eap_status_e status(eap_status_ok);
       
   403 
       
   404 	TRAP(err, matching = iClient->ComparePacStorePasswordL(pacStorePW8Ptr));
       
   405 	if (err)
       
   406 		{
       
   407 		matching = EFalse;
       
   408 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   409 		}
       
   410 
       
   411 	delete pacStorePW8;
       
   412 
       
   413 	m_partner->complete_compare_pac_store_password(matching);
       
   414 
       
   415 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   416 	}
       
   417 
       
   418 // ----------------------------------------------------------------------
       
   419 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::set_pac_store_password(
       
   420 		const eap_variable_data_c * pac_store_password)
       
   421 	{
       
   422 	EAP_TRACE_DEBUG(
       
   423 		m_am_tools,
       
   424 		TRACE_FLAGS_DEFAULT,
       
   425 		(EAPL("eap_am_pac_store_symbian_c::set_pac_store_password(): this=0x%08x.\n"),
       
   426 		this));
       
   427 
       
   428 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::set_pac_store_password()");
       
   429 
       
   430 	if(iClientCreated == EFalse)
       
   431 		{
       
   432 		m_partner->complete_set_pac_store_password(eap_status_process_general_error);
       
   433 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   434 		}
       
   435 		
       
   436 	TBuf<KMaxDBFieldNameLength> pacStoreDBColName;
       
   437 	HBufC8* pacStoreDBColValBuf8(NULL);
       
   438 	
       
   439 	pacStoreDBColName.Copy(cf_str_EAP_FAST_PAC_store_password_literal);			
       
   440 
       
   441 	eap_status_e status(eap_status_ok);
       
   442 
       
   443 	TRAPD(err, pacStoreDBColValBuf8 = HBufC8::NewL(KMaxPasswordLengthInDB));
       
   444 	if (err)
       
   445 		{
       
   446 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   447 		m_partner->complete_set_pac_store_password(status);
       
   448 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   449 		}
       
   450 
       
   451 	TPtr8 pacStoreDBColValPtr8 = pacStoreDBColValBuf8->Des();
       
   452 	pacStoreDBColValPtr8.Copy(pac_store_password->get_data(), pac_store_password->get_data_length());
       
   453 
       
   454 	TRAP( err, iClient->SetPacStoreDataL(pacStoreDBColName, pacStoreDBColValPtr8));
       
   455 	if (err)
       
   456 		{
       
   457 		status = EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err));
       
   458 		}
       
   459 
       
   460 	delete pacStoreDBColValBuf8;
       
   461 	m_partner->complete_set_pac_store_password(status);
       
   462 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   463 	}
       
   464 
       
   465 // ----------------------------------------------------------------------
       
   466 EAP_FUNC_EXPORT eap_status_e eap_am_pac_store_symbian_c::destroy_pac_store()
       
   467 	{
       
   468 	EAP_TRACE_DEBUG(
       
   469 		m_am_tools,
       
   470 		TRACE_FLAGS_DEFAULT,
       
   471 		(EAPL("eap_am_pac_store_symbian_c::destroy_pac_store(): this=0x%08x.\n"),
       
   472 		this));
       
   473 
       
   474 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_am_pac_store_symbian_c::destroy_pac_store()");
       
   475 
       
   476 	if(iClientCreated == EFalse)
       
   477 		{
       
   478 		eap_status_e status(eap_status_process_general_error);
       
   479 
       
   480 		m_partner->complete_destroy_pac_store(status);
       
   481 
       
   482 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   483 		}
       
   484 
       
   485 	iClient->DestroyPacStore();
       
   486 
       
   487 	EAP_TRACE_DEBUG_SYMBIAN((_L("eap_am_pac_store_symbian_c::open_pac_store destroy_pac_store end")));
       
   488 
       
   489 	m_partner->complete_destroy_pac_store(eap_status_ok);
       
   490 
       
   491 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   492 	}
       
   493 
       
   494 // End