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