sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "comparisontest.h"
|
sl@0
|
20 |
#include "t_input.h"
|
sl@0
|
21 |
#include "t_output.h"
|
sl@0
|
22 |
#include <s32file.h>
|
sl@0
|
23 |
#include <x509cert.h>
|
sl@0
|
24 |
|
sl@0
|
25 |
_LIT8(KCertificate1Start,"<certificate1>");
|
sl@0
|
26 |
_LIT8(KCertificate2Start,"<certificate2>");
|
sl@0
|
27 |
_LIT8(KMatchExpectedStart, "<matchexpected>");
|
sl@0
|
28 |
|
sl@0
|
29 |
CTestAction* CComparisonTest::NewL(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
30 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
31 |
/**
|
sl@0
|
32 |
Factory method that creates a new CComparisonTest object.
|
sl@0
|
33 |
|
sl@0
|
34 |
@param aFs Shared file server session requried by base class
|
sl@0
|
35 |
@param aConsole The console used by the base class for logging
|
sl@0
|
36 |
@param aOut Output utilities for use by base class
|
sl@0
|
37 |
@param aTestActionSpec Parameters for this test
|
sl@0
|
38 |
@return a new instance of a CComparisonTest
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
{
|
sl@0
|
41 |
CTestAction* self = CComparisonTest::NewLC(aFs, aConsole, aOut, aTestActionSpec);
|
sl@0
|
42 |
CleanupStack::Pop(self);
|
sl@0
|
43 |
return self;
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
CTestAction* CComparisonTest::NewLC(RFs& aFs, CConsoleBase& aConsole,
|
sl@0
|
47 |
Output& aOut, const TTestActionSpec& aTestActionSpec)
|
sl@0
|
48 |
/**
|
sl@0
|
49 |
Factory method that creates a new CComparisonTest object and places the pointer
|
sl@0
|
50 |
to the this on the cleanup stack.
|
sl@0
|
51 |
@param aFs Shared file server session requried by base class
|
sl@0
|
52 |
@param aConsole The console used by the base class for logging
|
sl@0
|
53 |
@param aOut Output utilities for use by base class
|
sl@0
|
54 |
@param aTestActionSpec Parameters for this test
|
sl@0
|
55 |
@return a new instance of a CComparisonTest
|
sl@0
|
56 |
*/
|
sl@0
|
57 |
{
|
sl@0
|
58 |
CComparisonTest* self = new(ELeave) CComparisonTest(aFs, aConsole, aOut);
|
sl@0
|
59 |
CleanupStack::PushL(self);
|
sl@0
|
60 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
61 |
return self;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
CComparisonTest::CComparisonTest(RFs& aFs,
|
sl@0
|
65 |
CConsoleBase& aConsole,
|
sl@0
|
66 |
Output& aOut)
|
sl@0
|
67 |
: CTestAction(aConsole, aOut), iFs(aFs)
|
sl@0
|
68 |
/**
|
sl@0
|
69 |
Constructor
|
sl@0
|
70 |
@param aFs Shared file server session required by base-class
|
sl@0
|
71 |
@param aConsole Console implemenation required by base class
|
sl@0
|
72 |
@param aOut Output utilities required by base class
|
sl@0
|
73 |
*/
|
sl@0
|
74 |
{
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
void CComparisonTest::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
78 |
/**
|
sl@0
|
79 |
Second phase constructor
|
sl@0
|
80 |
@param aTestActionSpec parameters for this test base
|
sl@0
|
81 |
*/
|
sl@0
|
82 |
{
|
sl@0
|
83 |
CTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
84 |
HBufC8* body = HBufC8::NewLC(aTestActionSpec.iActionBody.Length());
|
sl@0
|
85 |
body->Des().Copy(aTestActionSpec.iActionBody);
|
sl@0
|
86 |
|
sl@0
|
87 |
TPtrC8 cert1FileName = Input::ParseElement(*body, KCertificate1Start);
|
sl@0
|
88 |
if (! cert1FileName.Length() > 0)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
SetScriptError(ESyntax, _L("Missing tag: certificate1"));
|
sl@0
|
91 |
iFinished = ETrue;
|
sl@0
|
92 |
return;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
iCert1 = ReadCertificateL(cert1FileName);
|
sl@0
|
96 |
|
sl@0
|
97 |
TPtrC8 cert2FileName = Input::ParseElement(*body, KCertificate2Start);
|
sl@0
|
98 |
if (! cert2FileName.Length() > 0)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
SetScriptError(ESyntax, _L("Missing tag: certificate1"));
|
sl@0
|
101 |
iFinished = ETrue;
|
sl@0
|
102 |
return;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
iCert2 = ReadCertificateL(cert2FileName);
|
sl@0
|
105 |
iMatchExpected = Input::ParseElementBoolL(*body, KMatchExpectedStart);
|
sl@0
|
106 |
CleanupStack::PopAndDestroy(body);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
CX509Certificate* CComparisonTest::ReadCertificateL(const TDesC8& aFileName)
|
sl@0
|
110 |
/**
|
sl@0
|
111 |
Reads an X.509 certificate from a file.
|
sl@0
|
112 |
@param aFileName The name of the certificate file.
|
sl@0
|
113 |
@return A pointer to the new certificate object.
|
sl@0
|
114 |
*/
|
sl@0
|
115 |
{
|
sl@0
|
116 |
TFileName fn;
|
sl@0
|
117 |
fn.Copy(aFileName);
|
sl@0
|
118 |
|
sl@0
|
119 |
iOut.write(_L("Loading: %S\n"), &fn);
|
sl@0
|
120 |
RFile file;
|
sl@0
|
121 |
User::LeaveIfError(file.Open(iFs, fn, EFileRead | EFileShareReadersOnly));
|
sl@0
|
122 |
CleanupClosePushL(file);
|
sl@0
|
123 |
TInt size;
|
sl@0
|
124 |
User::LeaveIfError(file.Size(size));
|
sl@0
|
125 |
RBuf8 buf;
|
sl@0
|
126 |
buf.CreateL(size);
|
sl@0
|
127 |
CleanupClosePushL(buf);
|
sl@0
|
128 |
|
sl@0
|
129 |
User::LeaveIfError(file.Read(buf, size));
|
sl@0
|
130 |
|
sl@0
|
131 |
CX509Certificate* cert = CX509Certificate::NewL(buf);
|
sl@0
|
132 |
CleanupStack::PopAndDestroy(2, &file);
|
sl@0
|
133 |
return cert;
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
CComparisonTest::~CComparisonTest()
|
sl@0
|
137 |
/**
|
sl@0
|
138 |
Destructor
|
sl@0
|
139 |
*/
|
sl@0
|
140 |
{
|
sl@0
|
141 |
delete iCert1;
|
sl@0
|
142 |
delete iCert2;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
void CComparisonTest::DoPerformPrerequisite(TRequestStatus& aStatus)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
iActionState = EAction;
|
sl@0
|
148 |
TRequestStatus* status = &aStatus;
|
sl@0
|
149 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
void CComparisonTest::DoPerformPostrequisite(TRequestStatus& aStatus)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
TRequestStatus* status = &aStatus;
|
sl@0
|
155 |
iFinished = ETrue;
|
sl@0
|
156 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
void CComparisonTest::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
TRAPD(err, DoActionL());
|
sl@0
|
162 |
TRequestStatus* status = &aStatus;
|
sl@0
|
163 |
iActionState = EPostrequisite;
|
sl@0
|
164 |
User::RequestComplete(status, err);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
void CComparisonTest::DoActionL()
|
sl@0
|
168 |
/**
|
sl@0
|
169 |
Compares iCert1 and iCert2 using CX509Certificate::IsEqualL
|
sl@0
|
170 |
*/
|
sl@0
|
171 |
{
|
sl@0
|
172 |
HBufC* subject1 = iCert1->SubjectL();
|
sl@0
|
173 |
CleanupStack::PushL(subject1);
|
sl@0
|
174 |
HBufC* subject2 = iCert2->SubjectL();
|
sl@0
|
175 |
CleanupStack::PushL(subject2);
|
sl@0
|
176 |
|
sl@0
|
177 |
HBufC* issuer1 = iCert1->IssuerL();
|
sl@0
|
178 |
CleanupStack::PushL(issuer1);
|
sl@0
|
179 |
HBufC* issuer2 = iCert2->IssuerL();
|
sl@0
|
180 |
CleanupStack::PushL(issuer2);
|
sl@0
|
181 |
|
sl@0
|
182 |
iConsole.Printf(_L("Comparing certificates\n"));
|
sl@0
|
183 |
iOut.write(_L("Comparing certificates\n"));
|
sl@0
|
184 |
|
sl@0
|
185 |
iConsole.Printf(_L("cert1:\n\tsubject: %S\n\tissuer %S\n"), subject1, issuer1);
|
sl@0
|
186 |
iOut.write(_L("cert1:\n\tsubject: %S\n\tissuer %S\n"), subject1, issuer1);
|
sl@0
|
187 |
|
sl@0
|
188 |
iConsole.Printf(_L("cert2:\n\tsubject: %S\n\tissuer %S\n"), subject2, issuer2);
|
sl@0
|
189 |
iOut.write(_L("cert2:\n\tsubject: %S issuer\n\t%S\n"), subject2, issuer2);
|
sl@0
|
190 |
|
sl@0
|
191 |
TBool match = iCert1->IsEqualL(*iCert2);
|
sl@0
|
192 |
iConsole.Printf(_L("Match expected %d, result %d\n"), iMatchExpected, match);
|
sl@0
|
193 |
iOut.write(_L("Match expected %d, result %d\n"), iMatchExpected, match);
|
sl@0
|
194 |
|
sl@0
|
195 |
iResult = (match == iMatchExpected);
|
sl@0
|
196 |
|
sl@0
|
197 |
if (iResult)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
iConsole.Printf(_L(" Success\n"));
|
sl@0
|
200 |
iOut.writeString(_L(" Success\n"));
|
sl@0
|
201 |
}
|
sl@0
|
202 |
else
|
sl@0
|
203 |
{
|
sl@0
|
204 |
iConsole.Printf(_L(" Failed\n"));
|
sl@0
|
205 |
iOut.writeString(_L(" Failed"));
|
sl@0
|
206 |
};
|
sl@0
|
207 |
CleanupStack::PopAndDestroy(4, subject1);
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
void CComparisonTest::DoReportAction()
|
sl@0
|
211 |
{
|
sl@0
|
212 |
}
|
sl@0
|
213 |
|
sl@0
|
214 |
void CComparisonTest::DoCheckResult(TInt /*aError*/)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
}
|