os/security/cryptoservices/certificateandkeymgmt/twtlscert/TestChain.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/twtlscert/TestChain.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,202 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-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 +/**
    1.23 + @file
    1.24 +*/
    1.25 +
    1.26 +
    1.27 +#include "TestChain.h"
    1.28 +#include "t_input.h"
    1.29 +
    1.30 +_LIT(KServerStart, "<server>");
    1.31 +_LIT(KRootStart, "<root>");
    1.32 +_LIT(KValueStart, "<value>");
    1.33 +
    1.34 +_LIT(KCertificateStart, "<certificate>");
    1.35 +_LIT(KLabelStart, "<label>");
    1.36 +_LIT(KResultStart, "<oresult>");
    1.37 +
    1.38 +//test chain superclass
    1.39 +CTestChain::CTestChain()
    1.40 +	{
    1.41 +	}
    1.42 +
    1.43 +CTestChain::~CTestChain()
    1.44 +	{
    1.45 +	delete iServerCerts;
    1.46 +	delete iServerLabels;
    1.47 +	delete iRootCerts;
    1.48 +	delete iRootLabels;
    1.49 +	delete iExtraCerts;
    1.50 +	delete iExtraLabels;
    1.51 +	}
    1.52 +
    1.53 +void CTestChain::ConstructL()
    1.54 +	{
    1.55 +	iServerCerts = new(ELeave) CDesCArrayFlat (1);
    1.56 +	iServerLabels = new(ELeave) CDesCArrayFlat (1);
    1.57 +	iRootCerts = new(ELeave) CDesCArrayFlat (1);
    1.58 +	iRootLabels = new(ELeave) CDesCArrayFlat (1);
    1.59 +	iExtraCerts = new(ELeave) CDesCArrayFlat (1);
    1.60 +	iExtraLabels = new(ELeave) CDesCArrayFlat (1);
    1.61 +	}
    1.62 +
    1.63 +//test build class		
    1.64 +CTestChainBuild* CTestChainBuild::NewL()
    1.65 +	{
    1.66 +	CTestChainBuild* self = CTestChainBuild::NewLC();
    1.67 +	CleanupStack::Pop();
    1.68 +	return self;
    1.69 +	}
    1.70 +
    1.71 +CTestChainBuild* CTestChainBuild::NewLC()
    1.72 +	{
    1.73 +	CTestChainBuild* self = new(ELeave) CTestChainBuild;
    1.74 +	CleanupStack::PushL(self);
    1.75 +	self->ConstructL();
    1.76 +	return self;
    1.77 +	}
    1.78 +
    1.79 +CTestChainBuild::~CTestChainBuild()
    1.80 +	{
    1.81 +	delete iCorrectChain;
    1.82 +	}
    1.83 +
    1.84 +//test chain validate class
    1.85 +CTestChainValidate* CTestChainValidate::NewL(void)
    1.86 +	{
    1.87 +	CTestChainValidate* self = CTestChainValidate::NewLC();
    1.88 +	CleanupStack::Pop();
    1.89 +	return self;
    1.90 +	}
    1.91 +
    1.92 +CTestChainValidate* CTestChainValidate::NewLC(void)
    1.93 +	{
    1.94 +	CTestChainValidate* self = new(ELeave) CTestChainValidate;
    1.95 +	CleanupStack::PushL(self);
    1.96 +	self->ConstructL();
    1.97 +	return self;
    1.98 +	}
    1.99 +
   1.100 +void CTestChainValidate::ConstructL(void)
   1.101 +	{
   1.102 +	CTestChain::ConstructL();
   1.103 +	iWarnings = new(ELeave)CArrayFixFlat<TWTLSValidationStatus> (1);
   1.104 +	iDateIssued = 0;
   1.105 +	}
   1.106 +
   1.107 +void CTestChainValidate::AddChainL(const TDesC& aValues)
   1.108 +	{
   1.109 +	AddServerL(aValues);
   1.110 +	AddRootL(aValues);
   1.111 +	}
   1.112 +
   1.113 +void CTestChainValidate::AddDateIssued(const TDesC& aValues)
   1.114 +	{
   1.115 +	TPtrC iResultBuf = Input::ParseElement(aValues, KValueStart);
   1.116 +	if((iResultBuf == _L("true")) || (iResultBuf == _L("1")))
   1.117 +		iDateIssued = ETrue;
   1.118 +	}
   1.119 +void CTestChainValidate::AddIOL(const TDesC& aValues)
   1.120 +	{
   1.121 +	TPtrC iResultBuf = Input::ParseElement(aValues, KResultStart);
   1.122 +	if (iResultBuf != KNullDesC)
   1.123 +		{
   1.124 +		TValidationError expectedError;
   1.125 +
   1.126 +		if(iResultBuf == _L("ValidatedOK"))
   1.127 +			expectedError = EValidatedOK;
   1.128 +		else if(iResultBuf == _L("SignatureInvalid"))
   1.129 +			expectedError = ESignatureInvalid;
   1.130 +		else if(iResultBuf == _L("ChainHasNoRoot"))
   1.131 +			expectedError = EChainHasNoRoot;
   1.132 +		else if(iResultBuf == _L("NamesDontChain"))
   1.133 +			expectedError = ENamesDontChain;
   1.134 +		else if(iResultBuf == _L("NotCACert"))
   1.135 +			expectedError = ENotCACert;
   1.136 +		else 
   1.137 +			return;
   1.138 +
   1.139 +		iError = new(ELeave) TWTLSValidationStatus(expectedError, 0);
   1.140 +		}
   1.141 +	}
   1.142 +
   1.143 +CTestChainValidate::~CTestChainValidate()
   1.144 +	{
   1.145 +	delete iError;
   1.146 +	delete iWarnings;
   1.147 +	};
   1.148 +
   1.149 +TBool CTestChainValidate::AddServerL(const TDesC& aBuf)
   1.150 +	{
   1.151 +	TInt nPos, n;
   1.152 +	TPtrC ioSection(aBuf);
   1.153 +	TPtrC ioBuf;
   1.154 +	if (ioSection != KNullDesC)
   1.155 +		{
   1.156 +		do
   1.157 +			{
   1.158 +			nPos = 0;
   1.159 +			ioBuf.Set(Input::ParseElement(ioSection, KServerStart, nPos));
   1.160 +			if(nPos > 0)
   1.161 +				{
   1.162 +				ioSection.Set(ioSection.Mid(nPos));
   1.163 +				n=0;
   1.164 +				TPtrC iCertBuf = Input::ParseElement(ioBuf, KCertificateStart, n);
   1.165 +				iServerCerts->AppendL(iCertBuf);
   1.166 +				TPtrC iLabelBuf = Input::ParseElement(ioBuf, KLabelStart, n);
   1.167 +				iServerLabels->AppendL(iLabelBuf);
   1.168 +				};
   1.169 +			
   1.170 +			}
   1.171 +		while(nPos > 0);
   1.172 +		return ETrue;
   1.173 +		}
   1.174 +	return EFalse;
   1.175 +	}
   1.176 +
   1.177 +TBool CTestChainValidate::AddRootL(const TDesC& aBuf)
   1.178 +	{
   1.179 +	TInt nPos, n;
   1.180 +	TPtrC ioSection(aBuf);
   1.181 +	TPtrC ioBuf;
   1.182 +	if (ioSection != KNullDesC)
   1.183 +		{
   1.184 +		do
   1.185 +			{
   1.186 +			nPos = 0;
   1.187 +			ioBuf.Set(Input::ParseElement(ioSection, KRootStart, nPos));
   1.188 +			if(nPos > 0)
   1.189 +				{
   1.190 +				ioSection.Set(ioSection.Mid(nPos));
   1.191 +				n=0;
   1.192 +				TPtrC iCertBuf = Input::ParseElement(ioBuf, KCertificateStart, n);
   1.193 +				iRootCerts->AppendL(iCertBuf);
   1.194 +				TPtrC iLabelBuf = Input::ParseElement(ioBuf, KLabelStart, n);
   1.195 +				iRootLabels->AppendL(iLabelBuf);
   1.196 +				};
   1.197 +			
   1.198 +			}
   1.199 +		while(nPos > 0);
   1.200 +		return ETrue;
   1.201 +		}
   1.202 +	return EFalse;
   1.203 +	}
   1.204 +
   1.205 +