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