sl@0: /* sl@0: * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "apiteststeps.h" sl@0: #include "cleanuputils.h" sl@0: sl@0: sl@0: CPkixCertAddSupportedOidsStep::CPkixCertAddSupportedOidsStep() sl@0: { sl@0: SetTestStepName(KAddSupportedOidsTestStep); sl@0: } sl@0: sl@0: //1. make a copy(A) of the supported oids at the start sl@0: //2. add in the oids from the config file(B), make a copy of these and add to A sl@0: //3. get the supported oids now(C) sl@0: //4. iterate over C, for each oid find copies in A and remove them. if it is not found we error sl@0: //5. if A is non empty we error sl@0: void CPkixCertAddSupportedOidsStep::PerformTestL() sl@0: { sl@0: CPkixCertStepBase::PerformTestL(); sl@0: sl@0: //1. make a copy(A) of the supported oids at the start sl@0: sl@0: const RPointerArray& suppOids = iCertChain->SupportedCriticalExtensions(); sl@0: //CleanupClosePushL(suppOids); //don't need to do this as a ref and done in stepbase destructor sl@0: RPointerArray startSuppOids; sl@0: CleanupResetAndDestroy >::PushL(startSuppOids); sl@0: sl@0: HBufC* des; sl@0: TInt i; sl@0: for (i=0; i < suppOids.Count(); ++i) sl@0: { sl@0: des = (suppOids[i])->AllocLC(); sl@0: startSuppOids.AppendL(des); sl@0: CleanupStack::Pop(des); sl@0: } sl@0: sl@0: sl@0: sl@0: //2. add in the oids from the config file(B) sl@0: iCertChain->AddSupportedCriticalExtensionsL(iProcessedOids); sl@0: sl@0: //make a copy of these and add to A sl@0: for (i=0; i < iProcessedOids.Count(); ++i) sl@0: { sl@0: des = (iProcessedOids[i])->AllocLC(); sl@0: startSuppOids.AppendL(des); sl@0: CleanupStack::Pop(des); sl@0: } sl@0: sl@0: //3. get the supported oids now(C) sl@0: const RPointerArray& suppOids2 = iCertChain->SupportedCriticalExtensions(); sl@0: sl@0: sl@0: //4. iterate over C, for each oid find copies in A and remove them. if it is not found we error sl@0: TBool found; sl@0: for (i=0; i < suppOids2.Count(); ++i) sl@0: { sl@0: found = EFalse; sl@0: for (TInt j=0; j < startSuppOids.Count(); ++j) sl@0: { sl@0: if ((*startSuppOids[j]) == (*suppOids2[i])) sl@0: { sl@0: found = ETrue; sl@0: delete (startSuppOids[j]); sl@0: startSuppOids.Remove(j); sl@0: --j; sl@0: } sl@0: } //startSuppOids loop sl@0: if (!found) sl@0: { sl@0: ERR_PRINTF2(_L("Extra ERROR: OID in result: %S"), suppOids2[i]); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: } //suppOids2 loop sl@0: sl@0: sl@0: //5. if A is non empty we error sl@0: if (startSuppOids.Count() != 0) sl@0: { sl@0: for (TInt j=0; j < startSuppOids.Count(); ++j) sl@0: { sl@0: ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]); sl@0: } sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, iCertChain); sl@0: } sl@0: sl@0: sl@0: /////////////////////////////////////////////////////////////////// sl@0: sl@0: sl@0: sl@0: CPkixCertRemoveSupportedOidsStep::CPkixCertRemoveSupportedOidsStep() sl@0: { sl@0: SetTestStepName(KRemoveSupportedOidsTestStep); sl@0: } sl@0: sl@0: sl@0: //1. make a copy(A) of the supported oids at the start sl@0: //2. remove the oids read from the config file(B) sl@0: //3. make a copy(C) of the supported oids now sl@0: //4. add B to C sl@0: //5. iterate over A, for each oid find and remove first occurence only in C. if not found we error sl@0: //6. iterate over B removing each from C sl@0: //7. if C is non empty we error sl@0: void CPkixCertRemoveSupportedOidsStep::PerformTestL() sl@0: { sl@0: CPkixCertStepBase::PerformTestL(); sl@0: sl@0: //1. make a copy(A) of the supported oids at the start sl@0: sl@0: sl@0: sl@0: const RPointerArray& suppOids = iCertChain->SupportedCriticalExtensions(); sl@0: //CleanupClosePushL(suppOids); //don't need to do this as a ref and done in stepbase destructor sl@0: RPointerArray startSuppOids; sl@0: CleanupResetAndDestroy >::PushL(startSuppOids); sl@0: sl@0: HBufC* des; sl@0: TInt i; sl@0: for (i=0; i < suppOids.Count(); ++i) sl@0: { sl@0: des = (suppOids[i])->AllocLC(); sl@0: startSuppOids.AppendL(des); sl@0: CleanupStack::Pop(des); sl@0: } sl@0: sl@0: sl@0: //2. remove the oids read from the config file(B) sl@0: iCertChain->RemoveSupportedCriticalExtensions(iProcessedOids); sl@0: sl@0: //3. make a copy(C) of the supported oids now sl@0: const RPointerArray& suppOids2 = iCertChain->SupportedCriticalExtensions(); sl@0: sl@0: RPointerArray endSuppOids; sl@0: CleanupResetAndDestroy >::PushL(endSuppOids); sl@0: sl@0: for (i=0; i < suppOids2.Count(); ++i) sl@0: { sl@0: des = (suppOids2[i])->AllocLC(); sl@0: endSuppOids.AppendL(des); sl@0: CleanupStack::Pop(des); sl@0: } sl@0: sl@0: sl@0: //////////// sl@0: //4. add B to C sl@0: for (i=0; i < iProcessedOids.Count(); ++i) sl@0: { sl@0: des = (iProcessedOids[i])->AllocLC(); sl@0: endSuppOids.AppendL(des); sl@0: CleanupStack::Pop(des); sl@0: } sl@0: sl@0: sl@0: /////////// sl@0: //5. iterate over A, for each oid find and remove first occurence only in C. if not found we error sl@0: TBool found; sl@0: for (i=0; i < startSuppOids.Count(); ++i) sl@0: { sl@0: found = EFalse; sl@0: for (TInt j=0; j < endSuppOids.Count(); ++j) sl@0: { sl@0: if ((*endSuppOids[j]) == (*startSuppOids[i])) sl@0: { sl@0: found = ETrue; sl@0: delete (endSuppOids[j]); sl@0: endSuppOids.Remove(j); sl@0: break; sl@0: } sl@0: } sl@0: if (!found) sl@0: { sl@0: ERR_PRINTF2(_L("ERROR: Extra OID removed from result: %S"), startSuppOids[i]); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: } sl@0: sl@0: //6. iterate over B removing each from C sl@0: for (i=0; i < iProcessedOids.Count(); ++i) sl@0: { sl@0: for (TInt j=0; j < endSuppOids.Count(); ++j) sl@0: { sl@0: if ((*endSuppOids[j]) == (*iProcessedOids[i])) sl@0: { sl@0: delete (endSuppOids[j]); sl@0: endSuppOids.Remove(j); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: //7. if C is non empty we error sl@0: if (endSuppOids.Count() != 0) sl@0: { sl@0: for (TInt j=0; j < endSuppOids.Count(); ++j) sl@0: { sl@0: ERR_PRINTF2(_L("ERROR: Extra/duplicate OID found in result: %S"), endSuppOids[j]); sl@0: } sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, iCertChain); sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////////// sl@0: sl@0: CPkixCertSetSupportedOidsStep::CPkixCertSetSupportedOidsStep() sl@0: { sl@0: SetTestStepName(KSetSupportedOidsTestStep); sl@0: } sl@0: sl@0: sl@0: //1. set the supported oids to the ones from the config(A) sl@0: //2. make a copy(B) of supported oids sl@0: //3. iterate over B, remove every match found in copy(C) taken from A. if not found in C we error sl@0: //4. if C not empty we error sl@0: void CPkixCertSetSupportedOidsStep::PerformTestL() sl@0: { sl@0: CPkixCertStepBase::PerformTestL(); sl@0: sl@0: //1. set the supported oids to the ones from the config(A) sl@0: iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids); sl@0: sl@0: //2. make a copy(B) of supported oids sl@0: const RPointerArray& suppOids = iCertChain->SupportedCriticalExtensions(); sl@0: sl@0: RPointerArray endSuppOids; sl@0: CleanupResetAndDestroy >::PushL(endSuppOids); sl@0: sl@0: HBufC* des; sl@0: TInt i; sl@0: for (i=0; i < suppOids.Count(); ++i) sl@0: { sl@0: des = (suppOids[i])->AllocLC(); sl@0: endSuppOids.AppendL(des); sl@0: CleanupStack::Pop(des); sl@0: } sl@0: sl@0: //3. iterate over B, remove every match found in copy(C) taken from A. if not found in C we error sl@0: sl@0: RPointerArray oidsCopy; sl@0: CleanupClosePushL(oidsCopy); sl@0: sl@0: for (i=0; i < iOids.Count(); ++i) sl@0: { sl@0: oidsCopy.AppendL(&(iOids[i])); sl@0: } sl@0: sl@0: TBool found; sl@0: for (i=0; i < endSuppOids.Count(); ++i) sl@0: { sl@0: found = EFalse; sl@0: for (TInt j=(oidsCopy.Count() - 1); j >= 0; --j) sl@0: { sl@0: if ((*oidsCopy[j]) == (*endSuppOids[i])) sl@0: { sl@0: found = ETrue; sl@0: oidsCopy.Remove(j); sl@0: } sl@0: } sl@0: if (!found) sl@0: { sl@0: ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), endSuppOids[i]); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: } sl@0: sl@0: //4. if C not empty we error sl@0: if (oidsCopy.Count() != 0) sl@0: { sl@0: for (TInt j=0; j < oidsCopy.Count(); ++j) sl@0: { sl@0: ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), oidsCopy[j]); sl@0: } sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, iCertChain); sl@0: } sl@0: sl@0: sl@0: //////////////////////////////////////////////// sl@0: sl@0: CPkixCertResetSupportedOidsStep::CPkixCertResetSupportedOidsStep() sl@0: { sl@0: SetTestStepName(KResetSupportedOidsTestStep); sl@0: } sl@0: sl@0: //1. make a copy(A) of supported oids sl@0: //2. set supported oids to list from config sl@0: //3. reset supported oids sl@0: //4. get supported oids(B) sl@0: //5. iterate over B, find and remove first match in A. if not found we error sl@0: //6. if A is not empty we error sl@0: void CPkixCertResetSupportedOidsStep::PerformTestL() sl@0: { sl@0: CPkixCertStepBase::PerformTestL(); sl@0: sl@0: //1. make a copy(A) of supported oids sl@0: const RPointerArray& suppOids = iCertChain->SupportedCriticalExtensions(); sl@0: //CleanupClosePushL(suppOids); //don't need to do this as a ref and done in stepbase destructor sl@0: RPointerArray startSuppOids; sl@0: CleanupResetAndDestroy >::PushL(startSuppOids); sl@0: sl@0: HBufC* des; sl@0: TInt i; sl@0: for (i=0; i < suppOids.Count(); ++i) sl@0: { sl@0: des = (suppOids[i])->AllocLC(); sl@0: startSuppOids.AppendL(des); sl@0: CleanupStack::Pop(des); sl@0: } sl@0: sl@0: //2. set supported oids to list from config sl@0: iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids); sl@0: //3. reset supported oids sl@0: iCertChain->ResetSupportedCriticalExtsToDefaultL(); sl@0: //4. get supported oids(B) sl@0: const RPointerArray& suppOids2 = iCertChain->SupportedCriticalExtensions(); sl@0: sl@0: //5. iterate over B, find and remove first match in A. if not found we error sl@0: TBool found; sl@0: for (i=0; i < suppOids2.Count(); ++i) sl@0: { sl@0: found = EFalse; sl@0: for (TInt j=0; j < startSuppOids.Count(); ++j) sl@0: { sl@0: if ((*suppOids2[i]) == (*startSuppOids[j])) sl@0: { sl@0: found = ETrue; sl@0: delete (startSuppOids[j]); sl@0: startSuppOids.Remove(j); sl@0: break; sl@0: } sl@0: } sl@0: if (!found) sl@0: { sl@0: ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), suppOids2[i]); sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: } sl@0: sl@0: //6. if A is not empty we error sl@0: if (startSuppOids.Count() != 0) sl@0: { sl@0: for (TInt j=0; j < startSuppOids.Count(); ++j) sl@0: { sl@0: ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]); sl@0: } sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, iCertChain); sl@0: } sl@0: sl@0: