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