|
sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
sl@0
|
2 |
// All rights reserved.
|
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
sl@0
|
7 |
//
|
|
sl@0
|
8 |
// Initial Contributors:
|
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
|
sl@0
|
10 |
//
|
|
sl@0
|
11 |
// Contributors:
|
|
sl@0
|
12 |
//
|
|
sl@0
|
13 |
// Description:
|
|
sl@0
|
14 |
// Implements the Key Stream Sink usage tests.
|
|
sl@0
|
15 |
//
|
|
sl@0
|
16 |
//
|
|
sl@0
|
17 |
|
|
sl@0
|
18 |
#include "tkeystreamsink.h"
|
|
sl@0
|
19 |
|
|
sl@0
|
20 |
using namespace StreamAccess;
|
|
sl@0
|
21 |
|
|
sl@0
|
22 |
// CScafKeyStreamSink
|
|
sl@0
|
23 |
|
|
sl@0
|
24 |
CScafKeyStreamSink::CScafKeyStreamSink(CScafServer& aParent)
|
|
sl@0
|
25 |
/**
|
|
sl@0
|
26 |
Constructor.
|
|
sl@0
|
27 |
*/
|
|
sl@0
|
28 |
: CScafStep(aParent)
|
|
sl@0
|
29 |
{
|
|
sl@0
|
30 |
SetTestStepName(KScafKeyStreamSinkStep);
|
|
sl@0
|
31 |
}
|
|
sl@0
|
32 |
|
|
sl@0
|
33 |
CScafKeyStreamSink::~CScafKeyStreamSink()
|
|
sl@0
|
34 |
/**
|
|
sl@0
|
35 |
Destructor.
|
|
sl@0
|
36 |
*/
|
|
sl@0
|
37 |
{
|
|
sl@0
|
38 |
//empty
|
|
sl@0
|
39 |
}
|
|
sl@0
|
40 |
|
|
sl@0
|
41 |
TVerdict CScafKeyStreamSink::doTestL()
|
|
sl@0
|
42 |
{
|
|
sl@0
|
43 |
TPtrC privatePath;
|
|
sl@0
|
44 |
|
|
sl@0
|
45 |
if(iDecoderConfigurationArray[0]->iPrivateFolderPath.Length())
|
|
sl@0
|
46 |
{
|
|
sl@0
|
47 |
privatePath.Set(iDecoderConfigurationArray[0]->iPrivateFolderPath);
|
|
sl@0
|
48 |
}
|
|
sl@0
|
49 |
else
|
|
sl@0
|
50 |
{
|
|
sl@0
|
51 |
privatePath.Set(KStaPrivateFolder());
|
|
sl@0
|
52 |
}
|
|
sl@0
|
53 |
|
|
sl@0
|
54 |
//Ensure pre-conditions
|
|
sl@0
|
55 |
CleanAgentsPrivateFolderL(privatePath);
|
|
sl@0
|
56 |
|
|
sl@0
|
57 |
//First copy the service protected RO into the test agent's private directory
|
|
sl@0
|
58 |
CopyFile2AgentsPrivateFolderL(iParent.Fs(), KServiceProtectedRo(), privatePath);
|
|
sl@0
|
59 |
|
|
sl@0
|
60 |
_LIT8(KPlainString,"aplainstring");
|
|
sl@0
|
61 |
CSraRightsObject* ro = GetRightsObjectLC(KServiceProtectedRo(),privatePath);
|
|
sl@0
|
62 |
//Encrypt the string with the encryption key
|
|
sl@0
|
63 |
//Since encryption is not tested here, the encrypted key is
|
|
sl@0
|
64 |
//created by appending the encryption key.
|
|
sl@0
|
65 |
TBuf8<50> encryptedStr;
|
|
sl@0
|
66 |
encryptedStr.Append(KPlainString);
|
|
sl@0
|
67 |
encryptedStr.Append(*ro->Key());
|
|
sl@0
|
68 |
CleanupStack::PopAndDestroy(ro);
|
|
sl@0
|
69 |
|
|
sl@0
|
70 |
//Create an SDP document object and set the created key stream field object
|
|
sl@0
|
71 |
CSdpDocument* sdpDoc = CreateSdpDocumentLC();
|
|
sl@0
|
72 |
//Create an SDP key stream field object with an attribute requiring the service protected RO
|
|
sl@0
|
73 |
CSdpMediaField* sdp = CreateSdpLC(0);
|
|
sl@0
|
74 |
AddMediaFieldL(*sdpDoc, sdp);
|
|
sl@0
|
75 |
CleanupStack::Pop(sdp);
|
|
sl@0
|
76 |
|
|
sl@0
|
77 |
//Create a test key stream sink
|
|
sl@0
|
78 |
_LIT(KKeySinkOutputFileName,"testkeysstreamsink.dat");
|
|
sl@0
|
79 |
CKeyStreamSink* sink = CreateKeyStreamSinkLC(KKeySinkOutputFileName, privatePath);
|
|
sl@0
|
80 |
|
|
sl@0
|
81 |
CTestKeyStreamDecoderBase* decoder = NULL;
|
|
sl@0
|
82 |
|
|
sl@0
|
83 |
if(iDecoderConfigurationArray[0]->iSingleProcessAgent)
|
|
sl@0
|
84 |
{
|
|
sl@0
|
85 |
// Single Process Stream Agent
|
|
sl@0
|
86 |
decoder = CTestSingleProcessKeyStreamDecoder::NewL(*sink, *sdp, *sdpDoc);
|
|
sl@0
|
87 |
}
|
|
sl@0
|
88 |
else
|
|
sl@0
|
89 |
{
|
|
sl@0
|
90 |
// Client/Server Stream Agent
|
|
sl@0
|
91 |
decoder = CTestAgentKeyStreamDecoder::NewL(*sink, *sdp, *sdpDoc);
|
|
sl@0
|
92 |
}
|
|
sl@0
|
93 |
|
|
sl@0
|
94 |
CleanupStack::PushL(decoder);
|
|
sl@0
|
95 |
|
|
sl@0
|
96 |
//Send the encrypted string
|
|
sl@0
|
97 |
decoder->SendKeyStreamL(encryptedStr);
|
|
sl@0
|
98 |
|
|
sl@0
|
99 |
//Compare the output key with the original one
|
|
sl@0
|
100 |
HBufC* fOutput = GetFullPathLC(privatePath, KKeySinkOutputFileName);
|
|
sl@0
|
101 |
|
|
sl@0
|
102 |
RFile fOutputKey;
|
|
sl@0
|
103 |
User::LeaveIfError(fOutputKey.Open(iParent.Fs(), *fOutput, EFileRead));
|
|
sl@0
|
104 |
CleanupStack::PopAndDestroy(fOutput);
|
|
sl@0
|
105 |
CleanupClosePushL(fOutputKey);
|
|
sl@0
|
106 |
TBuf8<50> decryptedKey;
|
|
sl@0
|
107 |
User::LeaveIfError(fOutputKey.Read(decryptedKey));
|
|
sl@0
|
108 |
|
|
sl@0
|
109 |
if(decryptedKey.Compare(KPlainString))
|
|
sl@0
|
110 |
{
|
|
sl@0
|
111 |
SetTestStepResult(EFail);
|
|
sl@0
|
112 |
}
|
|
sl@0
|
113 |
|
|
sl@0
|
114 |
CleanupStack::PopAndDestroy(4, sdpDoc); // fOutputKey, decoder, sink, sdpDoc
|
|
sl@0
|
115 |
return TestStepResult();
|
|
sl@0
|
116 |
}
|
|
sl@0
|
117 |
|
|
sl@0
|
118 |
|
|
sl@0
|
119 |
//CScafConcurrentKeyStreamSinks
|
|
sl@0
|
120 |
|
|
sl@0
|
121 |
CScafConcurrentKeyStreamSinks::CScafConcurrentKeyStreamSinks(CScafServer& aParent)
|
|
sl@0
|
122 |
/**
|
|
sl@0
|
123 |
Constructor.
|
|
sl@0
|
124 |
*/
|
|
sl@0
|
125 |
: CScafStep(aParent)
|
|
sl@0
|
126 |
{
|
|
sl@0
|
127 |
SetTestStepName(KScafConcurrentKeyStreamSinksStep);
|
|
sl@0
|
128 |
}
|
|
sl@0
|
129 |
|
|
sl@0
|
130 |
CScafConcurrentKeyStreamSinks::~CScafConcurrentKeyStreamSinks()
|
|
sl@0
|
131 |
/**
|
|
sl@0
|
132 |
Destructor.
|
|
sl@0
|
133 |
*/
|
|
sl@0
|
134 |
{
|
|
sl@0
|
135 |
//empty
|
|
sl@0
|
136 |
}
|
|
sl@0
|
137 |
|
|
sl@0
|
138 |
TVerdict CScafConcurrentKeyStreamSinks::doTestL()
|
|
sl@0
|
139 |
{
|
|
sl@0
|
140 |
TPtrC privatePathA;
|
|
sl@0
|
141 |
|
|
sl@0
|
142 |
if(iDecoderConfigurationArray[0]->iPrivateFolderPath.Length())
|
|
sl@0
|
143 |
{
|
|
sl@0
|
144 |
privatePathA.Set(iDecoderConfigurationArray[0]->iPrivateFolderPath);
|
|
sl@0
|
145 |
}
|
|
sl@0
|
146 |
else
|
|
sl@0
|
147 |
{
|
|
sl@0
|
148 |
privatePathA.Set(KStaPrivateFolder());
|
|
sl@0
|
149 |
}
|
|
sl@0
|
150 |
|
|
sl@0
|
151 |
TPtrC privatePathB;
|
|
sl@0
|
152 |
|
|
sl@0
|
153 |
if(iDecoderConfigurationArray[1]->iPrivateFolderPath.Length())
|
|
sl@0
|
154 |
{
|
|
sl@0
|
155 |
privatePathB.Set(iDecoderConfigurationArray[1]->iPrivateFolderPath);
|
|
sl@0
|
156 |
}
|
|
sl@0
|
157 |
else
|
|
sl@0
|
158 |
{
|
|
sl@0
|
159 |
privatePathB.Set(KStaPrivateFolder());
|
|
sl@0
|
160 |
}
|
|
sl@0
|
161 |
|
|
sl@0
|
162 |
//Ensure pre-conditions
|
|
sl@0
|
163 |
CleanAgentsPrivateFolderL(privatePathA);
|
|
sl@0
|
164 |
CleanAgentsPrivateFolderL(privatePathB);
|
|
sl@0
|
165 |
|
|
sl@0
|
166 |
//First copy the service protected RO into the private directories of each stream agent
|
|
sl@0
|
167 |
CopyFile2AgentsPrivateFolderL(iParent.Fs(), KServiceProtectedRo(), privatePathA);
|
|
sl@0
|
168 |
CopyFile2AgentsPrivateFolderL(iParent.Fs(), KServiceProtectedRo(), privatePathB);
|
|
sl@0
|
169 |
|
|
sl@0
|
170 |
//Secondly copy the program protected RO into the private directories of each stream agent
|
|
sl@0
|
171 |
CopyFile2AgentsPrivateFolderL(iParent.Fs(), KProgramProtectedRo(), privatePathA);
|
|
sl@0
|
172 |
CopyFile2AgentsPrivateFolderL(iParent.Fs(), KProgramProtectedRo(), privatePathB);
|
|
sl@0
|
173 |
|
|
sl@0
|
174 |
//Create an SDP document object and set the created key stream field object for each decoder
|
|
sl@0
|
175 |
CSdpDocument* sdpDoc = CreateSdpDocumentLC();
|
|
sl@0
|
176 |
|
|
sl@0
|
177 |
//Create a SDP object for RO-A
|
|
sl@0
|
178 |
TInt sdpNum = 0;
|
|
sl@0
|
179 |
CSdpMediaField* sdpA = CreateSdpLC(sdpNum++);
|
|
sl@0
|
180 |
AddMediaFieldL(*sdpDoc, sdpA);
|
|
sl@0
|
181 |
CleanupStack::Pop(sdpA);
|
|
sl@0
|
182 |
|
|
sl@0
|
183 |
//Create a SDP object for RO-B
|
|
sl@0
|
184 |
CSdpMediaField* sdpB = CreateSdpLC(sdpNum);
|
|
sl@0
|
185 |
AddMediaFieldL(*sdpDoc, sdpB);
|
|
sl@0
|
186 |
CleanupStack::Pop(sdpB);
|
|
sl@0
|
187 |
|
|
sl@0
|
188 |
//Create a test key stream sink for test key stream decoder A
|
|
sl@0
|
189 |
_LIT(KKeySinkOutputFileNameA,"testkeysstreamsinkA.dat");
|
|
sl@0
|
190 |
CKeyStreamSink* sinkA = CreateKeyStreamSinkLC(KKeySinkOutputFileNameA,privatePathA);
|
|
sl@0
|
191 |
|
|
sl@0
|
192 |
|
|
sl@0
|
193 |
//Create test key stream decoder A
|
|
sl@0
|
194 |
CTestKeyStreamDecoderBase* decoderA = NULL;
|
|
sl@0
|
195 |
|
|
sl@0
|
196 |
if(iDecoderConfigurationArray[0]->iSingleProcessAgent)
|
|
sl@0
|
197 |
{
|
|
sl@0
|
198 |
// Single Process Stream Agent
|
|
sl@0
|
199 |
decoderA = CTestSingleProcessKeyStreamDecoder::NewL(*sinkA, *sdpA, *sdpDoc);
|
|
sl@0
|
200 |
}
|
|
sl@0
|
201 |
else
|
|
sl@0
|
202 |
{
|
|
sl@0
|
203 |
// Client/Server Stream Agent
|
|
sl@0
|
204 |
decoderA = CTestAgentKeyStreamDecoder::NewL(*sinkA, *sdpA, *sdpDoc);
|
|
sl@0
|
205 |
}
|
|
sl@0
|
206 |
|
|
sl@0
|
207 |
CleanupStack::PushL(decoderA);
|
|
sl@0
|
208 |
|
|
sl@0
|
209 |
//Create a test key stream sink for test key stream decoder B
|
|
sl@0
|
210 |
_LIT(KKeySinkOutputFileNameB,"testkeysstreamsinkB.dat");
|
|
sl@0
|
211 |
CKeyStreamSink* sinkB = CreateKeyStreamSinkLC(KKeySinkOutputFileNameB,privatePathB);
|
|
sl@0
|
212 |
|
|
sl@0
|
213 |
//Create test key stream decoder B
|
|
sl@0
|
214 |
CTestKeyStreamDecoderBase* decoderB = NULL;
|
|
sl@0
|
215 |
|
|
sl@0
|
216 |
if(iDecoderConfigurationArray[1]->iSingleProcessAgent)
|
|
sl@0
|
217 |
{
|
|
sl@0
|
218 |
// Single Process Stream Agent
|
|
sl@0
|
219 |
decoderB = CTestSingleProcessKeyStreamDecoder::NewL(*sinkB, *sdpB, *sdpDoc);
|
|
sl@0
|
220 |
}
|
|
sl@0
|
221 |
else
|
|
sl@0
|
222 |
{
|
|
sl@0
|
223 |
// Client/Server Stream Agent
|
|
sl@0
|
224 |
decoderB = CTestAgentKeyStreamDecoder::NewL(*sinkB, *sdpB, *sdpDoc);
|
|
sl@0
|
225 |
}
|
|
sl@0
|
226 |
|
|
sl@0
|
227 |
CleanupStack::PushL(decoderB);
|
|
sl@0
|
228 |
|
|
sl@0
|
229 |
_LIT8(KPlainStringA,"plainstringA");
|
|
sl@0
|
230 |
CSraRightsObject* roA = GetRightsObjectLC(KServiceProtectedRo,privatePathA);
|
|
sl@0
|
231 |
//Encrypt the plain string A
|
|
sl@0
|
232 |
TBuf8<50> encryptedStr;
|
|
sl@0
|
233 |
encryptedStr.Append(KPlainStringA);
|
|
sl@0
|
234 |
encryptedStr.Append(*roA->Key());
|
|
sl@0
|
235 |
CleanupStack::PopAndDestroy(roA);
|
|
sl@0
|
236 |
//Send the encrypted string A
|
|
sl@0
|
237 |
decoderA->SendKeyStreamL(encryptedStr);
|
|
sl@0
|
238 |
|
|
sl@0
|
239 |
_LIT8(KPlainStringB,"plainstringB");
|
|
sl@0
|
240 |
CSraRightsObject* roB = GetRightsObjectLC(KProgramProtectedRo,privatePathB);
|
|
sl@0
|
241 |
//Encrypt the plain string B
|
|
sl@0
|
242 |
encryptedStr.Zero();
|
|
sl@0
|
243 |
encryptedStr.Append(KPlainStringB);
|
|
sl@0
|
244 |
encryptedStr.Append(*roB->Key());
|
|
sl@0
|
245 |
CleanupStack::PopAndDestroy(roB);
|
|
sl@0
|
246 |
//Send the encrypted string B
|
|
sl@0
|
247 |
decoderB->SendKeyStreamL(encryptedStr);
|
|
sl@0
|
248 |
|
|
sl@0
|
249 |
//Compare the output key file A with the original one
|
|
sl@0
|
250 |
HBufC* fOutputA = GetFullPathLC(privatePathA, KKeySinkOutputFileNameA);
|
|
sl@0
|
251 |
RFile fOutputKey;
|
|
sl@0
|
252 |
User::LeaveIfError(fOutputKey.Open(iParent.Fs(), *fOutputA, EFileRead));
|
|
sl@0
|
253 |
CleanupStack::PopAndDestroy(fOutputA);
|
|
sl@0
|
254 |
CleanupClosePushL(fOutputKey);
|
|
sl@0
|
255 |
TBuf8<50> decryptedKey;
|
|
sl@0
|
256 |
User::LeaveIfError(fOutputKey.Read(decryptedKey));
|
|
sl@0
|
257 |
CleanupStack::PopAndDestroy(&fOutputKey);
|
|
sl@0
|
258 |
|
|
sl@0
|
259 |
if(decryptedKey.Compare(KPlainStringA))
|
|
sl@0
|
260 |
{
|
|
sl@0
|
261 |
SetTestStepResult(EFail);
|
|
sl@0
|
262 |
}
|
|
sl@0
|
263 |
|
|
sl@0
|
264 |
//Compare the output key file B with the original one
|
|
sl@0
|
265 |
HBufC* fOutputB = GetFullPathLC(privatePathB, KKeySinkOutputFileNameB);
|
|
sl@0
|
266 |
User::LeaveIfError(fOutputKey.Open(iParent.Fs(), *fOutputB, EFileRead));
|
|
sl@0
|
267 |
CleanupStack::PopAndDestroy(fOutputB);
|
|
sl@0
|
268 |
CleanupClosePushL(fOutputKey);
|
|
sl@0
|
269 |
decryptedKey.Zero();
|
|
sl@0
|
270 |
User::LeaveIfError(fOutputKey.Read(decryptedKey));
|
|
sl@0
|
271 |
CleanupStack::PopAndDestroy(&fOutputKey);
|
|
sl@0
|
272 |
|
|
sl@0
|
273 |
if(decryptedKey.Compare(KPlainStringB))
|
|
sl@0
|
274 |
{
|
|
sl@0
|
275 |
SetTestStepResult(EFail);
|
|
sl@0
|
276 |
}
|
|
sl@0
|
277 |
|
|
sl@0
|
278 |
//Release allocated resources
|
|
sl@0
|
279 |
CleanupStack::PopAndDestroy(2, sinkB); //< decoderB, sink B
|
|
sl@0
|
280 |
CleanupStack::PopAndDestroy(2, sinkA); //< decoderA, sinkA
|
|
sl@0
|
281 |
CleanupStack::PopAndDestroy(sdpDoc); //< sdpDoc
|
|
sl@0
|
282 |
return TestStepResult();
|
|
sl@0
|
283 |
}
|