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