os/security/cryptoservices/certificateandkeymgmt/tpkixcert/tpkixcertval.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 #include "tpkixcertval.h"
    24 #include "tcertutils.h"
    25 #include "t_input.h"
    26 
    27 //tags for elements in specification file
    28 _LIT(KRootStart, "<root>");
    29 _LIT(KRootEnd, "</root>");
    30 _LIT(KCertificateStart, "<certificate>");
    31 _LIT(KCertificateEnd, "</certificate>");
    32 _LIT(KLabelStart, "<label>");
    33 _LIT(KLabelEnd, "</label>");
    34 _LIT(KEEStart, "<ee>");
    35 _LIT(KEEEnd, "</ee>");
    36 _LIT(KInterStart, "<inter>");
    37 _LIT(KInterEnd, "</inter>");
    38 _LIT(KIPoliciesStart, "<ipolicies>");
    39 _LIT(KIPoliciesEnd, "</ipolicies>");
    40 _LIT(KIPolicyStart, "<ipolicy>");
    41 _LIT(KIPolicyEnd, "</ipolicy>");
    42 _LIT(KOResultStart, "<oresult>");
    43 _LIT(KOResultEnd, "</oresult>");
    44 _LIT(KOPoliciesStart, "<opolicies>");
    45 _LIT(KOPoliciesEnd, "</opolicies>");
    46 _LIT(KOPolicyStart, "<opolicy>");
    47 _LIT(KOPolicyEnd, "</opolicy>");
    48 
    49 //const TUint KUnicodeMarker = 0xfeff;
    50 
    51 //**Cert Chain**//
    52 CTestChain* CTestChain::NewL(const TDesC& aBuf)
    53 	{
    54 	CTestChain* self = CTestChain::NewLC(aBuf);
    55 	CleanupStack::Pop();
    56 	return self;
    57 	}
    58 
    59 CTestChain* CTestChain::NewLC(const TDesC& aBuf)
    60 	{
    61 	CTestChain* self = new(ELeave) CTestChain;
    62 	CleanupStack::PushL(self);
    63 	self->ConstructL(aBuf);
    64 	return self;
    65 	}
    66 
    67 CTestChain::~CTestChain()
    68 	{
    69 	delete iIntermediateCertsFileName;
    70 	delete iIntermediateCertsLabel;
    71 	}
    72 
    73 CTestChain::CTestChain()
    74 	{
    75 	}
    76 
    77 void CTestChain::ConstructL(const TDesC& aBuf)
    78 	{
    79 	TInt pos = 0;
    80 	TInt err = KErrNone;
    81 	TPtrC rootCert(Input::ParseElement(aBuf, KRootStart, KRootEnd, pos, err));
    82 	TInt dummyPos = 0;
    83 	iRootCertFileName = Input::ParseElement(rootCert, KCertificateStart, 
    84 		KCertificateEnd, dummyPos, err);
    85 	iRootCertLabel = Input::ParseElement(rootCert, KLabelStart,
    86 		KLabelEnd, dummyPos, err);
    87 	if (iRootCertLabel == KNullDesC)
    88 		{
    89 		User::Leave(KErrNotFound);
    90 		}
    91 
    92 	TPtrC EECert(Input::ParseElement(aBuf, KEEStart, KEEEnd, pos));
    93 	dummyPos = 0;
    94 	iEECertFileName = Input::ParseElement(EECert, KCertificateStart,
    95 		KCertificateEnd, dummyPos);
    96 	iEECertLabel = Input::ParseElement(EECert, KLabelStart,
    97 		KLabelEnd, dummyPos);
    98 
    99 	iIntermediateCertsFileName = new(ELeave) CDesCArrayFlat(1);
   100 	iIntermediateCertsLabel = new(ELeave) CDesCArrayFlat(1);
   101 	while(AddInter(aBuf, pos))
   102 		{
   103 		}
   104 	}
   105 
   106 TBool CTestChain::AddInter(const TDesC& aBuf, TInt& aPos)
   107 	{
   108 	TPtrC interBuf = Input::ParseElement(aBuf, KInterStart, KInterEnd, aPos);
   109 	TInt dummyPos = 0;
   110 	if (interBuf != KNullDesC)
   111 		{
   112 		iIntermediateCertsFileName->AppendL(Input::ParseElement(interBuf, 
   113 			KCertificateStart, KCertificateEnd, dummyPos));
   114 		iIntermediateCertsLabel->AppendL(Input::ParseElement(interBuf,
   115 			KLabelStart, KLabelEnd, dummyPos));
   116 		return ETrue;
   117 		}
   118 	return EFalse;
   119 	}
   120 
   121 //**Policy Input/Output**//
   122 CTestParameters* CTestParameters::NewL(const TDesC& aBuf)
   123 	{
   124 	CTestParameters* self = CTestParameters::NewLC(aBuf);
   125 	CleanupStack::Pop();
   126 	return self;
   127 	}
   128 
   129 CTestParameters* CTestParameters::NewLC(const TDesC& aBuf)
   130 	{
   131 	CTestParameters* self = new(ELeave) CTestParameters;
   132 	CleanupStack::PushL(self);
   133 	self->ConstructL(aBuf);
   134 	return self;
   135 	}
   136 
   137 CTestParameters::~CTestParameters()
   138 	{
   139 	delete iWarnings;
   140 	delete iPolicyInput;
   141 	delete iExpectedPolicyOutput;
   142 	}
   143 
   144 CTestParameters::CTestParameters()
   145 	:iIPoliciesSet(ETrue), iOPoliciesSet(ETrue), iOWarningsSet(ETrue)
   146 	{
   147 	}
   148 
   149 void CTestParameters::ConstructL(const TDesC& aBuf)
   150 	{
   151 	iWarnings = new(ELeave)CArrayFixFlat<TValidationStatus> (1);
   152 	iPolicyInput = new(ELeave) CDesCArrayFlat (1);
   153 	iExpectedPolicyOutput = new(ELeave) CDesCArrayFlat (1);
   154 
   155 	TInt pos = 0;
   156 	TInt err = KErrNone;
   157 	TPtrC iIPolicyBuf = Input::ParseElement(aBuf, KIPoliciesStart, KIPoliciesEnd, pos, err);
   158 	if (err != KErrNone)
   159 		{
   160 		iIPoliciesSet = EFalse;//input policies are optional
   161 		}
   162 	pos = 0;
   163 	while(AddPolicy(iIPolicyBuf, KIPolicyStart, KIPolicyEnd,pos, *iPolicyInput))
   164 		{
   165 		}	
   166 	iError = Input::ParseElement(aBuf, KOResultStart, KOResultEnd, pos);
   167 	TPtrC iOPolicyBuf = Input::ParseElement(aBuf, KOPoliciesStart, KOPoliciesEnd, pos, err);
   168 	if (err != KErrNone)
   169 		{
   170 		iOPoliciesSet = EFalse;//output policies are optional
   171 		}
   172 	pos = 0;
   173 	while(AddPolicy(iOPolicyBuf, KOPolicyStart, KOPolicyEnd, pos, *iExpectedPolicyOutput))
   174 		{
   175 		}	
   176 	}
   177 
   178 TBool CTestParameters::AddPolicy(const TDesC& aBuf, const TDesC& aStart, const TDesC& aEnd, TInt& aPos, CDesCArray& aPolicySet)
   179 	{
   180 	TPtrC policyBuf = Input::ParseElement(aBuf, aStart, aEnd, aPos);
   181 	if (policyBuf != KNullDesC)
   182 		{
   183 		aPolicySet.AppendL(policyBuf);
   184 		return ETrue;
   185 		}
   186 	return EFalse;
   187 	}