|
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 reference agent test case. |
|
15 // |
|
16 // |
|
17 |
|
18 #include <caf/streaming/keystreamdecoder.h> |
|
19 #include <caf/streaming/protectedstreamdesc.h> |
|
20 #include "treferenceagent.h" |
|
21 #include "stkm.h" |
|
22 |
|
23 using namespace StreamAccess; |
|
24 |
|
25 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY |
|
26 const TUint32 KTestSpiBase = 667; |
|
27 #endif |
|
28 |
|
29 CScafRefAgent::CScafRefAgent(CScafServer& aParent): CScafIpSec(aParent) |
|
30 { |
|
31 SetTestStepName(KScafRefAgent); |
|
32 } |
|
33 |
|
34 |
|
35 TVerdict CScafRefAgent::doTestL() |
|
36 { |
|
37 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY |
|
38 SetTestStepResult(EPass); |
|
39 CleanAgentsPrivateFolderL(KSraPrivateFolder()); |
|
40 CopyFile2AgentsPrivateFolderL(iParent.Fs(), KProgramProtectedRo(), KSraPrivateFolder()); |
|
41 |
|
42 //Create an SDP document object and set the created key stream field object |
|
43 CSdpDocument* sdpDoc = CreateSdpDocumentLC(); |
|
44 // Generate an SDP object by reading the values from the configuration file |
|
45 CSdpMediaField* sdp = CreateSdpLC(0); |
|
46 AddMediaFieldL(*sdpDoc, sdp); |
|
47 CleanupStack::Pop(sdp); |
|
48 |
|
49 // Create a trivial source IP address. Since the protected content is not required |
|
50 // in this test, this IP address used here is not important, any IP address can be used. |
|
51 TInetAddr sourceAddr; |
|
52 User::LeaveIfError(sourceAddr.Input(_L("192.168.174.5"))); |
|
53 sourceAddr.SetPort(3004); |
|
54 |
|
55 // Destination IP address must be the agent's address |
|
56 TInetAddr destinationAddr (iClientAddr); |
|
57 |
|
58 // Create an IPSec protected key stream description object from the source and destination IP addresses |
|
59 CProtectedStreamDesc *protectedStreamDesc = CIpSecProtectedStreamDesc::NewLC(sourceAddr, destinationAddr); |
|
60 // Create a key stream decoder by using the IPSec key stream decoder and sdp requiring the reference agent |
|
61 CKeyStreamDecoder* keyStreamDecoder = CKeyStreamDecoder::NewLC(*protectedStreamDesc, *sdp, *sdpDoc); |
|
62 |
|
63 // Create a short term key message (STKM) |
|
64 CStkm* stkm = CStkm::NewLC(0, KTestSpiBase, *iEncryptionKey, *iAuthenticationKey); |
|
65 CBufFlat* buf = CBufFlat::NewL(KExpandSize); |
|
66 CleanupStack::PushL(buf); |
|
67 |
|
68 RBufWriteStream stream(*buf); |
|
69 CleanupClosePushL(stream); |
|
70 stkm->ExternalizeL(stream); |
|
71 CleanupStack::PopAndDestroy(&stream); |
|
72 |
|
73 HBufC8* des = HBufC8::NewL(buf->Size()); |
|
74 TPtr8 ptr((des)->Des()); |
|
75 buf->Read(0, ptr, buf->Size()); |
|
76 CleanupStack::PopAndDestroy(buf); |
|
77 CleanupStack::PushL(des); |
|
78 |
|
79 // Send the STKM to the reference agent |
|
80 TRequestStatus status; |
|
81 iClientSocket.Send(*des, 0, status); |
|
82 User::WaitForRequest(status); |
|
83 User::LeaveIfError(status.Int()); |
|
84 |
|
85 // Wait until the agent is finished with the key processing |
|
86 RMutex mutex; |
|
87 _LIT(KSraMutexName, "MutexBtwTestHarnessAndRefAgent"); |
|
88 User::LeaveIfError(mutex.OpenGlobal(KSraMutexName())); |
|
89 CleanupClosePushL(mutex); |
|
90 mutex.Wait(); |
|
91 |
|
92 // Check whether the STKM message has been added to the SADB |
|
93 CallValidateSadbL(KTestSpiBase, sourceAddr, destinationAddr, ETrue); |
|
94 |
|
95 // Release the allocated memories |
|
96 CleanupStack::PopAndDestroy(5, protectedStreamDesc); |
|
97 CleanupStack::PopAndDestroy(); // sdpDoc |
|
98 #endif |
|
99 return TestStepResult(); |
|
100 } |