os/security/cryptoservices/certificateandkeymgmt/tpkixcert_tef/src/apiteststeps.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2008-2009 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: 
    15 *
    16 */
    17 
    18 
    19 #include "apiteststeps.h"
    20 #include "cleanuputils.h"
    21 
    22 	
    23 CPkixCertAddSupportedOidsStep::CPkixCertAddSupportedOidsStep()
    24 	{
    25 	SetTestStepName(KAddSupportedOidsTestStep);
    26 	}
    27 
    28 //1. make a copy(A) of the supported oids at the start
    29 //2. add in the oids from the config file(B), make a copy of these and add to A
    30 //3. get the supported oids now(C)
    31 //4. iterate over C, for each oid find copies in A and remove them.  if it is not found we error
    32 //5. if A is non empty we error
    33 void CPkixCertAddSupportedOidsStep::PerformTestL()
    34 	{
    35 	CPkixCertStepBase::PerformTestL();
    36 	
    37 	//1. make a copy(A) of the supported oids at the start
    38 	
    39 	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();	
    40 	//CleanupClosePushL(suppOids);	//don't need to do this as a ref and done in stepbase destructor
    41 	RPointerArray<HBufC> startSuppOids;
    42 	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
    43 		
    44 	HBufC* des;
    45 	TInt i;
    46 	for (i=0; i < suppOids.Count(); ++i)
    47 		{
    48 		des = (suppOids[i])->AllocLC();
    49 		startSuppOids.AppendL(des);
    50 		CleanupStack::Pop(des);
    51 		}
    52 	
    53 	
    54 	
    55 	//2. add in the oids from the config file(B)
    56 	iCertChain->AddSupportedCriticalExtensionsL(iProcessedOids);
    57 	
    58 	//make a copy of these and add to A
    59 	for (i=0; i < iProcessedOids.Count(); ++i)
    60 		{
    61 		des = (iProcessedOids[i])->AllocLC();
    62 		startSuppOids.AppendL(des);
    63 		CleanupStack::Pop(des);
    64 		}
    65 	
    66 	//3. get the supported oids now(C)
    67 	const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
    68 	
    69 	
    70 	//4. iterate over C, for each oid find copies in A and remove them.  if it is not found we error
    71 	TBool found;
    72 	for (i=0; i < suppOids2.Count(); ++i)
    73 		{
    74 		found = EFalse;
    75 		for (TInt j=0; j < startSuppOids.Count(); ++j)
    76 			{
    77 			if ((*startSuppOids[j]) == (*suppOids2[i]))
    78 				{
    79 				found = ETrue;
    80 				delete (startSuppOids[j]);
    81 				startSuppOids.Remove(j);
    82 				--j;
    83 				}
    84 			}	//startSuppOids loop
    85 		if (!found)	
    86 			{
    87 			ERR_PRINTF2(_L("Extra ERROR: OID in result: %S"), suppOids2[i]);
    88 			User::Leave(KErrGeneral);
    89 			}			
    90 		}	//suppOids2 loop
    91 	
    92 	
    93 	//5. if A is non empty we error
    94 	if (startSuppOids.Count() != 0)
    95 		{
    96 		for (TInt j=0; j < startSuppOids.Count(); ++j)
    97 			{	
    98 			ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]);
    99 			}
   100 		User::Leave(KErrGeneral);
   101 		}
   102 	
   103 	CleanupStack::PopAndDestroy(2, iCertChain);
   104 	}
   105 
   106 
   107 ///////////////////////////////////////////////////////////////////
   108 
   109 
   110 
   111 CPkixCertRemoveSupportedOidsStep::CPkixCertRemoveSupportedOidsStep()
   112 	{
   113 	SetTestStepName(KRemoveSupportedOidsTestStep);
   114 	}
   115 
   116 
   117 //1. make a copy(A) of the supported oids at the start
   118 //2. remove the oids read from the config file(B)
   119 //3. make a copy(C) of the supported oids now
   120 //4. add B to C
   121 //5. iterate over A, for each oid find and remove first occurence only in C.  if not found we error
   122 //6. iterate over B removing each from C
   123 //7. if C is non empty we error	
   124 void CPkixCertRemoveSupportedOidsStep::PerformTestL()
   125 	{
   126 	CPkixCertStepBase::PerformTestL();
   127 	
   128 	//1. make a copy(A) of the supported oids at the start
   129 	
   130 	
   131 	
   132 	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();	
   133 	//CleanupClosePushL(suppOids);	//don't need to do this as a ref and done in stepbase destructor
   134 	RPointerArray<HBufC> startSuppOids;
   135 	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
   136 		
   137 	HBufC* des;
   138 	TInt i;
   139 	for (i=0; i < suppOids.Count(); ++i)
   140 		{
   141 		des = (suppOids[i])->AllocLC();
   142 		startSuppOids.AppendL(des);
   143 		CleanupStack::Pop(des);
   144 		}
   145 
   146 	
   147 	//2. remove the oids read from the config file(B)
   148 	iCertChain->RemoveSupportedCriticalExtensions(iProcessedOids);
   149 	
   150 	//3. make a copy(C) of the supported oids now
   151 	const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
   152 	
   153 	RPointerArray<HBufC> endSuppOids;
   154 	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(endSuppOids);
   155 		
   156 	for (i=0; i < suppOids2.Count(); ++i)
   157 		{
   158 		des = (suppOids2[i])->AllocLC();
   159 		endSuppOids.AppendL(des);
   160 		CleanupStack::Pop(des);
   161 		}
   162 
   163 
   164 	////////////
   165 	//4. add B to C
   166 	for (i=0; i < iProcessedOids.Count(); ++i)
   167 		{
   168 		des = (iProcessedOids[i])->AllocLC();
   169 		endSuppOids.AppendL(des);
   170 		CleanupStack::Pop(des);
   171 		}
   172 		
   173 	
   174 	///////////
   175 	//5. iterate over A, for each oid find and remove first occurence only in C.  if not found we error
   176 	TBool found;
   177 	for (i=0; i < startSuppOids.Count(); ++i)
   178 		{
   179 		found = EFalse;
   180 		for (TInt j=0; j < endSuppOids.Count(); ++j)
   181 			{
   182 			if ((*endSuppOids[j]) == (*startSuppOids[i]))
   183 				{
   184 				found = ETrue;
   185 				delete (endSuppOids[j]);
   186 				endSuppOids.Remove(j);
   187 				break;
   188 				}
   189 			}
   190 		if (!found)
   191 			{
   192 			ERR_PRINTF2(_L("ERROR: Extra OID removed from result: %S"), startSuppOids[i]);
   193 			User::Leave(KErrGeneral);
   194 			}
   195 		}
   196 		
   197 	//6. iterate over B removing each from C
   198 	for (i=0; i < iProcessedOids.Count(); ++i)
   199 		{
   200 		for (TInt j=0; j < endSuppOids.Count(); ++j)
   201 			{
   202 			if ((*endSuppOids[j]) == (*iProcessedOids[i]))
   203 				{
   204 				delete (endSuppOids[j]);
   205 				endSuppOids.Remove(j);
   206 				break;
   207 				}
   208 			}
   209 		}
   210 	
   211 	//7. if C is non empty we error		
   212 	if (endSuppOids.Count() != 0)
   213 		{	
   214 		for (TInt j=0; j < endSuppOids.Count(); ++j)
   215 			{	
   216 			ERR_PRINTF2(_L("ERROR: Extra/duplicate OID found in result: %S"), endSuppOids[j]);
   217 			}
   218 		User::Leave(KErrGeneral);
   219 		}
   220 	
   221 	CleanupStack::PopAndDestroy(3, iCertChain);
   222 	}
   223 
   224 /////////////////////////////////////////////////////////////////////
   225 
   226 CPkixCertSetSupportedOidsStep::CPkixCertSetSupportedOidsStep()
   227 	{
   228 	SetTestStepName(KSetSupportedOidsTestStep);
   229 	}
   230 
   231 
   232 //1. set the supported oids to the ones from the config(A)
   233 //2. make a copy(B) of supported oids
   234 //3. iterate over B, remove every match found in copy(C) taken from A.  if not found in C we error
   235 //4. if C not empty we error
   236 void CPkixCertSetSupportedOidsStep::PerformTestL()
   237 	{
   238 	CPkixCertStepBase::PerformTestL();
   239 	
   240 	//1. set the supported oids to the ones from the config(A)
   241 	iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids);
   242 	
   243 	//2. make a copy(B) of supported oids
   244 	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();
   245 	
   246 	RPointerArray<HBufC> endSuppOids;
   247 	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(endSuppOids);
   248 	
   249 	HBufC* des;
   250 	TInt i;	
   251 	for (i=0; i < suppOids.Count(); ++i)
   252 		{
   253 		des = (suppOids[i])->AllocLC();
   254 		endSuppOids.AppendL(des);
   255 		CleanupStack::Pop(des);
   256 		}
   257 	
   258 	//3. iterate over B, remove every match found in copy(C) taken from A.  if not found in C we error
   259 	
   260 	RPointerArray<TDesC> oidsCopy;
   261 	CleanupClosePushL(oidsCopy);
   262 	
   263 	for (i=0; i < iOids.Count(); ++i)
   264 		{
   265 		oidsCopy.AppendL(&(iOids[i]));
   266 		}
   267 	
   268 	TBool found;
   269 	for (i=0; i < endSuppOids.Count(); ++i)
   270 		{
   271 		found = EFalse;
   272 		for (TInt j=(oidsCopy.Count() - 1); j >= 0; --j)
   273 			{
   274 			if ((*oidsCopy[j]) == (*endSuppOids[i]))
   275 				{
   276 				found = ETrue;
   277 				oidsCopy.Remove(j);
   278 				}
   279 			}
   280 		if (!found)	
   281 			{
   282 			ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), endSuppOids[i]);
   283 			User::Leave(KErrGeneral);
   284 			}
   285 		}
   286 	
   287 	//4. if C not empty we error	
   288 	if (oidsCopy.Count() != 0)
   289 		{
   290 		for (TInt j=0; j < oidsCopy.Count(); ++j)
   291 			{	
   292 			ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), oidsCopy[j]);
   293 			}		
   294 		User::Leave(KErrGeneral);
   295 		}	
   296 	
   297 	CleanupStack::PopAndDestroy(3, iCertChain);
   298 	}
   299 	
   300 	
   301 ////////////////////////////////////////////////
   302 
   303 CPkixCertResetSupportedOidsStep::CPkixCertResetSupportedOidsStep()
   304 	{
   305 	SetTestStepName(KResetSupportedOidsTestStep);
   306 	}
   307 
   308 //1. make a copy(A) of supported oids
   309 //2. set supported oids to list from config
   310 //3. reset supported oids
   311 //4. get supported oids(B)
   312 //5. iterate over B, find and remove first match in A.  if not found we error
   313 //6. if A is not empty we error
   314 void CPkixCertResetSupportedOidsStep::PerformTestL()
   315 	{
   316 	CPkixCertStepBase::PerformTestL();
   317 	
   318 	//1. make a copy(A) of supported oids
   319 	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();	
   320 	//CleanupClosePushL(suppOids);	//don't need to do this as a ref and done in stepbase destructor
   321 	RPointerArray<HBufC> startSuppOids;
   322 	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
   323 		
   324 	HBufC* des;
   325 	TInt i;
   326 	for (i=0; i < suppOids.Count(); ++i)
   327 		{
   328 		des = (suppOids[i])->AllocLC();
   329 		startSuppOids.AppendL(des);
   330 		CleanupStack::Pop(des);
   331 		}
   332 
   333 	//2. set supported oids to list from config
   334 	iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids);
   335 	//3. reset supported oids
   336 	iCertChain->ResetSupportedCriticalExtsToDefaultL();
   337 	//4. get supported oids(B)
   338 	const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
   339 	
   340 	//5. iterate over B, find and remove first match in A.  if not found we error
   341 	TBool found;
   342 	for (i=0; i < suppOids2.Count(); ++i)
   343 		{
   344 		found = EFalse;
   345 		for (TInt j=0; j < startSuppOids.Count(); ++j)
   346 			{
   347 			if ((*suppOids2[i]) == (*startSuppOids[j]))
   348 				{
   349 				found = ETrue;
   350 				delete (startSuppOids[j]);
   351 				startSuppOids.Remove(j);
   352 				break;
   353 				}
   354 			}
   355 		if (!found)	
   356 			{
   357 			ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), suppOids2[i]);
   358 			User::Leave(KErrGeneral);
   359 			}
   360 		}
   361 		
   362 	//6. if A is not empty we error
   363 	if (startSuppOids.Count() != 0)
   364 		{
   365 		for (TInt j=0; j < startSuppOids.Count(); ++j)
   366 			{	
   367 			ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]);
   368 			}
   369 		User::Leave(KErrGeneral);
   370 		}		
   371 	
   372 	CleanupStack::PopAndDestroy(2, iCertChain);	
   373 	}
   374 	
   375