os/security/cryptoservices/certificateandkeymgmt/twtlscert/TestChain.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) 2005-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 /**
    20  @file
    21 */
    22 
    23 
    24 #include "TestChain.h"
    25 #include "t_input.h"
    26 
    27 _LIT(KServerStart, "<server>");
    28 _LIT(KRootStart, "<root>");
    29 _LIT(KValueStart, "<value>");
    30 
    31 _LIT(KCertificateStart, "<certificate>");
    32 _LIT(KLabelStart, "<label>");
    33 _LIT(KResultStart, "<oresult>");
    34 
    35 //test chain superclass
    36 CTestChain::CTestChain()
    37 	{
    38 	}
    39 
    40 CTestChain::~CTestChain()
    41 	{
    42 	delete iServerCerts;
    43 	delete iServerLabels;
    44 	delete iRootCerts;
    45 	delete iRootLabels;
    46 	delete iExtraCerts;
    47 	delete iExtraLabels;
    48 	}
    49 
    50 void CTestChain::ConstructL()
    51 	{
    52 	iServerCerts = new(ELeave) CDesCArrayFlat (1);
    53 	iServerLabels = new(ELeave) CDesCArrayFlat (1);
    54 	iRootCerts = new(ELeave) CDesCArrayFlat (1);
    55 	iRootLabels = new(ELeave) CDesCArrayFlat (1);
    56 	iExtraCerts = new(ELeave) CDesCArrayFlat (1);
    57 	iExtraLabels = new(ELeave) CDesCArrayFlat (1);
    58 	}
    59 
    60 //test build class		
    61 CTestChainBuild* CTestChainBuild::NewL()
    62 	{
    63 	CTestChainBuild* self = CTestChainBuild::NewLC();
    64 	CleanupStack::Pop();
    65 	return self;
    66 	}
    67 
    68 CTestChainBuild* CTestChainBuild::NewLC()
    69 	{
    70 	CTestChainBuild* self = new(ELeave) CTestChainBuild;
    71 	CleanupStack::PushL(self);
    72 	self->ConstructL();
    73 	return self;
    74 	}
    75 
    76 CTestChainBuild::~CTestChainBuild()
    77 	{
    78 	delete iCorrectChain;
    79 	}
    80 
    81 //test chain validate class
    82 CTestChainValidate* CTestChainValidate::NewL(void)
    83 	{
    84 	CTestChainValidate* self = CTestChainValidate::NewLC();
    85 	CleanupStack::Pop();
    86 	return self;
    87 	}
    88 
    89 CTestChainValidate* CTestChainValidate::NewLC(void)
    90 	{
    91 	CTestChainValidate* self = new(ELeave) CTestChainValidate;
    92 	CleanupStack::PushL(self);
    93 	self->ConstructL();
    94 	return self;
    95 	}
    96 
    97 void CTestChainValidate::ConstructL(void)
    98 	{
    99 	CTestChain::ConstructL();
   100 	iWarnings = new(ELeave)CArrayFixFlat<TWTLSValidationStatus> (1);
   101 	iDateIssued = 0;
   102 	}
   103 
   104 void CTestChainValidate::AddChainL(const TDesC& aValues)
   105 	{
   106 	AddServerL(aValues);
   107 	AddRootL(aValues);
   108 	}
   109 
   110 void CTestChainValidate::AddDateIssued(const TDesC& aValues)
   111 	{
   112 	TPtrC iResultBuf = Input::ParseElement(aValues, KValueStart);
   113 	if((iResultBuf == _L("true")) || (iResultBuf == _L("1")))
   114 		iDateIssued = ETrue;
   115 	}
   116 void CTestChainValidate::AddIOL(const TDesC& aValues)
   117 	{
   118 	TPtrC iResultBuf = Input::ParseElement(aValues, KResultStart);
   119 	if (iResultBuf != KNullDesC)
   120 		{
   121 		TValidationError expectedError;
   122 
   123 		if(iResultBuf == _L("ValidatedOK"))
   124 			expectedError = EValidatedOK;
   125 		else if(iResultBuf == _L("SignatureInvalid"))
   126 			expectedError = ESignatureInvalid;
   127 		else if(iResultBuf == _L("ChainHasNoRoot"))
   128 			expectedError = EChainHasNoRoot;
   129 		else if(iResultBuf == _L("NamesDontChain"))
   130 			expectedError = ENamesDontChain;
   131 		else if(iResultBuf == _L("NotCACert"))
   132 			expectedError = ENotCACert;
   133 		else 
   134 			return;
   135 
   136 		iError = new(ELeave) TWTLSValidationStatus(expectedError, 0);
   137 		}
   138 	}
   139 
   140 CTestChainValidate::~CTestChainValidate()
   141 	{
   142 	delete iError;
   143 	delete iWarnings;
   144 	};
   145 
   146 TBool CTestChainValidate::AddServerL(const TDesC& aBuf)
   147 	{
   148 	TInt nPos, n;
   149 	TPtrC ioSection(aBuf);
   150 	TPtrC ioBuf;
   151 	if (ioSection != KNullDesC)
   152 		{
   153 		do
   154 			{
   155 			nPos = 0;
   156 			ioBuf.Set(Input::ParseElement(ioSection, KServerStart, nPos));
   157 			if(nPos > 0)
   158 				{
   159 				ioSection.Set(ioSection.Mid(nPos));
   160 				n=0;
   161 				TPtrC iCertBuf = Input::ParseElement(ioBuf, KCertificateStart, n);
   162 				iServerCerts->AppendL(iCertBuf);
   163 				TPtrC iLabelBuf = Input::ParseElement(ioBuf, KLabelStart, n);
   164 				iServerLabels->AppendL(iLabelBuf);
   165 				};
   166 			
   167 			}
   168 		while(nPos > 0);
   169 		return ETrue;
   170 		}
   171 	return EFalse;
   172 	}
   173 
   174 TBool CTestChainValidate::AddRootL(const TDesC& aBuf)
   175 	{
   176 	TInt nPos, n;
   177 	TPtrC ioSection(aBuf);
   178 	TPtrC ioBuf;
   179 	if (ioSection != KNullDesC)
   180 		{
   181 		do
   182 			{
   183 			nPos = 0;
   184 			ioBuf.Set(Input::ParseElement(ioSection, KRootStart, nPos));
   185 			if(nPos > 0)
   186 				{
   187 				ioSection.Set(ioSection.Mid(nPos));
   188 				n=0;
   189 				TPtrC iCertBuf = Input::ParseElement(ioBuf, KCertificateStart, n);
   190 				iRootCerts->AppendL(iCertBuf);
   191 				TPtrC iLabelBuf = Input::ParseElement(ioBuf, KLabelStart, n);
   192 				iRootLabels->AppendL(iLabelBuf);
   193 				};
   194 			
   195 			}
   196 		while(nPos > 0);
   197 		return ETrue;
   198 		}
   199 	return EFalse;
   200 	}
   201 
   202