sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 1998-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 |
* tactiondecodepkcs5.cpp
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*/
|
sl@0
|
18 |
|
sl@0
|
19 |
|
sl@0
|
20 |
#include "tactiontestpkcs8.h"
|
sl@0
|
21 |
#include "t_input.h"
|
sl@0
|
22 |
#include "t_output.h"
|
sl@0
|
23 |
#include <asnpkcs.h>
|
sl@0
|
24 |
#include <pbedata.h>
|
sl@0
|
25 |
#include <pbe.h>
|
sl@0
|
26 |
#include <asn1enc.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT8(KFilenameStart, "<filename>");
|
sl@0
|
29 |
_LIT8(KMatchesStart, "<matches>");
|
sl@0
|
30 |
|
sl@0
|
31 |
_LIT8(KOutcomeNoMatch, "noMatch");
|
sl@0
|
32 |
_LIT8(KOutcomeMatchesPKCS8, "pkcs8");
|
sl@0
|
33 |
_LIT8(KOutcomeMatchesEncryptedPKCS8, "encryptedPkcs8");
|
sl@0
|
34 |
|
sl@0
|
35 |
_LIT(KFilenameBase, "\\tkeystore\\data\\");
|
sl@0
|
36 |
|
sl@0
|
37 |
CTestAction* CActionTestPKCS8::NewL(RFs& aFs,
|
sl@0
|
38 |
CConsoleBase& aConsole,
|
sl@0
|
39 |
Output& aOut,
|
sl@0
|
40 |
const TTestActionSpec& aTestActionSpec)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
CActionTestPKCS8* self = new(ELeave) CActionTestPKCS8(aFs, aConsole, aOut);
|
sl@0
|
43 |
CleanupStack::PushL(self);
|
sl@0
|
44 |
self->ConstructL(aTestActionSpec);
|
sl@0
|
45 |
CleanupStack::Pop();
|
sl@0
|
46 |
return self;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
CActionTestPKCS8::~CActionTestPKCS8()
|
sl@0
|
50 |
{
|
sl@0
|
51 |
delete iInput;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
CActionTestPKCS8::CActionTestPKCS8(RFs& aFs,
|
sl@0
|
55 |
CConsoleBase& aConsole,
|
sl@0
|
56 |
Output& aOut)
|
sl@0
|
57 |
|
sl@0
|
58 |
: CTestAction(aConsole, aOut), iFs(aFs)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
void CActionTestPKCS8::ConstructL(const TTestActionSpec& aTestActionSpec)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
CTestAction::ConstructL(aTestActionSpec);
|
sl@0
|
65 |
ReadInputFileL(Input::ParseElement(aTestActionSpec.iActionBody, KFilenameStart));
|
sl@0
|
66 |
SetExpectedOutcomeL(Input::ParseElement(aTestActionSpec.iActionBody, KMatchesStart));
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
void CActionTestPKCS8::ReadInputFileL(const TDesC8& aFilename)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
if (aFilename == KNullDesC8)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
User::Leave(KErrArgument);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
TFileName tempFilename;
|
sl@0
|
77 |
tempFilename.Copy(aFilename); // convert from 8 -> 16 bit descriptor
|
sl@0
|
78 |
|
sl@0
|
79 |
TDriveUnit sysDrive = RFs::GetSystemDrive();
|
sl@0
|
80 |
TDriveName sysDriveName (sysDrive.Name());
|
sl@0
|
81 |
tempFilename.Insert(0,sysDriveName);
|
sl@0
|
82 |
tempFilename.Insert(2,KFilenameBase);
|
sl@0
|
83 |
|
sl@0
|
84 |
RFile file;
|
sl@0
|
85 |
User::LeaveIfError(file.Open(iFs, tempFilename, EFileRead));
|
sl@0
|
86 |
CleanupClosePushL(file);
|
sl@0
|
87 |
TInt size = 0;
|
sl@0
|
88 |
User::LeaveIfError(file.Size(size));
|
sl@0
|
89 |
|
sl@0
|
90 |
iInput = HBufC8::NewMaxL(size);
|
sl@0
|
91 |
TPtr8 ptr = iInput->Des();
|
sl@0
|
92 |
User::LeaveIfError(file.Read(ptr));
|
sl@0
|
93 |
|
sl@0
|
94 |
CleanupStack::PopAndDestroy(&file);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
void CActionTestPKCS8::SetExpectedOutcomeL(const TDesC8& aOutcome)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
if (aOutcome == KOutcomeNoMatch)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
iExpectedOutcome = ENoMatch;
|
sl@0
|
102 |
}
|
sl@0
|
103 |
else if (aOutcome == KOutcomeMatchesPKCS8)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
iExpectedOutcome = EMatchesPKCS8;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
else if (aOutcome == KOutcomeMatchesEncryptedPKCS8)
|
sl@0
|
108 |
{
|
sl@0
|
109 |
iExpectedOutcome = EMatchesEncryptedPKCS8;
|
sl@0
|
110 |
}
|
sl@0
|
111 |
else
|
sl@0
|
112 |
{
|
sl@0
|
113 |
User::Leave(KErrArgument);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
void CActionTestPKCS8::DoReportAction(void)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
void CActionTestPKCS8::DoCheckResult(TInt)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
void CActionTestPKCS8::PerformAction(TRequestStatus& aStatus)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
TRequestStatus* status = &aStatus;
|
sl@0
|
128 |
iResult = EFalse;
|
sl@0
|
129 |
|
sl@0
|
130 |
TBool matchesPKCS8 = TASN1DecPKCS8::IsPKCS8Data(*iInput);
|
sl@0
|
131 |
TBool matchesEncryptedPKCS8 = TASN1DecPKCS8::IsEncryptedPKCS8Data(*iInput);
|
sl@0
|
132 |
|
sl@0
|
133 |
if (matchesPKCS8 && matchesEncryptedPKCS8)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
iOut.writeString(_L("!! Data matches both cleartext and encrypted pkcs8\n"));
|
sl@0
|
136 |
User::Leave(KErrGeneral);
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
TOutcome outcome = ENoMatch;
|
sl@0
|
140 |
|
sl@0
|
141 |
if (matchesPKCS8)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
iOut.writeString(_L("Data matches cleartext pkcs8\n"));
|
sl@0
|
144 |
outcome = EMatchesPKCS8;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
else if (matchesEncryptedPKCS8)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
iOut.writeString(_L("Data matches encrypted pkcs8\n"));
|
sl@0
|
149 |
outcome = EMatchesEncryptedPKCS8;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
else
|
sl@0
|
152 |
{
|
sl@0
|
153 |
iOut.writeString(_L("Data doesn't match anything\n"));
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
if(outcome == iExpectedOutcome)
|
sl@0
|
157 |
{
|
sl@0
|
158 |
iResult = ETrue;
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
User::RequestComplete(status, KErrNone);
|
sl@0
|
162 |
iActionState = CTestAction::EPostrequisite;
|
sl@0
|
163 |
}
|