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