1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tpkixcert/tpkixcertval.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,187 @@
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 +#include "tpkixcertval.h"
1.27 +#include "tcertutils.h"
1.28 +#include "t_input.h"
1.29 +
1.30 +//tags for elements in specification file
1.31 +_LIT(KRootStart, "<root>");
1.32 +_LIT(KRootEnd, "</root>");
1.33 +_LIT(KCertificateStart, "<certificate>");
1.34 +_LIT(KCertificateEnd, "</certificate>");
1.35 +_LIT(KLabelStart, "<label>");
1.36 +_LIT(KLabelEnd, "</label>");
1.37 +_LIT(KEEStart, "<ee>");
1.38 +_LIT(KEEEnd, "</ee>");
1.39 +_LIT(KInterStart, "<inter>");
1.40 +_LIT(KInterEnd, "</inter>");
1.41 +_LIT(KIPoliciesStart, "<ipolicies>");
1.42 +_LIT(KIPoliciesEnd, "</ipolicies>");
1.43 +_LIT(KIPolicyStart, "<ipolicy>");
1.44 +_LIT(KIPolicyEnd, "</ipolicy>");
1.45 +_LIT(KOResultStart, "<oresult>");
1.46 +_LIT(KOResultEnd, "</oresult>");
1.47 +_LIT(KOPoliciesStart, "<opolicies>");
1.48 +_LIT(KOPoliciesEnd, "</opolicies>");
1.49 +_LIT(KOPolicyStart, "<opolicy>");
1.50 +_LIT(KOPolicyEnd, "</opolicy>");
1.51 +
1.52 +//const TUint KUnicodeMarker = 0xfeff;
1.53 +
1.54 +//**Cert Chain**//
1.55 +CTestChain* CTestChain::NewL(const TDesC& aBuf)
1.56 + {
1.57 + CTestChain* self = CTestChain::NewLC(aBuf);
1.58 + CleanupStack::Pop();
1.59 + return self;
1.60 + }
1.61 +
1.62 +CTestChain* CTestChain::NewLC(const TDesC& aBuf)
1.63 + {
1.64 + CTestChain* self = new(ELeave) CTestChain;
1.65 + CleanupStack::PushL(self);
1.66 + self->ConstructL(aBuf);
1.67 + return self;
1.68 + }
1.69 +
1.70 +CTestChain::~CTestChain()
1.71 + {
1.72 + delete iIntermediateCertsFileName;
1.73 + delete iIntermediateCertsLabel;
1.74 + }
1.75 +
1.76 +CTestChain::CTestChain()
1.77 + {
1.78 + }
1.79 +
1.80 +void CTestChain::ConstructL(const TDesC& aBuf)
1.81 + {
1.82 + TInt pos = 0;
1.83 + TInt err = KErrNone;
1.84 + TPtrC rootCert(Input::ParseElement(aBuf, KRootStart, KRootEnd, pos, err));
1.85 + TInt dummyPos = 0;
1.86 + iRootCertFileName = Input::ParseElement(rootCert, KCertificateStart,
1.87 + KCertificateEnd, dummyPos, err);
1.88 + iRootCertLabel = Input::ParseElement(rootCert, KLabelStart,
1.89 + KLabelEnd, dummyPos, err);
1.90 + if (iRootCertLabel == KNullDesC)
1.91 + {
1.92 + User::Leave(KErrNotFound);
1.93 + }
1.94 +
1.95 + TPtrC EECert(Input::ParseElement(aBuf, KEEStart, KEEEnd, pos));
1.96 + dummyPos = 0;
1.97 + iEECertFileName = Input::ParseElement(EECert, KCertificateStart,
1.98 + KCertificateEnd, dummyPos);
1.99 + iEECertLabel = Input::ParseElement(EECert, KLabelStart,
1.100 + KLabelEnd, dummyPos);
1.101 +
1.102 + iIntermediateCertsFileName = new(ELeave) CDesCArrayFlat(1);
1.103 + iIntermediateCertsLabel = new(ELeave) CDesCArrayFlat(1);
1.104 + while(AddInter(aBuf, pos))
1.105 + {
1.106 + }
1.107 + }
1.108 +
1.109 +TBool CTestChain::AddInter(const TDesC& aBuf, TInt& aPos)
1.110 + {
1.111 + TPtrC interBuf = Input::ParseElement(aBuf, KInterStart, KInterEnd, aPos);
1.112 + TInt dummyPos = 0;
1.113 + if (interBuf != KNullDesC)
1.114 + {
1.115 + iIntermediateCertsFileName->AppendL(Input::ParseElement(interBuf,
1.116 + KCertificateStart, KCertificateEnd, dummyPos));
1.117 + iIntermediateCertsLabel->AppendL(Input::ParseElement(interBuf,
1.118 + KLabelStart, KLabelEnd, dummyPos));
1.119 + return ETrue;
1.120 + }
1.121 + return EFalse;
1.122 + }
1.123 +
1.124 +//**Policy Input/Output**//
1.125 +CTestParameters* CTestParameters::NewL(const TDesC& aBuf)
1.126 + {
1.127 + CTestParameters* self = CTestParameters::NewLC(aBuf);
1.128 + CleanupStack::Pop();
1.129 + return self;
1.130 + }
1.131 +
1.132 +CTestParameters* CTestParameters::NewLC(const TDesC& aBuf)
1.133 + {
1.134 + CTestParameters* self = new(ELeave) CTestParameters;
1.135 + CleanupStack::PushL(self);
1.136 + self->ConstructL(aBuf);
1.137 + return self;
1.138 + }
1.139 +
1.140 +CTestParameters::~CTestParameters()
1.141 + {
1.142 + delete iWarnings;
1.143 + delete iPolicyInput;
1.144 + delete iExpectedPolicyOutput;
1.145 + }
1.146 +
1.147 +CTestParameters::CTestParameters()
1.148 + :iIPoliciesSet(ETrue), iOPoliciesSet(ETrue), iOWarningsSet(ETrue)
1.149 + {
1.150 + }
1.151 +
1.152 +void CTestParameters::ConstructL(const TDesC& aBuf)
1.153 + {
1.154 + iWarnings = new(ELeave)CArrayFixFlat<TValidationStatus> (1);
1.155 + iPolicyInput = new(ELeave) CDesCArrayFlat (1);
1.156 + iExpectedPolicyOutput = new(ELeave) CDesCArrayFlat (1);
1.157 +
1.158 + TInt pos = 0;
1.159 + TInt err = KErrNone;
1.160 + TPtrC iIPolicyBuf = Input::ParseElement(aBuf, KIPoliciesStart, KIPoliciesEnd, pos, err);
1.161 + if (err != KErrNone)
1.162 + {
1.163 + iIPoliciesSet = EFalse;//input policies are optional
1.164 + }
1.165 + pos = 0;
1.166 + while(AddPolicy(iIPolicyBuf, KIPolicyStart, KIPolicyEnd,pos, *iPolicyInput))
1.167 + {
1.168 + }
1.169 + iError = Input::ParseElement(aBuf, KOResultStart, KOResultEnd, pos);
1.170 + TPtrC iOPolicyBuf = Input::ParseElement(aBuf, KOPoliciesStart, KOPoliciesEnd, pos, err);
1.171 + if (err != KErrNone)
1.172 + {
1.173 + iOPoliciesSet = EFalse;//output policies are optional
1.174 + }
1.175 + pos = 0;
1.176 + while(AddPolicy(iOPolicyBuf, KOPolicyStart, KOPolicyEnd, pos, *iExpectedPolicyOutput))
1.177 + {
1.178 + }
1.179 + }
1.180 +
1.181 +TBool CTestParameters::AddPolicy(const TDesC& aBuf, const TDesC& aStart, const TDesC& aEnd, TInt& aPos, CDesCArray& aPolicySet)
1.182 + {
1.183 + TPtrC policyBuf = Input::ParseElement(aBuf, aStart, aEnd, aPos);
1.184 + if (policyBuf != KNullDesC)
1.185 + {
1.186 + aPolicySet.AppendL(policyBuf);
1.187 + return ETrue;
1.188 + }
1.189 + return EFalse;
1.190 + }