os/security/cryptoservices/certificateandkeymgmt/tpkixcert_tef/src/apiteststeps.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tpkixcert_tef/src/apiteststeps.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,375 @@
     1.4 +/*
     1.5 +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "apiteststeps.h"
    1.23 +#include "cleanuputils.h"
    1.24 +
    1.25 +	
    1.26 +CPkixCertAddSupportedOidsStep::CPkixCertAddSupportedOidsStep()
    1.27 +	{
    1.28 +	SetTestStepName(KAddSupportedOidsTestStep);
    1.29 +	}
    1.30 +
    1.31 +//1. make a copy(A) of the supported oids at the start
    1.32 +//2. add in the oids from the config file(B), make a copy of these and add to A
    1.33 +//3. get the supported oids now(C)
    1.34 +//4. iterate over C, for each oid find copies in A and remove them.  if it is not found we error
    1.35 +//5. if A is non empty we error
    1.36 +void CPkixCertAddSupportedOidsStep::PerformTestL()
    1.37 +	{
    1.38 +	CPkixCertStepBase::PerformTestL();
    1.39 +	
    1.40 +	//1. make a copy(A) of the supported oids at the start
    1.41 +	
    1.42 +	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();	
    1.43 +	//CleanupClosePushL(suppOids);	//don't need to do this as a ref and done in stepbase destructor
    1.44 +	RPointerArray<HBufC> startSuppOids;
    1.45 +	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
    1.46 +		
    1.47 +	HBufC* des;
    1.48 +	TInt i;
    1.49 +	for (i=0; i < suppOids.Count(); ++i)
    1.50 +		{
    1.51 +		des = (suppOids[i])->AllocLC();
    1.52 +		startSuppOids.AppendL(des);
    1.53 +		CleanupStack::Pop(des);
    1.54 +		}
    1.55 +	
    1.56 +	
    1.57 +	
    1.58 +	//2. add in the oids from the config file(B)
    1.59 +	iCertChain->AddSupportedCriticalExtensionsL(iProcessedOids);
    1.60 +	
    1.61 +	//make a copy of these and add to A
    1.62 +	for (i=0; i < iProcessedOids.Count(); ++i)
    1.63 +		{
    1.64 +		des = (iProcessedOids[i])->AllocLC();
    1.65 +		startSuppOids.AppendL(des);
    1.66 +		CleanupStack::Pop(des);
    1.67 +		}
    1.68 +	
    1.69 +	//3. get the supported oids now(C)
    1.70 +	const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
    1.71 +	
    1.72 +	
    1.73 +	//4. iterate over C, for each oid find copies in A and remove them.  if it is not found we error
    1.74 +	TBool found;
    1.75 +	for (i=0; i < suppOids2.Count(); ++i)
    1.76 +		{
    1.77 +		found = EFalse;
    1.78 +		for (TInt j=0; j < startSuppOids.Count(); ++j)
    1.79 +			{
    1.80 +			if ((*startSuppOids[j]) == (*suppOids2[i]))
    1.81 +				{
    1.82 +				found = ETrue;
    1.83 +				delete (startSuppOids[j]);
    1.84 +				startSuppOids.Remove(j);
    1.85 +				--j;
    1.86 +				}
    1.87 +			}	//startSuppOids loop
    1.88 +		if (!found)	
    1.89 +			{
    1.90 +			ERR_PRINTF2(_L("Extra ERROR: OID in result: %S"), suppOids2[i]);
    1.91 +			User::Leave(KErrGeneral);
    1.92 +			}			
    1.93 +		}	//suppOids2 loop
    1.94 +	
    1.95 +	
    1.96 +	//5. if A is non empty we error
    1.97 +	if (startSuppOids.Count() != 0)
    1.98 +		{
    1.99 +		for (TInt j=0; j < startSuppOids.Count(); ++j)
   1.100 +			{	
   1.101 +			ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]);
   1.102 +			}
   1.103 +		User::Leave(KErrGeneral);
   1.104 +		}
   1.105 +	
   1.106 +	CleanupStack::PopAndDestroy(2, iCertChain);
   1.107 +	}
   1.108 +
   1.109 +
   1.110 +///////////////////////////////////////////////////////////////////
   1.111 +
   1.112 +
   1.113 +
   1.114 +CPkixCertRemoveSupportedOidsStep::CPkixCertRemoveSupportedOidsStep()
   1.115 +	{
   1.116 +	SetTestStepName(KRemoveSupportedOidsTestStep);
   1.117 +	}
   1.118 +
   1.119 +
   1.120 +//1. make a copy(A) of the supported oids at the start
   1.121 +//2. remove the oids read from the config file(B)
   1.122 +//3. make a copy(C) of the supported oids now
   1.123 +//4. add B to C
   1.124 +//5. iterate over A, for each oid find and remove first occurence only in C.  if not found we error
   1.125 +//6. iterate over B removing each from C
   1.126 +//7. if C is non empty we error	
   1.127 +void CPkixCertRemoveSupportedOidsStep::PerformTestL()
   1.128 +	{
   1.129 +	CPkixCertStepBase::PerformTestL();
   1.130 +	
   1.131 +	//1. make a copy(A) of the supported oids at the start
   1.132 +	
   1.133 +	
   1.134 +	
   1.135 +	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();	
   1.136 +	//CleanupClosePushL(suppOids);	//don't need to do this as a ref and done in stepbase destructor
   1.137 +	RPointerArray<HBufC> startSuppOids;
   1.138 +	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
   1.139 +		
   1.140 +	HBufC* des;
   1.141 +	TInt i;
   1.142 +	for (i=0; i < suppOids.Count(); ++i)
   1.143 +		{
   1.144 +		des = (suppOids[i])->AllocLC();
   1.145 +		startSuppOids.AppendL(des);
   1.146 +		CleanupStack::Pop(des);
   1.147 +		}
   1.148 +
   1.149 +	
   1.150 +	//2. remove the oids read from the config file(B)
   1.151 +	iCertChain->RemoveSupportedCriticalExtensions(iProcessedOids);
   1.152 +	
   1.153 +	//3. make a copy(C) of the supported oids now
   1.154 +	const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
   1.155 +	
   1.156 +	RPointerArray<HBufC> endSuppOids;
   1.157 +	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(endSuppOids);
   1.158 +		
   1.159 +	for (i=0; i < suppOids2.Count(); ++i)
   1.160 +		{
   1.161 +		des = (suppOids2[i])->AllocLC();
   1.162 +		endSuppOids.AppendL(des);
   1.163 +		CleanupStack::Pop(des);
   1.164 +		}
   1.165 +
   1.166 +
   1.167 +	////////////
   1.168 +	//4. add B to C
   1.169 +	for (i=0; i < iProcessedOids.Count(); ++i)
   1.170 +		{
   1.171 +		des = (iProcessedOids[i])->AllocLC();
   1.172 +		endSuppOids.AppendL(des);
   1.173 +		CleanupStack::Pop(des);
   1.174 +		}
   1.175 +		
   1.176 +	
   1.177 +	///////////
   1.178 +	//5. iterate over A, for each oid find and remove first occurence only in C.  if not found we error
   1.179 +	TBool found;
   1.180 +	for (i=0; i < startSuppOids.Count(); ++i)
   1.181 +		{
   1.182 +		found = EFalse;
   1.183 +		for (TInt j=0; j < endSuppOids.Count(); ++j)
   1.184 +			{
   1.185 +			if ((*endSuppOids[j]) == (*startSuppOids[i]))
   1.186 +				{
   1.187 +				found = ETrue;
   1.188 +				delete (endSuppOids[j]);
   1.189 +				endSuppOids.Remove(j);
   1.190 +				break;
   1.191 +				}
   1.192 +			}
   1.193 +		if (!found)
   1.194 +			{
   1.195 +			ERR_PRINTF2(_L("ERROR: Extra OID removed from result: %S"), startSuppOids[i]);
   1.196 +			User::Leave(KErrGeneral);
   1.197 +			}
   1.198 +		}
   1.199 +		
   1.200 +	//6. iterate over B removing each from C
   1.201 +	for (i=0; i < iProcessedOids.Count(); ++i)
   1.202 +		{
   1.203 +		for (TInt j=0; j < endSuppOids.Count(); ++j)
   1.204 +			{
   1.205 +			if ((*endSuppOids[j]) == (*iProcessedOids[i]))
   1.206 +				{
   1.207 +				delete (endSuppOids[j]);
   1.208 +				endSuppOids.Remove(j);
   1.209 +				break;
   1.210 +				}
   1.211 +			}
   1.212 +		}
   1.213 +	
   1.214 +	//7. if C is non empty we error		
   1.215 +	if (endSuppOids.Count() != 0)
   1.216 +		{	
   1.217 +		for (TInt j=0; j < endSuppOids.Count(); ++j)
   1.218 +			{	
   1.219 +			ERR_PRINTF2(_L("ERROR: Extra/duplicate OID found in result: %S"), endSuppOids[j]);
   1.220 +			}
   1.221 +		User::Leave(KErrGeneral);
   1.222 +		}
   1.223 +	
   1.224 +	CleanupStack::PopAndDestroy(3, iCertChain);
   1.225 +	}
   1.226 +
   1.227 +/////////////////////////////////////////////////////////////////////
   1.228 +
   1.229 +CPkixCertSetSupportedOidsStep::CPkixCertSetSupportedOidsStep()
   1.230 +	{
   1.231 +	SetTestStepName(KSetSupportedOidsTestStep);
   1.232 +	}
   1.233 +
   1.234 +
   1.235 +//1. set the supported oids to the ones from the config(A)
   1.236 +//2. make a copy(B) of supported oids
   1.237 +//3. iterate over B, remove every match found in copy(C) taken from A.  if not found in C we error
   1.238 +//4. if C not empty we error
   1.239 +void CPkixCertSetSupportedOidsStep::PerformTestL()
   1.240 +	{
   1.241 +	CPkixCertStepBase::PerformTestL();
   1.242 +	
   1.243 +	//1. set the supported oids to the ones from the config(A)
   1.244 +	iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids);
   1.245 +	
   1.246 +	//2. make a copy(B) of supported oids
   1.247 +	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();
   1.248 +	
   1.249 +	RPointerArray<HBufC> endSuppOids;
   1.250 +	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(endSuppOids);
   1.251 +	
   1.252 +	HBufC* des;
   1.253 +	TInt i;	
   1.254 +	for (i=0; i < suppOids.Count(); ++i)
   1.255 +		{
   1.256 +		des = (suppOids[i])->AllocLC();
   1.257 +		endSuppOids.AppendL(des);
   1.258 +		CleanupStack::Pop(des);
   1.259 +		}
   1.260 +	
   1.261 +	//3. iterate over B, remove every match found in copy(C) taken from A.  if not found in C we error
   1.262 +	
   1.263 +	RPointerArray<TDesC> oidsCopy;
   1.264 +	CleanupClosePushL(oidsCopy);
   1.265 +	
   1.266 +	for (i=0; i < iOids.Count(); ++i)
   1.267 +		{
   1.268 +		oidsCopy.AppendL(&(iOids[i]));
   1.269 +		}
   1.270 +	
   1.271 +	TBool found;
   1.272 +	for (i=0; i < endSuppOids.Count(); ++i)
   1.273 +		{
   1.274 +		found = EFalse;
   1.275 +		for (TInt j=(oidsCopy.Count() - 1); j >= 0; --j)
   1.276 +			{
   1.277 +			if ((*oidsCopy[j]) == (*endSuppOids[i]))
   1.278 +				{
   1.279 +				found = ETrue;
   1.280 +				oidsCopy.Remove(j);
   1.281 +				}
   1.282 +			}
   1.283 +		if (!found)	
   1.284 +			{
   1.285 +			ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), endSuppOids[i]);
   1.286 +			User::Leave(KErrGeneral);
   1.287 +			}
   1.288 +		}
   1.289 +	
   1.290 +	//4. if C not empty we error	
   1.291 +	if (oidsCopy.Count() != 0)
   1.292 +		{
   1.293 +		for (TInt j=0; j < oidsCopy.Count(); ++j)
   1.294 +			{	
   1.295 +			ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), oidsCopy[j]);
   1.296 +			}		
   1.297 +		User::Leave(KErrGeneral);
   1.298 +		}	
   1.299 +	
   1.300 +	CleanupStack::PopAndDestroy(3, iCertChain);
   1.301 +	}
   1.302 +	
   1.303 +	
   1.304 +////////////////////////////////////////////////
   1.305 +
   1.306 +CPkixCertResetSupportedOidsStep::CPkixCertResetSupportedOidsStep()
   1.307 +	{
   1.308 +	SetTestStepName(KResetSupportedOidsTestStep);
   1.309 +	}
   1.310 +
   1.311 +//1. make a copy(A) of supported oids
   1.312 +//2. set supported oids to list from config
   1.313 +//3. reset supported oids
   1.314 +//4. get supported oids(B)
   1.315 +//5. iterate over B, find and remove first match in A.  if not found we error
   1.316 +//6. if A is not empty we error
   1.317 +void CPkixCertResetSupportedOidsStep::PerformTestL()
   1.318 +	{
   1.319 +	CPkixCertStepBase::PerformTestL();
   1.320 +	
   1.321 +	//1. make a copy(A) of supported oids
   1.322 +	const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();	
   1.323 +	//CleanupClosePushL(suppOids);	//don't need to do this as a ref and done in stepbase destructor
   1.324 +	RPointerArray<HBufC> startSuppOids;
   1.325 +	CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
   1.326 +		
   1.327 +	HBufC* des;
   1.328 +	TInt i;
   1.329 +	for (i=0; i < suppOids.Count(); ++i)
   1.330 +		{
   1.331 +		des = (suppOids[i])->AllocLC();
   1.332 +		startSuppOids.AppendL(des);
   1.333 +		CleanupStack::Pop(des);
   1.334 +		}
   1.335 +
   1.336 +	//2. set supported oids to list from config
   1.337 +	iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids);
   1.338 +	//3. reset supported oids
   1.339 +	iCertChain->ResetSupportedCriticalExtsToDefaultL();
   1.340 +	//4. get supported oids(B)
   1.341 +	const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
   1.342 +	
   1.343 +	//5. iterate over B, find and remove first match in A.  if not found we error
   1.344 +	TBool found;
   1.345 +	for (i=0; i < suppOids2.Count(); ++i)
   1.346 +		{
   1.347 +		found = EFalse;
   1.348 +		for (TInt j=0; j < startSuppOids.Count(); ++j)
   1.349 +			{
   1.350 +			if ((*suppOids2[i]) == (*startSuppOids[j]))
   1.351 +				{
   1.352 +				found = ETrue;
   1.353 +				delete (startSuppOids[j]);
   1.354 +				startSuppOids.Remove(j);
   1.355 +				break;
   1.356 +				}
   1.357 +			}
   1.358 +		if (!found)	
   1.359 +			{
   1.360 +			ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), suppOids2[i]);
   1.361 +			User::Leave(KErrGeneral);
   1.362 +			}
   1.363 +		}
   1.364 +		
   1.365 +	//6. if A is not empty we error
   1.366 +	if (startSuppOids.Count() != 0)
   1.367 +		{
   1.368 +		for (TInt j=0; j < startSuppOids.Count(); ++j)
   1.369 +			{	
   1.370 +			ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]);
   1.371 +			}
   1.372 +		User::Leave(KErrGeneral);
   1.373 +		}		
   1.374 +	
   1.375 +	CleanupStack::PopAndDestroy(2, iCertChain);	
   1.376 +	}
   1.377 +	
   1.378 +