contentmgmt/cafstreamingsupport/test/streamingtestagent_singleprocess/source/shared/testsingleprocesskeystreamdecoder.cpp
branchRCL_3
changeset 43 2f10d260163b
child 61 641f389e9157
equal deleted inserted replaced
42:eb9b28acd381 43:2f10d260163b
       
     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 Test 'Single Process' Stream Agent Key Stream Decoder object.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21 */
       
    22 
       
    23 #include "testsingleprocesskeystreamdecoder.h"
       
    24 
       
    25 using namespace StreamAccess;
       
    26 
       
    27 CTestSingleProcessKeyStreamDecoder::CTestSingleProcessKeyStreamDecoder()
       
    28 /**
       
    29  	Constructor.
       
    30  */
       
    31 	: CTestKeyStreamDecoderBase()
       
    32 	{
       
    33 	//empty
       
    34 	}
       
    35 
       
    36 CTestSingleProcessKeyStreamDecoder::~CTestSingleProcessKeyStreamDecoder()
       
    37 /**
       
    38  	Destructor.
       
    39  */
       
    40 	{	
       
    41 	iFs.Close();
       
    42 	
       
    43 	delete iKeyStreamSink;
       
    44 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY	
       
    45 	delete iSdp;
       
    46 	delete iSdpDoc;
       
    47 #endif
       
    48 	delete iRo;
       
    49 	}
       
    50 
       
    51 EXPORT_C CTestSingleProcessKeyStreamDecoder* CTestSingleProcessKeyStreamDecoder::NewL(const CKeyStreamSink& aKeyStreamSink,
       
    52 	    															  const CSdpMediaField& aSdpKeyStream,
       
    53 	    															  const CSdpDocument& aSdpDoc)
       
    54 /**
       
    55 	Factory function allocates a new instance of CTestSingleProcessKeyStreamDecoder.
       
    56 	@return		New instance of CTestSingleProcessKeyStreamDecoder
       
    57  */
       
    58 	{
       
    59 	CTestSingleProcessKeyStreamDecoder* self = CTestSingleProcessKeyStreamDecoder::NewLC(aKeyStreamSink, aSdpKeyStream, aSdpDoc);
       
    60 	CleanupStack::Pop(self);
       
    61 	return self;
       
    62 	}
       
    63 
       
    64 EXPORT_C CTestSingleProcessKeyStreamDecoder* CTestSingleProcessKeyStreamDecoder::NewLC(const CKeyStreamSink& aKeyStreamSink,
       
    65 	    															   const CSdpMediaField& aSdpKeyStream,
       
    66 	    															   const CSdpDocument& aSdpDoc)
       
    67 /**
       
    68 	Factory function allocates a new instance of CTestSingleProcessKeyStreamDecoder 
       
    69 	and places the object on the cleanup stack.
       
    70 	@return		A new instance of CTestSingleProcessKeyStreamDecoder 
       
    71 				which is left on the cleanup stack.
       
    72  */
       
    73 	{
       
    74 	CTestSingleProcessKeyStreamDecoder* self = new (ELeave) CTestSingleProcessKeyStreamDecoder();
       
    75 	CleanupStack::PushL(self);
       
    76 	self->ConstructL(aKeyStreamSink, aSdpKeyStream, aSdpDoc);
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 void CTestSingleProcessKeyStreamDecoder::ConstructL(const CKeyStreamSink& aKeyStreamSink,
       
    81 											const CSdpMediaField& aSdpKeyStream,
       
    82 											const CSdpDocument& aSdpDoc)
       
    83 /**
       
    84  	Second phase constructor.
       
    85  */
       
    86 	{
       
    87 	User::LeaveIfError(iFs.Connect());
       
    88 	
       
    89 	iKeyStreamSink = aKeyStreamSink.CloneLC();
       
    90 	CleanupStack::Pop(iKeyStreamSink);
       
    91 	
       
    92 	// Set the encryption and authentication algorithm of the key stream sink
       
    93 	iKeyStreamSink->SetEncryptionAlgorithmL(EAES_128_CBC);
       
    94 	iKeyStreamSink->SetAuthenticationAlgorithmL(EHMAC_SHA1);
       
    95 
       
    96 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY	
       
    97 	iSdp = aSdpKeyStream.CloneL();
       
    98 	iSdpDoc = aSdpDoc.CloneL();
       
    99 #else
       
   100     (void) aSdpKeyStream;
       
   101 	(void) aSdpDoc;
       
   102 #endif
       
   103 	SetRoL();
       
   104 	}
       
   105 
       
   106 EXPORT_C void CTestSingleProcessKeyStreamDecoder::GetAttributeL(const TAttribute& aAttribute, TBool& aValue)
       
   107 /**
       
   108  	@see CAgentKeyStreamDecoder::GetAttributeL
       
   109  */ 	
       
   110 	{
       
   111 	VerifyRoL();
       
   112 	
       
   113 	aValue = EFalse;
       
   114 	
       
   115 	switch(aAttribute)
       
   116 		{
       
   117 		case EIsProgramProtected:
       
   118 			aValue = iRo->AccessRights() & EProgramProtected;
       
   119 			break;
       
   120 		case EIsServiceProtected:
       
   121 			aValue = iRo->AccessRights() & EServiceProtected;
       
   122 			break;
       
   123 		case ECanExport:
       
   124 			aValue = iRo->AccessRights() & ECanExportContent;
       
   125 			break;
       
   126 		case EMustProtectIfRecording:
       
   127 			aValue = iRo->AccessRights() & EMustProtectContentIfRecording;
       
   128 			break;
       
   129 		case ECanPlay:
       
   130 			aValue = iRo->AccessRights() & ECanPlayContent;
       
   131 			break;
       
   132 		default:
       
   133 			User::Leave(KErrCAOutOfRange);
       
   134 		}
       
   135 	
       
   136 	// If the the return value is greater than 0, set the boolean value to ETrue
       
   137 	if(aValue)
       
   138 		{
       
   139 		aValue = ETrue;
       
   140 		}
       
   141 	}
       
   142 
       
   143 EXPORT_C HBufC* CTestSingleProcessKeyStreamDecoder::GetStringAttributeLC(const TStringAttribute& aAttribute)
       
   144 /**
       
   145  	@see CAgentKeyStreamDecoder::GetStringAttributeL
       
   146  */
       
   147 	{
       
   148 	VerifyRoL();
       
   149 	
       
   150 	HBufC8* str8 = NULL;
       
   151 	
       
   152 	switch(aAttribute)
       
   153 		{
       
   154 		case EContentID:
       
   155 			str8 = iRo->ContentId();
       
   156 			break;
       
   157 		case ERightsIssuerURI:
       
   158 			str8 = iRo->RightsIssuer();
       
   159 			break;
       
   160 		default:
       
   161 			User::Leave(KErrCAOutOfRange);
       
   162 		}
       
   163 	
       
   164 	//Convert 8-bit to 16-bit
       
   165 	HBufC* value = HBufC::NewL(str8->Des().Size());
       
   166 	TPtr ptr(value->Des());
       
   167 	ptr.Copy(str8->Des());
       
   168 
       
   169 	CleanupStack::PushL(value);
       
   170 	return value;
       
   171 	}
       
   172  
       
   173 EXPORT_C void CTestSingleProcessKeyStreamDecoder::GetPostDeliveryRightsL(RFile& /*aFile*/, TDes8& /*aCid*/, TDes8& /*aRightsMimeType*/, TDes8& /*aContentMimeType*/)
       
   174 /**
       
   175  	@see CAgentKeyStreamDecoder::GetPostDeliveryRightsHandleL
       
   176  */
       
   177 	{
       
   178 	User::Leave(KErrNotSupported);
       
   179 	}
       
   180 
       
   181 EXPORT_C void CTestSingleProcessKeyStreamDecoder::SendKeyStreamL(const TDesC8& aKey) const
       
   182 /**
       
   183  	Sends an encrypted short-term key to the key stream sink
       
   184  	@param aKey An encrypted key.
       
   185  */
       
   186 	{
       
   187 	HBufC8* shortTermKey = aKey.AllocLC();
       
   188 	
       
   189 	//Check if the long-term key key exists in the short-term key
       
   190 	TInt ret = shortTermKey->Find(*iRo->Key());
       
   191 	if(ret == KErrNotFound)
       
   192 		{
       
   193 		User::Leave(KErrGeneral);
       
   194 		}
       
   195 	
       
   196 	//Get the plain string (key)
       
   197 	HBufC8* decryptedKey = HBufC8::NewLC(ret);
       
   198 	TPtr8 ptrKey(decryptedKey->Des());
       
   199 	ptrKey.Copy(shortTermKey->Des().Ptr(), ret);
       
   200 	
       
   201 	CTestKeyAssociation* decryptedAssoc = CTestKeyAssociation::NewL(ptrKey);
       
   202 	CleanupStack::PushL(decryptedAssoc);
       
   203 	
       
   204 	iKeyStreamSink->ProcessNewKeyAssociationL(*decryptedAssoc);
       
   205 	
       
   206 	CleanupStack::PopAndDestroy(3, shortTermKey); //< shortTermKey, decryptedKey, decryptedAssoc
       
   207 	}
       
   208 
       
   209 EXPORT_C void CTestSingleProcessKeyStreamDecoder::SendIpSecAssociationL(TInt32 aSpi, HBufC8* aEncryptionKey, HBufC8* aAuthenticationKey) const
       
   210 	{
       
   211 	CKeyAssociation* ipSecKeyAssociation = CIpSecKeyAssociation::NewLC(aSpi, aEncryptionKey, aAuthenticationKey);			
       
   212 	iKeyStreamSink->ProcessNewKeyAssociationL(*ipSecKeyAssociation);
       
   213 	CleanupStack::PopAndDestroy(ipSecKeyAssociation);
       
   214 	}
       
   215 
       
   216 void CTestSingleProcessKeyStreamDecoder::SetRoL()
       
   217 	{
       
   218 	_LIT(KDriveFormat,"!:");
       
   219 	TBuf<50> privateFolder;
       
   220 	iFs.PrivatePath(privateFolder);
       
   221 	privateFolder.Insert(0,KDriveFormat);
       
   222 	
       
   223 	DoSetRightsObjectL(iFs, *iSdp, iRo, privateFolder);
       
   224 	}
       
   225 
       
   226 void CTestSingleProcessKeyStreamDecoder::VerifyRoL()
       
   227 /**
       
   228  	Verifies that the rights object exists.
       
   229  */
       
   230 	{
       
   231 	if(!iRo)
       
   232 		{//The RO defined in the SDP does not exist
       
   233 		User::Leave(KErrCANoRights);
       
   234 		}
       
   235 	if(iRo->IsExpired())
       
   236 		{
       
   237 		User::Leave(KErrCANoPermission);
       
   238 		}
       
   239 	}