multimediacommsengine/mmcesrv/mmcemediamanager/src/mcesecuredesstream.cpp
branchRCL_3
changeset 19 3f7c7e6eea8a
parent 13 fb1bbf85a302
child 20 4da1f672912e
equal deleted inserted replaced
18:817c922b90eb 19:3f7c7e6eea8a
    81 //
    81 //
    82 CMceSecureDesStream::CMceSecureDesStream(	CMceSecureMediaSession& aSecureSession,
    82 CMceSecureDesStream::CMceSecureDesStream(	CMceSecureMediaSession& aSecureSession,
    83 											CMccSecureInterface& aSecureInterface,
    83 											CMccSecureInterface& aSecureInterface,
    84         									CMceComMediaStream& aMediaStream
    84         									CMceComMediaStream& aMediaStream
    85         									):
    85         									):
    86 	iWaitingBinding(EFalse),
    86 	
    87 	iSecureSession(aSecureSession),
    87 	iSecureSession(aSecureSession),
    88 	iSecInf(aSecureInterface),
    88 	iSecInf(aSecureInterface),
    89 	iMediaStream(aMediaStream),
    89 	iMediaStream(aMediaStream),
    90 	iIsSAVP(ETrue),
    90 	iIsSAVP(ETrue),
    91 	iRemoteChangeKey(EFalse),
    91 	iWaitingBinding(EFalse),
    92 	iCryptoContextOutId(0),
    92 	iCryptoContextOutId(0),
    93 	iCryptoContextInId(0),
    93 	iCryptoContextInId(0),
    94 	iOldLocalMediaPort(0)
    94 	iOldLocalMediaPort(0)
    95 	{
    95 	{
    96 	
    96 	
   335     	{
   335     	{
   336     	SetMultipleClientCryptoL( *iCryptoIns );
   336     	SetMultipleClientCryptoL( *iCryptoIns );
   337     	MCEMM_DEBUG(" Set Multiple Client Cryptoto")
   337     	MCEMM_DEBUG(" Set Multiple Client Cryptoto")
   338     	User::LeaveIfError ( CountCryptoInOffer( aMediaField ) );
   338     	User::LeaveIfError ( CountCryptoInOffer( aMediaField ) );
   339     	Session().iIsSecureSession =  !iGnoreSdpMsg ? ETrue : EFalse;
   339     	Session().iIsSecureSession =  !iGnoreSdpMsg ? ETrue : EFalse;
   340     	if( iSecureSession.iNatBind )
       
   341     		{
       
   342 			SetCryptoContextL( ETrue );
       
   343 			iSecureSession.iNatBind = EFalse;
       
   344     		}
       
   345     	}
   340     	}
   346     MCEMM_DEBUG("CMceSecureDesStream::DecodeSecureSdpL(), Exit")      
   341     MCEMM_DEBUG("CMceSecureDesStream::DecodeSecureSdpL(), Exit")      
   347     MSG_IGNORE_RETURN()
   342     MSG_IGNORE_RETURN()
   348     }
   343     }
   349 
   344 
   380 				
   375 				
   381 				SetClientCryptoL( iCryptoIn );
   376 				SetClientCryptoL( iCryptoIn );
   382 				}
   377 				}
   383 			if ( iSecureSession.iLSReadyToBind )
   378 			if ( iSecureSession.iLSReadyToBind )
   384 				{
   379 				{
   385 				SetCryptoContextL( EFalse );
   380 				SetCryptoContextL();
   386 				iRemoteChangeKey = EFalse;
       
   387 				}
   381 				}
   388 			MSG_IGNORE_RETURN()
   382 			MSG_IGNORE_RETURN()
   389 			if ( !iCryptoIn.iCryptoSuite.Length() )
   383 			if ( !iCryptoIn.iCryptoSuite.Length() )
   390 				{
   384 				{
   391 				User::Leave( KErrArgument );
   385 				User::Leave( KErrArgument );
   442 // -----------------------------------------------------------------------------
   436 // -----------------------------------------------------------------------------
   443 // CMceSecureDesStream::SetCryptoContext( )
   437 // CMceSecureDesStream::SetCryptoContext( )
   444 // Sets crypto context to MCC
   438 // Sets crypto context to MCC
   445 // -----------------------------------------------------------------------------
   439 // -----------------------------------------------------------------------------
   446 //
   440 //
   447 void CMceSecureDesStream::SetCryptoContextL( TBool aAnswer )
   441 void CMceSecureDesStream::SetCryptoContextL( )
   448     {
   442     {
   449     MCEMM_DEBUG("SetCryptoContext(), Entry") 
   443     MCEMM_DEBUG("SetCryptoContext(), Entry")   
   450     TBool bindContext = ETrue;
       
   451     TBool storedIgnoreSdpMsg = EFalse;
   444     TBool storedIgnoreSdpMsg = EFalse;
   452     //Check state first if the crypto has been set
   445     //Check state first if the crypto has been set
   453     if ( !iCryptoIn.iIfCryptoContextIdSet && 
   446     if ( !iCryptoIn.iIfCryptoContextIdSet && 
   454     	!iCryptoOut.iIfCryptoContextIdSet &&
   447     	!iCryptoOut.iIfCryptoContextIdSet &&
   455     	iCryptoIn.iSetMasterKey.Length() && 
   448     	iCryptoIn.iSetMasterKey.Length() && 
   460     	MCEMM_DEBUG("First Time Bind")
   453     	MCEMM_DEBUG("First Time Bind")
   461     	CreateCryptoContextL( iCryptoIn );
   454     	CreateCryptoContextL( iCryptoIn );
   462     	CreateCryptoContextL( iCryptoOut ); 
   455     	CreateCryptoContextL( iCryptoOut ); 
   463     	MCEMM_DEBUG_DVALUE( "iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   456     	MCEMM_DEBUG_DVALUE( "iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   464 		MCEMM_DEBUG_DVALUE( "iCryptoContextInId", iCryptoOut.iCryptoContextId )
   457 		MCEMM_DEBUG_DVALUE( "iCryptoContextInId", iCryptoOut.iCryptoContextId )
   465     	
       
   466     	if( !aAnswer )
       
   467     		{
       
   468 			bindContext = EFalse;
       
   469     	    MCEMM_DEBUG("delay to bind!");
       
   470     		}
       
   471 
   458 
   472     	iCryptoOuts->Reset();
   459     	iCryptoOuts->Reset();
   473     	
   460     	
   474     
   461     
   475     	}
   462     	}
   484 			iCryptoIn.iCryptoContextId = iCryptoContextInId;
   471 			iCryptoIn.iCryptoContextId = iCryptoContextInId;
   485 			iCryptoOut.iCryptoContextId =  iCryptoContextOutId;
   472 			iCryptoOut.iCryptoContextId =  iCryptoContextOutId;
   486 			}
   473 			}
   487 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   474 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   488 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextInId", iCryptoOut.iCryptoContextId )
   475 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextInId", iCryptoOut.iCryptoContextId )
   489     	if ( iSecureSession.iKeyNeedUpdated  || iRemoteChangeKey )
   476     	if ( iSecureSession.iKeyNeedUpdated )
   490     		{
   477     		{
   491     		UpdateCryptoContextL( iCryptoIn ); 
   478     		UpdateCryptoContextL( iCryptoIn ); 
   492     		storedIgnoreSdpMsg = iGnoreSdpMsg;
   479     		storedIgnoreSdpMsg = iGnoreSdpMsg;
   493     		UpdateCryptoContextL( iCryptoOut ); 
   480     		UpdateCryptoContextL( iCryptoOut ); 
   494     		iGnoreSdpMsg = iGnoreSdpMsg && storedIgnoreSdpMsg;
   481     		iGnoreSdpMsg = iGnoreSdpMsg && storedIgnoreSdpMsg;
   500     	iCryptoOuts->Reset(); 
   487     	iCryptoOuts->Reset(); 
   501     	}
   488     	}
   502     iGnoreSdpMsg = (iCryptoIn.iIfCryptoContextIdSet && 
   489     iGnoreSdpMsg = (iCryptoIn.iIfCryptoContextIdSet && 
   503     				iCryptoOut.iIfCryptoContextIdSet ) &&
   490     				iCryptoOut.iIfCryptoContextIdSet ) &&
   504     				!iGnoreSdpMsg ? EFalse : ETrue;		
   491     				!iGnoreSdpMsg ? EFalse : ETrue;		
   505     if ( iWaitingBinding && bindContext )
   492     if ( iWaitingBinding )
   506     	{
   493     	{
   507     	iSecureSession.BindStreamCrypto();
   494     	iSecureSession.BindStreamCrypto();
   508     	}
   495     	}
   509     	
   496     	
   510     MCEMM_DEBUG("SetCryptoContext(), Exit")
   497     MCEMM_DEBUG("SetCryptoContext(), Exit")
   855         	MCEMM_DEBUG("GenerateRandomKeys Key is updated")
   842         	MCEMM_DEBUG("GenerateRandomKeys Key is updated")
   856         	iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   843         	iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   857         	}
   844         	}
   858         else
   845         else
   859         	{
   846         	{
   860 			if( iRemoteChangeKey )
       
   861 				{
       
   862 				MCEMM_DEBUG("Update CryptoIn" )
       
   863 				TBool tmpSet = iCryptoIn.iIfCryptoContextIdSet;
       
   864 				iCryptoIn.Copy( iCryptoIns->At( 0 ) );
       
   865 				iCryptoIn.iIfCryptoContextIdSet = tmpSet;
       
   866 				}
       
   867         	if(iOldLocalMediaPort != iMediaStream.iLocalMediaPort)
   847         	if(iOldLocalMediaPort != iMediaStream.iLocalMediaPort)
   868         		{
   848         		{
   869         	    GenerateRandomKeys( iCryptoOut );
   849         	    GenerateRandomKeys( iCryptoOut );
   870         	    MCEMM_DEBUG("GenerateRandomKeys Key is updated when oldport is different from newport")
   850         	    MCEMM_DEBUG("GenerateRandomKeys Key is updated when oldport is different from newport")
   871         	    iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   851         	    iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   875 		aResult.Append( KSpace );
   855 		aResult.Append( KSpace );
   876         GenerateCryptoSuiteLineL( aResult, iCryptoOut );
   856         GenerateCryptoSuiteLineL( aResult, iCryptoOut );
   877         MSG_IGNORE_RETURN()
   857         MSG_IGNORE_RETURN()
   878       	if ( iSecureSession.iLSReadyToBind )
   858       	if ( iSecureSession.iLSReadyToBind )
   879       		{
   859       		{
   880       		SetCryptoContextL( ETrue );
   860       		SetCryptoContextL();
   881       		iRemoteChangeKey = EFalse;
       
   882       		}
   861       		}
   883         MSG_IGNORE_RETURN()
   862         MSG_IGNORE_RETURN()
   884         }
   863         }
   885 	 else
   864 	 else
   886     	{
   865     	{
  1226 	        	{
  1205 	        	{
  1227 	        	keyInfoLen = aSecDec.Length()-keyInfoPos;
  1206 	        	keyInfoLen = aSecDec.Length()-keyInfoPos;
  1228 	        	}
  1207 	        	}
  1229     
  1208     
  1230 	    TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1209 	    TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
       
  1210 	    if ( iSecureSession.iKeyNeedUpdated )
       
  1211 	    	{
  1231 	    	
  1212 	    	
  1232 	    	
  1213 		    TBool valid = ValidateSecurityDescriptions( keyInfo );
  1233 		TBool valid = ValidateSecurityDescriptions( keyInfo );
  1214 	   		if ( valid )
  1234 		if ( valid )
       
  1235 	   		{
       
  1236 		    iRemoteChangeKey = iCryptoIn.iEncodedKey.Compare( keyInfo ) != 0;
       
  1237 	   		if( iSecureSession.iKeyNeedUpdated || iRemoteChangeKey ) 
       
  1238 	   			{
  1215 	   			{
       
  1216 	   			
  1239 		    	// check keyInfo 
  1217 		    	// check keyInfo 
  1240 			    if (iCryptoOut.iEncodedKey.Compare( keyInfo ) == 0)
  1218 			    if (iCryptoOut.iEncodedKey.Compare( keyInfo ) == 0)
  1241 			    	{
  1219 			    	{
  1242 			    	User::Leave( KErrArgument );
  1220 			    	User::Leave( KErrArgument );
  1243 			    	}
  1221 			    	}
  1247 				DecodeMKLifeTimeL( aSecDec, iCryptoIn );		
  1225 				DecodeMKLifeTimeL( aSecDec, iCryptoIn );		
  1248 					//check sessionparam later
  1226 					//check sessionparam later
  1249 				iCryptoIn.iEncodedKey = keyInfo;
  1227 				iCryptoIn.iEncodedKey = keyInfo;
  1250 				StoreKeys(iCryptoIn.iEncodedKey);
  1228 				StoreKeys(iCryptoIn.iEncodedKey);
  1251 	   			}
  1229 	   			}
  1252 	   		}
  1230 	   		else
  1253 		else
  1231 	   			{
  1254 	   		{
  1232 	   			User::Leave( KErrArgument );
  1255 		    User::Leave( KErrArgument );
  1233 	   			}
  1256 	   		}
  1234 	    	}
  1257 	   	}
  1235 	   	}
  1258  	else
  1236  	else
  1259  		{
  1237  		{
  1260  		User::Leave( KErrArgument );
  1238  		User::Leave( KErrArgument );
  1261  		}
  1239  		}
  1306         TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1284         TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1307         TBool valid = ValidateSecurityDescriptions( keyInfo );
  1285         TBool valid = ValidateSecurityDescriptions( keyInfo );
  1308         
  1286         
  1309         if ( valid )
  1287         if ( valid )
  1310         	{
  1288         	{
  1311         	if( !iSecureSession.iKeyNeedUpdated && 
  1289         	
  1312         			iCryptoIn.iEncodedKey.Compare( keyInfo ) != 0 )
       
  1313         		{
       
  1314         	    MCEMM_DEBUG("Remote change the key");
       
  1315         	    iRemoteChangeKey = ETrue;
       
  1316         		}
       
  1317             //check keyinfo mki 
  1290             //check keyinfo mki 
  1318 		     DecodeMKIValueL( aSecDec, EFalse, crypto );   
  1291 		     DecodeMKIValueL( aSecDec, EFalse, crypto );   
  1319 		     MSG_IGNORE_RETURN()
  1292 		     MSG_IGNORE_RETURN()
  1320 		     //set MKI value for our local crypto because all MKI in one crypto suite
  1293 		     //set MKI value for our local crypto because all MKI in one crypto suite
  1321 		     // should be the same
  1294 		     // should be the same