rtp/srtpstack/tsrc/ut_srtpstack/src/UT_CSRTPCryptoContext.cpp
changeset 0 307788aac0a8
child 19 b5e99d8877c7
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "UT_CSRTPCryptoContext.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <digia/eunit/eunitmacros.h>
       
    26 
       
    27 
       
    28 //  INTERNAL INCLUDES
       
    29 #include "srtpcryptocontext.h"
       
    30 #include "srtpcryptohandlersrtp.h"
       
    31 #include "srtpcryptohandlersrtcp.h"
       
    32 #include "srtpmastersalt.h"
       
    33 #include "srtpmasterkey.h"
       
    34 #include "srtpstreamin.h"
       
    35 #include "srtpstreamout.h"
       
    36 #include "srtpsession.h"
       
    37 
       
    38 // 128 bit master key, test 1
       
    39 _LIT8(K128bitMasterKey1,    "112233445566778899E6AABBCCDDEEFF");
       
    40 // 128 bit master key, test 2
       
    41 _LIT8(K128bitMasterKey2,       "FFEEDDCCBBAA11223344556677889900");
       
    42 // 128 bit master key, test 3
       
    43 _LIT8(K128bitMasterKey3,       "33333333333333333333333333333333");
       
    44 // 112 bit master salt, test 1
       
    45 _LIT8(K112bitMasterSalt1,      "0EC675AD498AFEEBB6960B3AABE6");
       
    46 // 112 bit master salt, test 2
       
    47 _LIT8(K112bitMasterSalt2,      "112233445566778899E6AABBCCDD");
       
    48 // 112 bit master salt, test 3
       
    49 _LIT8(K112bitMasterSalt3,      "3333333333333333333333333333");
       
    50 // 128 bit MKI, test 1
       
    51 _LIT8(K128bitMKITest1,         "11111111111111111111111111111111");
       
    52 // 128 bit MKI, test 2
       
    53 _LIT8(K128bitMKITest2,         "22222222222222222222222222222222");
       
    54 // 128 bit MKI, test 3
       
    55 _LIT8(K128bitMKITest3,         "33333333333333333333333333333333");
       
    56 
       
    57 #define RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( func, val ) \
       
    58 {\
       
    59 TRAPD( rtpUnitTestRetVal, func );\
       
    60 if ( val != KErrNoMemory && rtpUnitTestRetVal == KErrNoMemory ){\
       
    61 	User::Leave( KErrNoMemory );\
       
    62 	}\
       
    63 else{\
       
    64 	EUNIT_ASSERT_EQUALS( rtpUnitTestRetVal, val );\
       
    65 	}\
       
    66 }
       
    67 
       
    68 // CONSTRUCTION
       
    69 UT_CSRTPCryptoContext* UT_CSRTPCryptoContext::NewL()
       
    70     {
       
    71     UT_CSRTPCryptoContext* self = UT_CSRTPCryptoContext::NewLC(); 
       
    72     CleanupStack::Pop();
       
    73 
       
    74     return self;
       
    75     }
       
    76 
       
    77 UT_CSRTPCryptoContext* UT_CSRTPCryptoContext::NewLC()
       
    78     {
       
    79     UT_CSRTPCryptoContext* self = new( ELeave ) UT_CSRTPCryptoContext();
       
    80     CleanupStack::PushL( self );
       
    81 
       
    82 	self->ConstructL(); 
       
    83 
       
    84     return self;
       
    85     }
       
    86 
       
    87 // Destructor (virtual by CBase)
       
    88 UT_CSRTPCryptoContext::~UT_CSRTPCryptoContext()
       
    89     {
       
    90     }
       
    91 
       
    92 // Default constructor
       
    93 UT_CSRTPCryptoContext::UT_CSRTPCryptoContext() 
       
    94     {
       
    95     }
       
    96 
       
    97 // Second phase construct
       
    98 void UT_CSRTPCryptoContext::ConstructL()
       
    99     {
       
   100     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
   101     // It generates the test case table.
       
   102     CEUnitTestSuiteClass::ConstructL();
       
   103     }
       
   104 
       
   105 //  METHODS
       
   106 
       
   107 
       
   108 
       
   109 void UT_CSRTPCryptoContext::SetupL(  )
       
   110     {
       
   111 
       
   112     HBufC8* masterKey1 = HBufC8::NewL(K128bitMasterKey1().Length());
       
   113     CleanupStack::PushL( masterKey1 );
       
   114     *masterKey1 = K128bitMasterKey1;
       
   115 	
       
   116 	HBufC8* masterKey2 = HBufC8::NewL(K128bitMasterKey2().Length());
       
   117     CleanupStack::PushL( masterKey2 );
       
   118     *masterKey2 = K128bitMasterKey2;
       
   119 	
       
   120 	
       
   121     
       
   122     HBufC8* masterSalt1 =HBufC8::NewL(K112bitMasterSalt1().Length());
       
   123     CleanupStack::PushL( masterSalt1);
       
   124 	*masterSalt1 = K112bitMasterSalt1;
       
   125 
       
   126 	
       
   127 	
       
   128     HBufC8* masterSalt2 =HBufC8::NewL(K112bitMasterSalt2().Length());
       
   129     CleanupStack::PushL( masterSalt2);
       
   130 	*masterSalt2 = K112bitMasterSalt2;
       
   131 
       
   132 	
       
   133 
       
   134 	HBufC8* mki =HBufC8::NewL(K128bitMKITest1().Length());
       
   135     CleanupStack::PushL( mki);
       
   136 	*mki = K128bitMKITest1;
       
   137 	Hex(*mki);
       
   138 
       
   139 	HBufC8* mki2 =HBufC8::NewL(K128bitMKITest2().Length());
       
   140     CleanupStack::PushL( mki2);
       
   141 	*mki2 = K128bitMKITest2;
       
   142 	Hex(*mki2);
       
   143 	
       
   144 	iMasterKey = CSRTPMasterKey::NewL( *masterKey1, *mki,
       
   145 									KSRTPDefSessionEncryptionKeyLength, 
       
   146         							KSRTPDefSessionAuthenticationKeyLength );
       
   147     iMasterSalt = CSRTPMasterSalt::NewL( *masterSalt1,KSRTPDefSessionSaltingKeyLength );
       
   148     
       
   149     iMasterKey2 = CSRTPMasterKey::NewL( *masterKey2, *mki2,
       
   150 								        KSRTPDefSessionEncryptionKeyLength,
       
   151 								        KSRTPDefSessionAuthenticationKeyLength  );
       
   152     iMasterSalt2 = CSRTPMasterSalt::NewL( *masterSalt2, KSRTPDefSessionSaltingKeyLength );
       
   153     
       
   154  
       
   155     
       
   156     
       
   157     
       
   158     
       
   159 	TSrtpCryptoParams params;
       
   160     iContext = CSRTPCryptoContext::NewL(iMasterKey, iMasterSalt,params   );
       
   161 								        
       
   162  	//iContext2 is valid context costructed with automatic values
       
   163  	
       
   164  	params.iSrtcpAuthTagLen=32;
       
   165    	iContext2= CSRTPCryptoContext::NewL(iMasterKey2,iMasterSalt2, params);
       
   166    	
       
   167  
       
   168 
       
   169 	CleanupStack::PopAndDestroy( mki2 );            
       
   170     CleanupStack::PopAndDestroy( mki );
       
   171     CleanupStack::PopAndDestroy( masterSalt2 );
       
   172     CleanupStack::PopAndDestroy( masterSalt1 );
       
   173     CleanupStack::PopAndDestroy( masterKey2 ); 
       
   174     CleanupStack::PopAndDestroy( masterKey1 ); 
       
   175     iDestination.Input(_L("127.0.0.1"));
       
   176     
       
   177  
       
   178   
       
   179 	i128bitMasterKey1  = HBufC8::NewL(K128bitMasterKey1().Length());
       
   180 	i128bitMasterKey2  = HBufC8::NewL(K128bitMasterKey2().Length());
       
   181 	i128bitMasterKey3  = HBufC8::NewL(K128bitMasterKey3().Length());
       
   182 	i112bitMasterSalt1 = HBufC8::NewL(K112bitMasterSalt1().Length());
       
   183 	i112bitMasterSalt2 = HBufC8::NewL(K112bitMasterSalt2().Length());
       
   184 	i112bitMasterSalt3 = HBufC8::NewL(K112bitMasterSalt3().Length());
       
   185 	//i128bitMKI1        = HBufC8::NewL(K128bitMKITest1().Length());
       
   186 	//i128bitMKI2        = HBufC8::NewL(K128bitMKITest2().Length());
       
   187 	//i128bitMKI3        = HBufC8::NewL(K128bitMKITest3().Length());
       
   188 	
       
   189 	*i128bitMasterKey1  = K128bitMasterKey1;
       
   190 	*i128bitMasterKey2  = K128bitMasterKey2;
       
   191 	*i128bitMasterKey3  = K128bitMasterKey3;
       
   192 	*i112bitMasterSalt1 = K112bitMasterSalt1;
       
   193 	*i112bitMasterSalt2 = K112bitMasterSalt2;
       
   194 	*i112bitMasterSalt3 = K112bitMasterSalt3;
       
   195 	//*i128bitMKI1        = K128bitMKITest1;
       
   196 	//*i128bitMKI2        = K128bitMKITest2;
       
   197 	//*i128bitMKI3        = K128bitMKITest3;
       
   198 	
       
   199     Hex(*i128bitMasterKey1);
       
   200     Hex(*i128bitMasterKey2);
       
   201     Hex(*i128bitMasterKey3);
       
   202     Hex(*i112bitMasterSalt1);
       
   203     Hex(*i112bitMasterSalt2);
       
   204     Hex(*i112bitMasterSalt3);
       
   205 	//Hex(*i128bitMKI1);
       
   206 	//Hex(*i128bitMKI2);  
       
   207 	//Hex(*i128bitMKI3);  
       
   208 	
       
   209 	// we need to create these in order to test adding CSRTPCryptoHandler
       
   210 	// object to CSRTPCryptoContext lists
       
   211     iSRTPSession = CSRTPSession::NewL( iDestination, iContext, *this ); 
       
   212     iStreamIn = CSRTPStreamIn::NewL(*iSRTPSession, (TUint)1);
       
   213     iStreamOut = CSRTPStreamOut::NewL(*iSRTPSession, (TUint)2);   
       
   214     } 
       
   215     
       
   216         
       
   217 void UT_CSRTPCryptoContext::Teardown(  )
       
   218     { 
       
   219     delete i128bitMasterKey1;
       
   220     delete i128bitMasterKey2;
       
   221     delete i128bitMasterKey3;
       
   222     delete i112bitMasterSalt1;
       
   223     delete i112bitMasterSalt2;
       
   224     delete i112bitMasterSalt3;
       
   225 
       
   226 	delete iStreamIn;
       
   227     delete iStreamOut; 
       
   228     delete iSRTPSession; 
       
   229 	
       
   230     delete iContext2;
       
   231     			
       
   232     }
       
   233 
       
   234 void UT_CSRTPCryptoContext::UT_CSRTPCryptoContext_Test1L(  )
       
   235     {  
       
   236     HBufC8* masterKey3 = HBufC8::NewL(K128bitMasterKey3().Length());
       
   237     CleanupStack::PushL( masterKey3 );
       
   238     *masterKey3 = K128bitMasterKey3;
       
   239 	
       
   240 	HBufC8* masterSalt3 =HBufC8::NewL(K112bitMasterSalt3().Length());
       
   241     CleanupStack::PushL( masterSalt3);
       
   242 	*masterSalt3 = K112bitMasterSalt3;
       
   243 
       
   244 		
       
   245 	HBufC8* mki3 =HBufC8::NewL(K128bitMKITest3().Length());
       
   246     CleanupStack::PushL( mki3);
       
   247 	*mki3 = K128bitMKITest3;
       
   248 	Hex(*mki3);
       
   249  
       
   250 
       
   251     TSrtpCryptoParams params;
       
   252     //test constructL  
       
   253     iMasterKey3 = CSRTPMasterKey::NewLC( *masterKey3, *mki3,
       
   254     							    KSRTPDefSessionEncryptionKeyLength, 
       
   255     							    KSRTPDefSessionAuthenticationKeyLength );
       
   256     iMasterSalt3 = CSRTPMasterSalt::NewL( *masterSalt3, 1100 );
       
   257     CleanupStack::Pop( iMasterKey3 );
       
   258     CleanupStack::PopAndDestroy( mki3 );
       
   259 	
       
   260     CleanupStack::PopAndDestroy( masterSalt3 );
       
   261     CleanupStack::PopAndDestroy( masterKey3 ); 
       
   262     CleanupStack::PushL( iMasterKey3 );
       
   263     CleanupStack::PushL( iMasterSalt3 );
       
   264     params.iSrtcpAuthTagLen=80;
       
   265    	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( iContext3= CSRTPCryptoContext::NewL(iMasterKey3,iMasterSalt3, params ),
       
   266    		 KErrArgument );
       
   267    	CleanupStack::Pop( iMasterSalt3 );
       
   268     CleanupStack::Pop( iMasterKey3 );
       
   269    	delete iContext3;	 
       
   270    	
       
   271     }
       
   272 
       
   273 void UT_CSRTPCryptoContext::UT_CSRTPCryptoContext_Test2L(  )
       
   274 	{
       
   275 	HBufC8* masterKey3 = HBufC8::NewL(K128bitMasterKey3().Length());
       
   276     CleanupStack::PushL( masterKey3 );
       
   277     *masterKey3 = K128bitMasterKey3;
       
   278 	
       
   279 	HBufC8* masterSalt3 =HBufC8::NewL(K112bitMasterSalt3().Length());
       
   280     CleanupStack::PushL( masterSalt3);
       
   281 	*masterSalt3 = K112bitMasterSalt3;
       
   282 
       
   283 		
       
   284 	HBufC8* mki3 =HBufC8::NewL(K128bitMKITest3().Length());
       
   285     CleanupStack::PushL( mki3);
       
   286 	*mki3 = K128bitMKITest3;
       
   287 	Hex(*mki3);
       
   288  
       
   289 
       
   290     TSrtpCryptoParams params;
       
   291    	iMasterKey3 = CSRTPMasterKey::NewLC( *masterKey3, *mki3,
       
   292     							    KSRTPDefSessionEncryptionKeyLength, 
       
   293     							    KSRTPDefSessionAuthenticationKeyLength );
       
   294     iMasterSalt3 = CSRTPMasterSalt::NewL( *masterSalt3, 1100 );
       
   295     CleanupStack::Pop( iMasterKey3 );
       
   296     CleanupStack::PopAndDestroy( mki3 );
       
   297 	CleanupStack::PopAndDestroy( masterSalt3 );
       
   298     CleanupStack::PopAndDestroy( masterKey3 ); 
       
   299     
       
   300     params.iSrtcpAuthTagLen=80;
       
   301     
       
   302     CleanupStack::PushL( iMasterKey3 );
       
   303     CleanupStack::PushL( iMasterSalt3 );
       
   304    	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( iContext3= CSRTPCryptoContext::NewL(iMasterKey3,iMasterSalt3, params ),
       
   305    		 KErrArgument );
       
   306    	
       
   307    	CleanupStack::Pop( iMasterSalt3 );
       
   308     CleanupStack::Pop( iMasterKey3 );	 
       
   309    	delete iContext3;	 
       
   310    
       
   311 	}
       
   312 	
       
   313 void UT_CSRTPCryptoContext::UT_CSRTPCryptoContext_Test3L(  )
       
   314 	{
       
   315     HBufC8* masterKey = HBufC8::NewL(K128bitMasterKey1().Length());
       
   316     CleanupStack::PushL( masterKey );
       
   317     *masterKey = K128bitMasterKey1;
       
   318     
       
   319     HBufC8* masterSalt =HBufC8::NewL(K112bitMasterSalt1().Length());
       
   320     CleanupStack::PushL( masterSalt);
       
   321 	*masterSalt = K112bitMasterSalt1;
       
   322 	HBufC8* mki =HBufC8::NewL(K128bitMKITest1().Length());
       
   323     CleanupStack::PushL( mki);
       
   324 	*mki = K128bitMKITest1;
       
   325 	Hex(*mki);
       
   326 	
       
   327 	iMasterKey4 = CSRTPMasterKey::NewLC( *masterKey, *mki,
       
   328 									KSRTPDefSessionEncryptionKeyLength, 
       
   329         							KSRTPDefSessionAuthenticationKeyLength );
       
   330     iMasterSalt4 = CSRTPMasterSalt::NewL( *masterSalt,KSRTPDefSessionSaltingKeyLength );
       
   331     CleanupStack::Pop( iMasterKey4 );
       
   332     CleanupStack::PopAndDestroy( mki );
       
   333 	
       
   334     CleanupStack::PopAndDestroy( masterSalt );
       
   335     CleanupStack::PopAndDestroy( masterKey );  
       
   336     
       
   337     CleanupStack::PushL( iMasterKey4 );
       
   338     CleanupStack::PushL( iMasterSalt4 );
       
   339      
       
   340 	 //invalid authalg
       
   341 	 TSrtpCryptoParams params;
       
   342      params.iSrtpAuthAlg=TSRTPAuthAlg(10);   
       
   343     RTP_EUNIT_ASSERT_SPECIFIC_LEAVE(iContext4=CSRTPCryptoContext::NewL(iMasterKey4,iMasterSalt4, params),
       
   344      KErrArgument );
       
   345      
       
   346     CleanupStack::Pop( iMasterSalt4 );
       
   347     CleanupStack::Pop( iMasterKey4 );
       
   348     }
       
   349 
       
   350 void UT_CSRTPCryptoContext::UT_CSRTPCryptoContext_Test4L(  )
       
   351 	{
       
   352 	HBufC8* masterKey = HBufC8::NewL(K128bitMasterKey1().Length());
       
   353     CleanupStack::PushL( masterKey );
       
   354     *masterKey = K128bitMasterKey1;
       
   355     
       
   356     HBufC8* masterSalt =HBufC8::NewL(K112bitMasterSalt1().Length());
       
   357     CleanupStack::PushL( masterSalt);
       
   358 	*masterSalt = K112bitMasterSalt1;
       
   359 	HBufC8* mki =HBufC8::NewL(K128bitMKITest1().Length());
       
   360     CleanupStack::PushL( mki);
       
   361 	*mki = K128bitMKITest1;
       
   362 	Hex(*mki);
       
   363 	
       
   364 	iMasterKey5 = CSRTPMasterKey::NewLC( *masterKey, *mki,
       
   365 									KSRTPDefSessionEncryptionKeyLength, 
       
   366         							KSRTPDefSessionAuthenticationKeyLength);
       
   367     iMasterSalt5 = CSRTPMasterSalt::NewL( *masterSalt,KSRTPDefSessionSaltingKeyLength ); 
       
   368     CleanupStack::Pop( iMasterKey5 );
       
   369    	CleanupStack::PopAndDestroy( mki );
       
   370 	CleanupStack::PopAndDestroy( masterSalt );
       
   371     CleanupStack::PopAndDestroy( masterKey );   
       
   372 	
       
   373 	CleanupStack::PushL( iMasterKey5 );
       
   374     CleanupStack::PushL( iMasterSalt5 );
       
   375     
       
   376 	TSrtpCryptoParams params;
       
   377 	 //invalid auth tag length in context5
       
   378 	  params.iSrtpAuthTagLen=20;
       
   379 	 RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( iContext5=CSRTPCryptoContext::NewL(iMasterKey5,iMasterSalt5,params ),
       
   380      KErrArgument );
       
   381      
       
   382      CleanupStack::Pop( iMasterSalt5 );
       
   383      CleanupStack::Pop( iMasterKey5 );
       
   384 	 }
       
   385 
       
   386 void UT_CSRTPCryptoContext::UT_CSRTPCryptoContext_Test5L(  )
       
   387 	{
       
   388 	HBufC8* masterKey = HBufC8::NewL(K128bitMasterKey1().Length());
       
   389     CleanupStack::PushL( masterKey );
       
   390     *masterKey = K128bitMasterKey1;
       
   391     
       
   392     HBufC8* masterSalt =HBufC8::NewL(K112bitMasterSalt1().Length());
       
   393     CleanupStack::PushL( masterSalt);
       
   394 	*masterSalt = K112bitMasterSalt1;
       
   395 	HBufC8* mki =HBufC8::NewL(K128bitMKITest1().Length());
       
   396     CleanupStack::PushL( mki);
       
   397 	*mki = K128bitMKITest1;
       
   398 	Hex(*mki);
       
   399 	iMasterKey6 = CSRTPMasterKey::NewLC( *masterKey, *mki,
       
   400 									KSRTPDefSessionEncryptionKeyLength, 
       
   401         							KSRTPDefSessionAuthenticationKeyLength );
       
   402     iMasterSalt6 = CSRTPMasterSalt::NewL( *masterSalt,KSRTPDefSessionSaltingKeyLength );
       
   403     CleanupStack::Pop( iMasterKey6 );
       
   404 	TSrtpCryptoParams params;
       
   405 	CleanupStack::PopAndDestroy( mki );
       
   406 	CleanupStack::PopAndDestroy( masterSalt );
       
   407     CleanupStack::PopAndDestroy( masterKey );   
       
   408 	
       
   409 	CleanupStack::PushL( iMasterKey6 );
       
   410     CleanupStack::PushL( iMasterSalt6 );
       
   411     
       
   412 	//invalid prefix length in context6
       
   413 	params.iPrefixLen=10;
       
   414 	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( iContext6=CSRTPCryptoContext::NewL(iMasterKey6,iMasterSalt6, params )  ,
       
   415      KErrArgument ); 
       
   416      
       
   417 	CleanupStack::Pop( iMasterSalt6 );
       
   418     CleanupStack::Pop( iMasterKey6 );
       
   419      
       
   420 	}
       
   421 void UT_CSRTPCryptoContext::UT_MasterKey_Test1L(  )
       
   422     {    
       
   423     
       
   424     EUNIT_ASSERT( iContext->MasterKey().MasterKey().Compare(*i128bitMasterKey1) == 0 );
       
   425     }
       
   426 
       
   427 void UT_CSRTPCryptoContext::UT_MasterSalt_Test1L(  )
       
   428     {    
       
   429     
       
   430     EUNIT_ASSERT( iContext->MasterSalt().MasterSalt().Compare(*i112bitMasterSalt1) == 0 );
       
   431     }
       
   432 
       
   433 void UT_CSRTPCryptoContext::UT_AddCryptoChangeObserver_Test1L(  )
       
   434     {
       
   435     //iContext->AddCryptoChangeObserver(iCryptoHandlerSRTCP);
       
   436     //iContext.AddCryptoChangeObserver(iCryptoHandlerSRTCP);
       
   437     iStreamIn->CreateCryptoHandlerSRTPL();	
       
   438     iStreamIn->CreateCryptoHandlerSRTCPL();
       
   439     
       
   440 
       
   441     EUNIT_ASSERT( iContext->iHandlerList.IsEmpty() == EFalse );
       
   442 
       
   443     }
       
   444 
       
   445 
       
   446 void UT_CSRTPCryptoContext::UT_SetMasterKey_Test1L(  )
       
   447     {
       
   448     
       
   449 	HBufC8* masterKey3 = HBufC8::NewL(K128bitMasterKey3().Length());
       
   450     CleanupStack::PushL( masterKey3 );
       
   451     *masterKey3 = K128bitMasterKey3;
       
   452 		
       
   453 	
       
   454 	HBufC8* mki3 =HBufC8::NewL(K128bitMKITest3().Length());
       
   455     CleanupStack::PushL( mki3);
       
   456 	*mki3 = K128bitMKITest3;
       
   457 	Hex(*mki3);
       
   458 	    
       
   459     CSRTPMasterKey *masterKey = CSRTPMasterKey::NewL( *masterKey3, *mki3,
       
   460     							    KSRTPDefSessionEncryptionKeyLength, 80 );
       
   461 
       
   462    iContext->SetMasterKey(masterKey);
       
   463     EUNIT_ASSERT( iContext->MasterKey().MasterKey().Compare(*i128bitMasterKey3) == 0 );
       
   464     CleanupStack::PopAndDestroy(mki3);
       
   465     CleanupStack::PopAndDestroy(masterKey3);
       
   466     }
       
   467 
       
   468 void UT_CSRTPCryptoContext::UT_SetMasterSalt_Test1L(  )
       
   469     {
       
   470     	
       
   471 	HBufC8* masterSalt3 =HBufC8::NewL(K112bitMasterSalt3().Length());
       
   472     CleanupStack::PushL( masterSalt3);
       
   473 	*masterSalt3 = K112bitMasterSalt3;
       
   474     CSRTPMasterSalt* masterSalt = CSRTPMasterSalt::NewL( *masterSalt3, 1100 );
       
   475     iContext->SetMasterSalt(masterSalt);
       
   476     
       
   477     EUNIT_ASSERT( iContext->MasterSalt().MasterSalt().Compare(*i112bitMasterSalt3) == 0 );
       
   478      
       
   479      CleanupStack::PopAndDestroy(masterSalt3);
       
   480     }
       
   481 
       
   482 void UT_CSRTPCryptoContext::UT_ValidL(  )
       
   483     {
       
   484     //this one should pass
       
   485     EUNIT_ASSERT( iContext->Valid());    
       
   486     // test constructing with default values
       
   487     EUNIT_ASSERT(iContext2->Valid());    
       
   488     //invalid encoding algorithm
       
   489     }
       
   490 
       
   491 
       
   492  void UT_CSRTPCryptoContext::TestOperatorEqualL()
       
   493     {
       
   494   
       
   495     const CSRTPCryptoContext& tempContext2= iContext2->operator=(*iContext2);
       
   496     
       
   497     
       
   498    	HBufC8* masterKey2 = HBufC8::NewL(K128bitMasterKey2().Length());
       
   499     CleanupStack::PushL( masterKey2 );
       
   500     *masterKey2 = K128bitMasterKey2;
       
   501     Hex(*masterKey2);
       
   502     EUNIT_ASSERT(tempContext2.MasterKey().MasterKey()==*masterKey2);
       
   503     
       
   504     CleanupStack::PopAndDestroy(masterKey2);
       
   505     
       
   506     }
       
   507     
       
   508 void UT_CSRTPCryptoContext::TestPrefixLenL()
       
   509     {
       
   510     EUNIT_ASSERT(iContext->CryptoParams().iPrefixLen== 0);
       
   511     }    
       
   512     
       
   513 void UT_CSRTPCryptoContext::TestReplayProtectionL()
       
   514     {
       
   515     EUNIT_ASSERT(iContext->CryptoParams().iSrtpReplayProtection  == ETrue);
       
   516     }    
       
   517     
       
   518 void UT_CSRTPCryptoContext::TestIsEqualL()
       
   519 	{
       
   520 	EUNIT_ASSERT(iContext->IsEqual(*iContext2)==EFalse);
       
   521 	
       
   522 	HBufC8* masterKey3 = HBufC8::NewL(K128bitMasterKey1().Length());
       
   523     CleanupStack::PushL( masterKey3 );
       
   524     *masterKey3 = K128bitMasterKey1;
       
   525 	
       
   526 	HBufC8* masterSalt3 =HBufC8::NewL(K112bitMasterSalt1().Length());
       
   527     CleanupStack::PushL( masterSalt3);
       
   528 	*masterSalt3 = K112bitMasterSalt1;
       
   529 
       
   530 		
       
   531 	HBufC8* mki3 =HBufC8::NewL(K128bitMKITest1().Length());
       
   532     CleanupStack::PushL( mki3);
       
   533 	*mki3 = K128bitMKITest1;
       
   534 	Hex(*mki3);
       
   535  
       
   536 
       
   537     TSrtpCryptoParams params;
       
   538     //test constructL  
       
   539     iMasterKey3 = CSRTPMasterKey::NewLC( *masterKey3, *mki3 );
       
   540     iMasterSalt3 = CSRTPMasterSalt::NewL( *masterSalt3);
       
   541     CleanupStack::Pop( iMasterKey3 );
       
   542     CleanupStack::PopAndDestroy( mki3 );
       
   543 	
       
   544     CleanupStack::PopAndDestroy( masterSalt3 );
       
   545     CleanupStack::PopAndDestroy( masterKey3 ); 
       
   546     
       
   547     CleanupStack::PushL( iMasterKey3 );
       
   548     CleanupStack::PushL( iMasterSalt3 );
       
   549     
       
   550    	iContext3= CSRTPCryptoContext::NewL(iMasterKey3,iMasterSalt3, params );
       
   551    	CleanupStack::Pop( iMasterSalt3 );
       
   552     CleanupStack::Pop( iMasterKey3 );
       
   553      
       
   554    	params.iSrtpAuthTagLen=112;
       
   555    	iContext3->UpdateCryptoParams(params );
       
   556    	EUNIT_ASSERT(iContext->IsEqual(*iContext3)==EFalse);
       
   557    
       
   558    	delete iContext3;	 
       
   559    	//test only param is different
       
   560    	HBufC8* masterKey1 = HBufC8::NewL(K128bitMasterKey1().Length());
       
   561     CleanupStack::PushL( masterKey1 );
       
   562     *masterKey1 = K128bitMasterKey1;
       
   563 	
       
   564 	
       
   565     HBufC8* masterSalt1 =HBufC8::NewL(K112bitMasterSalt1().Length());
       
   566     CleanupStack::PushL( masterSalt1);
       
   567 	*masterSalt1 = K112bitMasterSalt1;
       
   568 
       
   569 	HBufC8* mki =HBufC8::NewL(K128bitMKITest1().Length());
       
   570     CleanupStack::PushL( mki);
       
   571 	*mki = K128bitMKITest1;
       
   572 	Hex(*mki);
       
   573 
       
   574 	iMasterKey = CSRTPMasterKey::NewLC( *masterKey1, *mki,
       
   575 									KSRTPDefSessionEncryptionKeyLength, 
       
   576         							KSRTPDefSessionAuthenticationKeyLength );
       
   577     iMasterSalt = CSRTPMasterSalt::NewL( *masterSalt1,KSRTPDefSessionSaltingKeyLength );
       
   578     CleanupStack::Pop( iMasterKey );
       
   579     CleanupStack::PopAndDestroy( mki );
       
   580     CleanupStack::PopAndDestroy( masterSalt1 );
       
   581     CleanupStack::PopAndDestroy( masterKey1 );
       
   582     TSrtpCryptoParams params2;
       
   583     params2.iSrtpAuthTagLen=32;
       
   584     CleanupStack::PushL( iMasterKey );
       
   585     CleanupStack::PushL( iMasterSalt );
       
   586     CSRTPCryptoContext* context = CSRTPCryptoContext::NewL(iMasterKey, iMasterSalt,params2   );
       
   587     EUNIT_ASSERT(!iContext->IsEqual(*context));
       
   588     CleanupStack::Pop( iMasterSalt );
       
   589     CleanupStack::Pop( iMasterKey );
       
   590     params2.iSrtpAuthTagLen=80;
       
   591     params2.iMasterKeysLifeTime = 0;
       
   592     context->UpdateCryptoParams(params2 );
       
   593     
       
   594     EUNIT_ASSERT(iContext->IsEqual(*context));
       
   595     delete context;
       
   596 								        
       
   597 	}
       
   598 void UT_CSRTPCryptoContext::TestSetRCCm3SyncL()
       
   599 	{
       
   600 	TBool sync= ETrue;
       
   601 	iContext->SetRCCm3Sync(sync);
       
   602 	EUNIT_ASSERT(iContext->CryptoParams().iIsRCCm3Sync);
       
   603 	}
       
   604 	
       
   605 void UT_CSRTPCryptoContext::TestIsValid()
       
   606 	{
       
   607 	TSrtpCryptoParams params;
       
   608 	//TEst cases 1 about Encryption method
       
   609 	params.iSrtpEncAlg=TSRTPEncAlg(10);
       
   610 	iContext->UpdateCryptoParams(params );
       
   611 	EUNIT_ASSERT(!iContext->Valid());
       
   612 	//Test case 2 : alg method
       
   613 	params.iSrtpEncAlg=EEncAES_CM;
       
   614 	params.iSrtpAuthAlg=TSRTPAuthAlg(10);
       
   615 	iContext->UpdateCryptoParams(params);
       
   616 	EUNIT_ASSERT(!iContext->Valid());
       
   617 	EUNIT_ASSERT(!iContext->Valid());
       
   618 	
       
   619 	//Test case 3.:
       
   620 	params.iSrtpAuthAlg=EAuthHMAC_SHA1;
       
   621 	params.iSrtcpAuthAlg=EAuthHMAC_SHA1;
       
   622 	params.iSrtcpAuthTagLen=0;
       
   623 	iContext->UpdateCryptoParams(params );
       
   624 	EUNIT_ASSERT(!iContext->Valid());
       
   625 	//Test case 4:
       
   626 	params.iSrtcpAuthTagLen=32;
       
   627 	params.iSrtpAuthAlg=EAuthRCCm1;
       
   628 	params.iSrtpAuthTagLen=32;
       
   629 	iContext->UpdateCryptoParams(params );
       
   630 	EUNIT_ASSERT(!iContext->Valid());
       
   631 		
       
   632 	//Test case 5:
       
   633 	params.iSrtpAuthAlg=EAuthRCCm3;
       
   634 	params.iSrtpAuthTagLen=0;
       
   635 	iContext->UpdateCryptoParams(params );
       
   636 	EUNIT_ASSERT(!iContext->Valid());	
       
   637 	
       
   638 	//Test case 6:
       
   639 	params.iSrtpAuthAlg=EAuthNull;
       
   640 	params.iSrtpAuthTagLen=10;
       
   641 	iContext->UpdateCryptoParams(params );
       
   642 	EUNIT_ASSERT(!iContext->Valid());	
       
   643 	
       
   644 	//Test case 7
       
   645 	params.iSrtpAuthTagLen=0;
       
   646 	params.iROCTransRate=0;
       
   647 	iContext->UpdateCryptoParams(params );
       
   648 	EUNIT_ASSERT(!iContext->Valid());	
       
   649 	params.iROCTransRate=1;
       
   650 	//make all the value to valid
       
   651 	iContext->UpdateCryptoParams(params );
       
   652 	EUNIT_ASSERT(iContext->Valid());	
       
   653 	//test is master key valid 
       
   654 	HBufC8* masterKey3 = HBufC8::NewL(K128bitMasterKey3().Length());
       
   655     CleanupStack::PushL( masterKey3 );
       
   656     *masterKey3 = K128bitMasterKey3;
       
   657 	
       
   658 	HBufC8* masterSalt3 =HBufC8::NewL(K112bitMasterSalt3().Length());
       
   659     CleanupStack::PushL( masterSalt3);
       
   660 	*masterSalt3 = K112bitMasterSalt3;
       
   661 
       
   662 		
       
   663 	HBufC8* mki3 =HBufC8::NewL(K128bitMKITest3().Length());
       
   664     CleanupStack::PushL( mki3);
       
   665 	*mki3 = K128bitMKITest3;
       
   666 	Hex(*mki3);
       
   667  
       
   668     iMasterKey3 = CSRTPMasterKey::NewLC( *masterKey3, *mki3,
       
   669     								KSRTPDefSessionAuthenticationKeyLength, 
       
   670     							    KSRTPDefSessionEncryptionKeyLength
       
   671     							    );
       
   672     iMasterSalt3 = CSRTPMasterSalt::NewL( *masterSalt3, 1100 );
       
   673     CleanupStack::Pop( iMasterKey3 );
       
   674     CleanupStack::PopAndDestroy( mki3 );
       
   675 	
       
   676     CleanupStack::PopAndDestroy( masterSalt3 );
       
   677     CleanupStack::PopAndDestroy( masterKey3 ); 
       
   678     CleanupStack::PushL( iMasterKey3 );
       
   679     CleanupStack::PushL( iMasterSalt3 );
       
   680    	RTP_EUNIT_ASSERT_SPECIFIC_LEAVE( iContext3= CSRTPCryptoContext::NewL(iMasterKey3,iMasterSalt3, params ),
       
   681    		 KErrArgument );
       
   682    
       
   683 	CleanupStack::Pop( iMasterSalt3 );
       
   684     CleanupStack::Pop( iMasterKey3 );
       
   685 	}
       
   686 	
       
   687 void UT_CSRTPCryptoContext::SRTPMasterKeyStaleEvent(const CSRTPStream& /*aStream*/)
       
   688     {
       
   689     
       
   690     }
       
   691 void UT_CSRTPCryptoContext::SRTPMasterKeyStaleEvent(const CSRTPSession& /*aSession*/)
       
   692     {
       
   693     }
       
   694 
       
   695 
       
   696 void UT_CSRTPCryptoContext::Hex(HBufC8& aString)
       
   697 {
       
   698     TPtr8 ptr=aString.Des();
       
   699     if (aString.Length()%2)
       
   700         {
       
   701         ptr.SetLength(0);
       
   702         return;
       
   703         }
       
   704     TInt i;
       
   705     for (i=0;i<aString.Length();i+=2)
       
   706         {
       
   707         TUint8 tmp;
       
   708         tmp=(TUint8)(aString[i]-(aString[i]>'9'?('A'-10):'0'));
       
   709         tmp*=16;
       
   710         tmp|=(TUint8)(aString[i+1]-(aString[i+1]>'9'?('A'-10):'0'));
       
   711         ptr[i/2]=tmp;
       
   712         }
       
   713     ptr.SetLength(aString.Length()/2);
       
   714 
       
   715 }
       
   716 
       
   717 
       
   718 //  TEST TABLE
       
   719 EUNIT_BEGIN_TEST_TABLE( 
       
   720     UT_CSRTPCryptoContext,
       
   721     "CSRTPCryptoContext",
       
   722     "UNIT" )
       
   723 
       
   724 EUNIT_TEST(
       
   725     "CSRTPCryptoContext - 1 ",
       
   726     "CSRTPCryptoContext1",
       
   727     "CSRTPCryptoContext1",
       
   728     "FUNCTIONALITY",
       
   729     SetupL, UT_CSRTPCryptoContext_Test1L, Teardown)
       
   730 
       
   731 EUNIT_TEST(
       
   732     "CSRTPCryptoContext - 2 ",
       
   733     "CSRTPCryptoContext2",
       
   734     "CSRTPCryptoContext2",
       
   735     "FUNCTIONALITY",
       
   736     SetupL, UT_CSRTPCryptoContext_Test2L, Teardown)
       
   737 EUNIT_TEST(
       
   738     "CSRTPCryptoContext - 3 ",
       
   739     "CSRTPCryptoContext3",
       
   740     "CSRTPCryptoContext3",
       
   741     "FUNCTIONALITY",
       
   742     SetupL, UT_CSRTPCryptoContext_Test3L, Teardown)
       
   743 
       
   744 EUNIT_TEST(
       
   745     "CSRTPCryptoContext - 4 ",
       
   746     "CSRTPCryptoContext4",
       
   747     "CSRTPCryptoContext4",
       
   748     "FUNCTIONALITY",
       
   749     SetupL, UT_CSRTPCryptoContext_Test4L, Teardown)
       
   750     
       
   751 EUNIT_TEST(
       
   752     "CSRTPCryptoContext - 5 ",
       
   753     "CSRTPCryptoContext5",
       
   754     "CSRTPCryptoContext5",
       
   755     "FUNCTIONALITY",
       
   756     SetupL, UT_CSRTPCryptoContext_Test5L, Teardown)
       
   757 EUNIT_TEST(
       
   758     "MasterKey - 1 ",
       
   759     "CSRTPCryptoContext",
       
   760     "MasterKey",
       
   761     "FUNCTIONALITY",
       
   762     SetupL, UT_MasterKey_Test1L, Teardown)
       
   763 
       
   764 EUNIT_TEST(
       
   765     "MasterSalt - 1 ",
       
   766     "CSRTPCryptoContext",
       
   767     "MasterSalt",
       
   768     "FUNCTIONALITY",
       
   769     SetupL, UT_MasterSalt_Test1L, Teardown)
       
   770 
       
   771 EUNIT_TEST(
       
   772     "AddCryptoChangeObserver - 1 ",
       
   773     "CSRTPCryptoContext",
       
   774     "AddCryptoChangeObserver",
       
   775     "FUNCTIONALITY",
       
   776     SetupL, UT_AddCryptoChangeObserver_Test1L, Teardown)
       
   777 
       
   778 EUNIT_TEST(
       
   779     "SetMasterKey - 1 ",
       
   780     "CSRTPCryptoContext",
       
   781     "SetMasterKey",
       
   782     "FUNCTIONALITY",
       
   783     SetupL, UT_SetMasterKey_Test1L, Teardown)
       
   784 
       
   785 EUNIT_TEST(
       
   786     "SetMasterSalt - 1 ",
       
   787     "CSRTPCryptoContext",
       
   788     "SetMasterSalt",
       
   789     "FUNCTIONALITY",
       
   790     SetupL, UT_SetMasterSalt_Test1L, Teardown)
       
   791 
       
   792 EUNIT_TEST(
       
   793     "Valid - test ",
       
   794     "CSRTPCryptoContext",
       
   795     "Valid",
       
   796     "FUNCTIONALITY",
       
   797     SetupL, UT_ValidL, Teardown)
       
   798 
       
   799 EUNIT_TEST(
       
   800     "Test = ",
       
   801     "CSRTPCryptoContext",
       
   802     "TestOperatorEqualL",
       
   803     "FUNCTIONALITY",
       
   804     SetupL, TestOperatorEqualL, Teardown)
       
   805     
       
   806  EUNIT_TEST(
       
   807     "PrefixLenL ",
       
   808     "CSRTPCryptoContext",
       
   809     "TestPrefixLenL",
       
   810     "FUNCTIONALITY",
       
   811     SetupL, TestPrefixLenL, Teardown)
       
   812     
       
   813 EUNIT_TEST(
       
   814     "IsEqual ",
       
   815     "CSRTPCryptoContext",
       
   816     "IsEqual",
       
   817     "FUNCTIONALITY",
       
   818     SetupL, TestIsEqualL, Teardown)   
       
   819 
       
   820 EUNIT_TEST(
       
   821     "SetRCCm3Sync",
       
   822     "CSRTPCryptoContext",
       
   823     "SetRCCm3Sync",
       
   824     "FUNCTIONALITY",
       
   825     SetupL, TestSetRCCm3SyncL, Teardown)   
       
   826  EUNIT_TEST(
       
   827     "TestIsValid",
       
   828     "CSRTPCryptoContext",
       
   829     "TestIsValid",
       
   830     "FUNCTIONALITY",
       
   831     SetupL, TestIsValid, Teardown)  
       
   832     
       
   833 EUNIT_END_TEST_TABLE
       
   834 
       
   835 //  END OF FILE