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