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