eapol/eapol_framework/eapol_symbian/am/type/tls_peap/symbian/EapTlsPeapCertInterface.cpp
changeset 39 fe6b6762fccd
parent 33 938269283a16
child 49 43351a4f2da3
equal deleted inserted replaced
38:7a0216d033ac 39:fe6b6762fccd
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 38.1.24 %
    19 * %version: 38.1.26 %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
   143 	}
   143 	}
   144 
   144 
   145 	EAP_TRACE_DEBUG(
   145 	EAP_TRACE_DEBUG(
   146 		m_am_tools,
   146 		m_am_tools,
   147 		TRACE_FLAGS_DEFAULT,
   147 		TRACE_FLAGS_DEFAULT,
   148 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iMatchingUserCerts.ResetAndDestroy()\n")));
   148 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iMatchingUserCerts.ResetAndDestroy(): count=%d\n"),
       
   149 		iMatchingUserCerts.Count()));
   149 
   150 
   150 	iMatchingUserCerts.ResetAndDestroy();
   151 	iMatchingUserCerts.ResetAndDestroy();
   151 
   152 
   152 	EAP_TRACE_DEBUG(
   153 	EAP_TRACE_DEBUG(
   153 		m_am_tools,
   154 		m_am_tools,
   154 		TRACE_FLAGS_DEFAULT,
   155 		TRACE_FLAGS_DEFAULT,
   155 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iMatchingUserCertInfos.ResetAndDestroy()\n")));
   156 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iMatchingUserCertInfos.ResetAndDestroy(): count=%d\n"),
       
   157 		iMatchingUserCertInfos.Count()));
   156 
   158 
   157 	iMatchingUserCertInfos.ResetAndDestroy();
   159 	iMatchingUserCertInfos.ResetAndDestroy();
   158 	
   160 	
   159 	EAP_TRACE_DEBUG(
   161 	EAP_TRACE_DEBUG(
   160 		m_am_tools,
   162 		m_am_tools,
   161 		TRACE_FLAGS_DEFAULT,
   163 		TRACE_FLAGS_DEFAULT,
   162 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iAllowedUserCerts.ResetAndDestroy()\n")));
   164 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iAllowedUserCerts.ResetAndDestroy(): count=%d\n"),
       
   165 		iAllowedUserCerts.Count()));
   163 
   166 
   164 	iAllowedUserCerts.ResetAndDestroy();
   167 	iAllowedUserCerts.ResetAndDestroy();
   165 
   168 
   166 	EAP_TRACE_DEBUG(
   169 	EAP_TRACE_DEBUG(
   167 		m_am_tools,
   170 		m_am_tools,
   168 		TRACE_FLAGS_DEFAULT,
   171 		TRACE_FLAGS_DEFAULT,
   169 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iAllowedCACerts.ResetAndDestroy()\n")));
   172 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iAllowedCACerts.ResetAndDestroy(): count=%d\n"),
       
   173 		iAllowedCACerts.Count()));
   170 
   174 
   171 	iAllowedCACerts.ResetAndDestroy();
   175 	iAllowedCACerts.ResetAndDestroy();
   172 
   176 
   173 	EAP_TRACE_DEBUG(
   177 	EAP_TRACE_DEBUG(
   174 		m_am_tools,
   178 		m_am_tools,
   175 		TRACE_FLAGS_DEFAULT,
   179 		TRACE_FLAGS_DEFAULT,
   176 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iRootCerts.ResetAndDestroy()\n")));
   180 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iRootCerts.ResetAndDestroy(): count=%d\n"),
       
   181 		iRootCerts.Count()));
   177 
   182 
   178 	iRootCerts.ResetAndDestroy();
   183 	iRootCerts.ResetAndDestroy();
   179 
   184 
   180 	EAP_TRACE_DEBUG(
   185 	EAP_TRACE_DEBUG(
   181 		m_am_tools,
   186 		m_am_tools,
   182 		TRACE_FLAGS_DEFAULT,
   187 		TRACE_FLAGS_DEFAULT,
   183 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iUserCertChain.ResetAndDestroy()\n")));
   188 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iUserCertChain.ResetAndDestroy(): count=%d\n"),
       
   189 		iUserCertChain.Count()));
   184 
   190 
   185 	iUserCertChain.ResetAndDestroy();
   191 	iUserCertChain.ResetAndDestroy();
   186 	
   192 	
   187 	EAP_TRACE_DEBUG(
   193 	EAP_TRACE_DEBUG(
   188 		m_am_tools,
   194 		m_am_tools,
   189 		TRACE_FLAGS_DEFAULT,
   195 		TRACE_FLAGS_DEFAULT,
   190 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iCertAuthorities.ResetAndDestroy()\n")));
   196 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iCertAuthorities.ResetAndDestroy(): count=%d\n"),
       
   197 		iCertAuthorities.Count()));
   191 
   198 
   192 	iCertAuthorities.ResetAndDestroy();
   199 	iCertAuthorities.ResetAndDestroy();
   193 	
   200 	
   194 	EAP_TRACE_DEBUG(
   201 	EAP_TRACE_DEBUG(
   195 		m_am_tools,
   202 		m_am_tools,
   196 		TRACE_FLAGS_DEFAULT,
   203 		TRACE_FLAGS_DEFAULT,
   197 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iCertInfos.Reset()\n")));
   204 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iCertInfos.Reset(): count=%d\n"),
       
   205 		iCertInfos.Count()));
   198 
   206 
   199 	TInt i(0);
   207 	TInt i(0);
   200 	for (i = 0; i < iCertInfos.Count(); i++)
   208 	for (i = 0; i < iCertInfos.Count(); i++)
   201 	{
   209 	{
   202 		iCertInfos[i]->Release();
   210 		iCertInfos[i]->Release();
   204 	iCertInfos.Reset();
   212 	iCertInfos.Reset();
   205 
   213 
   206 	EAP_TRACE_DEBUG(
   214 	EAP_TRACE_DEBUG(
   207 		m_am_tools,
   215 		m_am_tools,
   208 		TRACE_FLAGS_DEFAULT,
   216 		TRACE_FLAGS_DEFAULT,
   209 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iKeyInfos.Reset()\n")));
   217 		(EAPL("CEapTlsPeapCertInterface::~CEapTlsPeapCertInterface(): iKeyInfos.Reset(): count=%d\n"),
       
   218 		iKeyInfos.Count()));
   210 
   219 
   211 	for (i = 0; i < iKeyInfos.Count(); i++)
   220 	for (i = 0; i < iKeyInfos.Count(); i++)
   212 	{
   221 	{
   213 		iKeyInfos[i]->Release();
   222 		iKeyInfos[i]->Release();
   214 	}
   223 	}
  1111 					m_am_tools,
  1120 					m_am_tools,
  1112 					TRACE_FLAGS_DEFAULT,
  1121 					TRACE_FLAGS_DEFAULT,
  1113 					(EAPL("CEapTlsPeapCertInterface::RunL(): EGetMatchingCertsInitialize - No matching Certificates.\n")));
  1122 					(EAPL("CEapTlsPeapCertInterface::RunL(): EGetMatchingCertsInitialize - No matching Certificates.\n")));
  1114 			
  1123 			
  1115 				// No matching certs
  1124 				// No matching certs
  1116 				
  1125 			
  1117 				RPointerArray<EapCertificateEntry>* tmp = NULL;
  1126 				// Timeout handles error situation
  1118 				
  1127 				RPointerArray<EapCertificateEntry> empty(sizeof(EapCertificateEntry));
  1119 				tmp = new (ELeave) RPointerArray<EapCertificateEntry>(1);
  1128 
  1120 				if (tmp == 0)
       
  1121 				{
       
  1122 					// Timeout handles error situation
       
  1123 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));					
       
  1124 				}
       
  1125 				
       
  1126 				m_am_tools->enter_global_mutex();
  1129 				m_am_tools->enter_global_mutex();
  1127 				
  1130 
  1128 				iParent->complete_get_matching_certificates(*tmp, eap_status_illegal_certificate); //Failure
  1131 				iParent->complete_get_matching_certificates(empty, eap_status_illegal_certificate); //Failure
  1129 				
  1132 
  1130 				m_am_tools->leave_global_mutex();
  1133 				m_am_tools->leave_global_mutex();
  1131 
  1134 
  1132 				delete tmp;
       
  1133 				break;
  1135 				break;
  1134 			}
  1136 			}
  1135 
  1137 
  1136 			// Get the first certificate
  1138 			// Get the first certificate
  1137 			iUserCertIndex = 0;
  1139 			iUserCertIndex = 0;
  1140 							
  1142 							
  1141 			iState = EGetMatchingCertsLoop;
  1143 			iState = EGetMatchingCertsLoop;
  1142 
  1144 
  1143 			iEncodedCertificate->Des().SetLength(0);
  1145 			iEncodedCertificate->Des().SetLength(0);
  1144 			
  1146 			
  1145 			TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(iCertInfos[iUserCertIndex]->Size()));
  1147 			HBufC8 * tmpCert = 0;
       
  1148 			TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(iCertInfos[iUserCertIndex]->Size()));
  1146 			if (error != KErrNone)
  1149 			if (error != KErrNone)
  1147 			{
  1150 			{
  1148 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1151 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1149 
  1152 
  1150 				RPointerArray<EapCertificateEntry> tmp(sizeof(EapCertificateEntry));
  1153 				RPointerArray<EapCertificateEntry> empty(sizeof(EapCertificateEntry));
  1151 
  1154 
  1152 				m_am_tools->enter_global_mutex();
  1155 				m_am_tools->enter_global_mutex();
  1153 
  1156 
  1154 				iParent->complete_get_matching_certificates(tmp, eap_status_allocation_error); //Failure
  1157 				iParent->complete_get_matching_certificates(empty, eap_status_allocation_error); //Failure
  1155 
  1158 
  1156 				m_am_tools->leave_global_mutex();
  1159 				m_am_tools->leave_global_mutex();
  1157 
  1160 
  1158 				break;
  1161 				break;
  1159 			}
  1162 			}
       
  1163 
       
  1164 			iEncodedCertificate = tmpCert;
  1160 
  1165 
  1161 			iCertPtr.Set(iEncodedCertificate->Des());
  1166 			iCertPtr.Set(iEncodedCertificate->Des());
  1162 
  1167 
  1163 			iCertStore->Retrieve(
  1168 			iCertStore->Retrieve(
  1164 				*(iCertInfos[iUserCertIndex]), 
  1169 				*(iCertInfos[iUserCertIndex]), 
  1180 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  1185 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  1181 			if (error != KErrNone || cert == 0)
  1186 			if (error != KErrNone || cert == 0)
  1182 			{
  1187 			{
  1183 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1188 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1184 				
  1189 				
  1185 				RPointerArray<EapCertificateEntry> tmp(sizeof(EapCertificateEntry));
  1190 				RPointerArray<EapCertificateEntry> empty(sizeof(EapCertificateEntry));
  1186 											
  1191 											
  1187 				m_am_tools->enter_global_mutex();
  1192 				m_am_tools->enter_global_mutex();
  1188 				
  1193 				
  1189 				iParent->complete_get_matching_certificates(tmp, eap_status_allocation_error); //Failure
  1194 				iParent->complete_get_matching_certificates(empty, eap_status_allocation_error); //Failure
  1190 				
  1195 				
  1191 				m_am_tools->leave_global_mutex();
  1196 				m_am_tools->leave_global_mutex();
  1192 
  1197 
  1193 				break;
  1198 				break;
  1194 			}
  1199 			}
  1196 			if (iMatchingUserCerts.Append(cert) != KErrNone)
  1201 			if (iMatchingUserCerts.Append(cert) != KErrNone)
  1197 			{
  1202 			{
  1198 				delete cert;
  1203 				delete cert;
  1199 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1204 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1200 				
  1205 				
  1201 				RPointerArray<EapCertificateEntry> tmp(sizeof(EapCertificateEntry));
  1206 				RPointerArray<EapCertificateEntry> empty(sizeof(EapCertificateEntry));
  1202 
  1207 
  1203 				m_am_tools->enter_global_mutex();
  1208 				m_am_tools->enter_global_mutex();
  1204 				
  1209 				
  1205 				iParent->complete_get_matching_certificates(tmp, eap_status_allocation_error); //Failure
  1210 				iParent->complete_get_matching_certificates(empty, eap_status_allocation_error); //Failure
  1206 				
  1211 				
  1207 				m_am_tools->leave_global_mutex();
  1212 				m_am_tools->leave_global_mutex();
  1208 							
  1213 							
  1209 				break;
  1214 				break;
  1210 			}
  1215 			}
  1211 			
  1216 
  1212 			// No need to validate iCertInfos here as the execution doesn't come to this case if iCertInfos
  1217 			// No need to validate iCertInfos here as the execution doesn't come to this case if iCertInfos
  1213 			// is empty, check is done in the above case.
  1218 			// is empty, check is done in the above case.
  1214 						
  1219 
  1215 			EapCertificateEntry * entry = new EapCertificateEntry;
  1220 			EapCertificateEntry * entry = new EapCertificateEntry;
  1216 			entry = new (ELeave) EapCertificateEntry;
  1221 			if (entry == 0)
  1217 			if (entry == 0 || error != KErrNone)
       
  1218 			{
  1222 			{
  1219 				// Timeout handles error situation
  1223 				// Timeout handles error situation
  1220 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));					
  1224 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));					
  1221 
  1225 
  1222 				RPointerArray<EapCertificateEntry> tmp(sizeof(EapCertificateEntry));
  1226 				RPointerArray<EapCertificateEntry> empty(sizeof(EapCertificateEntry));
  1223 
  1227 
  1224 				m_am_tools->enter_global_mutex();
  1228 				m_am_tools->enter_global_mutex();
  1225 				
  1229 				
  1226 				iParent->complete_get_matching_certificates(tmp, eap_status_allocation_error); //Failure
  1230 				iParent->complete_get_matching_certificates(empty, eap_status_allocation_error); //Failure
  1227 				
  1231 				
  1228 				m_am_tools->leave_global_mutex();
  1232 				m_am_tools->leave_global_mutex();
  1229 
  1233 
  1230 				delete entry;
  1234 				delete entry;
  1231 
  1235 
  1238 			TRAP(error, iMatchingUserCertInfos.AppendL(entry));
  1242 			TRAP(error, iMatchingUserCertInfos.AppendL(entry));
  1239 			if (error != KErrNone)
  1243 			if (error != KErrNone)
  1240 			{
  1244 			{
  1241 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1245 				EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1242 				
  1246 				
  1243 				RPointerArray<EapCertificateEntry> tmp(sizeof(EapCertificateEntry));
  1247 				RPointerArray<EapCertificateEntry> empty(sizeof(EapCertificateEntry));
  1244 
  1248 
  1245 				m_am_tools->enter_global_mutex();
  1249 				m_am_tools->enter_global_mutex();
  1246 				
  1250 				
  1247 				iParent->complete_get_matching_certificates(tmp, eap_status_allocation_error); //Failure
  1251 				iParent->complete_get_matching_certificates(empty, eap_status_allocation_error); //Failure
  1248 				
  1252 				
  1249 				m_am_tools->leave_global_mutex();
  1253 				m_am_tools->leave_global_mutex();
  1250 							
  1254 							
       
  1255 				delete entry;
       
  1256 
  1251 				break;
  1257 				break;
  1252 			}
  1258 			}
  1253 
  1259 
  1254 			iUserCertIndex++;
  1260 			iUserCertIndex++;
  1255 
  1261 
  1388 				
  1394 				
  1389 				iState = EGetMatchingCertsLoop;
  1395 				iState = EGetMatchingCertsLoop;
  1390 
  1396 
  1391 				iEncodedCertificate->Des().SetLength(0);
  1397 				iEncodedCertificate->Des().SetLength(0);
  1392 
  1398 
  1393 				TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(iCertInfos[iUserCertIndex]->Size()));
  1399 				HBufC8 * tmpCert = 0;
       
  1400 				TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(iCertInfos[iUserCertIndex]->Size()));
  1394 				if (error != KErrNone)
  1401 				if (error != KErrNone)
  1395 				{
  1402 				{
  1396 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1403 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1397 				
  1404 				
  1398 					RPointerArray<EapCertificateEntry> tmp(sizeof(EapCertificateEntry));
  1405 					RPointerArray<EapCertificateEntry> empty(sizeof(EapCertificateEntry));
  1399 
  1406 
  1400 					m_am_tools->enter_global_mutex();
  1407 					m_am_tools->enter_global_mutex();
  1401 					
  1408 					
  1402 					iParent->complete_get_matching_certificates(tmp, eap_status_allocation_error); //Failure
  1409 					iParent->complete_get_matching_certificates(empty, eap_status_allocation_error); //Failure
  1403 					
  1410 					
  1404 					m_am_tools->leave_global_mutex();
  1411 					m_am_tools->leave_global_mutex();
  1405 					
  1412 					
  1406 					break;
  1413 					break;
  1407 				}
  1414 				}
       
  1415 
       
  1416 				iEncodedCertificate = tmpCert;
  1408 				
  1417 				
  1409 				iCertPtr.Set(iEncodedCertificate->Des());
  1418 				iCertPtr.Set(iEncodedCertificate->Des());
  1410 
  1419 
  1411 				iCertStore->Retrieve(
  1420 				iCertStore->Retrieve(
  1412 					*(iCertInfos[iUserCertIndex]), 
  1421 					*(iCertInfos[iUserCertIndex]), 
  1438 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  1447 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  1439 			if (error != KErrNone || iCertFilter == 0)
  1448 			if (error != KErrNone || iCertFilter == 0)
  1440 			{ 
  1449 			{ 
  1441 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1450 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1442 				
  1451 				
  1443 				RPointerArray<CX509Certificate> tmp;
  1452 				RPointerArray<CX509Certificate> empty;
  1444 				
  1453 				
  1445 				m_am_tools->enter_global_mutex();
  1454 				m_am_tools->enter_global_mutex();
  1446 				
  1455 				
  1447 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1456 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1448 				
  1457 				
  1449 				m_am_tools->leave_global_mutex();
  1458 				m_am_tools->leave_global_mutex();
  1450 				
  1459 				
  1451 				break;
  1460 				break;
  1452 			}
  1461 			}
  1481 			// Now we should have all the cert infos in iCertInfos.			
  1490 			// Now we should have all the cert infos in iCertInfos.			
  1482 			if (iCertInfos.Count() == 0)
  1491 			if (iCertInfos.Count() == 0)
  1483 			{
  1492 			{
  1484 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EReadCertList iCertInfos.Count = 0.\n")));			
  1493 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EReadCertList iCertInfos.Count = 0.\n")));			
  1485 				
  1494 				
  1486 				RPointerArray<CX509Certificate> tmp;
  1495 				RPointerArray<CX509Certificate> empty;
  1487 				
  1496 				
  1488 				m_am_tools->enter_global_mutex();
  1497 				m_am_tools->enter_global_mutex();
  1489 				
  1498 				
  1490 				iParent->complete_read_own_certificate(tmp, eap_status_illegal_certificate); //Failure
  1499 				iParent->complete_read_own_certificate(empty, eap_status_illegal_certificate); //Failure
  1491 				
  1500 				
  1492 				m_am_tools->leave_global_mutex();
  1501 				m_am_tools->leave_global_mutex();
  1493 
  1502 
  1494 				break;
  1503 				break;
  1495 			}
  1504 			}
  1500 
  1509 
  1501 			iState = EReadCert;
  1510 			iState = EReadCert;
  1502 			
  1511 			
  1503 			iEncodedCertificate->Des().SetLength(0);
  1512 			iEncodedCertificate->Des().SetLength(0);
  1504 
  1513 
  1505 			TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(info->Size()));
  1514 			HBufC8 * tmpCert = 0;
       
  1515 			TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(info->Size()));
  1506 			if (error != KErrNone)
  1516 			if (error != KErrNone)
  1507 			{
  1517 			{
  1508 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1518 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1509 				
  1519 				
  1510 				RPointerArray<CX509Certificate> tmp;
  1520 				RPointerArray<CX509Certificate> empty;
  1511 								
  1521 								
  1512 				m_am_tools->enter_global_mutex();
  1522 				m_am_tools->enter_global_mutex();
  1513 				
  1523 				
  1514 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1524 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1515 				
  1525 				
  1516 				m_am_tools->leave_global_mutex();
  1526 				m_am_tools->leave_global_mutex();
  1517 				
  1527 				
  1518 				break;
  1528 				break;
  1519 			}
  1529 			}
       
  1530 
       
  1531 			iEncodedCertificate = tmpCert;
  1520 				
  1532 				
  1521 			iCertPtr.Set(iEncodedCertificate->Des());
  1533 			iCertPtr.Set(iEncodedCertificate->Des());
  1522 			
  1534 			
  1523 			iCertStore->Retrieve(
  1535 			iCertStore->Retrieve(
  1524 				*info, 
  1536 				*info, 
  1539 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  1551 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  1540 			if (error != KErrNone)
  1552 			if (error != KErrNone)
  1541 			{
  1553 			{
  1542 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1554 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1543 				
  1555 				
  1544 				RPointerArray<CX509Certificate> tmp;
  1556 				RPointerArray<CX509Certificate> empty;
  1545 								
  1557 								
  1546 				m_am_tools->enter_global_mutex();
  1558 				m_am_tools->enter_global_mutex();
  1547 				
  1559 				
  1548 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1560 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1549 				
  1561 				
  1550 				m_am_tools->leave_global_mutex();
  1562 				m_am_tools->leave_global_mutex();
  1551 				
  1563 				
  1552 				break;
  1564 				break;
  1553 			}
  1565 			}
  1556 			if (iUserCertChain.Append(cert) != KErrNone)
  1568 			if (iUserCertChain.Append(cert) != KErrNone)
  1557 			{
  1569 			{
  1558 				delete cert;
  1570 				delete cert;
  1559 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1571 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1560 				
  1572 				
  1561 				RPointerArray<CX509Certificate> tmp;
  1573 				RPointerArray<CX509Certificate> empty;
  1562 								
  1574 								
  1563 				m_am_tools->enter_global_mutex();
  1575 				m_am_tools->enter_global_mutex();
  1564 				
  1576 				
  1565 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1577 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1566 				
  1578 				
  1567 				m_am_tools->leave_global_mutex();
  1579 				m_am_tools->leave_global_mutex();
  1568 				
  1580 				
  1569 				break;
  1581 				break;
  1570 			}
  1582 			}
  1617 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  1629 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  1618 			if (error != KErrNone)
  1630 			if (error != KErrNone)
  1619 			{ 
  1631 			{ 
  1620 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1632 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1621 				
  1633 				
  1622 				RPointerArray<CX509Certificate> tmp;
  1634 				RPointerArray<CX509Certificate> empty;
  1623 								
  1635 								
  1624 				m_am_tools->enter_global_mutex();
  1636 				m_am_tools->enter_global_mutex();
  1625 				
  1637 				
  1626 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1638 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1627 				
  1639 				
  1628 				m_am_tools->leave_global_mutex();
  1640 				m_am_tools->leave_global_mutex();
  1629 				
  1641 				
  1630 				break;
  1642 				break;
  1631 			}
  1643 			}
  1686 			iCAIndex = 0;
  1698 			iCAIndex = 0;
  1687 
  1699 
  1688 			iState = ECreateCertChain;
  1700 			iState = ECreateCertChain;
  1689 			
  1701 			
  1690 			iEncodedCertificate->Des().SetLength(0);
  1702 			iEncodedCertificate->Des().SetLength(0);
  1691 			TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(info->Size()));
  1703 
       
  1704 			HBufC8 * tmpCert = 0;
       
  1705 			TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(info->Size()));
  1692 			if (error != KErrNone)
  1706 			if (error != KErrNone)
  1693 			{
  1707 			{
  1694 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1708 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1695 				
  1709 				
  1696 				RPointerArray<CX509Certificate> tmp;
  1710 				RPointerArray<CX509Certificate> empty;
  1697 								
  1711 								
  1698 				m_am_tools->enter_global_mutex();
  1712 				m_am_tools->enter_global_mutex();
  1699 				
  1713 				
  1700 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1714 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1701 				
  1715 				
  1702 				m_am_tools->leave_global_mutex();
  1716 				m_am_tools->leave_global_mutex();
  1703 				
  1717 				
  1704 				break;
  1718 				break;
  1705 			}
  1719 			}
       
  1720 
       
  1721 			iEncodedCertificate = tmpCert;
  1706 				
  1722 				
  1707 			iCertPtr.Set(iEncodedCertificate->Des());
  1723 			iCertPtr.Set(iEncodedCertificate->Des());
  1708 			
  1724 			
  1709 			iCertStore->Retrieve(
  1725 			iCertStore->Retrieve(
  1710 				*info, 
  1726 				*info, 
  1726 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  1742 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  1727 			if (error != KErrNone || cert == 0)
  1743 			if (error != KErrNone || cert == 0)
  1728 			{
  1744 			{
  1729 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1745 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1730 				
  1746 				
  1731 				RPointerArray<CX509Certificate> tmp;
  1747 				RPointerArray<CX509Certificate> empty;
  1732 								
  1748 								
  1733 				m_am_tools->enter_global_mutex();
  1749 				m_am_tools->enter_global_mutex();
  1734 				
  1750 				
  1735 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1751 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1736 				
  1752 				
  1737 				m_am_tools->leave_global_mutex();
  1753 				m_am_tools->leave_global_mutex();
  1738 				
  1754 				
  1739 				break;
  1755 				break;
  1740 			}
  1756 			}
  1811 			if (iRootCerts.Append(cert) != KErrNone)
  1827 			if (iRootCerts.Append(cert) != KErrNone)
  1812 			{
  1828 			{
  1813 				delete cert;
  1829 				delete cert;
  1814 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1830 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1815 				
  1831 				
  1816 				RPointerArray<CX509Certificate> tmp;
  1832 				RPointerArray<CX509Certificate> empty;
  1817 								
  1833 								
  1818 				m_am_tools->enter_global_mutex();
  1834 				m_am_tools->enter_global_mutex();
  1819 				
  1835 				
  1820 				iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1836 				iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1821 				
  1837 				
  1822 				m_am_tools->leave_global_mutex();
  1838 				m_am_tools->leave_global_mutex();
  1823 				
  1839 				
  1824 				break;
  1840 				break;
  1825 			}
  1841 			}
  1873 							
  1889 							
  1874 							TRAPD(error, dsaParams = CX509DSAPublicKey::DSAParametersL(params));
  1890 							TRAPD(error, dsaParams = CX509DSAPublicKey::DSAParametersL(params));
  1875 							if (error != KErrNone)
  1891 							if (error != KErrNone)
  1876 							{				
  1892 							{				
  1877 				
  1893 				
  1878 								RPointerArray<CX509Certificate> tmp;
  1894 								RPointerArray<CX509Certificate> empty;
  1879 								m_am_tools->enter_global_mutex();
  1895 								m_am_tools->enter_global_mutex();
  1880 								
  1896 								
  1881 								iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1897 								iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1882 								
  1898 								
  1883 								m_am_tools->leave_global_mutex();
  1899 								m_am_tools->leave_global_mutex();
  1884 				
  1900 				
  1885 								return;
  1901 								return;
  1886 							}					
  1902 							}					
  1887 									
  1903 									
  1888 							TRAP(error, signParams = CSigningKeyParameters::NewL());
  1904 							TRAP(error, signParams = CSigningKeyParameters::NewL());
  1889 							if (error != KErrNone)
  1905 							if (error != KErrNone)
  1890 							{				
  1906 							{				
  1891 								RPointerArray<CX509Certificate> tmp;
  1907 								RPointerArray<CX509Certificate> empty;
  1892 				
  1908 				
  1893 								m_am_tools->enter_global_mutex();
  1909 								m_am_tools->enter_global_mutex();
  1894 								
  1910 								
  1895 								iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1911 								iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1896 								
  1912 								
  1897 								m_am_tools->leave_global_mutex();				
  1913 								m_am_tools->leave_global_mutex();				
  1898 
  1914 
  1899 								delete dsaParams;
  1915 								delete dsaParams;
  1900 								return;
  1916 								return;
  1901 							}
  1917 							}
  1902 							TRAP(error, signParams->SetDSAParamsL(*dsaParams));
  1918 							TRAP(error, signParams->SetDSAParamsL(*dsaParams));
  1903 							if (error != KErrNone)
  1919 							if (error != KErrNone)
  1904 							{				
  1920 							{				
  1905 								RPointerArray<CX509Certificate> tmp;
  1921 								RPointerArray<CX509Certificate> empty;
  1906 								
  1922 								
  1907 								m_am_tools->enter_global_mutex();
  1923 								m_am_tools->enter_global_mutex();
  1908 								
  1924 								
  1909 								iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1925 								iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1910 								
  1926 								
  1911 								m_am_tools->leave_global_mutex();
  1927 								m_am_tools->leave_global_mutex();
  1912 				
  1928 				
  1913 								delete dsaParams;
  1929 								delete dsaParams;
  1914 								delete signParams;
  1930 								delete signParams;
  1916 							}
  1932 							}
  1917 
  1933 
  1918 							TRAP(error, iUserCertChain[iUserCertChain.Count()-1]->SetParametersL(*signParams));
  1934 							TRAP(error, iUserCertChain[iUserCertChain.Count()-1]->SetParametersL(*signParams));
  1919 							if (error != KErrNone)
  1935 							if (error != KErrNone)
  1920 							{
  1936 							{
  1921 								RPointerArray<CX509Certificate> tmp;
  1937 								RPointerArray<CX509Certificate> empty;
  1922 								m_am_tools->enter_global_mutex();
  1938 								m_am_tools->enter_global_mutex();
  1923 								
  1939 								
  1924 								iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1940 								iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1925 								
  1941 								
  1926 								m_am_tools->leave_global_mutex();				
  1942 								m_am_tools->leave_global_mutex();				
  1927 							
  1943 							
  1928 								delete dsaParams;
  1944 								delete dsaParams;
  1929 								delete signParams;
  1945 								delete signParams;
  1937 							if (iUserCertChain.Append(iRootCerts[i]) != KErrNone)
  1953 							if (iUserCertChain.Append(iRootCerts[i]) != KErrNone)
  1938 							{
  1954 							{
  1939 								delete dsaParams;
  1955 								delete dsaParams;
  1940 								delete signParams;
  1956 								delete signParams;
  1941 								EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1957 								EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  1942 								RPointerArray<CX509Certificate> tmp;
  1958 
       
  1959 								RPointerArray<CX509Certificate> empty;
  1943 								
  1960 								
  1944 								m_am_tools->enter_global_mutex();
  1961 								m_am_tools->enter_global_mutex();
  1945 								
  1962 								
  1946 								iParent->complete_read_own_certificate(tmp, eap_status_allocation_error); //Failure
  1963 								iParent->complete_read_own_certificate(empty, eap_status_allocation_error); //Failure
  1947 								
  1964 								
  1948 								m_am_tools->leave_global_mutex();
  1965 								m_am_tools->leave_global_mutex();
  1949 				
  1966 				
  1950 								return;
  1967 								return;
  1951 							}
  1968 							}
  1982 					m_am_tools,
  1999 					m_am_tools,
  1983 					TRACE_FLAGS_DEFAULT,
  2000 					TRACE_FLAGS_DEFAULT,
  1984 					(EAPL("CEapTlsPeapCertInterface::RunL()- ECreateCertChain - Before Retrieve(): iCAIndex=%d, size=%d\n"),
  2001 					(EAPL("CEapTlsPeapCertInterface::RunL()- ECreateCertChain - Before Retrieve(): iCAIndex=%d, size=%d\n"),
  1985 					iCAIndex, info->Size()));			
  2002 					iCAIndex, info->Size()));			
  1986 
  2003 
  1987 				
       
  1988 				
       
  1989 				iEncodedCertificate->Des().SetLength(0);
  2004 				iEncodedCertificate->Des().SetLength(0);
  1990 				TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(info->Size()));
  2005 
       
  2006 				HBufC8 * tmpCert = 0;
       
  2007 				TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(info->Size()));
  1991 				if (error != KErrNone)
  2008 				if (error != KErrNone)
  1992 				{
  2009 				{
  1993 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2010 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  1994 				
  2011 				
  1995 					RPointerArray<CX509Certificate> tmp;
  2012 					RPointerArray<CX509Certificate> empty;
  1996 					
  2013 					
  1997 					m_am_tools->enter_global_mutex();
  2014 					m_am_tools->enter_global_mutex();
  1998 					
  2015 					
  1999 					iParent->complete_read_ca_certificate(tmp, eap_status_allocation_error); //Failure
  2016 					iParent->complete_read_ca_certificate(empty, eap_status_allocation_error); //Failure
  2000 					
  2017 					
  2001 					m_am_tools->leave_global_mutex();
  2018 					m_am_tools->leave_global_mutex();
  2002 				
  2019 				
  2003 					break;
  2020 					break;
  2004 				}
  2021 				}
       
  2022 
       
  2023 				iEncodedCertificate = tmpCert;
  2005 				
  2024 				
  2006 				iCertPtr.Set(iEncodedCertificate->Des());
  2025 				iCertPtr.Set(iEncodedCertificate->Des());
  2007 			
  2026 			
  2008 				iCertStore->Retrieve(
  2027 				iCertStore->Retrieve(
  2009 					*info, 
  2028 					*info, 
  2034 			
  2053 			
  2035 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  2054 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  2036 			if (error != KErrNone)
  2055 			if (error != KErrNone)
  2037 			{ 
  2056 			{ 
  2038 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2057 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2039 				RPointerArray<CX509Certificate> tmp;
  2058 
       
  2059 				RPointerArray<CX509Certificate> empty;
  2040 				
  2060 				
  2041 				m_am_tools->enter_global_mutex();
  2061 				m_am_tools->enter_global_mutex();
  2042 				
  2062 				
  2043 				iParent->complete_read_ca_certificate(tmp, eap_status_allocation_error); //Failure
  2063 				iParent->complete_read_ca_certificate(empty, eap_status_allocation_error); //Failure
  2044 				
  2064 				
  2045 				m_am_tools->leave_global_mutex();
  2065 				m_am_tools->leave_global_mutex();
  2046 				break;
  2066 				break;
  2047 			}
  2067 			}
  2048 			
  2068 			
  2075 
  2095 
  2076 			// Now we should have all the cert infos in iCertInfos.			
  2096 			// Now we should have all the cert infos in iCertInfos.			
  2077 			if (iCertInfos.Count() == 0)
  2097 			if (iCertInfos.Count() == 0)
  2078 			{
  2098 			{
  2079 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EReadCACertList iCertInfos.Count = 0.\n")));
  2099 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EReadCACertList iCertInfos.Count = 0.\n")));
  2080 				RPointerArray<CX509Certificate> tmp;
  2100 
       
  2101 				RPointerArray<CX509Certificate> empty;
  2081 				
  2102 				
  2082 				m_am_tools->enter_global_mutex();
  2103 				m_am_tools->enter_global_mutex();
  2083 				
  2104 				
  2084 				iParent->complete_read_ca_certificate(tmp, eap_status_allocation_error); //Failure
  2105 				iParent->complete_read_ca_certificate(empty, eap_status_allocation_error); //Failure
  2085 				
  2106 				
  2086 				m_am_tools->leave_global_mutex();
  2107 				m_am_tools->leave_global_mutex();
  2087 				break;
  2108 				break;
  2088 			}
  2109 			}
  2089 			
  2110 			
  2093 
  2114 
  2094 			iState = EReadCACert;
  2115 			iState = EReadCACert;
  2095 			
  2116 			
  2096 			iEncodedCertificate->Des().SetLength(0);
  2117 			iEncodedCertificate->Des().SetLength(0);
  2097 
  2118 
  2098 			TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(info->Size()));
  2119 			HBufC8 * tmpCert = 0;
       
  2120 			TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(info->Size()));
  2099 			if (error != KErrNone)
  2121 			if (error != KErrNone)
  2100 			{
  2122 			{
  2101 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2123 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2102 				RPointerArray<CX509Certificate> tmp;
  2124 
       
  2125 				RPointerArray<CX509Certificate> empty;
  2103 				
  2126 				
  2104 				m_am_tools->enter_global_mutex();
  2127 				m_am_tools->enter_global_mutex();
  2105 				
  2128 				
  2106 				iParent->complete_read_ca_certificate(tmp, eap_status_allocation_error); //Failure
  2129 				iParent->complete_read_ca_certificate(empty, eap_status_allocation_error); //Failure
  2107 				
  2130 				
  2108 				m_am_tools->leave_global_mutex();
  2131 				m_am_tools->leave_global_mutex();
  2109 				break;
  2132 				break;
  2110 			}
  2133 			}
       
  2134 
       
  2135 			iEncodedCertificate = tmpCert;
  2111 				
  2136 				
  2112 			iCertPtr.Set(iEncodedCertificate->Des());
  2137 			iCertPtr.Set(iEncodedCertificate->Des());
  2113 			
  2138 			
  2114 			iCertStore->Retrieve(
  2139 			iCertStore->Retrieve(
  2115 				*info, 
  2140 				*info, 
  2136 			CX509Certificate* cert = 0;
  2161 			CX509Certificate* cert = 0;
  2137 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  2162 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  2138 			if (error != KErrNone)
  2163 			if (error != KErrNone)
  2139 			{
  2164 			{
  2140 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2165 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2141 				RPointerArray<CX509Certificate> tmp;
  2166 
       
  2167 				RPointerArray<CX509Certificate> empty;
  2142 				
  2168 				
  2143 				m_am_tools->enter_global_mutex();
  2169 				m_am_tools->enter_global_mutex();
  2144 				
  2170 				
  2145 				iParent->complete_read_ca_certificate(tmp, eap_status_allocation_error); //Failure
  2171 				iParent->complete_read_ca_certificate(empty, eap_status_allocation_error); //Failure
  2146 				
  2172 				
  2147 				m_am_tools->leave_global_mutex();
  2173 				m_am_tools->leave_global_mutex();
  2148 				break;
  2174 				break;
  2149 			}
  2175 			}
  2150 			
  2176 			
  2152 			iUserCertChain.ResetAndDestroy();
  2178 			iUserCertChain.ResetAndDestroy();
  2153 			if (iUserCertChain.Append(cert) != KErrNone)
  2179 			if (iUserCertChain.Append(cert) != KErrNone)
  2154 			{
  2180 			{
  2155 				delete cert;
  2181 				delete cert;
  2156 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2182 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2157 				RPointerArray<CX509Certificate> tmp;
  2183 
       
  2184 				RPointerArray<CX509Certificate> empty;
  2158 				
  2185 				
  2159 				m_am_tools->enter_global_mutex();
  2186 				m_am_tools->enter_global_mutex();
  2160 				
  2187 				
  2161 				iParent->complete_read_ca_certificate(tmp, eap_status_allocation_error); //Failure
  2188 				iParent->complete_read_ca_certificate(empty, eap_status_allocation_error); //Failure
  2162 				
  2189 				
  2163 				m_am_tools->leave_global_mutex();
  2190 				m_am_tools->leave_global_mutex();
  2164 				break;
  2191 				break;
  2165 			}
  2192 			}
  2166 			
  2193 			
  2187 			
  2214 			
  2188 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  2215 			TRAPD(error, iCertFilter = CCertAttributeFilter::NewL());
  2189 			if (error != KErrNone)
  2216 			if (error != KErrNone)
  2190 			{ 
  2217 			{ 
  2191 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2218 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2192 				CPKIXValidationResult* tmp = 0;
  2219 
       
  2220 				const CPKIXValidationResult * const empty = 0;
  2193 				
  2221 				
  2194 				m_am_tools->enter_global_mutex();
  2222 				m_am_tools->enter_global_mutex();
  2195 
  2223 
  2196 				iParent->complete_validate_chain(*tmp, eap_status_ca_certificate_unknown); //Failure.
  2224 				iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2197 
  2225 
  2198 				m_am_tools->leave_global_mutex();
  2226 				m_am_tools->leave_global_mutex();
  2199 				break;
  2227 				break;
  2200 			}
  2228 			}
  2201 
  2229 
  2253 			if (iCertInfos.Count() == 0)
  2281 			if (iCertInfos.Count() == 0)
  2254 			{	
  2282 			{	
  2255 				// Create new validation result for this failure case. 
  2283 				// Create new validation result for this failure case. 
  2256 				// CPKIXValidationResult does include a Reset-member function
  2284 				// CPKIXValidationResult does include a Reset-member function
  2257 				// but it is not in x500.lib as the documentation says.
  2285 				// but it is not in x500.lib as the documentation says.
  2258 				CPKIXValidationResult* validationResult = 0;
  2286 				const CPKIXValidationResult * const empty = 0;
  2259 				TRAPD(error, validationResult = CPKIXValidationResult::NewL());
  2287 
  2260 				if (error != KErrNone)
  2288 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: No cert infos\n")));
  2261 				{
  2289 
  2262 					// Do nothing. Session timeout takes care of cleanup...
       
  2263 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
       
  2264 				}
       
  2265 				m_am_tools->enter_global_mutex();
  2290 				m_am_tools->enter_global_mutex();
  2266 
  2291 
  2267 				iParent->complete_validate_chain(*validationResult, eap_status_ca_certificate_unknown); //Failure.
  2292 				iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2268 
  2293 
  2269 				m_am_tools->leave_global_mutex();
  2294 				m_am_tools->leave_global_mutex();
  2270 				delete validationResult;
       
  2271 				break;
  2295 				break;
  2272 			}
  2296 			}
  2273 
  2297 
  2274 			{
  2298 			{
  2275 				CCTCertInfo* info;
  2299 				CCTCertInfo* info;
  2277 				iCAIndex = 0;
  2301 				iCAIndex = 0;
  2278 
  2302 
  2279 				iState = EValidateChainGetCACert;
  2303 				iState = EValidateChainGetCACert;
  2280 
  2304 
  2281 				iEncodedCertificate->Des().SetLength(0);
  2305 				iEncodedCertificate->Des().SetLength(0);
  2282 				TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(info->Size()));
  2306 
       
  2307 				HBufC8 * tmpCert = 0;
       
  2308 				TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(info->Size()));
  2283 				if (error != KErrNone)
  2309 				if (error != KErrNone)
  2284 				{
  2310 				{
  2285 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2311 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2286 					
  2312 					
  2287 					CPKIXValidationResult* tmp = 0;
  2313 					const CPKIXValidationResult * const empty = 0;
  2288 					
  2314 					
  2289 					m_am_tools->enter_global_mutex();
  2315 					m_am_tools->enter_global_mutex();
  2290 
  2316 
  2291 					iParent->complete_validate_chain(*tmp, eap_status_ca_certificate_unknown); //Failure.
  2317 					iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2292 
  2318 
  2293 					m_am_tools->leave_global_mutex();
  2319 					m_am_tools->leave_global_mutex();
  2294 					break;
  2320 					break;
  2295 				}
  2321 				}
       
  2322 
       
  2323 				iEncodedCertificate = tmpCert;
  2296 
  2324 
  2297 				iCertPtr.Set(iEncodedCertificate->Des());
  2325 				iCertPtr.Set(iEncodedCertificate->Des());
  2298 
  2326 
  2299 				iCertStore->Retrieve(
  2327 				iCertStore->Retrieve(
  2300 					*info, 
  2328 					*info, 
  2315 
  2343 
  2316 			CX509Certificate* cert = 0;
  2344 			CX509Certificate* cert = 0;
  2317 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  2345 			TRAPD(error, cert = CX509Certificate::NewL(iEncodedCertificate->Des()));
  2318 			if (error != KErrNone)
  2346 			if (error != KErrNone)
  2319 			{
  2347 			{
  2320 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2348 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2321 				CPKIXValidationResult* tmp = 0;
  2349 
       
  2350 				const CPKIXValidationResult * const empty = 0;
  2322 				
  2351 				
  2323 				m_am_tools->enter_global_mutex();
  2352 				m_am_tools->enter_global_mutex();
  2324 
  2353 
  2325 				iParent->complete_validate_chain(*tmp, eap_status_ca_certificate_unknown); //Failure.
  2354 				iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2326 
  2355 
  2327 				m_am_tools->leave_global_mutex();
  2356 				m_am_tools->leave_global_mutex();
  2328 				break;
  2357 				break;
  2329 			}
  2358 			}
  2330 		
  2359 		
  2331 			// Signal completition
  2360 			// Signal completition
  2332 			if (iRootCerts.Append(cert) != KErrNone)
  2361 			if (iRootCerts.Append(cert) != KErrNone)
  2333 			{
  2362 			{
  2334 				delete cert;
  2363 				delete cert;
  2335 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2364 				EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2336 				CPKIXValidationResult* tmp = 0;
  2365 
       
  2366 				const CPKIXValidationResult * const empty = 0;
  2337 				
  2367 				
  2338 				m_am_tools->enter_global_mutex();
  2368 				m_am_tools->enter_global_mutex();
  2339 
  2369 
  2340 				iParent->complete_validate_chain(*tmp, eap_status_ca_certificate_unknown); //Failure.
  2370 				iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2341 
  2371 
  2342 				m_am_tools->leave_global_mutex();
  2372 				m_am_tools->leave_global_mutex();
  2343 				break;
  2373 				break;
  2344 			}
  2374 			}
  2345 
  2375 
  2351 
  2381 
  2352 				TRAPD(error, iCertChain = CPKIXCertChain::NewL(iFs, *iInputCertChain, iRootCerts));
  2382 				TRAPD(error, iCertChain = CPKIXCertChain::NewL(iFs, *iInputCertChain, iRootCerts));
  2353 				if (error != KErrNone)
  2383 				if (error != KErrNone)
  2354 				{
  2384 				{
  2355 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EAP-TLS error %d.\n"), error));
  2385 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: EAP-TLS error %d.\n"), error));
  2356 					CPKIXValidationResult* tmp = 0;
  2386 
       
  2387 					const CPKIXValidationResult * const empty = 0;
  2357 					
  2388 					
  2358 					m_am_tools->enter_global_mutex();
  2389 					m_am_tools->enter_global_mutex();
  2359 
  2390 
  2360 					iParent->complete_validate_chain(*tmp, eap_status_ca_certificate_unknown); //Failure.
  2391 					iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2361 
  2392 
  2362 					m_am_tools->leave_global_mutex();
  2393 					m_am_tools->leave_global_mutex();
  2363 					break;
  2394 					break;
  2364 				}
  2395 				}
  2365 
  2396 
  2375 
  2406 
  2376 				TRAP(error, iCertChain->ValidateL(*iValidationResult, iTime, iStatus));
  2407 				TRAP(error, iCertChain->ValidateL(*iValidationResult, iTime, iStatus));
  2377 				if (error != KErrNone)
  2408 				if (error != KErrNone)
  2378 				{
  2409 				{
  2379 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Error in certificate validation in EAP-TLS, error = %d.\n"),
  2410 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Error in certificate validation in EAP-TLS, error = %d.\n"),
  2380 						error));			
  2411 						error));
  2381 					CPKIXValidationResult* tmp = 0;
  2412 
       
  2413 					const CPKIXValidationResult * const empty = 0;
  2382 					
  2414 					
  2383 					m_am_tools->enter_global_mutex();
  2415 					m_am_tools->enter_global_mutex();
  2384 
  2416 
  2385 					iParent->complete_validate_chain(*tmp, eap_status_ca_certificate_unknown); //Failure.
  2417 					iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2386 
  2418 
  2387 					m_am_tools->leave_global_mutex();
  2419 					m_am_tools->leave_global_mutex();
  2388 					break;
  2420 					break;
  2389 				}
  2421 				}
  2390 				SetActive();	// Validate.
  2422 				SetActive();	// Validate.
  2395 				info = iCertInfos[iCAIndex];
  2427 				info = iCertInfos[iCAIndex];
  2396 
  2428 
  2397 				iState = EValidateChainGetCACert;
  2429 				iState = EValidateChainGetCACert;
  2398 				
  2430 				
  2399 				iEncodedCertificate->Des().SetLength(0);
  2431 				iEncodedCertificate->Des().SetLength(0);
  2400 				TRAPD(error, iEncodedCertificate = iEncodedCertificate->ReAllocL(info->Size()));
  2432 
       
  2433 				HBufC8 * tmpCert = 0;
       
  2434 				TRAPD(error, tmpCert = iEncodedCertificate->ReAllocL(info->Size()));
  2401 				if (error != KErrNone)
  2435 				if (error != KErrNone)
  2402 				{
  2436 				{
  2403 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));			
  2437 					EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("ERROR: Out of memory in EAP-TLS.\n")));
  2404 					CPKIXValidationResult* tmp = 0;
  2438 
       
  2439 					const CPKIXValidationResult * const empty = 0;
  2405 					
  2440 					
  2406 					m_am_tools->enter_global_mutex();
  2441 					m_am_tools->enter_global_mutex();
  2407 
  2442 
  2408 					iParent->complete_validate_chain(*tmp, eap_status_ca_certificate_unknown); //Failure.
  2443 					iParent->complete_validate_chain(empty, eap_status_ca_certificate_unknown); //Failure.
  2409 
  2444 
  2410 					m_am_tools->leave_global_mutex();
  2445 					m_am_tools->leave_global_mutex();
  2411 					break;
  2446 					break;
  2412 				}
  2447 				}
       
  2448 
       
  2449 				iEncodedCertificate = tmpCert;
  2413 				
  2450 				
  2414 				iCertPtr.Set(iEncodedCertificate->Des());
  2451 				iCertPtr.Set(iEncodedCertificate->Des());
  2415 			
  2452 			
  2416 				iCertStore->Retrieve(
  2453 				iCertStore->Retrieve(
  2417 					*info, 
  2454 					*info, 
  2430 			TRACE_FLAGS_DEFAULT,
  2467 			TRACE_FLAGS_DEFAULT,
  2431 			(EAPL("CEapTlsPeapCertInterface::RunL(): EValidateChainEnd, iValidationResult->Error().iReason=%d\n"),
  2468 			(EAPL("CEapTlsPeapCertInterface::RunL(): EValidateChainEnd, iValidationResult->Error().iReason=%d\n"),
  2432 			iValidationResult->Error().iReason));
  2469 			iValidationResult->Error().iReason));
  2433 		
  2470 		
  2434 		m_am_tools->enter_global_mutex();
  2471 		m_am_tools->enter_global_mutex();
  2435 		
  2472 
  2436 		iParent->complete_validate_chain(*iValidationResult, eap_status_ok);
  2473 		iParent->complete_validate_chain(iValidationResult, eap_status_ok);
  2437 
  2474 
  2438 		m_am_tools->leave_global_mutex();
  2475 		m_am_tools->leave_global_mutex();
  2439 		// Ignore error because there is nothing that can be done.
  2476 		// Ignore error because there is nothing that can be done.
  2440 		break;
  2477 		break;
  2441 
  2478